rubygoo 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ class Button < Widget
2
+ can_fire :pressed
3
+ def initialize(text, opts={})
4
+ super opts
5
+ @text = text
6
+ end
7
+
8
+ def added()
9
+ font = theme_property :font
10
+ @font_size = theme_property :font_size
11
+ @color = theme_property :color
12
+ @bg_color = theme_property :bg_color
13
+ @border_color = theme_property :border_color
14
+ @focus_color = theme_property :focus_color
15
+ @font_file = File.join(@app.theme_dir,font)
16
+
17
+ @rendered_text ||= @app.renderer.render_text @text, @font_file, @font_size, @color
18
+ @rect = Rect.new [@x-@x_pad,@y-@y_pad,@rendered_text.width+2*@x_pad,@rendered_text.height+2*@y_pad]
19
+ end
20
+
21
+ # called when there is a mouse click
22
+ def mouse_up(event)
23
+ fire :pressed, event
24
+ end
25
+
26
+ # called when a key press is sent to us
27
+ def key_pressed(event)
28
+ case event.data[:key]
29
+ when K_SPACE
30
+ fire :pressed, event
31
+ end
32
+ end
33
+
34
+ def draw(adapter)
35
+ if @focussed
36
+ adapter.fill @focus_color, @rect
37
+ elsif @bg_color
38
+ adapter.fill @bg_color, @rect
39
+ end
40
+ if @border_color
41
+ x1 = @rect[0]
42
+ y1 = @rect[1]
43
+ x2 = @rect[2] + x1
44
+ y2 = @rect[3] + y1
45
+ adapter.draw_box x1, y1, x2, y2, @border_color
46
+ end
47
+
48
+
49
+ adapter.draw_image @rendered_text, @x, @y
50
+
51
+ end
52
+ end
53
+
@@ -0,0 +1,74 @@
1
+ class CheckBox < Widget
2
+ attr_accessor :checked
3
+ can_fire :checked
4
+ def initialize(opts={})
5
+ super opts
6
+ end
7
+
8
+ def added()
9
+ @checked = false
10
+ @color = theme_property :color
11
+ @bg_color = theme_property :bg_color
12
+ @border_color = theme_property :border_color
13
+ @focus_color = theme_property :focus_color
14
+ @checked_color = theme_property :checked_color
15
+
16
+ @rect = Rect.new [@x-@x_pad,@y-@y_pad,@w+2*@x_pad,@h+2*@y_pad]
17
+ end
18
+
19
+ def checked?()
20
+ @checked
21
+ end
22
+
23
+ def toggle()
24
+ if checked?
25
+ uncheck
26
+ else
27
+ check
28
+ end
29
+ end
30
+
31
+ def check()
32
+ @checked = true
33
+ fire :checked
34
+ end
35
+
36
+ def uncheck()
37
+ @checked = false
38
+ fire :checked
39
+ end
40
+
41
+ # called when there is a mouse click
42
+ def mouse_up(event)
43
+ toggle
44
+ end
45
+
46
+ # called when a key press is sent to us
47
+ def key_pressed(event)
48
+ case event.data[:key]
49
+ when K_SPACE
50
+ toggle
51
+ end
52
+ end
53
+
54
+ def draw(screen)
55
+ if @focussed
56
+ screen.fill @focus_color, @rect
57
+ elsif @bg_color
58
+ screen.fill @bg_color, @rect
59
+ end
60
+
61
+ if @checked
62
+ screen.fill @checked_color, @rect.inflate(-@x_pad,-@y_pad)
63
+ end
64
+
65
+ if @border_color
66
+ x1 = @rect[0]
67
+ y1 = @rect[1]
68
+ x2 = @rect[2] + x1
69
+ y2 = @rect[3] + y1
70
+ screen.draw_box x1, y1, x2, y2, @border_color
71
+ end
72
+ end
73
+ end
74
+
@@ -0,0 +1,130 @@
1
+ class Container < Widget
2
+
3
+ attr_accessor :widgets, :bg_color, :rect
4
+
5
+ def initialize(opts={})
6
+ super opts
7
+ # cannot get this if we don't have an app yet
8
+ @bg_color = theme_property :bg_color if self.app
9
+ @queued_widgets = []
10
+ @widgets = []
11
+ @modal_widgets = []
12
+ end
13
+
14
+ # called when we are added to another container
15
+ def added()
16
+ add *@queued_widgets
17
+ @queued_widgets = []
18
+ end
19
+
20
+ def add_modal(widget)
21
+ @modal_widgets << widget
22
+ add widget
23
+ end
24
+
25
+ # Add widget(s) to the container.
26
+ def add(*widgets)
27
+ widgets.uniq.each do |w|
28
+ unless @widgets.include? w
29
+ if self.app
30
+ w.container = self
31
+ w.parent = self
32
+ w.app = self.app
33
+ w.app.add_tabbed_widget w
34
+ w.added
35
+ @widgets << w
36
+ else
37
+ @queued_widgets << w
38
+ end
39
+ end
40
+ end
41
+ widgets
42
+ end
43
+
44
+ # Remove widget(s) to the container.
45
+ def remove(*widgets)
46
+ widgets.uniq.each do |w|
47
+ widget = @widgets.delete(w)
48
+ queued_widget = @queued_widgets.delete(w)
49
+ modal_widget = @modal_widgets.delete(w)
50
+ if widget or queued_widget or modal_widget
51
+ w.removed
52
+ end
53
+ end
54
+ end
55
+
56
+ # draw ourself and our children
57
+ def draw(screen)
58
+ # any container specific code here (border_colors?)
59
+ if @bg_color
60
+ if app == self
61
+ screen.fill @bg_color
62
+ else
63
+ screen.fill @bg_color, @rect
64
+ end
65
+ end
66
+
67
+ # draw kiddies
68
+ @widgets.each do |w|
69
+ w.draw screen
70
+ end
71
+ end
72
+
73
+ # called when there is a mouse motion
74
+ def mouse_motion(event)
75
+ @widgets.each do |w|
76
+ w.mouse_motion event if w.contains? [event.data[:x],event.data[:y]]
77
+ end
78
+ end
79
+
80
+ # called when there is a mouse click
81
+ def mouse_down(event)
82
+ @widgets.each do |w|
83
+ w.mouse_down event if w.contains? [event.data[:x],event.data[:y]]
84
+ end
85
+ end
86
+
87
+ # called when there is a mouse release
88
+ def mouse_up(event)
89
+ @widgets.each do |w|
90
+ w.mouse_up event if w.contains? [event.data[:x],event.data[:y]]
91
+ end
92
+ end
93
+
94
+ # pass on the key press to our widgets
95
+ def key_pressed(event)
96
+ @widgets.each do |w|
97
+ w.key_pressed event if w.focussed?
98
+ end
99
+ end
100
+
101
+ # pass on the key release to our widgets
102
+ def key_released(event)
103
+ @widgets.each do |w|
104
+ w.key_released event if w.focussed?
105
+ end
106
+ end
107
+
108
+ # distribute our mouse events to our modals first
109
+ def modal_mouse_call(meth, event)
110
+ if @modal_widgets.empty?
111
+ @widgets.each do |w|
112
+ w.send meth, event if w.contains? [event.data[:x],event.data[:y]]
113
+ end
114
+ else
115
+ @modal_widgets.last.send meth, event
116
+ end
117
+ end
118
+
119
+ # distribute our keyboard events to our modals first
120
+ def modal_keyboard_call(meth, event)
121
+ if @modal_widgets.empty?
122
+ @widgets.each do |w|
123
+ w.send meth, event if w.focussed?
124
+ end
125
+ else
126
+ @modal_widgets.last.send meth, event
127
+ end
128
+ end
129
+ end
130
+
@@ -0,0 +1,151 @@
1
+
2
+ # colors from: http://www.w3schools.com/css/css_colornames.asp
3
+ CSS_COLORS = {
4
+ :AliceBlue => [240,248,255,255],
5
+ :AntiqueWhite => [250,235,215,255],
6
+ :Aqua => [0,255,255,255],
7
+ :Aquamarine => [127,255,212,255],
8
+ :Azure => [240,255,255,255],
9
+ :Beige => [245,245,220,255],
10
+ :Bisque => [255,228,196,255],
11
+ :Black => [0,0,0,255],
12
+ :BlanchedAlmond => [255,235,205,255],
13
+ :Blue => [0,0,255,255],
14
+ :BlueViolet => [138,43,226,255],
15
+ :Brown => [165,42,42,255],
16
+ :BurlyWood => [222,184,135,255],
17
+ :CadetBlue => [95,158,160,255],
18
+ :Chartreuse => [127,255,0,255],
19
+ :Chocolate => [210,105,30,255],
20
+ :Coral => [255,127,80,255],
21
+ :CornflowerBlue => [100,149,237,255],
22
+ :Cornsilk => [255,248,220,255],
23
+ :Crimson => [237,164,61,255],
24
+ :Cyan => [0,255,255,255],
25
+ :DarkBlue => [0,0,139,255],
26
+ :DarkCyan => [0,139,139,255],
27
+ :DarkGoldenRod => [184,134,11,255],
28
+ :DarkGray => [169,169,169,255],
29
+ :DarkGrey => [169,169,169,255],
30
+ :DarkGreen => [0,100,0,255],
31
+ :DarkKhaki => [189,183,107,255],
32
+ :DarkMagenta => [139,0,139,255],
33
+ :DarkOliveGreen => [85,107,47,255],
34
+ :Darkorange => [255,140,0,255],
35
+ :DarkOrchid => [153,50,204,255],
36
+ :DarkRed => [139,0,0,255],
37
+ :DarkSalmon => [233,150,122,255],
38
+ :DarkSeaGreen => [143,188,143,255],
39
+ :DarkSlateBlue => [72,61,139,255],
40
+ :DarkSlateGray => [47,79,79,255],
41
+ :DarkSlateGrey => [47,79,79,255],
42
+ :DarkTurquoise => [0,206,209,255],
43
+ :DarkViolet => [148,0,211,255],
44
+ :DeepPink => [255,20,147,255],
45
+ :DeepSkyBlue => [0,191,255,255],
46
+ :DimGray => [105,105,105,255],
47
+ :DimGrey => [105,105,105,255],
48
+ :DodgerBlue => [30,144,255,255],
49
+ :FireBrick => [178,34,34,255],
50
+ :FloralWhite => [255,250,240,255],
51
+ :ForestGreen => [34,139,34,255],
52
+ :Fuchsia => [255,0,255,255],
53
+ :Gainsboro => [220,220,220,255],
54
+ :GhostWhite => [248,248,255,255],
55
+ :Gold => [255,215,0,255],
56
+ :GoldenRod => [218,165,32,255],
57
+ :Gray => [128,128,128,255],
58
+ :Grey => [128,128,128,255],
59
+ :Green => [0,128,0,255],
60
+ :GreenYellow => [173,255,47,255],
61
+ :HoneyDew => [240,255,240,255],
62
+ :HotPink => [255,105,180,255],
63
+ :IndianRed => [205,92,92,255],
64
+ :Indigo => [75,0,130,255],
65
+ :Ivory => [255,255,240,255],
66
+ :Khaki => [240,230,140,255],
67
+ :Lavender => [230,230,250,255],
68
+ :LavenderBlush => [255,240,245,255],
69
+ :LawnGreen => [124,252,0,255],
70
+ :LemonChiffon => [255,250,205,255],
71
+ :LightBlue => [173,216,230,255],
72
+ :LightCoral => [240,128,128,255],
73
+ :LightCyan => [224,255,255,255],
74
+ :LightGoldenRodYellow => [250,250,210,255],
75
+ :LightGray => [211,211,211,255],
76
+ :LightGrey => [211,211,211,255],
77
+ :LightGreen => [144,238,144,255],
78
+ :LightPink => [255,182,193,255],
79
+ :LightSalmon => [255,160,122,255],
80
+ :LightSeaGreen => [32,178,170,255],
81
+ :LightSkyBlue => [135,206,250,255],
82
+ :LightSlateGray => [119,136,153,255],
83
+ :LightSlateGrey => [119,136,153,255],
84
+ :LightSteelBlue => [176,196,222,255],
85
+ :LightYellow => [255,255,224,255],
86
+ :Lime => [0,255,0,255],
87
+ :LimeGreen => [50,205,50,255],
88
+ :Linen => [250,240,230,255],
89
+ :Magenta => [255,0,255,255],
90
+ :Maroon => [128,0,0,255],
91
+ :MediumAquaMarine => [102,205,170,255],
92
+ :MediumBlue => [0,0,205,255],
93
+ :MediumOrchid => [186,85,211,255],
94
+ :MediumPurple => [147,112,219,255],
95
+ :MediumSeaGreen => [60,179,113,255],
96
+ :MediumSlateBlue => [123,104,238,255],
97
+ :MediumSpringGreen => [0,250,154,255],
98
+ :MediumTurquoise => [72,209,204,255],
99
+ :MediumVioletRed => [199,21,133,255],
100
+ :MidnightBlue => [25,25,112,255],
101
+ :MintCream => [245,255,250,255],
102
+ :MistyRose => [255,228,225,255],
103
+ :Moccasin => [255,228,181,255],
104
+ :NavajoWhite => [255,222,173,255],
105
+ :Navy => [0,0,128,255],
106
+ :OldLace => [253,245,230,255],
107
+ :Olive => [128,128,0,255],
108
+ :OliveDrab => [107,142,35,255],
109
+ :Orange => [255,165,0,255],
110
+ :OrangeRed => [255,69,0,255],
111
+ :Orchid => [218,112,214,255],
112
+ :PaleGoldenRod => [238,232,170,255],
113
+ :PaleGreen => [152,251,152,255],
114
+ :PaleTurquoise => [175,238,238,255],
115
+ :PaleVioletRed => [219,112,147,255],
116
+ :PapayaWhip => [255,239,213,255],
117
+ :PeachPuff => [255,218,185,255],
118
+ :Peru => [205,133,63,255],
119
+ :Pink => [255,192,203,255],
120
+ :Plum => [221,160,221,255],
121
+ :PowderBlue => [176,224,230,255],
122
+ :Purple => [128,0,128,255],
123
+ :Red => [255,0,0,255],
124
+ :RosyBrown => [188,143,143],
125
+ :RoyalBlue => [65,105,225,255],
126
+ :SaddleBrown => [139,69,19,255],
127
+ :Salmon => [250,128,114,255],
128
+ :SandyBrown => [244,164,96,255],
129
+ :SeaGreen => [46,139,87,255],
130
+ :SeaShell => [255,245,238,255],
131
+ :Sienna => [160,82,45,255],
132
+ :Silver => [192,192,192,255],
133
+ :SkyBlue => [135,206,235,255],
134
+ :SlateBlue => [106,90,205,255],
135
+ :SlateGray => [112,128,144,255],
136
+ :SlateGrey => [112,128,144,255],
137
+ :Snow => [255,250,250,255],
138
+ :SpringGreen => [0,255,127,255],
139
+ :SteelBlue => [70,130,180,255],
140
+ :Tan => [210,180,140,255],
141
+ :Teal => [0,128,128,255],
142
+ :Thistle => [216,191,216,255],
143
+ :Tomato => [255,99,71,255],
144
+ :Turquoise => [64,224,208,255],
145
+ :Violet => [238,130,238,255],
146
+ :Wheat => [245,222,179,255],
147
+ :White => [255,255,255,255],
148
+ :WhiteSmoke => [245,245,245,255],
149
+ :Yellow => [255,255,0],
150
+ :YellowGreen => [154,205,50,255]
151
+ }
@@ -0,0 +1,40 @@
1
+ class Dialog < Container
2
+
3
+ def initialize(opts, &close_callback)
4
+ super opts
5
+ @close_callback = close_callback if block_given?
6
+ @modal_target = opts[:modal]
7
+ end
8
+
9
+ def added()
10
+ super
11
+ font = theme_property :font
12
+ font_size = theme_property :font_size
13
+ @font = TTF.new(File.join(@app.theme_dir,font), font_size)
14
+
15
+ @bg_color = theme_property :bg_color
16
+ @color = theme_property :color
17
+
18
+ @border_color = theme_property :border_color
19
+ @focus_color = theme_property :focus_color
20
+
21
+ @rect = Rect.new [@x-@x_pad,@y-@y_pad,@w+2*@x_pad,@h+2*@y_pad]
22
+ end
23
+
24
+ # show the dialog by adding it to the @modal_target and
25
+ # intercepting all of its events
26
+ def show()
27
+ @modal_target.add_modal self
28
+ end
29
+
30
+ # def on_mouse_dragging(x,y,event); end
31
+ # def on_mouse_motion(event); end
32
+ # def on_mouse_drag(start_x, start_y, event); end
33
+ # def on_click(event); end
34
+ # def on_key_up(event); end
35
+ # def draw(destination); end
36
+ # def on_network(event); end
37
+ # def update(time);end
38
+
39
+ end
40
+