cyberarm_engine 0.13.0 → 0.13.1

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -8
  3. data/.travis.yml +5 -5
  4. data/Gemfile +6 -6
  5. data/LICENSE.txt +21 -21
  6. data/README.md +73 -43
  7. data/Rakefile +10 -10
  8. data/bin/console +14 -14
  9. data/bin/setup +8 -8
  10. data/cyberarm_engine.gemspec +36 -36
  11. data/lib/cyberarm_engine.rb +49 -47
  12. data/lib/cyberarm_engine/animator.rb +53 -53
  13. data/lib/cyberarm_engine/background.rb +175 -175
  14. data/lib/cyberarm_engine/bounding_box.rb +149 -149
  15. data/lib/cyberarm_engine/common.rb +96 -96
  16. data/lib/cyberarm_engine/config_file.rb +46 -0
  17. data/lib/cyberarm_engine/engine.rb +101 -101
  18. data/lib/cyberarm_engine/game_object.rb +256 -256
  19. data/lib/cyberarm_engine/game_state.rb +88 -88
  20. data/lib/cyberarm_engine/gosu_ext/circle.rb +8 -8
  21. data/lib/cyberarm_engine/ray.rb +55 -55
  22. data/lib/cyberarm_engine/shader.rb +398 -262
  23. data/lib/cyberarm_engine/text.rb +146 -146
  24. data/lib/cyberarm_engine/timer.rb +22 -22
  25. data/lib/cyberarm_engine/transform.rb +272 -272
  26. data/lib/cyberarm_engine/ui/border_canvas.rb +100 -100
  27. data/lib/cyberarm_engine/ui/dsl.rb +98 -98
  28. data/lib/cyberarm_engine/ui/element.rb +275 -275
  29. data/lib/cyberarm_engine/ui/elements/button.rb +66 -66
  30. data/lib/cyberarm_engine/ui/elements/check_box.rb +58 -58
  31. data/lib/cyberarm_engine/ui/elements/container.rb +176 -176
  32. data/lib/cyberarm_engine/ui/elements/edit_line.rb +171 -171
  33. data/lib/cyberarm_engine/ui/elements/flow.rb +16 -16
  34. data/lib/cyberarm_engine/ui/elements/image.rb +51 -51
  35. data/lib/cyberarm_engine/ui/elements/label.rb +49 -49
  36. data/lib/cyberarm_engine/ui/elements/progress.rb +49 -49
  37. data/lib/cyberarm_engine/ui/elements/stack.rb +12 -12
  38. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +55 -55
  39. data/lib/cyberarm_engine/ui/event.rb +46 -46
  40. data/lib/cyberarm_engine/ui/gui_state.rb +134 -134
  41. data/lib/cyberarm_engine/ui/style.rb +36 -36
  42. data/lib/cyberarm_engine/ui/theme.rb +120 -120
  43. data/lib/cyberarm_engine/vector.rb +289 -202
  44. data/lib/cyberarm_engine/version.rb +4 -4
  45. metadata +3 -2
@@ -1,101 +1,101 @@
1
- module CyberarmEngine
2
- class BorderCanvas
3
- attr_reader :element, :top, :right, :bottom, :left
4
- def initialize(element:)
5
- @element = element
6
-
7
- @top = Background.new
8
- @right = Background.new
9
- @bottom = Background.new
10
- @left = Background.new
11
- end
12
-
13
- def color=(color)
14
- if color.is_a?(Numeric)
15
- @top.background = color
16
- @right.background = color
17
- @bottom.background = color
18
- @left.background = color
19
-
20
- elsif color.is_a?(Gosu::Color)
21
- @top.background = color
22
- @right.background = color
23
- @bottom.background = color
24
- @left.background = color
25
-
26
- elsif color.is_a?(Array)
27
- if color.size == 1
28
- color=color.first
29
-
30
- elsif color.size == 2
31
- @top.background = color.first
32
- @right.background = color.first
33
- @bottom.background = color.last
34
- @left.background = color.last
35
-
36
- elsif color.size == 4
37
- @top.background = color[0]
38
- @right.background = color[1]
39
- @bottom.background = color[2]
40
- @left.background = color[3]
41
- else
42
- raise ArgumentError, "color array was empty or had wrong number of elements (expected 2 or 4 elements)"
43
- end
44
-
45
- elsif color.is_a?(Hash)
46
- @top.background = color[:top]
47
- @right.background = color[:right]
48
- @bottom.background = color[:bottom]
49
- @left.background = color[:left]
50
- else
51
- raise ArgumentError, "color '#{color}' of type '#{color.class}' was not able to be processed"
52
- end
53
- end
54
-
55
- def draw
56
- @top.draw
57
- @right.draw
58
- @bottom.draw
59
- @left.draw
60
- end
61
-
62
- def update
63
- # TOP
64
- @top.x = @element.x# + @element.border_thickness_left
65
- @top.y = @element.y
66
- @top.z = @element.z
67
-
68
- @top.width = @element.width
69
- @top.height = @element.style.border_thickness_top
70
-
71
- # RIGHT
72
- @right.x = @element.x + @element.width
73
- @right.y = @element.y + @element.style.border_thickness_top
74
- @right.z = @element.z
75
-
76
- @right.width = -@element.style.border_thickness_right
77
- @right.height = @element.height - @element.style.border_thickness_top
78
-
79
- # BOTTOM
80
- @bottom.x = @element.x
81
- @bottom.y = @element.y + @element.height
82
- @bottom.z = @element.z
83
-
84
- @bottom.width = @element.width - @element.style.border_thickness_right
85
- @bottom.height = -@element.style.border_thickness_bottom
86
-
87
- # LEFT
88
- @left.x = @element.x
89
- @left.y = @element.y
90
- @left.z = @element.z
91
-
92
- @left.width = @element.style.border_thickness_left
93
- @left.height = @element.height - @element.style.border_thickness_bottom
94
-
95
- @top.update
96
- @right.update
97
- @bottom.update
98
- @left.update
99
- end
100
- end
1
+ module CyberarmEngine
2
+ class BorderCanvas
3
+ attr_reader :element, :top, :right, :bottom, :left
4
+ def initialize(element:)
5
+ @element = element
6
+
7
+ @top = Background.new
8
+ @right = Background.new
9
+ @bottom = Background.new
10
+ @left = Background.new
11
+ end
12
+
13
+ def color=(color)
14
+ if color.is_a?(Numeric)
15
+ @top.background = color
16
+ @right.background = color
17
+ @bottom.background = color
18
+ @left.background = color
19
+
20
+ elsif color.is_a?(Gosu::Color)
21
+ @top.background = color
22
+ @right.background = color
23
+ @bottom.background = color
24
+ @left.background = color
25
+
26
+ elsif color.is_a?(Array)
27
+ if color.size == 1
28
+ color=color.first
29
+
30
+ elsif color.size == 2
31
+ @top.background = color.first
32
+ @right.background = color.first
33
+ @bottom.background = color.last
34
+ @left.background = color.last
35
+
36
+ elsif color.size == 4
37
+ @top.background = color[0]
38
+ @right.background = color[1]
39
+ @bottom.background = color[2]
40
+ @left.background = color[3]
41
+ else
42
+ raise ArgumentError, "color array was empty or had wrong number of elements (expected 2 or 4 elements)"
43
+ end
44
+
45
+ elsif color.is_a?(Hash)
46
+ @top.background = color[:top]
47
+ @right.background = color[:right]
48
+ @bottom.background = color[:bottom]
49
+ @left.background = color[:left]
50
+ else
51
+ raise ArgumentError, "color '#{color}' of type '#{color.class}' was not able to be processed"
52
+ end
53
+ end
54
+
55
+ def draw
56
+ @top.draw
57
+ @right.draw
58
+ @bottom.draw
59
+ @left.draw
60
+ end
61
+
62
+ def update
63
+ # TOP
64
+ @top.x = @element.x# + @element.border_thickness_left
65
+ @top.y = @element.y
66
+ @top.z = @element.z
67
+
68
+ @top.width = @element.width
69
+ @top.height = @element.style.border_thickness_top
70
+
71
+ # RIGHT
72
+ @right.x = @element.x + @element.width
73
+ @right.y = @element.y + @element.style.border_thickness_top
74
+ @right.z = @element.z
75
+
76
+ @right.width = -@element.style.border_thickness_right
77
+ @right.height = @element.height - @element.style.border_thickness_top
78
+
79
+ # BOTTOM
80
+ @bottom.x = @element.x
81
+ @bottom.y = @element.y + @element.height
82
+ @bottom.z = @element.z
83
+
84
+ @bottom.width = @element.width - @element.style.border_thickness_right
85
+ @bottom.height = -@element.style.border_thickness_bottom
86
+
87
+ # LEFT
88
+ @left.x = @element.x
89
+ @left.y = @element.y
90
+ @left.z = @element.z
91
+
92
+ @left.width = @element.style.border_thickness_left
93
+ @left.height = @element.height - @element.style.border_thickness_bottom
94
+
95
+ @top.update
96
+ @right.update
97
+ @bottom.update
98
+ @left.update
99
+ end
100
+ end
101
101
  end
@@ -1,99 +1,99 @@
1
- module CyberarmEngine
2
- module DSL
3
- def flow(options = {}, &block)
4
- container(CyberarmEngine::Element::Flow, options, &block)
5
- end
6
-
7
- def stack(options = {}, &block)
8
- container(CyberarmEngine::Element::Stack, options, &block)
9
- end
10
-
11
- def label(text, options = {}, &block)
12
- options[:parent] = element_parent
13
- options[:theme] = current_theme
14
-
15
- add_element( Element::Label.new(text, options, block) )
16
- end
17
-
18
- def button(text, options = {}, &block)
19
- options[:parent] = element_parent
20
- options[:theme] = current_theme
21
-
22
- add_element( Element::Button.new(text, options, block) { if block.is_a?(Proc); block.call; end } )
23
- end
24
-
25
- def edit_line(text, options = {}, &block)
26
- options[:parent] = element_parent
27
- options[:theme] = current_theme
28
-
29
- add_element( Element::EditLine.new(text, options, block) )
30
- end
31
-
32
- def toggle_button(options = {}, &block)
33
- options[:parent] = element_parent
34
- options[:theme] = current_theme
35
-
36
- add_element( Element::ToggleButton.new(options, block) )
37
- end
38
-
39
- def check_box(text, options = {}, &block)
40
- options[:parent] = element_parent
41
- options[:theme] = current_theme
42
-
43
- add_element( Element::CheckBox.new(text, options, block) )
44
- end
45
-
46
- def image(path, options = {}, &block)
47
- options[:parent] = element_parent
48
- options[:theme] = current_theme
49
-
50
- add_element( Element::Image.new(path, options, block) )
51
- end
52
-
53
- def progress(options = {}, &block)
54
- options[:parent] = element_parent
55
- options[:theme] = current_theme
56
-
57
- add_element( Element::Progress.new(options, block) )
58
- end
59
-
60
- def background(color = Gosu::Color::NONE)
61
- element_parent.style.background = color
62
- end
63
-
64
- def theme(theme)
65
- element_parent.options[:theme] = theme
66
- end
67
-
68
- def current_theme
69
- element_parent.options[:theme]
70
- end
71
-
72
- private def add_element(element)
73
- element_parent.add(element)
74
-
75
- return element
76
- end
77
-
78
- private def element_parent
79
- $__current_container__
80
- end
81
-
82
- private def container(klass, options = {}, &block)
83
- options[:parent] = element_parent
84
- options[:theme] = current_theme
85
-
86
- _container = klass.new(options, block)
87
-
88
- old_parent = element_parent
89
- $__current_container__ = _container
90
-
91
- _container.build
92
- _container.parent.add(_container)
93
-
94
- $__current_container__ = old_parent
95
-
96
- return _container
97
- end
98
- end
1
+ module CyberarmEngine
2
+ module DSL
3
+ def flow(options = {}, &block)
4
+ container(CyberarmEngine::Element::Flow, options, &block)
5
+ end
6
+
7
+ def stack(options = {}, &block)
8
+ container(CyberarmEngine::Element::Stack, options, &block)
9
+ end
10
+
11
+ def label(text, options = {}, &block)
12
+ options[:parent] = element_parent
13
+ options[:theme] = current_theme
14
+
15
+ add_element( Element::Label.new(text, options, block) )
16
+ end
17
+
18
+ def button(text, options = {}, &block)
19
+ options[:parent] = element_parent
20
+ options[:theme] = current_theme
21
+
22
+ add_element( Element::Button.new(text, options, block) { if block.is_a?(Proc); block.call; end } )
23
+ end
24
+
25
+ def edit_line(text, options = {}, &block)
26
+ options[:parent] = element_parent
27
+ options[:theme] = current_theme
28
+
29
+ add_element( Element::EditLine.new(text, options, block) )
30
+ end
31
+
32
+ def toggle_button(options = {}, &block)
33
+ options[:parent] = element_parent
34
+ options[:theme] = current_theme
35
+
36
+ add_element( Element::ToggleButton.new(options, block) )
37
+ end
38
+
39
+ def check_box(text, options = {}, &block)
40
+ options[:parent] = element_parent
41
+ options[:theme] = current_theme
42
+
43
+ add_element( Element::CheckBox.new(text, options, block) )
44
+ end
45
+
46
+ def image(path, options = {}, &block)
47
+ options[:parent] = element_parent
48
+ options[:theme] = current_theme
49
+
50
+ add_element( Element::Image.new(path, options, block) )
51
+ end
52
+
53
+ def progress(options = {}, &block)
54
+ options[:parent] = element_parent
55
+ options[:theme] = current_theme
56
+
57
+ add_element( Element::Progress.new(options, block) )
58
+ end
59
+
60
+ def background(color = Gosu::Color::NONE)
61
+ element_parent.style.background = color
62
+ end
63
+
64
+ def theme(theme)
65
+ element_parent.options[:theme] = theme
66
+ end
67
+
68
+ def current_theme
69
+ element_parent.options[:theme]
70
+ end
71
+
72
+ private def add_element(element)
73
+ element_parent.add(element)
74
+
75
+ return element
76
+ end
77
+
78
+ private def element_parent
79
+ $__current_container__
80
+ end
81
+
82
+ private def container(klass, options = {}, &block)
83
+ options[:parent] = element_parent
84
+ options[:theme] = current_theme
85
+
86
+ _container = klass.new(options, block)
87
+
88
+ old_parent = element_parent
89
+ $__current_container__ = _container
90
+
91
+ _container.build
92
+ _container.parent.add(_container)
93
+
94
+ $__current_container__ = old_parent
95
+
96
+ return _container
97
+ end
98
+ end
99
99
  end
@@ -1,276 +1,276 @@
1
- module CyberarmEngine
2
- class Element
3
- include Theme
4
- include Event
5
- include Common
6
-
7
- attr_accessor :x, :y, :z, :enabled
8
- attr_reader :parent, :options, :style, :event_handler, :background_canvas, :border_canvas
9
-
10
- def initialize(options = {}, block = nil)
11
- @parent = options.delete(:parent) # parent Container (i.e. flow/stack)
12
- options = theme_defaults(options)
13
- @options = options
14
- @block = block
15
-
16
- @focus = false
17
- @enabled = true
18
- @visible = true
19
-
20
- @style = Style.new(options)
21
-
22
- @x = @style.x
23
- @y = @style.y
24
- @z = @style.z
25
-
26
- @width = 0
27
- @height = 0
28
-
29
- @fixed_x = @x if @x != 0
30
- @fixed_y = @y if @y != 0
31
-
32
- @style.width = default(:width) || nil
33
- @style.height = default(:height) || nil
34
-
35
- @style.background_canvas = Background.new
36
- @style.border_canvas = BorderCanvas.new(element: self)
37
-
38
- stylize
39
-
40
- default_events
41
- end
42
-
43
- def stylize
44
- set_border_thickness(@style.border_thickness)
45
-
46
- set_padding(@style.padding)
47
-
48
- set_margin(@style.margin)
49
-
50
- set_background(@style.background)
51
- set_border_color(@style.border_color)
52
- end
53
-
54
- def set_background(background)
55
- @style.background = background
56
- @style.background_canvas.background = background
57
- end
58
-
59
- def set_border_thickness(border_thickness)
60
- @style.border_thickness = border_thickness
61
-
62
- @style.border_thickness_left = default(:border_thickness_left) || @style.border_thickness
63
- @style.border_thickness_right = default(:border_thickness_right) || @style.border_thickness
64
- @style.border_thickness_top = default(:border_thickness_top) || @style.border_thickness
65
- @style.border_thickness_bottom = default(:border_thickness_bottom) || @style.border_thickness
66
- end
67
-
68
- def set_border_color(color)
69
- @style.border_color = color
70
-
71
- @style.border_color_left = default(:border_color_left) || @style.border_color
72
- @style.border_color_right = default(:border_color_right) || @style.border_color
73
- @style.border_color_top = default(:border_color_top) || @style.border_color
74
- @style.border_color_bottom = default(:border_color_bottom) || @style.border_color
75
-
76
- @style.border_canvas.color = color
77
- end
78
-
79
- def set_padding(padding)
80
- @style.padding = padding
81
-
82
- @style.padding_left = default(:padding_left) || @style.padding
83
- @style.padding_right = default(:padding_right) || @style.padding
84
- @style.padding_top = default(:padding_top) || @style.padding
85
- @style.padding_bottom = default(:padding_bottom) || @style.padding
86
- end
87
-
88
- def set_margin(margin)
89
- @style.margin = margin
90
-
91
- @style.margin_left = default(:margin_left) || @style.margin
92
- @style.margin_right = default(:margin_right) || @style.margin
93
- @style.margin_top = default(:margin_top) || @style.margin
94
- @style.margin_bottom = default(:margin_bottom) || @style.margin
95
- end
96
-
97
- def default_events
98
- [:left, :middle, :right].each do |button|
99
- event(:"#{button}_mouse_button")
100
- event(:"released_#{button}_mouse_button")
101
- event(:"clicked_#{button}_mouse_button")
102
- event(:"holding_#{button}_mouse_button")
103
- end
104
-
105
- event(:mouse_wheel_up)
106
- event(:mouse_wheel_down)
107
-
108
- event(:enter)
109
- event(:hover)
110
- event(:leave)
111
-
112
- event(:blur)
113
- end
114
-
115
- def enabled?
116
- @enabled
117
- end
118
-
119
- def visible?
120
- @visible
121
- end
122
-
123
- def toggle
124
- @visible = !@visible
125
- root.gui_state.request_recalculate
126
- end
127
-
128
- def show
129
- @visible = true
130
- root.gui_state.request_recalculate
131
- end
132
-
133
- def hide
134
- @visible = false
135
- root.gui_state.request_recalculate
136
- end
137
-
138
- def draw
139
- return unless @visible
140
-
141
- @style.background_canvas.draw
142
- @style.border_canvas.draw
143
- render
144
- end
145
-
146
- def update
147
- end
148
-
149
- def button_down(id)
150
- end
151
-
152
- def button_up(id)
153
- end
154
-
155
- def render
156
- end
157
-
158
- def hit?(x, y)
159
- x.between?(@x, @x + width) &&
160
- y.between?(@y, @y + height)
161
- end
162
-
163
- def width
164
- if visible?
165
- inner_width + @width
166
- else
167
- 0
168
- end
169
- end
170
-
171
- def content_width
172
- @width
173
- end
174
-
175
- def noncontent_width
176
- (inner_width + outer_width) - width
177
- end
178
-
179
- def outer_width
180
- @style.margin_left + width + @style.margin_right
181
- end
182
-
183
- def inner_width
184
- (@style.border_thickness_left + @style.padding_left) + (@style.padding_right + @style.border_thickness_right)
185
- end
186
-
187
- def height
188
- if visible?
189
- inner_height + @height
190
- else
191
- 0
192
- end
193
- end
194
-
195
- def content_height
196
- @height
197
- end
198
-
199
- def noncontent_height
200
- (inner_height + outer_height) - height
201
- end
202
-
203
- def outer_height
204
- @style.margin_top + height + @style.margin_bottom
205
- end
206
-
207
- def inner_height
208
- (@style.border_thickness_top + @style.padding_top) + (@style.padding_bottom + @style.border_thickness_bottom)
209
- end
210
-
211
- private def dimensional_size(size, dimension)
212
- raise "dimension must be either :width or :height" unless dimension == :width || dimension == :height
213
- if size && size.is_a?(Numeric)
214
- if size.between?(0.0, 1.0)
215
- ((@parent.send(:"content_#{dimension}") - self.send(:"noncontent_#{dimension}") - 1) * size).round
216
- else
217
- size
218
- end
219
- else
220
- nil
221
- end
222
- end
223
-
224
- def background=(_background)
225
- @style.background_canvas.background=(_background)
226
- update_background
227
- end
228
-
229
- def update_background
230
- @style.background_canvas.x = @x
231
- @style.background_canvas.y = @y
232
- @style.background_canvas.z = @z
233
- @style.background_canvas.width = width
234
- @style.background_canvas.height = height
235
-
236
- @style.background_canvas.update
237
-
238
- @style.border_canvas.update
239
- end
240
-
241
- def root
242
- unless @root && @root.parent.nil?
243
- @root = parent
244
-
245
- loop do
246
- if @root.parent.nil?
247
- break
248
- else
249
- @root = @root.parent
250
- end
251
- end
252
- end
253
-
254
- @root
255
- end
256
-
257
- def is_root?
258
- @gui_state != nil
259
- end
260
-
261
- def recalculate
262
- raise "#{self.class}#recalculate was not overridden!"
263
- end
264
-
265
- def reposition
266
- end
267
-
268
- def value
269
- raise "#{self.class}#value was not overridden!"
270
- end
271
-
272
- def value=(value)
273
- raise "#{self.class}#value= was not overridden!"
274
- end
275
- end
1
+ module CyberarmEngine
2
+ class Element
3
+ include Theme
4
+ include Event
5
+ include Common
6
+
7
+ attr_accessor :x, :y, :z, :enabled
8
+ attr_reader :parent, :options, :style, :event_handler, :background_canvas, :border_canvas
9
+
10
+ def initialize(options = {}, block = nil)
11
+ @parent = options.delete(:parent) # parent Container (i.e. flow/stack)
12
+ options = theme_defaults(options)
13
+ @options = options
14
+ @block = block
15
+
16
+ @focus = false
17
+ @enabled = true
18
+ @visible = true
19
+
20
+ @style = Style.new(options)
21
+
22
+ @x = @style.x
23
+ @y = @style.y
24
+ @z = @style.z
25
+
26
+ @width = 0
27
+ @height = 0
28
+
29
+ @fixed_x = @x if @x != 0
30
+ @fixed_y = @y if @y != 0
31
+
32
+ @style.width = default(:width) || nil
33
+ @style.height = default(:height) || nil
34
+
35
+ @style.background_canvas = Background.new
36
+ @style.border_canvas = BorderCanvas.new(element: self)
37
+
38
+ stylize
39
+
40
+ default_events
41
+ end
42
+
43
+ def stylize
44
+ set_border_thickness(@style.border_thickness)
45
+
46
+ set_padding(@style.padding)
47
+
48
+ set_margin(@style.margin)
49
+
50
+ set_background(@style.background)
51
+ set_border_color(@style.border_color)
52
+ end
53
+
54
+ def set_background(background)
55
+ @style.background = background
56
+ @style.background_canvas.background = background
57
+ end
58
+
59
+ def set_border_thickness(border_thickness)
60
+ @style.border_thickness = border_thickness
61
+
62
+ @style.border_thickness_left = default(:border_thickness_left) || @style.border_thickness
63
+ @style.border_thickness_right = default(:border_thickness_right) || @style.border_thickness
64
+ @style.border_thickness_top = default(:border_thickness_top) || @style.border_thickness
65
+ @style.border_thickness_bottom = default(:border_thickness_bottom) || @style.border_thickness
66
+ end
67
+
68
+ def set_border_color(color)
69
+ @style.border_color = color
70
+
71
+ @style.border_color_left = default(:border_color_left) || @style.border_color
72
+ @style.border_color_right = default(:border_color_right) || @style.border_color
73
+ @style.border_color_top = default(:border_color_top) || @style.border_color
74
+ @style.border_color_bottom = default(:border_color_bottom) || @style.border_color
75
+
76
+ @style.border_canvas.color = color
77
+ end
78
+
79
+ def set_padding(padding)
80
+ @style.padding = padding
81
+
82
+ @style.padding_left = default(:padding_left) || @style.padding
83
+ @style.padding_right = default(:padding_right) || @style.padding
84
+ @style.padding_top = default(:padding_top) || @style.padding
85
+ @style.padding_bottom = default(:padding_bottom) || @style.padding
86
+ end
87
+
88
+ def set_margin(margin)
89
+ @style.margin = margin
90
+
91
+ @style.margin_left = default(:margin_left) || @style.margin
92
+ @style.margin_right = default(:margin_right) || @style.margin
93
+ @style.margin_top = default(:margin_top) || @style.margin
94
+ @style.margin_bottom = default(:margin_bottom) || @style.margin
95
+ end
96
+
97
+ def default_events
98
+ [:left, :middle, :right].each do |button|
99
+ event(:"#{button}_mouse_button")
100
+ event(:"released_#{button}_mouse_button")
101
+ event(:"clicked_#{button}_mouse_button")
102
+ event(:"holding_#{button}_mouse_button")
103
+ end
104
+
105
+ event(:mouse_wheel_up)
106
+ event(:mouse_wheel_down)
107
+
108
+ event(:enter)
109
+ event(:hover)
110
+ event(:leave)
111
+
112
+ event(:blur)
113
+ end
114
+
115
+ def enabled?
116
+ @enabled
117
+ end
118
+
119
+ def visible?
120
+ @visible
121
+ end
122
+
123
+ def toggle
124
+ @visible = !@visible
125
+ root.gui_state.request_recalculate
126
+ end
127
+
128
+ def show
129
+ @visible = true
130
+ root.gui_state.request_recalculate
131
+ end
132
+
133
+ def hide
134
+ @visible = false
135
+ root.gui_state.request_recalculate
136
+ end
137
+
138
+ def draw
139
+ return unless @visible
140
+
141
+ @style.background_canvas.draw
142
+ @style.border_canvas.draw
143
+ render
144
+ end
145
+
146
+ def update
147
+ end
148
+
149
+ def button_down(id)
150
+ end
151
+
152
+ def button_up(id)
153
+ end
154
+
155
+ def render
156
+ end
157
+
158
+ def hit?(x, y)
159
+ x.between?(@x, @x + width) &&
160
+ y.between?(@y, @y + height)
161
+ end
162
+
163
+ def width
164
+ if visible?
165
+ inner_width + @width
166
+ else
167
+ 0
168
+ end
169
+ end
170
+
171
+ def content_width
172
+ @width
173
+ end
174
+
175
+ def noncontent_width
176
+ (inner_width + outer_width) - width
177
+ end
178
+
179
+ def outer_width
180
+ @style.margin_left + width + @style.margin_right
181
+ end
182
+
183
+ def inner_width
184
+ (@style.border_thickness_left + @style.padding_left) + (@style.padding_right + @style.border_thickness_right)
185
+ end
186
+
187
+ def height
188
+ if visible?
189
+ inner_height + @height
190
+ else
191
+ 0
192
+ end
193
+ end
194
+
195
+ def content_height
196
+ @height
197
+ end
198
+
199
+ def noncontent_height
200
+ (inner_height + outer_height) - height
201
+ end
202
+
203
+ def outer_height
204
+ @style.margin_top + height + @style.margin_bottom
205
+ end
206
+
207
+ def inner_height
208
+ (@style.border_thickness_top + @style.padding_top) + (@style.padding_bottom + @style.border_thickness_bottom)
209
+ end
210
+
211
+ private def dimensional_size(size, dimension)
212
+ raise "dimension must be either :width or :height" unless dimension == :width || dimension == :height
213
+ if size && size.is_a?(Numeric)
214
+ if size.between?(0.0, 1.0)
215
+ ((@parent.send(:"content_#{dimension}") - self.send(:"noncontent_#{dimension}") - 1) * size).round
216
+ else
217
+ size
218
+ end
219
+ else
220
+ nil
221
+ end
222
+ end
223
+
224
+ def background=(_background)
225
+ @style.background_canvas.background=(_background)
226
+ update_background
227
+ end
228
+
229
+ def update_background
230
+ @style.background_canvas.x = @x
231
+ @style.background_canvas.y = @y
232
+ @style.background_canvas.z = @z
233
+ @style.background_canvas.width = width
234
+ @style.background_canvas.height = height
235
+
236
+ @style.background_canvas.update
237
+
238
+ @style.border_canvas.update
239
+ end
240
+
241
+ def root
242
+ unless @root && @root.parent.nil?
243
+ @root = parent
244
+
245
+ loop do
246
+ if @root.parent.nil?
247
+ break
248
+ else
249
+ @root = @root.parent
250
+ end
251
+ end
252
+ end
253
+
254
+ @root
255
+ end
256
+
257
+ def is_root?
258
+ @gui_state != nil
259
+ end
260
+
261
+ def recalculate
262
+ raise "#{self.class}#recalculate was not overridden!"
263
+ end
264
+
265
+ def reposition
266
+ end
267
+
268
+ def value
269
+ raise "#{self.class}#value was not overridden!"
270
+ end
271
+
272
+ def value=(value)
273
+ raise "#{self.class}#value= was not overridden!"
274
+ end
275
+ end
276
276
  end