cyberarm_engine 0.19.0 → 0.19.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -8
  3. data/.rubocop.yml +7 -7
  4. data/.travis.yml +5 -5
  5. data/Gemfile +6 -6
  6. data/LICENSE.txt +21 -21
  7. data/README.md +74 -74
  8. data/Rakefile +10 -10
  9. data/bin/console +14 -14
  10. data/bin/setup +8 -8
  11. data/cyberarm_engine.gemspec +39 -39
  12. data/lib/cyberarm_engine/animator.rb +219 -219
  13. data/lib/cyberarm_engine/background.rb +179 -179
  14. data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
  15. data/lib/cyberarm_engine/bounding_box.rb +150 -150
  16. data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
  17. data/lib/cyberarm_engine/cache/download_manager.rb +121 -121
  18. data/lib/cyberarm_engine/cache.rb +4 -4
  19. data/lib/cyberarm_engine/common.rb +113 -113
  20. data/lib/cyberarm_engine/config_file.rb +46 -46
  21. data/lib/cyberarm_engine/console/command.rb +157 -157
  22. data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
  23. data/lib/cyberarm_engine/console/subcommand.rb +99 -99
  24. data/lib/cyberarm_engine/console.rb +248 -248
  25. data/lib/cyberarm_engine/game_object.rb +248 -248
  26. data/lib/cyberarm_engine/game_state.rb +97 -97
  27. data/lib/cyberarm_engine/model/material.rb +21 -21
  28. data/lib/cyberarm_engine/model/model_object.rb +131 -131
  29. data/lib/cyberarm_engine/model/parser.rb +74 -74
  30. data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
  31. data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
  32. data/lib/cyberarm_engine/model.rb +212 -212
  33. data/lib/cyberarm_engine/model_cache.rb +31 -31
  34. data/lib/cyberarm_engine/opengl/light.rb +50 -50
  35. data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
  36. data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -38
  37. data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
  38. data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -164
  39. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +298 -298
  40. data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -22
  41. data/lib/cyberarm_engine/opengl/shader.rb +406 -406
  42. data/lib/cyberarm_engine/opengl/texture.rb +69 -69
  43. data/lib/cyberarm_engine/opengl.rb +28 -28
  44. data/lib/cyberarm_engine/ray.rb +56 -56
  45. data/lib/cyberarm_engine/stats.rb +21 -21
  46. data/lib/cyberarm_engine/text.rb +197 -197
  47. data/lib/cyberarm_engine/timer.rb +23 -23
  48. data/lib/cyberarm_engine/transform.rb +296 -296
  49. data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
  50. data/lib/cyberarm_engine/ui/dsl.rb +139 -139
  51. data/lib/cyberarm_engine/ui/element.rb +488 -488
  52. data/lib/cyberarm_engine/ui/elements/button.rb +97 -97
  53. data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
  54. data/lib/cyberarm_engine/ui/elements/container.rb +256 -256
  55. data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
  56. data/lib/cyberarm_engine/ui/elements/edit_line.rb +263 -263
  57. data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
  58. data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
  59. data/lib/cyberarm_engine/ui/elements/list_box.rb +88 -82
  60. data/lib/cyberarm_engine/ui/elements/progress.rb +51 -51
  61. data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
  62. data/lib/cyberarm_engine/ui/elements/slider.rb +104 -104
  63. data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
  64. data/lib/cyberarm_engine/ui/elements/text_block.rb +162 -162
  65. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +65 -65
  66. data/lib/cyberarm_engine/ui/event.rb +54 -54
  67. data/lib/cyberarm_engine/ui/gui_state.rb +256 -256
  68. data/lib/cyberarm_engine/ui/style.rb +49 -49
  69. data/lib/cyberarm_engine/ui/theme.rb +207 -207
  70. data/lib/cyberarm_engine/vector.rb +293 -293
  71. data/lib/cyberarm_engine/version.rb +4 -4
  72. data/lib/cyberarm_engine/window.rb +120 -120
  73. data/lib/cyberarm_engine.rb +71 -71
  74. metadata +3 -3
@@ -1,256 +1,256 @@
1
- module CyberarmEngine
2
- class Element
3
- class Container < Element
4
- include Common
5
-
6
- attr_accessor :stroke_color, :fill_color
7
- attr_reader :children, :gui_state, :scroll_position
8
-
9
- def initialize(options = {}, block = nil)
10
- @gui_state = options.delete(:gui_state)
11
- super
12
-
13
- @scroll_position = Vector.new(0, 0)
14
- @scroll_speed = 40
15
-
16
- @text_color = options[:color]
17
-
18
- @children = []
19
-
20
- event(:window_size_changed)
21
- end
22
-
23
- def build
24
- @block.call(self) if @block
25
-
26
- root.gui_state.request_recalculate
27
- end
28
-
29
- def add(element)
30
- @children << element
31
-
32
- root.gui_state.request_recalculate
33
- end
34
-
35
- def clear(&block)
36
- @children.clear
37
-
38
- old_container = $__current_container__
39
-
40
- $__current_container__ = self
41
- block.call(self) if block
42
-
43
- $__current_container__ = old_container
44
-
45
- root.gui_state.request_recalculate
46
- end
47
-
48
- def apend(&block)
49
- old_container = $__current_container__
50
-
51
- $__current_container__ = self
52
- block.call(self) if block
53
-
54
- $__current_container__ = old_container
55
-
56
- root.gui_state.request_recalculate
57
- end
58
-
59
- def render
60
- Gosu.clip_to(@x, @y, width, height) do
61
- @children.each(&:draw)
62
- end
63
- end
64
-
65
- def debug_draw
66
- super
67
-
68
- @children.each do |child|
69
- child.debug_draw
70
- end
71
- end
72
-
73
- def update
74
- @children.each(&:update)
75
- end
76
-
77
- def hit_element?(x, y)
78
- return unless hit?(x, y)
79
-
80
- @children.reverse_each do |child|
81
- next unless child.visible?
82
-
83
- case child
84
- when Container
85
- if element = child.hit_element?(x, y)
86
- return element
87
- end
88
- else
89
- return child if child.hit?(x, y)
90
- end
91
- end
92
-
93
- self if hit?(x, y)
94
- end
95
-
96
- def recalculate
97
- @current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
98
- @current_position += @scroll_position
99
-
100
- return unless visible?
101
-
102
- Stats.increment(:gui_recalculations_last_frame, 1)
103
-
104
- stylize
105
-
106
- layout
107
-
108
- if is_root?
109
- @width = @style.width = window.width
110
- @height = @style.height = window.height
111
- else
112
- @width = 0
113
- @height = 0
114
-
115
- _width = dimensional_size(@style.width, :width)
116
- _height = dimensional_size(@style.height, :height)
117
-
118
- @width = _width || (@children.map { |c| c.x + c.outer_width }.max || 0).round
119
- @height = _height || (@children.map { |c| c.y + c.outer_height }.max || 0).round
120
- end
121
-
122
- # Move child to parent after positioning
123
- @children.each do |child|
124
- child.x += (@x + @style.border_thickness_left) - style.margin_left
125
- child.y += (@y + @style.border_thickness_top) - style.margin_top
126
-
127
- child.stylize
128
- child.recalculate
129
- child.reposition # TODO: Implement top,bottom,left,center, and right positioning
130
-
131
- Stats.increment(:gui_recalculations_last_frame, 1)
132
- end
133
-
134
- update_background
135
- end
136
-
137
- def layout
138
- raise "Not overridden"
139
- end
140
-
141
- def max_width
142
- _width = dimensional_size(@style.width, :width)
143
- if _width
144
- outer_width
145
- else
146
- window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
147
- end
148
- end
149
-
150
- def fits_on_line?(element) # Flow
151
- p [@options[:id], @width] if @options[:id]
152
- @current_position.x + element.outer_width <= max_width &&
153
- @current_position.x + element.outer_width <= window.width
154
- end
155
-
156
- def position_on_current_line(element) # Flow
157
- element.x = element.style.margin_left + @current_position.x
158
- element.y = element.style.margin_top + @current_position.y
159
-
160
- @current_position.x += element.outer_width
161
- @current_position.x = @style.margin_left if @current_position.x >= max_width
162
- end
163
-
164
- def tallest_neighbor(querier, _y_position) # Flow
165
- response = querier
166
- @children.each do |child|
167
- response = child if child.outer_height > response.outer_height
168
- break if child == querier
169
- end
170
-
171
- response
172
- end
173
-
174
- def position_on_next_line(child) # Flow
175
- @current_position.x = @style.margin_left
176
- @current_position.y += tallest_neighbor(child, @current_position.y).outer_height
177
-
178
- child.x = child.style.margin_left + @current_position.x
179
- child.y = child.style.margin_top + @current_position.y
180
-
181
- @current_position.x += child.outer_width
182
- end
183
-
184
- def move_to_next_line(element) # Stack
185
- element.x = element.style.margin_left + @current_position.x
186
- element.y = element.style.margin_top + @current_position.y
187
-
188
- @current_position.y += element.outer_height
189
- end
190
-
191
- def mouse_wheel_up(sender, x, y)
192
- return unless @style.scroll
193
-
194
- if @scroll_position.y < 0
195
- @scroll_position.y += @scroll_speed
196
- @scroll_position.y = 0 if @scroll_position.y > 0
197
- recalculate
198
-
199
- return :handled
200
- end
201
- end
202
-
203
- def mouse_wheel_down(sender, x, y)
204
- return unless @style.scroll
205
-
206
- return unless height < scroll_height
207
-
208
- if @scroll_position.y.abs < max_scroll_height
209
- @scroll_position.y -= @scroll_speed
210
- @scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height
211
- recalculate
212
-
213
- return :handled
214
- end
215
- end
216
-
217
- def scroll_top
218
- @scroll_position.y
219
- end
220
-
221
- def scroll_top=(n)
222
- n = 0 if n <= 0
223
- @scroll_position.y = -n
224
-
225
- if max_scroll_height.positive?
226
- @scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height
227
- else
228
- @scroll_position.y = 0
229
- end
230
- end
231
-
232
- def value
233
- @children.map { |c| c.class }.join(", ")
234
- end
235
-
236
- def to_s
237
- "#{self.class} x=#{x} y=#{y} width=#{width} height=#{height} children=#{@children.size}"
238
- end
239
-
240
- def write_tree(indent = "", _index = 0)
241
- puts self
242
-
243
- indent += " "
244
- @children.each_with_index do |child, i|
245
- print "#{indent}#{i}: "
246
-
247
- if child.is_a?(Container)
248
- child.write_tree(indent)
249
- else
250
- puts child
251
- end
252
- end
253
- end
254
- end
255
- end
256
- end
1
+ module CyberarmEngine
2
+ class Element
3
+ class Container < Element
4
+ include Common
5
+
6
+ attr_accessor :stroke_color, :fill_color
7
+ attr_reader :children, :gui_state, :scroll_position
8
+
9
+ def initialize(options = {}, block = nil)
10
+ @gui_state = options.delete(:gui_state)
11
+ super
12
+
13
+ @scroll_position = Vector.new(0, 0)
14
+ @scroll_speed = 40
15
+
16
+ @text_color = options[:color]
17
+
18
+ @children = []
19
+
20
+ event(:window_size_changed)
21
+ end
22
+
23
+ def build
24
+ @block.call(self) if @block
25
+
26
+ root.gui_state.request_recalculate
27
+ end
28
+
29
+ def add(element)
30
+ @children << element
31
+
32
+ root.gui_state.request_recalculate
33
+ end
34
+
35
+ def clear(&block)
36
+ @children.clear
37
+
38
+ old_container = $__current_container__
39
+
40
+ $__current_container__ = self
41
+ block.call(self) if block
42
+
43
+ $__current_container__ = old_container
44
+
45
+ root.gui_state.request_recalculate
46
+ end
47
+
48
+ def apend(&block)
49
+ old_container = $__current_container__
50
+
51
+ $__current_container__ = self
52
+ block.call(self) if block
53
+
54
+ $__current_container__ = old_container
55
+
56
+ root.gui_state.request_recalculate
57
+ end
58
+
59
+ def render
60
+ Gosu.clip_to(@x, @y, width, height) do
61
+ @children.each(&:draw)
62
+ end
63
+ end
64
+
65
+ def debug_draw
66
+ super
67
+
68
+ @children.each do |child|
69
+ child.debug_draw
70
+ end
71
+ end
72
+
73
+ def update
74
+ @children.each(&:update)
75
+ end
76
+
77
+ def hit_element?(x, y)
78
+ return unless hit?(x, y)
79
+
80
+ @children.reverse_each do |child|
81
+ next unless child.visible?
82
+
83
+ case child
84
+ when Container
85
+ if element = child.hit_element?(x, y)
86
+ return element
87
+ end
88
+ else
89
+ return child if child.hit?(x, y)
90
+ end
91
+ end
92
+
93
+ self if hit?(x, y)
94
+ end
95
+
96
+ def recalculate
97
+ @current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
98
+ @current_position += @scroll_position
99
+
100
+ return unless visible?
101
+
102
+ Stats.increment(:gui_recalculations_last_frame, 1)
103
+
104
+ stylize
105
+
106
+ layout
107
+
108
+ if is_root?
109
+ @width = @style.width = window.width
110
+ @height = @style.height = window.height
111
+ else
112
+ @width = 0
113
+ @height = 0
114
+
115
+ _width = dimensional_size(@style.width, :width)
116
+ _height = dimensional_size(@style.height, :height)
117
+
118
+ @width = _width || (@children.map { |c| c.x + c.outer_width }.max || 0).round
119
+ @height = _height || (@children.map { |c| c.y + c.outer_height }.max || 0).round
120
+ end
121
+
122
+ # Move child to parent after positioning
123
+ @children.each do |child|
124
+ child.x += (@x + @style.border_thickness_left) - style.margin_left
125
+ child.y += (@y + @style.border_thickness_top) - style.margin_top
126
+
127
+ child.stylize
128
+ child.recalculate
129
+ child.reposition # TODO: Implement top,bottom,left,center, and right positioning
130
+
131
+ Stats.increment(:gui_recalculations_last_frame, 1)
132
+ end
133
+
134
+ update_background
135
+ end
136
+
137
+ def layout
138
+ raise "Not overridden"
139
+ end
140
+
141
+ def max_width
142
+ _width = dimensional_size(@style.width, :width)
143
+ if _width
144
+ outer_width
145
+ else
146
+ window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
147
+ end
148
+ end
149
+
150
+ def fits_on_line?(element) # Flow
151
+ p [@options[:id], @width] if @options[:id]
152
+ @current_position.x + element.outer_width <= max_width &&
153
+ @current_position.x + element.outer_width <= window.width
154
+ end
155
+
156
+ def position_on_current_line(element) # Flow
157
+ element.x = element.style.margin_left + @current_position.x
158
+ element.y = element.style.margin_top + @current_position.y
159
+
160
+ @current_position.x += element.outer_width
161
+ @current_position.x = @style.margin_left if @current_position.x >= max_width
162
+ end
163
+
164
+ def tallest_neighbor(querier, _y_position) # Flow
165
+ response = querier
166
+ @children.each do |child|
167
+ response = child if child.outer_height > response.outer_height
168
+ break if child == querier
169
+ end
170
+
171
+ response
172
+ end
173
+
174
+ def position_on_next_line(child) # Flow
175
+ @current_position.x = @style.margin_left
176
+ @current_position.y += tallest_neighbor(child, @current_position.y).outer_height
177
+
178
+ child.x = child.style.margin_left + @current_position.x
179
+ child.y = child.style.margin_top + @current_position.y
180
+
181
+ @current_position.x += child.outer_width
182
+ end
183
+
184
+ def move_to_next_line(element) # Stack
185
+ element.x = element.style.margin_left + @current_position.x
186
+ element.y = element.style.margin_top + @current_position.y
187
+
188
+ @current_position.y += element.outer_height
189
+ end
190
+
191
+ def mouse_wheel_up(sender, x, y)
192
+ return unless @style.scroll
193
+
194
+ if @scroll_position.y < 0
195
+ @scroll_position.y += @scroll_speed
196
+ @scroll_position.y = 0 if @scroll_position.y > 0
197
+ recalculate
198
+
199
+ return :handled
200
+ end
201
+ end
202
+
203
+ def mouse_wheel_down(sender, x, y)
204
+ return unless @style.scroll
205
+
206
+ return unless height < scroll_height
207
+
208
+ if @scroll_position.y.abs < max_scroll_height
209
+ @scroll_position.y -= @scroll_speed
210
+ @scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height
211
+ recalculate
212
+
213
+ return :handled
214
+ end
215
+ end
216
+
217
+ def scroll_top
218
+ @scroll_position.y
219
+ end
220
+
221
+ def scroll_top=(n)
222
+ n = 0 if n <= 0
223
+ @scroll_position.y = -n
224
+
225
+ if max_scroll_height.positive?
226
+ @scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height
227
+ else
228
+ @scroll_position.y = 0
229
+ end
230
+ end
231
+
232
+ def value
233
+ @children.map { |c| c.class }.join(", ")
234
+ end
235
+
236
+ def to_s
237
+ "#{self.class} x=#{x} y=#{y} width=#{width} height=#{height} children=#{@children.size}"
238
+ end
239
+
240
+ def write_tree(indent = "", _index = 0)
241
+ puts self
242
+
243
+ indent += " "
244
+ @children.each_with_index do |child, i|
245
+ print "#{indent}#{i}: "
246
+
247
+ if child.is_a?(Container)
248
+ child.write_tree(indent)
249
+ else
250
+ puts child
251
+ end
252
+ end
253
+ end
254
+ end
255
+ end
256
+ end