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,172 +1,172 @@
1
- module CyberarmEngine
2
- class Element
3
- class EditLine < Button
4
- def initialize(text, options = {}, block = nil)
5
- super(text, options, block)
6
-
7
- @type = default(:type)
8
-
9
- @caret_width = default(:caret_width)
10
- @caret_height= @text.height
11
- @caret_color = default(:caret_color)
12
- @caret_interval = default(:caret_interval)
13
- @caret_last_interval = Gosu.milliseconds
14
- @show_caret = true
15
-
16
- @text_input = Gosu::TextInput.new
17
- @text_input.text = text
18
-
19
- @offset_x = 0
20
-
21
- return self
22
- end
23
-
24
- def render
25
- Gosu.clip_to(@text.x, @text.y, @style.width, @text.height) do
26
- Gosu.translate(-@offset_x, 0) do
27
- draw_selection
28
- draw_caret if @focus && @show_caret
29
- draw_text
30
- end
31
- end
32
- end
33
-
34
- def draw_caret
35
- Gosu.draw_rect(caret_position, @text.y, @caret_width, @caret_height, @caret_color, @z)
36
- end
37
-
38
- def draw_selection
39
- selection_width = caret_position - selection_start_position
40
-
41
- Gosu.draw_rect(selection_start_position, @text.y, selection_width, @text.height, default(:selection_color), @z)
42
- end
43
-
44
- def update
45
- if @type == :password
46
- @text.text = default(:password_character) * @text_input.text.length
47
- else
48
- @text.text = @text_input.text
49
- end
50
-
51
- if Gosu.milliseconds >= @caret_last_interval + @caret_interval
52
- @caret_last_interval = Gosu.milliseconds
53
-
54
- @show_caret = !@show_caret
55
- end
56
-
57
- keep_caret_visible
58
- end
59
-
60
- def move_caret_to_mouse(mouse_x)
61
- 1.upto(@text.text.length) do |i|
62
- if mouse_x < @text.x + @text.textobject.text_width(@text.text[0...i])
63
- @text_input.caret_pos = @text_input.selection_start = i - 1;
64
- return
65
- end
66
- end
67
-
68
- @text_input.caret_pos = @text_input.selection_start = @text_input.text.length
69
- end
70
-
71
- def keep_caret_visible
72
- caret_pos = (caret_position - @text.x) + @caret_width
73
-
74
- @last_text ||= "/\\"
75
- @last_pos ||= -1
76
-
77
- puts "caret pos: #{caret_pos}, width: #{@width}, offset: #{@offset_x}" if (@last_text != @text.text) || (@last_pos != caret_pos)
78
-
79
- @last_text = @text.text
80
- @last_pos = caret_pos
81
-
82
-
83
- if caret_pos.between?(@offset_x, @width + @offset_x)
84
- # Do nothing
85
-
86
- elsif caret_pos < @offset_x
87
- if caret_pos > @width
88
- @offset_x = caret_pos + @width
89
- else
90
- @offset_x = 0
91
- end
92
-
93
- elsif caret_pos > @width
94
- @offset_x = caret_pos - @width
95
- puts "triggered"
96
-
97
- else
98
- # Reset to Zero
99
- @offset_x = 0
100
- end
101
- end
102
-
103
- def left_mouse_button(sender, x, y)
104
- super
105
- window.text_input = @text_input
106
-
107
- @caret_last_interval = Gosu.milliseconds
108
- @show_caret = true
109
-
110
- move_caret_to_mouse(x)
111
-
112
- return :handled
113
- end
114
-
115
- def enter(sender)
116
- if @focus
117
- @style.background_canvas.background = default(:active, :background)
118
- @text.color = default(:active, :color)
119
- else
120
- @style.background_canvas.background = default(:hover, :background)
121
- @text.color = default(:hover, :color)
122
- end
123
-
124
- return :handled
125
- end
126
-
127
- def leave(sender)
128
- unless @focus
129
- super
130
- end
131
-
132
- return :handled
133
- end
134
-
135
- def blur(sender)
136
- @focus = false
137
- @style.background_canvas.background = default(:background)
138
- @text.color = default(:color)
139
- window.text_input = nil
140
-
141
- return :handled
142
- end
143
-
144
- def caret_position
145
- text_input_position_for(:caret_pos)
146
- end
147
-
148
- def selection_start_position
149
- text_input_position_for(:selection_start)
150
- end
151
-
152
- def text_input_position_for(method)
153
- if @type == :password
154
- @text.x + @text.textobject.text_width(default(:password_character) * @text_input.text[0..@text_input.send(method)].length)
155
- else
156
- @text.x + @text.textobject.text_width(@text_input.text[0..@text_input.send(method)])
157
- end
158
- end
159
-
160
- def recalculate
161
- super
162
-
163
- @width = dimensional_size(@style.width, :width) || default(:width)
164
- update_background
165
- end
166
-
167
- def value
168
- @text_input.text
169
- end
170
- end
171
- end
1
+ module CyberarmEngine
2
+ class Element
3
+ class EditLine < Button
4
+ def initialize(text, options = {}, block = nil)
5
+ super(text, options, block)
6
+
7
+ @type = default(:type)
8
+
9
+ @caret_width = default(:caret_width)
10
+ @caret_height= @text.height
11
+ @caret_color = default(:caret_color)
12
+ @caret_interval = default(:caret_interval)
13
+ @caret_last_interval = Gosu.milliseconds
14
+ @show_caret = true
15
+
16
+ @text_input = Gosu::TextInput.new
17
+ @text_input.text = text
18
+
19
+ @offset_x = 0
20
+
21
+ return self
22
+ end
23
+
24
+ def render
25
+ Gosu.clip_to(@text.x, @text.y, @style.width, @text.height) do
26
+ Gosu.translate(-@offset_x, 0) do
27
+ draw_selection
28
+ draw_caret if @focus && @show_caret
29
+ draw_text
30
+ end
31
+ end
32
+ end
33
+
34
+ def draw_caret
35
+ Gosu.draw_rect(caret_position, @text.y, @caret_width, @caret_height, @caret_color, @z)
36
+ end
37
+
38
+ def draw_selection
39
+ selection_width = caret_position - selection_start_position
40
+
41
+ Gosu.draw_rect(selection_start_position, @text.y, selection_width, @text.height, default(:selection_color), @z)
42
+ end
43
+
44
+ def update
45
+ if @type == :password
46
+ @text.text = default(:password_character) * @text_input.text.length
47
+ else
48
+ @text.text = @text_input.text
49
+ end
50
+
51
+ if Gosu.milliseconds >= @caret_last_interval + @caret_interval
52
+ @caret_last_interval = Gosu.milliseconds
53
+
54
+ @show_caret = !@show_caret
55
+ end
56
+
57
+ keep_caret_visible
58
+ end
59
+
60
+ def move_caret_to_mouse(mouse_x)
61
+ 1.upto(@text.text.length) do |i|
62
+ if mouse_x < @text.x + @text.textobject.text_width(@text.text[0...i])
63
+ @text_input.caret_pos = @text_input.selection_start = i - 1;
64
+ return
65
+ end
66
+ end
67
+
68
+ @text_input.caret_pos = @text_input.selection_start = @text_input.text.length
69
+ end
70
+
71
+ def keep_caret_visible
72
+ caret_pos = (caret_position - @text.x) + @caret_width
73
+
74
+ @last_text ||= "/\\"
75
+ @last_pos ||= -1
76
+
77
+ puts "caret pos: #{caret_pos}, width: #{@width}, offset: #{@offset_x}" if (@last_text != @text.text) || (@last_pos != caret_pos)
78
+
79
+ @last_text = @text.text
80
+ @last_pos = caret_pos
81
+
82
+
83
+ if caret_pos.between?(@offset_x, @width + @offset_x)
84
+ # Do nothing
85
+
86
+ elsif caret_pos < @offset_x
87
+ if caret_pos > @width
88
+ @offset_x = caret_pos + @width
89
+ else
90
+ @offset_x = 0
91
+ end
92
+
93
+ elsif caret_pos > @width
94
+ @offset_x = caret_pos - @width
95
+ puts "triggered"
96
+
97
+ else
98
+ # Reset to Zero
99
+ @offset_x = 0
100
+ end
101
+ end
102
+
103
+ def left_mouse_button(sender, x, y)
104
+ super
105
+ window.text_input = @text_input
106
+
107
+ @caret_last_interval = Gosu.milliseconds
108
+ @show_caret = true
109
+
110
+ move_caret_to_mouse(x)
111
+
112
+ return :handled
113
+ end
114
+
115
+ def enter(sender)
116
+ if @focus
117
+ @style.background_canvas.background = default(:active, :background)
118
+ @text.color = default(:active, :color)
119
+ else
120
+ @style.background_canvas.background = default(:hover, :background)
121
+ @text.color = default(:hover, :color)
122
+ end
123
+
124
+ return :handled
125
+ end
126
+
127
+ def leave(sender)
128
+ unless @focus
129
+ super
130
+ end
131
+
132
+ return :handled
133
+ end
134
+
135
+ def blur(sender)
136
+ @focus = false
137
+ @style.background_canvas.background = default(:background)
138
+ @text.color = default(:color)
139
+ window.text_input = nil
140
+
141
+ return :handled
142
+ end
143
+
144
+ def caret_position
145
+ text_input_position_for(:caret_pos)
146
+ end
147
+
148
+ def selection_start_position
149
+ text_input_position_for(:selection_start)
150
+ end
151
+
152
+ def text_input_position_for(method)
153
+ if @type == :password
154
+ @text.x + @text.textobject.text_width(default(:password_character) * @text_input.text[0..@text_input.send(method)].length)
155
+ else
156
+ @text.x + @text.textobject.text_width(@text_input.text[0..@text_input.send(method)])
157
+ end
158
+ end
159
+
160
+ def recalculate
161
+ super
162
+
163
+ @width = dimensional_size(@style.width, :width) || default(:width)
164
+ update_background
165
+ end
166
+
167
+ def value
168
+ @text_input.text
169
+ end
170
+ end
171
+ end
172
172
  end
@@ -1,17 +1,17 @@
1
- module CyberarmEngine
2
- class Element
3
- class Flow < Container
4
- include Common
5
-
6
- def layout
7
- @children.each do |child|
8
- if fits_on_line?(child)
9
- position_on_current_line(child)
10
- else
11
- position_on_next_line(child)
12
- end
13
- end
14
- end
15
- end
16
- end
1
+ module CyberarmEngine
2
+ class Element
3
+ class Flow < Container
4
+ include Common
5
+
6
+ def layout
7
+ @children.each do |child|
8
+ if fits_on_line?(child)
9
+ position_on_current_line(child)
10
+ else
11
+ position_on_next_line(child)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
17
  end
@@ -1,52 +1,52 @@
1
- module CyberarmEngine
2
- class Element
3
- class Image < Element
4
- def initialize(path, options = {}, block = nil)
5
- super(options, block)
6
- @path = path
7
-
8
- @image = Gosu::Image.new(path, retro: @options[:image_retro])
9
- @scale_x, @scale_y = 1, 1
10
- end
11
-
12
- def render
13
- @image.draw(
14
- @style.border_thickness_left + @style.padding_left + @x,
15
- @style.border_thickness_top + @style.padding_top + @y,
16
- @z + 2,
17
- @scale_x, @scale_y) # TODO: Add color support?
18
- end
19
-
20
- def clicked_left_mouse_button(sender, x, y)
21
- @block.call(self) if @block
22
-
23
- return :handled
24
- end
25
-
26
- def recalculate
27
- _width = dimensional_size(@style.width, :width)
28
- _height= dimensional_size(@style.height,:height)
29
-
30
- if _width && _height
31
- @scale_x = _width.to_f / @image.width
32
- @scale_y = _height.to_f / @image.height
33
- elsif _width
34
- @scale_x = _width.to_f / @image.width
35
- @scale_y = @scale_x
36
- elsif _height
37
- @scale_y = _height.to_f / @image.height
38
- @scale_x = @scale_y
39
- else
40
- @scale_x, @scale_y = 1, 1
41
- end
42
-
43
- @width = _width ? _width : @image.width.round * @scale_x
44
- @height= _height ? _height : @image.height.round * @scale_y
45
- end
46
-
47
- def value
48
- @path
49
- end
50
- end
51
- end
1
+ module CyberarmEngine
2
+ class Element
3
+ class Image < Element
4
+ def initialize(path, options = {}, block = nil)
5
+ super(options, block)
6
+ @path = path
7
+
8
+ @image = Gosu::Image.new(path, retro: @options[:image_retro])
9
+ @scale_x, @scale_y = 1, 1
10
+ end
11
+
12
+ def render
13
+ @image.draw(
14
+ @style.border_thickness_left + @style.padding_left + @x,
15
+ @style.border_thickness_top + @style.padding_top + @y,
16
+ @z + 2,
17
+ @scale_x, @scale_y) # TODO: Add color support?
18
+ end
19
+
20
+ def clicked_left_mouse_button(sender, x, y)
21
+ @block.call(self) if @block
22
+
23
+ return :handled
24
+ end
25
+
26
+ def recalculate
27
+ _width = dimensional_size(@style.width, :width)
28
+ _height= dimensional_size(@style.height,:height)
29
+
30
+ if _width && _height
31
+ @scale_x = _width.to_f / @image.width
32
+ @scale_y = _height.to_f / @image.height
33
+ elsif _width
34
+ @scale_x = _width.to_f / @image.width
35
+ @scale_y = @scale_x
36
+ elsif _height
37
+ @scale_y = _height.to_f / @image.height
38
+ @scale_x = @scale_y
39
+ else
40
+ @scale_x, @scale_y = 1, 1
41
+ end
42
+
43
+ @width = _width ? _width : @image.width.round * @scale_x
44
+ @height= _height ? _height : @image.height.round * @scale_y
45
+ end
46
+
47
+ def value
48
+ @path
49
+ end
50
+ end
51
+ end
52
52
  end