cyberarm_engine 0.13.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
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,50 +1,50 @@
1
- module CyberarmEngine
2
- class Element
3
- class Label < Element
4
- def initialize(text, options = {}, block = nil)
5
- super(options, block)
6
-
7
- @text = Text.new(text, font: @options[:font], z: @z, color: @options[:color], size: @options[:text_size], shadow: @options[:text_shadow])
8
- end
9
-
10
- def render
11
- @text.draw
12
- end
13
-
14
- def clicked_left_mouse_button(sender, x, y)
15
- @block.call(self) if @block
16
-
17
- return :handled
18
- end
19
-
20
- def recalculate
21
- @width, @height = 0, 0
22
-
23
- _width = dimensional_size(@style.width, :width)
24
- _height= dimensional_size(@style.height,:height)
25
-
26
- @width = _width ? _width : @text.width.round
27
- @height= _height ? _height : @text.height.round
28
-
29
- @text.x = @style.border_thickness_left + @style.padding_left + @x
30
- @text.y = @style.border_thickness_top + @style.padding_top + @y
31
- @text.z = @z + 3
32
-
33
- update_background
34
- end
35
-
36
- def value
37
- @text.text
38
- end
39
-
40
- def value=(value)
41
- @text.text = value
42
-
43
- old_width, old_height = width, height
44
- recalculate
45
-
46
- root.gui_state.request_recalculate if old_width != width || old_height != height
47
- end
48
- end
49
- end
1
+ module CyberarmEngine
2
+ class Element
3
+ class Label < Element
4
+ def initialize(text, options = {}, block = nil)
5
+ super(options, block)
6
+
7
+ @text = Text.new(text, font: @options[:font], z: @z, color: @options[:color], size: @options[:text_size], shadow: @options[:text_shadow])
8
+ end
9
+
10
+ def render
11
+ @text.draw
12
+ end
13
+
14
+ def clicked_left_mouse_button(sender, x, y)
15
+ @block.call(self) if @block
16
+
17
+ return :handled
18
+ end
19
+
20
+ def recalculate
21
+ @width, @height = 0, 0
22
+
23
+ _width = dimensional_size(@style.width, :width)
24
+ _height= dimensional_size(@style.height,:height)
25
+
26
+ @width = _width ? _width : @text.width.round
27
+ @height= _height ? _height : @text.height.round
28
+
29
+ @text.x = @style.border_thickness_left + @style.padding_left + @x
30
+ @text.y = @style.border_thickness_top + @style.padding_top + @y
31
+ @text.z = @z + 3
32
+
33
+ update_background
34
+ end
35
+
36
+ def value
37
+ @text.text
38
+ end
39
+
40
+ def value=(value)
41
+ @text.text = value
42
+
43
+ old_width, old_height = width, height
44
+ recalculate
45
+
46
+ root.gui_state.request_recalculate if old_width != width || old_height != height
47
+ end
48
+ end
49
+ end
50
50
  end
@@ -1,50 +1,50 @@
1
- module CyberarmEngine
2
- class Element
3
- class Progress < Element
4
- def initialize(options = {}, block = nil)
5
- super(options, block)
6
-
7
- @fraction_background = Background.new(background: @style.fraction_background)
8
- self.value = options[:fraction] ? options[:fraction] : 0.0
9
- end
10
-
11
- def render
12
- @fraction_background.draw
13
- end
14
-
15
- def recalculate
16
- _width = dimensional_size(@style.width, :width)
17
- _height= dimensional_size(@style.height,:height)
18
- @width = _width
19
- @height= _height
20
-
21
- update_background
22
- end
23
-
24
- def update_background
25
- super
26
-
27
- @fraction_background.x = @style.border_thickness_left + @style.padding_left + @x
28
- @fraction_background.y = @style.border_thickness_top + @style.padding_top + @y
29
- @fraction_background.z = @z
30
- @fraction_background.width = @width * @fraction
31
- @fraction_background.height = @height
32
-
33
- @fraction_background.background = @style.fraction_background
34
- end
35
-
36
- def value
37
- @fraction
38
- end
39
-
40
- def value=(decimal)
41
- raise "value must be number" unless decimal.is_a?(Numeric)
42
-
43
- @fraction = decimal.clamp(0.0, 1.0)
44
- update_background
45
-
46
- return @fraction
47
- end
48
- end
49
- end
1
+ module CyberarmEngine
2
+ class Element
3
+ class Progress < Element
4
+ def initialize(options = {}, block = nil)
5
+ super(options, block)
6
+
7
+ @fraction_background = Background.new(background: @style.fraction_background)
8
+ self.value = options[:fraction] ? options[:fraction] : 0.0
9
+ end
10
+
11
+ def render
12
+ @fraction_background.draw
13
+ end
14
+
15
+ def recalculate
16
+ _width = dimensional_size(@style.width, :width)
17
+ _height= dimensional_size(@style.height,:height)
18
+ @width = _width
19
+ @height= _height
20
+
21
+ update_background
22
+ end
23
+
24
+ def update_background
25
+ super
26
+
27
+ @fraction_background.x = @style.border_thickness_left + @style.padding_left + @x
28
+ @fraction_background.y = @style.border_thickness_top + @style.padding_top + @y
29
+ @fraction_background.z = @z
30
+ @fraction_background.width = @width * @fraction
31
+ @fraction_background.height = @height
32
+
33
+ @fraction_background.background = @style.fraction_background
34
+ end
35
+
36
+ def value
37
+ @fraction
38
+ end
39
+
40
+ def value=(decimal)
41
+ raise "value must be number" unless decimal.is_a?(Numeric)
42
+
43
+ @fraction = decimal.clamp(0.0, 1.0)
44
+ update_background
45
+
46
+ return @fraction
47
+ end
48
+ end
49
+ end
50
50
  end
@@ -1,13 +1,13 @@
1
- module CyberarmEngine
2
- class Element
3
- class Stack < Container
4
- include Common
5
-
6
- def layout
7
- @children.each do |child|
8
- move_to_next_line(child)
9
- end
10
- end
11
- end
12
- end
1
+ module CyberarmEngine
2
+ class Element
3
+ class Stack < Container
4
+ include Common
5
+
6
+ def layout
7
+ @children.each do |child|
8
+ move_to_next_line(child)
9
+ end
10
+ end
11
+ end
12
+ end
13
13
  end
@@ -1,56 +1,56 @@
1
- module CyberarmEngine
2
- class Element
3
- class ToggleButton < Button
4
- attr_reader :toggled
5
-
6
- def initialize(options, block = nil)
7
- super(options[:checkmark], options, block)
8
- @toggled = options[:toggled] || false
9
- if @toggled
10
- @text.text = @options[:checkmark]
11
- else
12
- @text.text = ""
13
- end
14
-
15
- return self
16
- end
17
-
18
- def toggled=(boolean)
19
- @toggled = !boolean
20
- toggle
21
- end
22
-
23
- def clicked_left_mouse_button(sender, x, y)
24
- toggle
25
-
26
- @block.call(self) if @block
27
-
28
- return :handled
29
- end
30
-
31
- def toggle
32
- if @toggled
33
- @toggled = false
34
- @text.text = ""
35
- else
36
- @toggled = true
37
- @text.text = @options[:checkmark]
38
- end
39
- end
40
-
41
- def recalculate
42
- super
43
-
44
- _width = dimensional_size(@style.width, :width)
45
- _height= dimensional_size(@style.height,:height)
46
- @width = _width ? _width : @text.textobject.text_width(@options[:checkmark])
47
- @height = _height ? _height : @text.height
48
- update_background
49
- end
50
-
51
- def value
52
- @toggled
53
- end
54
- end
55
- end
1
+ module CyberarmEngine
2
+ class Element
3
+ class ToggleButton < Button
4
+ attr_reader :toggled
5
+
6
+ def initialize(options, block = nil)
7
+ super(options[:checkmark], options, block)
8
+ @toggled = options[:toggled] || false
9
+ if @toggled
10
+ @text.text = @options[:checkmark]
11
+ else
12
+ @text.text = ""
13
+ end
14
+
15
+ return self
16
+ end
17
+
18
+ def toggled=(boolean)
19
+ @toggled = !boolean
20
+ toggle
21
+ end
22
+
23
+ def clicked_left_mouse_button(sender, x, y)
24
+ toggle
25
+
26
+ @block.call(self) if @block
27
+
28
+ return :handled
29
+ end
30
+
31
+ def toggle
32
+ if @toggled
33
+ @toggled = false
34
+ @text.text = ""
35
+ else
36
+ @toggled = true
37
+ @text.text = @options[:checkmark]
38
+ end
39
+ end
40
+
41
+ def recalculate
42
+ super
43
+
44
+ _width = dimensional_size(@style.width, :width)
45
+ _height= dimensional_size(@style.height,:height)
46
+ @width = _width ? _width : @text.textobject.text_width(@options[:checkmark])
47
+ @height = _height ? _height : @text.height
48
+ update_background
49
+ end
50
+
51
+ def value
52
+ @toggled
53
+ end
54
+ end
55
+ end
56
56
  end
@@ -1,47 +1,47 @@
1
- module CyberarmEngine
2
- module Event # Gets included into Element
3
- def subscribe(event, method = nil, &block)
4
- handler = method || block
5
- @event_handler[event] << handler
6
-
7
- Subscription.new(self, event, handler)
8
- end
9
-
10
- def unsubscribe(subscription)
11
- end
12
-
13
- def publish(event, *args)
14
- raise ArgumentError, "#{self.class} does not handle #{event.inspect}" unless @event_handler.include?(event)
15
-
16
- return unless enabled?
17
-
18
- if respond_to?(event)
19
- return :handled if send(event, self, *args) == :handled
20
- end
21
-
22
- @event_handler[event].reverse_each do |handler|
23
- return :handled if handler.call(self, *args) == :handled
24
- end
25
-
26
- parent.publish(event, *args) if parent
27
- return nil
28
- end
29
-
30
- def event(event)
31
- @event_handler ||= Hash.new
32
- @event_handler[event] ||= []
33
- end
34
- end
35
-
36
- class Subscription
37
- attr_reader :publisher, :event, :handler
38
-
39
- def initialize(publisher, event, handler)
40
- @publisher, @event, @handler = publisher, event, handler
41
- end
42
-
43
- def unsubscribe
44
- @publisher.unsubscribe(self)
45
- end
46
- end
1
+ module CyberarmEngine
2
+ module Event # Gets included into Element
3
+ def subscribe(event, method = nil, &block)
4
+ handler = method || block
5
+ @event_handler[event] << handler
6
+
7
+ Subscription.new(self, event, handler)
8
+ end
9
+
10
+ def unsubscribe(subscription)
11
+ end
12
+
13
+ def publish(event, *args)
14
+ raise ArgumentError, "#{self.class} does not handle #{event.inspect}" unless @event_handler.include?(event)
15
+
16
+ return unless enabled?
17
+
18
+ if respond_to?(event)
19
+ return :handled if send(event, self, *args) == :handled
20
+ end
21
+
22
+ @event_handler[event].reverse_each do |handler|
23
+ return :handled if handler.call(self, *args) == :handled
24
+ end
25
+
26
+ parent.publish(event, *args) if parent
27
+ return nil
28
+ end
29
+
30
+ def event(event)
31
+ @event_handler ||= Hash.new
32
+ @event_handler[event] ||= []
33
+ end
34
+ end
35
+
36
+ class Subscription
37
+ attr_reader :publisher, :event, :handler
38
+
39
+ def initialize(publisher, event, handler)
40
+ @publisher, @event, @handler = publisher, event, handler
41
+ end
42
+
43
+ def unsubscribe
44
+ @publisher.unsubscribe(self)
45
+ end
46
+ end
47
47
  end
@@ -1,135 +1,135 @@
1
- module CyberarmEngine
2
- class GuiState < GameState
3
- include Common
4
- include DSL
5
-
6
- def initialize(options = {})
7
- @options = options
8
- @game_objects = []
9
- @global_pause = false
10
-
11
- @down_keys = {}
12
-
13
- @root_container = Element::Stack.new(gui_state: self)
14
- @game_objects << @root_container
15
- $__current_container__ = @root_container
16
-
17
- @active_width = window.width
18
- @active_height = window.height
19
-
20
- @focus = nil
21
- @mouse_over = nil
22
- @mouse_down_on = {}
23
- @mouse_down_position = {}
24
- @pending_recalculate_request = false
25
- end
26
-
27
- # throws :blur event to focused element and sets GuiState focused element
28
- # Does NOT throw :focus event at element or set element as focused
29
- def focus=(element)
30
- @focus.publish(:blur) if @focus and element && @focus != element
31
- @focus = element
32
- end
33
-
34
- def focused
35
- @focus
36
- end
37
-
38
- def update
39
- if @pending_recalculate_request
40
- @root_container.recalculate
41
- @pending_recalculate_request = false
42
- end
43
-
44
- super
45
-
46
- new_mouse_over = @root_container.hit_element?(window.mouse_x, window.mouse_y)
47
- if new_mouse_over
48
- new_mouse_over.publish(:enter) if new_mouse_over != @mouse_over
49
- new_mouse_over.publish(:hover)
50
- # puts "#{new_mouse_over.class}[#{new_mouse_over.value}]: #{new_mouse_over.x}:#{new_mouse_over.y} #{new_mouse_over.width}:#{new_mouse_over.height}" if new_mouse_over != @mouse_over
51
- end
52
- @mouse_over.publish(:leave) if @mouse_over && new_mouse_over != @mouse_over
53
- @mouse_over = new_mouse_over
54
-
55
- redirect_holding_mouse_button(:left) if @mouse_over && Gosu.button_down?(Gosu::MsLeft)
56
- redirect_holding_mouse_button(:middle) if @mouse_over && Gosu.button_down?(Gosu::MsMiddle)
57
- redirect_holding_mouse_button(:right) if @mouse_over && Gosu.button_down?(Gosu::MsRight)
58
-
59
- request_recalculate if @active_width != window.width || @active_height != window.height
60
-
61
- @active_width = window.width
62
- @active_height = window.height
63
- end
64
-
65
- def button_down(id)
66
- super
67
-
68
- case id
69
- when Gosu::MsLeft
70
- redirect_mouse_button(:left)
71
- when Gosu::MsMiddle
72
- redirect_mouse_button(:middle)
73
- when Gosu::MsRight
74
- redirect_mouse_button(:right)
75
- end
76
- end
77
-
78
- def button_up(id)
79
- super
80
-
81
- case id
82
- when Gosu::MsLeft
83
- redirect_released_mouse_button(:left)
84
- when Gosu::MsMiddle
85
- redirect_released_mouse_button(:middle)
86
- when Gosu::MsRight
87
- redirect_released_mouse_button(:right)
88
- when Gosu::MsWheelUp
89
- redirect_mouse_wheel(:up)
90
- when Gosu::MsWheelDown
91
- redirect_mouse_wheel(:down)
92
- end
93
- end
94
-
95
- def redirect_mouse_button(button)
96
- if @focus && @mouse_over != @focus
97
- @focus.publish(:blur)
98
- @focus = nil
99
- end
100
-
101
- if @mouse_over
102
- @mouse_down_position[button] = Vector.new(window.mouse_x, window.mouse_y)
103
- @mouse_down_on[button] = @mouse_over
104
-
105
- @mouse_over.publish(:"#{button}_mouse_button", window.mouse_x, window.mouse_y)
106
- else
107
- @mouse_down_position[button] = nil
108
- @mouse_down_on[button] = nil
109
- end
110
- end
111
-
112
- def redirect_released_mouse_button(button)
113
- if @mouse_over
114
- @mouse_over.publish(:"released_#{button}_mouse_button", window.mouse_x, window.mouse_y)
115
- @mouse_over.publish(:"clicked_#{button}_mouse_button", window.mouse_x, window.mouse_y) if @mouse_over == @mouse_down_on[button]
116
- end
117
-
118
- @mouse_down_position[button] = nil
119
- @mouse_down_on[button] = nil
120
- end
121
-
122
- def redirect_holding_mouse_button(button)
123
- @mouse_over.publish(:"holding_#{button}_mouse_button", window.mouse_x, window.mouse_y) if @mouse_over
124
- end
125
-
126
- def redirect_mouse_wheel(button)
127
- @mouse_over.publish(:"mouse_wheel_#{button}", window.mouse_x, window.mouse_y) if @mouse_over
128
- end
129
-
130
- # Schedule a full GUI recalculation on next update
131
- def request_recalculate
132
- @pending_recalculate_request = true
133
- end
134
- end
1
+ module CyberarmEngine
2
+ class GuiState < GameState
3
+ include Common
4
+ include DSL
5
+
6
+ def initialize(options = {})
7
+ @options = options
8
+ @game_objects = []
9
+ @global_pause = false
10
+
11
+ @down_keys = {}
12
+
13
+ @root_container = Element::Stack.new(gui_state: self)
14
+ @game_objects << @root_container
15
+ $__current_container__ = @root_container
16
+
17
+ @active_width = window.width
18
+ @active_height = window.height
19
+
20
+ @focus = nil
21
+ @mouse_over = nil
22
+ @mouse_down_on = {}
23
+ @mouse_down_position = {}
24
+ @pending_recalculate_request = false
25
+ end
26
+
27
+ # throws :blur event to focused element and sets GuiState focused element
28
+ # Does NOT throw :focus event at element or set element as focused
29
+ def focus=(element)
30
+ @focus.publish(:blur) if @focus and element && @focus != element
31
+ @focus = element
32
+ end
33
+
34
+ def focused
35
+ @focus
36
+ end
37
+
38
+ def update
39
+ if @pending_recalculate_request
40
+ @root_container.recalculate
41
+ @pending_recalculate_request = false
42
+ end
43
+
44
+ super
45
+
46
+ new_mouse_over = @root_container.hit_element?(window.mouse_x, window.mouse_y)
47
+ if new_mouse_over
48
+ new_mouse_over.publish(:enter) if new_mouse_over != @mouse_over
49
+ new_mouse_over.publish(:hover)
50
+ # puts "#{new_mouse_over.class}[#{new_mouse_over.value}]: #{new_mouse_over.x}:#{new_mouse_over.y} #{new_mouse_over.width}:#{new_mouse_over.height}" if new_mouse_over != @mouse_over
51
+ end
52
+ @mouse_over.publish(:leave) if @mouse_over && new_mouse_over != @mouse_over
53
+ @mouse_over = new_mouse_over
54
+
55
+ redirect_holding_mouse_button(:left) if @mouse_over && Gosu.button_down?(Gosu::MsLeft)
56
+ redirect_holding_mouse_button(:middle) if @mouse_over && Gosu.button_down?(Gosu::MsMiddle)
57
+ redirect_holding_mouse_button(:right) if @mouse_over && Gosu.button_down?(Gosu::MsRight)
58
+
59
+ request_recalculate if @active_width != window.width || @active_height != window.height
60
+
61
+ @active_width = window.width
62
+ @active_height = window.height
63
+ end
64
+
65
+ def button_down(id)
66
+ super
67
+
68
+ case id
69
+ when Gosu::MsLeft
70
+ redirect_mouse_button(:left)
71
+ when Gosu::MsMiddle
72
+ redirect_mouse_button(:middle)
73
+ when Gosu::MsRight
74
+ redirect_mouse_button(:right)
75
+ end
76
+ end
77
+
78
+ def button_up(id)
79
+ super
80
+
81
+ case id
82
+ when Gosu::MsLeft
83
+ redirect_released_mouse_button(:left)
84
+ when Gosu::MsMiddle
85
+ redirect_released_mouse_button(:middle)
86
+ when Gosu::MsRight
87
+ redirect_released_mouse_button(:right)
88
+ when Gosu::MsWheelUp
89
+ redirect_mouse_wheel(:up)
90
+ when Gosu::MsWheelDown
91
+ redirect_mouse_wheel(:down)
92
+ end
93
+ end
94
+
95
+ def redirect_mouse_button(button)
96
+ if @focus && @mouse_over != @focus
97
+ @focus.publish(:blur)
98
+ @focus = nil
99
+ end
100
+
101
+ if @mouse_over
102
+ @mouse_down_position[button] = Vector.new(window.mouse_x, window.mouse_y)
103
+ @mouse_down_on[button] = @mouse_over
104
+
105
+ @mouse_over.publish(:"#{button}_mouse_button", window.mouse_x, window.mouse_y)
106
+ else
107
+ @mouse_down_position[button] = nil
108
+ @mouse_down_on[button] = nil
109
+ end
110
+ end
111
+
112
+ def redirect_released_mouse_button(button)
113
+ if @mouse_over
114
+ @mouse_over.publish(:"released_#{button}_mouse_button", window.mouse_x, window.mouse_y)
115
+ @mouse_over.publish(:"clicked_#{button}_mouse_button", window.mouse_x, window.mouse_y) if @mouse_over == @mouse_down_on[button]
116
+ end
117
+
118
+ @mouse_down_position[button] = nil
119
+ @mouse_down_on[button] = nil
120
+ end
121
+
122
+ def redirect_holding_mouse_button(button)
123
+ @mouse_over.publish(:"holding_#{button}_mouse_button", window.mouse_x, window.mouse_y) if @mouse_over
124
+ end
125
+
126
+ def redirect_mouse_wheel(button)
127
+ @mouse_over.publish(:"mouse_wheel_#{button}", window.mouse_x, window.mouse_y) if @mouse_over
128
+ end
129
+
130
+ # Schedule a full GUI recalculation on next update
131
+ def request_recalculate
132
+ @pending_recalculate_request = true
133
+ end
134
+ end
135
135
  end