cyberarm_engine 0.12.1 → 0.13.0

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 (44) 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 +43 -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 +47 -46
  12. data/lib/cyberarm_engine/animator.rb +54 -0
  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/engine.rb +101 -101
  17. data/lib/cyberarm_engine/game_object.rb +256 -256
  18. data/lib/cyberarm_engine/game_state.rb +88 -88
  19. data/lib/cyberarm_engine/gosu_ext/circle.rb +8 -8
  20. data/lib/cyberarm_engine/ray.rb +55 -55
  21. data/lib/cyberarm_engine/shader.rb +262 -205
  22. data/lib/cyberarm_engine/text.rb +146 -146
  23. data/lib/cyberarm_engine/timer.rb +22 -22
  24. data/lib/cyberarm_engine/transform.rb +272 -83
  25. data/lib/cyberarm_engine/ui/border_canvas.rb +100 -100
  26. data/lib/cyberarm_engine/ui/dsl.rb +98 -101
  27. data/lib/cyberarm_engine/ui/element.rb +275 -259
  28. data/lib/cyberarm_engine/ui/elements/button.rb +66 -66
  29. data/lib/cyberarm_engine/ui/elements/check_box.rb +58 -58
  30. data/lib/cyberarm_engine/ui/elements/container.rb +176 -162
  31. data/lib/cyberarm_engine/ui/elements/edit_line.rb +171 -102
  32. data/lib/cyberarm_engine/ui/elements/flow.rb +16 -16
  33. data/lib/cyberarm_engine/ui/elements/image.rb +51 -51
  34. data/lib/cyberarm_engine/ui/elements/label.rb +49 -49
  35. data/lib/cyberarm_engine/ui/elements/progress.rb +49 -49
  36. data/lib/cyberarm_engine/ui/elements/stack.rb +12 -12
  37. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +55 -55
  38. data/lib/cyberarm_engine/ui/event.rb +46 -45
  39. data/lib/cyberarm_engine/ui/gui_state.rb +134 -134
  40. data/lib/cyberarm_engine/ui/style.rb +36 -36
  41. data/lib/cyberarm_engine/ui/theme.rb +120 -119
  42. data/lib/cyberarm_engine/vector.rb +202 -198
  43. data/lib/cyberarm_engine/version.rb +4 -4
  44. metadata +6 -5
@@ -1,67 +1,67 @@
1
- module CyberarmEngine
2
- class Element
3
- class Button < Label
4
- def initialize(text, options = {}, block = nil)
5
- super(text, options, block)
6
-
7
- @style.background_canvas.background = default(:background)
8
- end
9
-
10
- def render
11
- draw_text
12
- end
13
-
14
- def draw_text
15
- @text.draw
16
- end
17
-
18
- def enter(sender)
19
- @focus = false unless window.button_down?(Gosu::MsLeft)
20
-
21
- if @focus
22
- @style.background_canvas.background = default(:active, :background)
23
- @text.color = default(:active, :color)
24
- else
25
- @style.background_canvas.background = default(:hover, :background)
26
- @text.color = default(:hover, :color)
27
- end
28
-
29
- return :handled
30
- end
31
-
32
- def left_mouse_button(sender, x, y)
33
- @focus = true
34
- @style.background_canvas.background = default(:active, :background)
35
- window.current_state.focus = self
36
- @text.color = default(:active, :color)
37
-
38
- return :handled
39
- end
40
-
41
- def released_left_mouse_button(sender,x, y)
42
- enter(sender)
43
-
44
- return :handled
45
- end
46
-
47
- def clicked_left_mouse_button(sender, x, y)
48
- @block.call(self) if @block
49
-
50
- return :handled
51
- end
52
-
53
- def leave(sender)
54
- @style.background_canvas.background = default(:background)
55
- @text.color = default(:color)
56
-
57
- return :handled
58
- end
59
-
60
- def blur(sender)
61
- @focus = false
62
-
63
- return :handled
64
- end
65
- end
66
- end
1
+ module CyberarmEngine
2
+ class Element
3
+ class Button < Label
4
+ def initialize(text, options = {}, block = nil)
5
+ super(text, options, block)
6
+
7
+ @style.background_canvas.background = default(:background)
8
+ end
9
+
10
+ def render
11
+ draw_text
12
+ end
13
+
14
+ def draw_text
15
+ @text.draw
16
+ end
17
+
18
+ def enter(sender)
19
+ @focus = false unless window.button_down?(Gosu::MsLeft)
20
+
21
+ if @focus
22
+ @style.background_canvas.background = default(:active, :background)
23
+ @text.color = default(:active, :color)
24
+ else
25
+ @style.background_canvas.background = default(:hover, :background)
26
+ @text.color = default(:hover, :color)
27
+ end
28
+
29
+ return :handled
30
+ end
31
+
32
+ def left_mouse_button(sender, x, y)
33
+ @focus = true
34
+ @style.background_canvas.background = default(:active, :background)
35
+ window.current_state.focus = self
36
+ @text.color = default(:active, :color)
37
+
38
+ return :handled
39
+ end
40
+
41
+ def released_left_mouse_button(sender,x, y)
42
+ enter(sender)
43
+
44
+ return :handled
45
+ end
46
+
47
+ def clicked_left_mouse_button(sender, x, y)
48
+ @block.call(self) if @block
49
+
50
+ return :handled
51
+ end
52
+
53
+ def leave(sender)
54
+ @style.background_canvas.background = default(:background)
55
+ @text.color = default(:color)
56
+
57
+ return :handled
58
+ end
59
+
60
+ def blur(sender)
61
+ @focus = false
62
+
63
+ return :handled
64
+ end
65
+ end
66
+ end
67
67
  end
@@ -1,59 +1,59 @@
1
- module CyberarmEngine
2
- class Element
3
- class CheckBox < Flow
4
- def initialize(text, options, block = nil)
5
- super({}, block = nil)
6
- options[:toggled] = options[:checked]
7
-
8
- @toggle_button = ToggleButton.new(options)
9
- @label = Label.new(text, options)
10
-
11
- define_label_singletons
12
-
13
- add(@toggle_button)
14
- add(@label)
15
- end
16
-
17
- def text=(text)
18
- @label.text = text
19
- recalculate
20
- end
21
-
22
- def value
23
- @toggle_button.value
24
- end
25
-
26
- def value=(bool)
27
- @toggle_button.vlaue = bool
28
- end
29
-
30
- def define_label_singletons
31
- @label.define_singleton_method(:_toggle_button) do |button|
32
- @_toggle_button = button
33
- end
34
-
35
- @label._toggle_button(@toggle_button)
36
-
37
- @label.define_singleton_method(:holding_left_mouse_button) do |sender, x, y|
38
- @_toggle_button.left_mouse_button(sender, x, y)
39
- end
40
-
41
- @label.define_singleton_method(:released_left_mouse_button) do |sender, x, y|
42
- @_toggle_button.released_left_mouse_button(sender, x, y)
43
- end
44
-
45
- @label.define_singleton_method(:clicked_left_mouse_button) do |sender, x, y|
46
- @_toggle_button.clicked_left_mouse_button(sender, x, y)
47
- end
48
-
49
- @label.define_singleton_method(:enter) do |sender|
50
- @_toggle_button.enter(sender)
51
- end
52
-
53
- @label.define_singleton_method(:leave) do |sender|
54
- @_toggle_button.leave(sender)
55
- end
56
- end
57
- end
58
- end
1
+ module CyberarmEngine
2
+ class Element
3
+ class CheckBox < Flow
4
+ def initialize(text, options, block = nil)
5
+ super({}, block = nil)
6
+ options[:toggled] = options[:checked]
7
+
8
+ @toggle_button = ToggleButton.new(options)
9
+ @label = Label.new(text, options)
10
+
11
+ define_label_singletons
12
+
13
+ add(@toggle_button)
14
+ add(@label)
15
+ end
16
+
17
+ def text=(text)
18
+ @label.text = text
19
+ recalculate
20
+ end
21
+
22
+ def value
23
+ @toggle_button.value
24
+ end
25
+
26
+ def value=(bool)
27
+ @toggle_button.vlaue = bool
28
+ end
29
+
30
+ def define_label_singletons
31
+ @label.define_singleton_method(:_toggle_button) do |button|
32
+ @_toggle_button = button
33
+ end
34
+
35
+ @label._toggle_button(@toggle_button)
36
+
37
+ @label.define_singleton_method(:holding_left_mouse_button) do |sender, x, y|
38
+ @_toggle_button.left_mouse_button(sender, x, y)
39
+ end
40
+
41
+ @label.define_singleton_method(:released_left_mouse_button) do |sender, x, y|
42
+ @_toggle_button.released_left_mouse_button(sender, x, y)
43
+ end
44
+
45
+ @label.define_singleton_method(:clicked_left_mouse_button) do |sender, x, y|
46
+ @_toggle_button.clicked_left_mouse_button(sender, x, y)
47
+ end
48
+
49
+ @label.define_singleton_method(:enter) do |sender|
50
+ @_toggle_button.enter(sender)
51
+ end
52
+
53
+ @label.define_singleton_method(:leave) do |sender|
54
+ @_toggle_button.leave(sender)
55
+ end
56
+ end
57
+ end
58
+ end
59
59
  end
@@ -1,162 +1,176 @@
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
8
- attr_reader :scroll_x, :scroll_y
9
-
10
- def initialize(options = {}, block = nil)
11
- @gui_state = options.delete(:gui_state)
12
- super
13
-
14
- @scroll_x, @scroll_y = 0, 0
15
- @scroll_speed = 10
16
-
17
- @text_color = options[:color]
18
-
19
- @children = []
20
- end
21
-
22
- def build
23
- @block.call(self) if @block
24
-
25
- recalculate
26
- end
27
-
28
- def add(element)
29
- @children << element
30
-
31
- recalculate
32
- end
33
-
34
- def render
35
- Gosu.clip_to(@x, @y, width, height) do
36
- @children.each(&:draw)
37
- end
38
- end
39
-
40
- def update
41
- @children.each(&:update)
42
- end
43
-
44
- def hit_element?(x, y)
45
- @children.reverse_each do |child|
46
- case child
47
- when Container
48
- if element = child.hit_element?(x, y)
49
- return element
50
- end
51
- else
52
- return child if child.hit?(x, y)
53
- end
54
- end
55
-
56
- self if hit?(x, y)
57
- end
58
-
59
- def recalculate
60
- @current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
61
- return unless visible?
62
- stylize
63
-
64
- layout
65
-
66
- if is_root?
67
- @width = @style.width = window.width
68
- @height = @style.height = window.height
69
- else
70
- @width, @height = 0, 0
71
-
72
- _width = dimensional_size(@style.width, :width)
73
- _height= dimensional_size(@style.height,:height)
74
-
75
- @width = _width ? _width : (@children.map {|c| c.x + c.outer_width }.max || 0).round
76
- @height = _height ? _height : (@children.map {|c| c.y + c.outer_height}.max || 0).round
77
- end
78
-
79
-
80
- # Move child to parent after positioning
81
- @children.each do |child|
82
- child.x += @x
83
- child.y += @y
84
-
85
- child.stylize
86
- child.recalculate
87
- child.reposition # TODO: Implement top,bottom,left,center, and right positioning
88
- end
89
-
90
- update_background
91
- end
92
-
93
- def layout
94
- raise "Not overridden"
95
- end
96
-
97
- def max_width
98
- @max_width ? @max_width : window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
99
- end
100
-
101
- def fits_on_line?(element) # Flow
102
- @current_position.x + element.outer_width <= max_width &&
103
- @current_position.x + element.outer_width <= window.width
104
- end
105
-
106
- def position_on_current_line(element) # Flow
107
- element.x = element.style.margin_left + @current_position.x
108
- element.y = element.style.margin_top + @current_position.y
109
-
110
- element.recalculate
111
-
112
- @current_position.x += element.outer_width
113
- @current_position.x = @style.margin_left if @current_position.x >= max_width
114
- end
115
-
116
- def tallest_neighbor(querier, y_position) # Flow
117
- response = querier
118
- @children.each do |child|
119
- response = child if child.outer_height > response.outer_height
120
- break if child == querier
121
- end
122
-
123
- return response
124
- end
125
-
126
- def position_on_next_line(child) # Flow
127
- @current_position.x = @style.margin_left
128
- @current_position.y += tallest_neighbor(child, @current_position.y).outer_height
129
-
130
- child.x = child.style.margin_left + @current_position.x
131
- child.y = child.style.margin_top + @current_position.y
132
-
133
- child.recalculate
134
-
135
- @current_position.x += child.outer_width
136
- end
137
-
138
- def move_to_next_line(element) # Stack
139
- element.x = element.style.margin_left + @current_position.x
140
- element.y = element.style.margin_top + @current_position.y
141
-
142
- element.recalculate
143
-
144
- @current_position.y += element.outer_height
145
- end
146
-
147
- # def mouse_wheel_up(sender, x, y)
148
- # @children.each {|c| c.y -= @scroll_speed}
149
- # @children.each {|c| c.recalculate}
150
- # end
151
-
152
- # def mouse_wheel_down(sender, x, y)
153
- # @children.each {|c| c.y += @scroll_speed}
154
- # @children.each {|c| c.recalculate}
155
- # end
156
-
157
- def value
158
- @children.map {|c| c.class}.join(", ")
159
- end
160
- end
161
- end
162
- 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
8
+ attr_reader :scroll_x, :scroll_y
9
+
10
+ def initialize(options = {}, block = nil)
11
+ @gui_state = options.delete(:gui_state)
12
+ super
13
+
14
+ @scroll_x, @scroll_y = 0, 0
15
+ @scroll_speed = 10
16
+
17
+ @text_color = options[:color]
18
+
19
+ @children = []
20
+ end
21
+
22
+ def build
23
+ @block.call(self) if @block
24
+
25
+ recalculate
26
+ end
27
+
28
+ def add(element)
29
+ @children << element
30
+
31
+ recalculate
32
+ end
33
+
34
+ def clear(&block)
35
+ @children.clear
36
+
37
+ old_container = $__current_container__
38
+
39
+ $__current_container__ = self
40
+ block.call(self) if block
41
+
42
+ $__current_container__ = old_container
43
+
44
+ recalculate
45
+ root.gui_state.request_recalculate
46
+ end
47
+
48
+ def render
49
+ Gosu.clip_to(@x, @y, width, height) do
50
+ @children.each(&:draw)
51
+ end
52
+ end
53
+
54
+ def update
55
+ @children.each(&:update)
56
+ end
57
+
58
+ def hit_element?(x, y)
59
+ @children.reverse_each do |child|
60
+ case child
61
+ when Container
62
+ if element = child.hit_element?(x, y)
63
+ return element
64
+ end
65
+ else
66
+ return child if child.hit?(x, y)
67
+ end
68
+ end
69
+
70
+ self if hit?(x, y)
71
+ end
72
+
73
+ def recalculate
74
+ @current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
75
+ return unless visible?
76
+ stylize
77
+
78
+ layout
79
+
80
+ if is_root?
81
+ @width = @style.width = window.width
82
+ @height = @style.height = window.height
83
+ else
84
+ @width, @height = 0, 0
85
+
86
+ _width = dimensional_size(@style.width, :width)
87
+ _height= dimensional_size(@style.height,:height)
88
+
89
+ @width = _width ? _width : (@children.map {|c| c.x + c.outer_width }.max || 0).round
90
+ @height = _height ? _height : (@children.map {|c| c.y + c.outer_height}.max || 0).round
91
+ end
92
+
93
+
94
+ # Move child to parent after positioning
95
+ @children.each do |child|
96
+ child.x += @x
97
+ child.y += @y
98
+
99
+ child.stylize
100
+ child.recalculate
101
+ child.reposition # TODO: Implement top,bottom,left,center, and right positioning
102
+ end
103
+
104
+ update_background
105
+ end
106
+
107
+ def layout
108
+ raise "Not overridden"
109
+ end
110
+
111
+ def max_width
112
+ @max_width ? @max_width : window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
113
+ end
114
+
115
+ def fits_on_line?(element) # Flow
116
+ @current_position.x + element.outer_width <= max_width &&
117
+ @current_position.x + element.outer_width <= window.width
118
+ end
119
+
120
+ def position_on_current_line(element) # Flow
121
+ element.x = element.style.margin_left + @current_position.x
122
+ element.y = element.style.margin_top + @current_position.y
123
+
124
+ element.recalculate
125
+
126
+ @current_position.x += element.outer_width
127
+ @current_position.x = @style.margin_left if @current_position.x >= max_width
128
+ end
129
+
130
+ def tallest_neighbor(querier, y_position) # Flow
131
+ response = querier
132
+ @children.each do |child|
133
+ response = child if child.outer_height > response.outer_height
134
+ break if child == querier
135
+ end
136
+
137
+ return response
138
+ end
139
+
140
+ def position_on_next_line(child) # Flow
141
+ @current_position.x = @style.margin_left
142
+ @current_position.y += tallest_neighbor(child, @current_position.y).outer_height
143
+
144
+ child.x = child.style.margin_left + @current_position.x
145
+ child.y = child.style.margin_top + @current_position.y
146
+
147
+ child.recalculate
148
+
149
+ @current_position.x += child.outer_width
150
+ end
151
+
152
+ def move_to_next_line(element) # Stack
153
+ element.x = element.style.margin_left + @current_position.x
154
+ element.y = element.style.margin_top + @current_position.y
155
+
156
+ element.recalculate
157
+
158
+ @current_position.y += element.outer_height
159
+ end
160
+
161
+ # def mouse_wheel_up(sender, x, y)
162
+ # @children.each {|c| c.y -= @scroll_speed}
163
+ # @children.each {|c| c.recalculate}
164
+ # end
165
+
166
+ # def mouse_wheel_down(sender, x, y)
167
+ # @children.each {|c| c.y += @scroll_speed}
168
+ # @children.each {|c| c.recalculate}
169
+ # end
170
+
171
+ def value
172
+ @children.map {|c| c.class}.join(", ")
173
+ end
174
+ end
175
+ end
176
+ end