gglib 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ spec = Gem::Specification.new do |s|
2
+ s.name = 'gglib'
3
+ s.version = '1.1.0'
4
+ s.summary = "A GUI Library for the Gosu graphics engine."
5
+ s.description = "A GUI library for the Gosu graphics engine."
6
+ s.files = Dir['lib/**/*.rb']
7
+ s.require_path = 'lib'
8
+ s.autorequire = 'builder'
9
+ s.has_rdoc = true
10
+ s.extra_rdoc_files = Dir['[A-Z]*']
11
+ s.rdoc_options << '--title' << 'GGLib - A Gosu GUI Library'
12
+ s.author = "Praneeth Sadda"
13
+ s.email = "psadda@comcast.net"
14
+ s.homepage = "http://gglib.rubyforge.org"
15
+ end
Binary file
@@ -0,0 +1,15 @@
1
+ spec = Gem::Specification.new do |s|
2
+ s.name = 'gglib'
3
+ s.version = '1.1.0'
4
+ s.summary = "A GUI Library for the Gosu graphics engine."
5
+ s.description = "A GUI library for the Gosu graphics engine."
6
+ s.files = Dir['lib/**/*.rb']
7
+ s.require_path = 'lib'
8
+ s.autorequire = 'builder'
9
+ s.has_rdoc = true
10
+ s.extra_rdoc_files = Dir['[A-Z]*']
11
+ s.rdoc_options << '--title' << 'GGLib - A Gosu GUI Library'
12
+ s.author = "Praneeth Sadda"
13
+ s.email = "psadda@comcast.net"
14
+ s.homepage = "http://gglib.rubyforge.org"
15
+ end
Binary file
@@ -0,0 +1,7 @@
1
+ class Camera
2
+ attr_accessor :x,:y
3
+ def initialize(x=0,y=0)
4
+ @x=x
5
+ @y=y
6
+ end
7
+ end
@@ -0,0 +1,71 @@
1
+ module GGLib
2
+
3
+ #CArray is an Array which does not compact. CArrays place a priority on preserving the indices of each element in order to allow identification of elements thier indices.
4
+ #CArrays are used by the Window and Tile classes.
5
+
6
+ class CArray < Array
7
+ public
8
+ @intsize
9
+ def initialize
10
+ @intsize=0
11
+ super
12
+ end
13
+ def push(item)
14
+ self[@intsize]=item
15
+ @intsize+=1
16
+ return @intsize-1
17
+ end
18
+ def <<(item)
19
+ self[@intsize]=item
20
+ @intsize+=1
21
+ return @intsize-1
22
+ end
23
+ def each
24
+ i=0
25
+ while i<=@intsize
26
+ if self[i] !=nil
27
+ yield self[i]
28
+ end
29
+ i+=1
30
+ end
31
+ end
32
+ def delete(obj)
33
+ if obj!=nil
34
+ i=0
35
+ while i<=@intsize
36
+ if self[i] == obj
37
+ self[i]=nil
38
+ end
39
+ i+1
40
+ end
41
+ else
42
+ return nil
43
+ end
44
+ end
45
+ def delete_at(loc)
46
+ if loc<@intsize
47
+ self[loc]=nil
48
+ end
49
+ return self[loc+1]
50
+ end
51
+ def pp
52
+ puts "CArray: "
53
+ i=0
54
+ while i<=@intsize
55
+ if self[i] !=nil
56
+ puts i.to_s+"\t"+self[i].to_s
57
+ else
58
+ puts i.to_s+"\tnil"
59
+ end
60
+ i+=1
61
+ end
62
+ end
63
+ def compact
64
+ return false
65
+ end
66
+ def compact!
67
+ return false
68
+ end
69
+ end
70
+
71
+ end #module GGLib
@@ -0,0 +1,71 @@
1
+ begin
2
+ # In case you use Gosu via RubyGems.
3
+ require 'rubygems'
4
+ rescue LoadError
5
+ # In case you don't.
6
+ end
7
+
8
+ #Load Gosu
9
+ require "gosu"
10
+ #Load GGLib
11
+ require "../gglib"
12
+ #Load some extra widgets for us to play with
13
+ require "../ext/widgets"
14
+ #And themes to make them look cool
15
+ require "../ext/themes"
16
+
17
+ class MyGUIWindow < GGLib::GUIWindow
18
+ def initialize
19
+ super(640, 480, false, 20)
20
+ self.caption = "GGLib Tutorial"
21
+ #Rather than override methods such as update, button_down,
22
+ #and draw, as we would with plain Gosu code, we will override
23
+ #these methods in state objects. This allows the user to switch
24
+ #between various game states, such as between menus and the
25
+ #actual game, without having to litter their functions with
26
+ #switch statements or if-else statements.
27
+ self.state = MyStateObj.new
28
+ end
29
+ end
30
+
31
+ #Now for our state object:
32
+ class MyStateObj < GGLib::StateObject
33
+ #We can override the constructor as normal, but be careful not
34
+ #to mess around with the window here! The window does not belong
35
+ #to this state object yet: another state object is using it.
36
+ def initialize
37
+ super
38
+ @myvar = 42
39
+ end
40
+ #This method is called right after our state object gains ownership
41
+ #over the window. Now we can perform operations that modify the
42
+ #window.
43
+ def onStart
44
+ puts "MyStateObj activated."
45
+ #Since Gosu only allows one window instance at a time, the current
46
+ #window is automatically sotred in the global $window.
47
+ $window.setBackground("img/bggray.png")
48
+ #Whats a GUI Library without widgets?
49
+ #A textbox:
50
+ $textbox = GGLib::TextBox.new("textbox1", 242, 100, 12, GGLib::Themes::Windows)
51
+ #Some buttons:
52
+ GGLib::Button.new("button1", "Click Me", 270, 50, Proc.new{ |widget| $textbox.text = "Thank you" }, GGLib::Themes::Windows)
53
+ GGLib::Button.new("button2", "Exit", 270, 200, Proc.new{ |widget| $window.close; exit }, GGLib::Themes::Windows)
54
+ end
55
+ #This method is called right after our state object looses
56
+ #ownership of the window. The window is automatically reset, but
57
+ #if you modified anything other than the window, this is where you
58
+ #should clean it up.
59
+ def onEnd
60
+ puts "MyStateObj terminated."
61
+ end
62
+ end
63
+
64
+ #Create and launch the window.
65
+ MyGUIWindow.new.show
66
+
67
+ #To see how easy it is to customize your GUI with themeing, try
68
+ #replacing all of the instances of GGLib::Themes::BlueSteel in
69
+ #this file to GGLib::Themes::Rubygoo for a Rubygoo like theme,
70
+ #GGLib::Themes::Shade for a dark theme, and GGLib::Themes::Windows
71
+ #for a Windows Vista like theme.
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'rubygems'
3
+ rescue LoadError
4
+ end
5
+
6
+ require "gosu"
7
+ require "../gglib"
8
+ require "../ext/widgets"
9
+ require "../ext/themes"
10
+
11
+ class ConsoleDemoWindow < GGLib::GUIWindow
12
+ def initialize
13
+ super(640, 480, false, 20)
14
+ self.caption = "GGLib Console Demo"
15
+ self.state = ConsoleDemoState.new
16
+ end
17
+ end
18
+
19
+ class ConsoleDemoState < GGLib::StateObject
20
+ def onStart
21
+ $window.setBackground("img/bg.png")
22
+ GGLib::Button.new("button2", "Open Console", 270, 200, Proc.new{ |widget| GGLib::DebugConsole.new }, GGLib::Themes::BlueSteel)
23
+ end
24
+ end
25
+
26
+ ConsoleDemoWindow.new.show
@@ -0,0 +1,40 @@
1
+ begin
2
+ # In case you use Gosu via RubyGems.
3
+ require 'rubygems'
4
+ rescue LoadError
5
+ # In case you don't.
6
+ end
7
+
8
+ #Load Gosu
9
+ require "gosu"
10
+ #Load GGLib
11
+ require "../gglib"
12
+ #Load extra widgets (for ThemeButton)
13
+ require "../ext/widgets"
14
+
15
+ class FadeExample < GGLib::GUIWindow
16
+ def initialize
17
+ super(640, 480, false, 20)
18
+ self.caption = "GGLib Tutorial"
19
+ self.state = StartMenu.new
20
+ end
21
+ end
22
+
23
+ #The menu we will fade from
24
+ class StartMenu < GGLib::StateObject
25
+ def onStart
26
+ $window.setBackground("img/splash.png")
27
+ GGLib::ThemeButton.new("button1", "Fade", 270, 200, Proc.new{ |widget| $window.state = GGLib::FadeScreen.new(EndMenu.new, 2) })
28
+ end
29
+ end
30
+
31
+ #The menu we will fade to
32
+ class EndMenu < GGLib::StateObject
33
+ def onStart
34
+ $window.setBackground("img/bg.png")
35
+ GGLib::ThemeButton.new("button1", "Fade Back", 270, 200, Proc.new{ |widget| $window.state = GGLib::FadeScreen.new(StartMenu.new, 2) })
36
+ end
37
+ end
38
+
39
+ #Launch the window
40
+ FadeExample.new.show
@@ -0,0 +1,30 @@
1
+ begin
2
+ # In case you use Gosu via RubyGems.
3
+ require 'rubygems'
4
+ rescue LoadError
5
+ # In case you don't.
6
+ end
7
+
8
+ require "gosu"
9
+ require "../gglib"
10
+ require "../ext/splash"
11
+
12
+ class MySplashScreen < GGLib::SplashScreen
13
+ def initialize
14
+ super(640, 480, "img/splash.png")
15
+ end
16
+ def load
17
+ #Put initialization code here.
18
+ #This example doesn't actually have to initialize anything,
19
+ #so we will just use Thread#sleep to kill some time.
20
+ sleep(1)
21
+ end
22
+ def createWindow
23
+ #Once the load method is finished, create window is called.
24
+ #This is where we should initialize and lauch our window.
25
+ #We'll just resuse the routines from BasicExample.rb.
26
+ require "BasicExample"
27
+ end
28
+ end
29
+
30
+ MySplashScreen.new.show
File without changes
@@ -0,0 +1,42 @@
1
+ module GGLib
2
+
3
+ class SplashScreen < Gosu::Window
4
+ def initialize(width=640, height=480, img = "null.png", caption = "Loading...")
5
+ super(width, height, false, 20)
6
+ self.caption = caption
7
+ @background_image = Gosu::Image.new(self, img, true)
8
+ @done=false
9
+ end
10
+
11
+ #Override this method and include all initialization methods here *except for opening the window*.
12
+ def load
13
+
14
+ end
15
+
16
+ #Override with method with the code needed to initialize the main application window.
17
+ def createWindow
18
+
19
+ end
20
+
21
+ def update
22
+ load
23
+ @done=true
24
+ if @done
25
+ puts "\nLaunching in:\n3"
26
+ sleep(1)
27
+ puts "2"
28
+ sleep(1)
29
+ puts "1"
30
+ sleep(1)
31
+ puts "0"
32
+ close
33
+ createWindow
34
+ end
35
+ end
36
+
37
+ def draw
38
+ @background_image.draw(0, 0, 0)
39
+ end
40
+ end
41
+
42
+ end #module GGLib
@@ -0,0 +1,159 @@
1
+ module GGLib
2
+
3
+ $initthemes = false
4
+
5
+ module Themes
6
+
7
+ class BlueSteelTheme < ImageTheme
8
+ @@button = nil
9
+ def initialize
10
+ image = ThemeImageGroup.new( $gglroot+"/media/bluesteel/generic/menusmall.png", $gglroot+"/media/bluesteel/generic/menusmall.png", $gglroot+"/media/bluesteel/generic/menusmall.png" )
11
+ font = ThemeFontGroup.new( Gosu::Font.new($window, Gosu::default_font_name, 17), Gosu::Font.new($window, Gosu::default_font_name, 25), Gosu::Font.new($window, Gosu::default_font_name, 20))
12
+ super("BlueSteel.Generic", font, image)
13
+ end
14
+ def request(obj)
15
+ if @@button == nil #Can't initialize atglobal scope because $window may not have been set
16
+ @@button = ImageTheme.new("BlueSteel.Button", ThemeFontGroup.new( Gosu::Font.new($window, Gosu::default_font_name, 17), Gosu::Font.new($window, Gosu::default_font_name, 25), Gosu::Font.new($window, Gosu::default_font_name, 20)), ThemeImageGroup.new( $gglroot+"/media/bluesteel/button/button.png", $gglroot+"/media/bluesteel/button/buttonup.png" , $gglroot+"/media/bluesteel/button/buttonup.png" ))
17
+ @@textbox = ImageTheme.new("BlueSteel.TextBox", ThemeFontGroup.new( Gosu::Font.new($window, Gosu::default_font_name, 17), Gosu::Font.new($window, Gosu::default_font_name, 25), Gosu::Font.new($window, Gosu::default_font_name, 20)), ThemeImageGroup.new( $gglroot+"/media/bluesteel/textbox/textbox.png", $gglroot+"/media/bluesteel/textbox/textboxactive.png" , $gglroot+"/media/bluesteel/textbox/textboxactive.png" ))
18
+ @@label = ImageTheme.new("BlueSteel.Label", ThemeFontGroup.new( Gosu::Font.new($window, Gosu::default_font_name, 17), Gosu::Font.new($window, Gosu::default_font_name, 25), Gosu::Font.new($window, Gosu::default_font_name, 20)), ThemeImageGroup.new( $gglroot+"/null.png", $gglroot+"/null.png" , $gglroot+"/null.png" ) )
19
+ end
20
+ if obj.kind_of?(Button)
21
+ return @@button
22
+ elsif obj.kind_of?(TextBox)
23
+ return @@textbox
24
+ elsif obj.kind_of?(Label)
25
+ return @@label
26
+ end
27
+ return self
28
+ end
29
+ end
30
+
31
+ class RubygooTheme < DrawnTheme
32
+ @@textbox = nil
33
+ def initialize
34
+ font = ThemeFontGroup.new( Gosu::Font.new($window, Gosu::default_font_name, 17), Gosu::Font.new($window, Gosu::default_font_name, 25), Gosu::Font.new($window, Gosu::default_font_name, 20), 0xff000000, 0xff848484)
35
+ super("Rubygoo.Generic", font)
36
+ end
37
+ def request(obj)
38
+ if @@textbox == nil #Can't initialize atglobal scope because $window may not have been set
39
+ @@textbox = RubygooTextTheme.new
40
+ @@label = RubygooLabelTheme.new
41
+ end
42
+ if obj.kind_of?(TextBox)
43
+ return @@textbox
44
+ elsif obj.kind_of?(Label)
45
+ return @@label
46
+ end
47
+ return self
48
+ end
49
+ def draw(x1,y1, x2, y2, state)
50
+ if state == 1
51
+ $window.draw_quad(x1, y1, 0xffb22222, x2, y1, 0xffb22222, x1, y2, 0xffb22222, x2, y2, 0xffb22222, ZOrder::Widget)
52
+ $window.draw_quad(x1+1, y1+1, 0xff6e6e6e, x2-1, y1+1, 0xff6e6e6e, x1+1, y2-1, 0xff6e6e6e, x2-1, y2-1, 0xff6e6e6e, ZOrder::Widget)
53
+ else
54
+ $window.draw_quad(x1, y1, 0xffb22222, x2, y1, 0xffb22222, x1, y2, 0xffb22222, x2, y2, 0xffb22222, ZOrder::Widget)
55
+ $window.draw_quad(x1+1, y1+1, 0xff808080, x2-1, y1+1, 0xff808080, x1+1, y2-1, 0xff808080, x2-1, y2-1, 0xff808080, ZOrder::Widget)
56
+ end
57
+ end
58
+ end
59
+
60
+ class RubygooTextTheme < DrawnTheme
61
+ @@textbox = nil
62
+ def initialize
63
+ font = ThemeFontGroup.new( Gosu::Font.new($window, Gosu::default_font_name, 17), Gosu::Font.new($window, Gosu::default_font_name, 25), Gosu::Font.new($window, Gosu::default_font_name, 20), 0xff000000, 0xffb22222)
64
+ super("Rubygoo.TextBox", font)
65
+ end
66
+ def draw(x1,y1, x2, y2, state)
67
+ if state == 1
68
+ $window.draw_quad(x1, y1, 0xff6e6e6e, x2, y1, 0xff6e6e6e, x1, y2, 0xff6e6e6e, x2, y2, 0xff6e6e6e, ZOrder::Widget)
69
+ $window.draw_quad(x1+2, y1+2, 0xff000000, x2-2, y1+2, 0xff000000, x1+2, y2-2, 0xff000000, x2-2, y2-2, 0xff000000, ZOrder::Widget)
70
+ $window.draw_quad(x1+3, y1+3, 0xff6e6e6e, x2-3, y1+3, 0xff6e6e6e, x1+3, y2-3, 0xff6e6e6e, x2-3, y2-3, 0xff6e6e6e, ZOrder::Widget)
71
+ else
72
+ $window.draw_quad(x1, y1, 0xff808080, x2, y1, 0xff808080, x1, y2, 0xff808080, x2, y2, 0xff808080, ZOrder::Widget)
73
+ $window.draw_quad(x1+2, y1+2, 0xff000000, x2-2, y1+2, 0xff000000, x1+2, y2-2, 0xff000000, x2-2, y2-2, 0xff000000, ZOrder::Widget)
74
+ $window.draw_quad(x1+3, y1+3, 0xff808080, x2-3, y1+3, 0xff808080, x1+3, y2-3, 0xff808080, x2-3, y2-3, 0xff808080, ZOrder::Widget)
75
+ end
76
+ end
77
+ end
78
+
79
+ class RubygooLabelTheme < DrawnTheme
80
+ @@textbox = nil
81
+ def initialize
82
+ font = ThemeFontGroup.new( Gosu::Font.new($window, Gosu::default_font_name, 17), Gosu::Font.new($window, Gosu::default_font_name, 25), Gosu::Font.new($window, Gosu::default_font_name, 20), 0xff000000, 0xffb22222)
83
+ super("Rubygoo.Label", font)
84
+ end
85
+ end
86
+
87
+ class ShadeTheme < DrawnTheme
88
+ @@label = nil
89
+ def initialize
90
+ font = ThemeFontGroup.new( Gosu::Font.new($window, Gosu::default_font_name, 17), Gosu::Font.new($window, Gosu::default_font_name, 25), Gosu::Font.new($window, Gosu::default_font_name, 20), 0xffe6e6e6, 0xffb22222)
91
+ super("Shade.Generic", font)
92
+ end
93
+ def request(obj)
94
+ if @@label == nil #Can't initialize atglobal scope because $window may not have been set
95
+ @@label = ShadeLabelTheme.new
96
+ end
97
+ if obj.kind_of?(Label)
98
+ return @@label
99
+ end
100
+ return self
101
+ end
102
+ def draw(x1,y1, x2, y2, state)
103
+ if state == 1
104
+ $window.draw_quad(x1, y1, 0xff2e2e2e, x2, y1, 0xff2e2e2e, x1, y2, 0xff2e2e2e, x2, y2, 0xff2e2e2e, ZOrder::Widget)
105
+ $window.draw_quad(x1+2, y1+2, 0xffbdbdbd, x2-2, y1+2, 0xffbdbdbd, x1+2, y2-2, 0xffbdbdbd, x2-2, y2-2, 0xffbdbdbd, ZOrder::Widget)
106
+ $window.draw_quad(x1+3, y1+3, 0xff2e2e2e, x2-3, y1+3, 0xff2e2e2e, x1+3, y2-3, 0xff2e2e2e, x2-3, y2-3, 0xff2e2e2e, ZOrder::Widget)
107
+ else
108
+ $window.draw_quad(x1, y1, 0xff2e2e2e, x2, y1, 0xff2e2e2e, x1, y2, 0xff2e2e2e, x2, y2, 0xff2e2e2e, ZOrder::Widget)
109
+ $window.draw_quad(x1+2, y1+2, 0xffffffff, x2-2, y1+2, 0xffffffff, x1+2, y2-2, 0xffffffff, x2-2, y2-2, 0xffffffff, ZOrder::Widget)
110
+ $window.draw_quad(x1+3, y1+3, 0xff2e2e2e, x2-3, y1+3, 0xff2e2e2e, x1+3, y2-3, 0xff2e2e2e, x2-3, y2-3, 0xff2e2e2e, ZOrder::Widget)
111
+ end
112
+ end
113
+ end
114
+
115
+ class ShadeLabelTheme < DrawnTheme
116
+ @@textbox = nil
117
+ def initialize
118
+ font = ThemeFontGroup.new( Gosu::Font.new($window, Gosu::default_font_name, 17), Gosu::Font.new($window, Gosu::default_font_name, 25), Gosu::Font.new($window, Gosu::default_font_name, 20), 0xffe6e6e6, 0xff848484)
119
+ super("Shade.Label", font)
120
+ end
121
+ end
122
+
123
+ class WindowsTheme < ImageTheme
124
+ @@button = nil
125
+ def initialize
126
+ image = ThemeImageGroup.new( $gglroot+"/media/windows/generic/menusmall.png", $gglroot+"/media/bluesteel/generic/menusmall.png", $gglroot+"/media/bluesteel/generic/menusmall.png" )
127
+ font = ThemeFontGroup.new( Gosu::Font.new($window, Gosu::default_font_name, 17), Gosu::Font.new($window, Gosu::default_font_name, 25), Gosu::Font.new($window, Gosu::default_font_name, 20))
128
+ super("Windows.Generic", font, image)
129
+ end
130
+ def request(obj)
131
+ if @@button == nil #Can't initialize atglobal scope because $window may not have been set
132
+ @@button = ImageTheme.new("Windows.Button", ThemeFontGroup.new( Gosu::Font.new($window, Gosu::default_font_name, 17), Gosu::Font.new($window, Gosu::default_font_name, 25), Gosu::Font.new($window, Gosu::default_font_name, 20)), ThemeImageGroup.new( $gglroot+"/media/windows/button/button.png", $gglroot+"/media/windows/button/buttonup.png" , $gglroot+"/media/windows/button/buttondown.png" ))
133
+ @@textbox = ImageTheme.new("Windows.TextBox", ThemeFontGroup.new( Gosu::Font.new($window, Gosu::default_font_name, 17), Gosu::Font.new($window, Gosu::default_font_name, 25), Gosu::Font.new($window, Gosu::default_font_name, 20)), ThemeImageGroup.new( $gglroot+"/media/windows/textbox/textbox.png", $gglroot+"/media/windows/textbox/textboxup.png" , $gglroot+"/media/windows/textbox/textboxup.png" ))
134
+ @@label = ImageTheme.new("Windows.Label", ThemeFontGroup.new( Gosu::Font.new($window, Gosu::default_font_name, 17), Gosu::Font.new($window, Gosu::default_font_name, 25), Gosu::Font.new($window, Gosu::default_font_name, 20)), ThemeImageGroup.new( $gglroot+"/null.png", $gglroot+"/null.png" , $gglroot+"/null.png" ) )
135
+ end
136
+ if obj.kind_of?(Button)
137
+ return @@button
138
+ elsif obj.kind_of?(TextBox)
139
+ return @@textbox
140
+ elsif obj.kind_of?(Label)
141
+ return @@label
142
+ end
143
+ return self
144
+ end
145
+ end
146
+
147
+ $theme_init_hook = Proc.new {
148
+ unless $initthemes
149
+ Themes.const_set("BlueSteel", BlueSteelTheme.new)
150
+ Themes.const_set("Rubygoo", RubygooTheme.new)
151
+ Themes.const_set("Shade", ShadeTheme.new)
152
+ Themes.const_set("Windows", WindowsTheme.new)
153
+ $initthemes = true
154
+ end
155
+ }
156
+
157
+ end #module Themes
158
+
159
+ end #module GGLib