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,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,176 +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 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
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