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.
- checksums.yaml +4 -4
- data/.gitignore +8 -8
- data/.rubocop.yml +7 -7
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +74 -74
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cyberarm_engine.gemspec +39 -39
- data/lib/cyberarm_engine/animator.rb +219 -219
- data/lib/cyberarm_engine/background.rb +179 -179
- data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
- data/lib/cyberarm_engine/bounding_box.rb +150 -150
- data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
- data/lib/cyberarm_engine/cache/download_manager.rb +121 -121
- data/lib/cyberarm_engine/cache.rb +4 -4
- data/lib/cyberarm_engine/common.rb +113 -113
- data/lib/cyberarm_engine/config_file.rb +46 -46
- data/lib/cyberarm_engine/console/command.rb +157 -157
- data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
- data/lib/cyberarm_engine/console/subcommand.rb +99 -99
- data/lib/cyberarm_engine/console.rb +248 -248
- data/lib/cyberarm_engine/game_object.rb +248 -248
- data/lib/cyberarm_engine/game_state.rb +97 -97
- data/lib/cyberarm_engine/model/material.rb +21 -21
- data/lib/cyberarm_engine/model/model_object.rb +131 -131
- data/lib/cyberarm_engine/model/parser.rb +74 -74
- data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
- data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
- data/lib/cyberarm_engine/model.rb +212 -212
- data/lib/cyberarm_engine/model_cache.rb +31 -31
- data/lib/cyberarm_engine/opengl/light.rb +50 -50
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -38
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -164
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +298 -298
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -22
- data/lib/cyberarm_engine/opengl/shader.rb +406 -406
- data/lib/cyberarm_engine/opengl/texture.rb +69 -69
- data/lib/cyberarm_engine/opengl.rb +28 -28
- data/lib/cyberarm_engine/ray.rb +56 -56
- data/lib/cyberarm_engine/stats.rb +21 -21
- data/lib/cyberarm_engine/text.rb +197 -197
- data/lib/cyberarm_engine/timer.rb +23 -23
- data/lib/cyberarm_engine/transform.rb +296 -296
- data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
- data/lib/cyberarm_engine/ui/dsl.rb +139 -139
- data/lib/cyberarm_engine/ui/element.rb +488 -488
- data/lib/cyberarm_engine/ui/elements/button.rb +97 -97
- data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
- data/lib/cyberarm_engine/ui/elements/container.rb +256 -256
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +263 -263
- data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
- data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
- data/lib/cyberarm_engine/ui/elements/list_box.rb +88 -82
- data/lib/cyberarm_engine/ui/elements/progress.rb +51 -51
- data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/slider.rb +104 -104
- data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
- data/lib/cyberarm_engine/ui/elements/text_block.rb +162 -162
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +65 -65
- data/lib/cyberarm_engine/ui/event.rb +54 -54
- data/lib/cyberarm_engine/ui/gui_state.rb +256 -256
- data/lib/cyberarm_engine/ui/style.rb +49 -49
- data/lib/cyberarm_engine/ui/theme.rb +207 -207
- data/lib/cyberarm_engine/vector.rb +293 -293
- data/lib/cyberarm_engine/version.rb +4 -4
- data/lib/cyberarm_engine/window.rb +120 -120
- data/lib/cyberarm_engine.rb +71 -71
- metadata +3 -3
@@ -1,72 +1,72 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Element
|
3
|
-
class Image < Element
|
4
|
-
def initialize(path_or_image, options = {}, block = nil)
|
5
|
-
super(options, block)
|
6
|
-
@path = path_or_image if path_or_image.is_a?(String)
|
7
|
-
|
8
|
-
@image = Gosu::Image.new(path_or_image, retro: @options[:retro], tileable: @options[:tileable]) if @path
|
9
|
-
@image = path_or_image unless @path
|
10
|
-
|
11
|
-
@scale_x = 1
|
12
|
-
@scale_y = 1
|
13
|
-
end
|
14
|
-
|
15
|
-
def render
|
16
|
-
@image.draw(
|
17
|
-
@style.border_thickness_left + @style.padding_left + @x,
|
18
|
-
@style.border_thickness_top + @style.padding_top + @y,
|
19
|
-
@z + 2,
|
20
|
-
@scale_x, @scale_y, @style.color
|
21
|
-
)
|
22
|
-
end
|
23
|
-
|
24
|
-
def clicked_left_mouse_button(_sender, _x, _y)
|
25
|
-
@block.call(self) if @block
|
26
|
-
|
27
|
-
:handled
|
28
|
-
end
|
29
|
-
|
30
|
-
def recalculate
|
31
|
-
_width = dimensional_size(@style.width, :width)
|
32
|
-
_height = dimensional_size(@style.height, :height)
|
33
|
-
|
34
|
-
if _width && _height
|
35
|
-
@scale_x = _width.to_f / @image.width
|
36
|
-
@scale_y = _height.to_f / @image.height
|
37
|
-
elsif _width
|
38
|
-
@scale_x = _width.to_f / @image.width
|
39
|
-
@scale_y = @scale_x
|
40
|
-
elsif _height
|
41
|
-
@scale_y = _height.to_f / @image.height
|
42
|
-
@scale_x = @scale_y
|
43
|
-
else
|
44
|
-
@scale_x = 1
|
45
|
-
@scale_y = 1
|
46
|
-
end
|
47
|
-
|
48
|
-
@width = _width || @image.width.round * @scale_x
|
49
|
-
@height = _height || @image.height.round * @scale_y
|
50
|
-
|
51
|
-
update_background
|
52
|
-
end
|
53
|
-
|
54
|
-
def value
|
55
|
-
@image
|
56
|
-
end
|
57
|
-
|
58
|
-
def value=(path_or_image, retro: false, tileable: false)
|
59
|
-
@path = path_or_image if path_or_image.is_a?(String)
|
60
|
-
|
61
|
-
@image = Gosu::Image.new(path_or_image, retro: retro, tileable: tileable) if @path
|
62
|
-
@image = path_or_image unless @path
|
63
|
-
|
64
|
-
recalculate
|
65
|
-
end
|
66
|
-
|
67
|
-
def path
|
68
|
-
@path
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Element
|
3
|
+
class Image < Element
|
4
|
+
def initialize(path_or_image, options = {}, block = nil)
|
5
|
+
super(options, block)
|
6
|
+
@path = path_or_image if path_or_image.is_a?(String)
|
7
|
+
|
8
|
+
@image = Gosu::Image.new(path_or_image, retro: @options[:retro], tileable: @options[:tileable]) if @path
|
9
|
+
@image = path_or_image unless @path
|
10
|
+
|
11
|
+
@scale_x = 1
|
12
|
+
@scale_y = 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def render
|
16
|
+
@image.draw(
|
17
|
+
@style.border_thickness_left + @style.padding_left + @x,
|
18
|
+
@style.border_thickness_top + @style.padding_top + @y,
|
19
|
+
@z + 2,
|
20
|
+
@scale_x, @scale_y, @style.color
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def clicked_left_mouse_button(_sender, _x, _y)
|
25
|
+
@block.call(self) if @block
|
26
|
+
|
27
|
+
:handled
|
28
|
+
end
|
29
|
+
|
30
|
+
def recalculate
|
31
|
+
_width = dimensional_size(@style.width, :width)
|
32
|
+
_height = dimensional_size(@style.height, :height)
|
33
|
+
|
34
|
+
if _width && _height
|
35
|
+
@scale_x = _width.to_f / @image.width
|
36
|
+
@scale_y = _height.to_f / @image.height
|
37
|
+
elsif _width
|
38
|
+
@scale_x = _width.to_f / @image.width
|
39
|
+
@scale_y = @scale_x
|
40
|
+
elsif _height
|
41
|
+
@scale_y = _height.to_f / @image.height
|
42
|
+
@scale_x = @scale_y
|
43
|
+
else
|
44
|
+
@scale_x = 1
|
45
|
+
@scale_y = 1
|
46
|
+
end
|
47
|
+
|
48
|
+
@width = _width || @image.width.round * @scale_x
|
49
|
+
@height = _height || @image.height.round * @scale_y
|
50
|
+
|
51
|
+
update_background
|
52
|
+
end
|
53
|
+
|
54
|
+
def value
|
55
|
+
@image
|
56
|
+
end
|
57
|
+
|
58
|
+
def value=(path_or_image, retro: false, tileable: false)
|
59
|
+
@path = path_or_image if path_or_image.is_a?(String)
|
60
|
+
|
61
|
+
@image = Gosu::Image.new(path_or_image, retro: retro, tileable: tileable) if @path
|
62
|
+
@image = path_or_image unless @path
|
63
|
+
|
64
|
+
recalculate
|
65
|
+
end
|
66
|
+
|
67
|
+
def path
|
68
|
+
@path
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -1,82 +1,88 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Element
|
3
|
-
class ListBox < Button
|
4
|
-
attr_accessor :items
|
5
|
-
attr_reader :choose
|
6
|
-
|
7
|
-
def initialize(options = {}, block = nil)
|
8
|
-
@items = options[:items] || []
|
9
|
-
@choose = options[:choose] || @items.first
|
10
|
-
|
11
|
-
super(@choose, options, block)
|
12
|
-
|
13
|
-
@style.background_canvas.background = default(:background)
|
14
|
-
|
15
|
-
# TODO: "Clean Up" into own class?
|
16
|
-
@menu = Stack.new(parent: parent, width: @options[:width], theme: @options[:theme])
|
17
|
-
@menu.define_singleton_method(:recalculate_menu) do
|
18
|
-
@x = @__list_box.x
|
19
|
-
@y = @__list_box.y + @__list_box.height
|
20
|
-
end
|
21
|
-
@menu.instance_variable_set(:"@__list_box", self)
|
22
|
-
|
23
|
-
def @menu.recalculate
|
24
|
-
super
|
25
|
-
|
26
|
-
recalculate_menu
|
27
|
-
end
|
28
|
-
|
29
|
-
self.choose = @choose
|
30
|
-
end
|
31
|
-
|
32
|
-
def choose=(item)
|
33
|
-
valid = @items.detect { |i| i == item }
|
34
|
-
raise "Invalid value '#{item}' for choose, valid options were: #{@items.map { |i| "#{i.inspect}" }.join(", ")}" unless valid
|
35
|
-
|
36
|
-
@choose = item
|
37
|
-
|
38
|
-
self.value = item.to_s
|
39
|
-
|
40
|
-
recalculate
|
41
|
-
end
|
42
|
-
|
43
|
-
def released_left_mouse_button(_sender, _x, _y)
|
44
|
-
show_menu
|
45
|
-
|
46
|
-
:handled
|
47
|
-
end
|
48
|
-
|
49
|
-
def
|
50
|
-
@
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
@
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
@menu
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
|
1
|
+
module CyberarmEngine
|
2
|
+
class Element
|
3
|
+
class ListBox < Button
|
4
|
+
attr_accessor :items
|
5
|
+
attr_reader :choose
|
6
|
+
|
7
|
+
def initialize(options = {}, block = nil)
|
8
|
+
@items = options[:items] || []
|
9
|
+
@choose = options[:choose] || @items.first
|
10
|
+
|
11
|
+
super(@choose, options, block)
|
12
|
+
|
13
|
+
@style.background_canvas.background = default(:background)
|
14
|
+
|
15
|
+
# TODO: "Clean Up" into own class?
|
16
|
+
@menu = Stack.new(parent: parent, width: @options[:width], theme: @options[:theme])
|
17
|
+
@menu.define_singleton_method(:recalculate_menu) do
|
18
|
+
@x = @__list_box.x
|
19
|
+
@y = @__list_box.y + @__list_box.height
|
20
|
+
end
|
21
|
+
@menu.instance_variable_set(:"@__list_box", self)
|
22
|
+
|
23
|
+
def @menu.recalculate
|
24
|
+
super
|
25
|
+
|
26
|
+
recalculate_menu
|
27
|
+
end
|
28
|
+
|
29
|
+
self.choose = @choose
|
30
|
+
end
|
31
|
+
|
32
|
+
def choose=(item)
|
33
|
+
valid = @items.detect { |i| i == item }
|
34
|
+
raise "Invalid value '#{item}' for choose, valid options were: #{@items.map { |i| "#{i.inspect}" }.join(", ")}" unless valid
|
35
|
+
|
36
|
+
@choose = item
|
37
|
+
|
38
|
+
self.value = item.to_s
|
39
|
+
|
40
|
+
recalculate
|
41
|
+
end
|
42
|
+
|
43
|
+
def released_left_mouse_button(_sender, _x, _y)
|
44
|
+
show_menu
|
45
|
+
|
46
|
+
:handled
|
47
|
+
end
|
48
|
+
|
49
|
+
def clicked_left_mouse_button(_sender, _x, _y)
|
50
|
+
@block&.call(self.value) if @enabled
|
51
|
+
|
52
|
+
:handled
|
53
|
+
end
|
54
|
+
|
55
|
+
def show_menu
|
56
|
+
@menu.clear
|
57
|
+
|
58
|
+
@items.each do |item|
|
59
|
+
btn = Button.new(
|
60
|
+
item,
|
61
|
+
{
|
62
|
+
parent: @menu,
|
63
|
+
width: 1.0,
|
64
|
+
theme: @options[:theme],
|
65
|
+
margin: 0,
|
66
|
+
border_color: 0x00ffffff
|
67
|
+
},
|
68
|
+
proc do
|
69
|
+
self.choose = item
|
70
|
+
@block&.call(self.value)
|
71
|
+
end
|
72
|
+
)
|
73
|
+
|
74
|
+
@menu.add(btn)
|
75
|
+
end
|
76
|
+
recalculate
|
77
|
+
|
78
|
+
root.gui_state.show_menu(@menu)
|
79
|
+
end
|
80
|
+
|
81
|
+
def recalculate
|
82
|
+
super
|
83
|
+
|
84
|
+
@menu.recalculate
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -1,51 +1,51 @@
|
|
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] || 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
|
-
publish(:changed, @fraction)
|
47
|
-
@fraction
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
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] || 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
|
+
publish(:changed, @fraction)
|
47
|
+
@fraction
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Element
|
3
|
-
class Radio < Element
|
4
|
-
end
|
5
|
-
end
|
6
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Element
|
3
|
+
class Radio < Element
|
4
|
+
end
|
5
|
+
end
|
6
|
+
end
|
@@ -1,104 +1,104 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Element
|
3
|
-
class Slider < Container
|
4
|
-
class Handle < Button
|
5
|
-
def initialize(*args)
|
6
|
-
super(*args)
|
7
|
-
|
8
|
-
event(:begin_drag)
|
9
|
-
event(:drag_update)
|
10
|
-
event(:end_drag)
|
11
|
-
|
12
|
-
subscribe :begin_drag do |_sender, x, y, _button|
|
13
|
-
@drag_start_pos = Vector.new(x, y)
|
14
|
-
|
15
|
-
:handled
|
16
|
-
end
|
17
|
-
|
18
|
-
subscribe :drag_update do |_sender, x, y, _button|
|
19
|
-
@parent.handle_dragged_to(x, y)
|
20
|
-
|
21
|
-
:handled
|
22
|
-
end
|
23
|
-
|
24
|
-
subscribe :end_drag do
|
25
|
-
@drag_start_pos = nil
|
26
|
-
|
27
|
-
:handled
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def draggable?(button)
|
32
|
-
button == :left
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
attr_reader :range, :step_size, :value
|
37
|
-
|
38
|
-
def initialize(options = {}, block = nil)
|
39
|
-
super(options, block)
|
40
|
-
|
41
|
-
@range = @options[:range] || (0.0..1.0)
|
42
|
-
@step_size = @options[:step] || 0.1
|
43
|
-
@value = @options[:value] || (@range.first + @range.last) / 2
|
44
|
-
|
45
|
-
@handle = Handle.new("", parent: self, width: 8, height: 1.0) { close }
|
46
|
-
add(@handle)
|
47
|
-
end
|
48
|
-
|
49
|
-
def recalculate
|
50
|
-
_width = dimensional_size(@style.width, :width)
|
51
|
-
_height = dimensional_size(@style.height, :height)
|
52
|
-
|
53
|
-
@width = _width
|
54
|
-
@height = _height
|
55
|
-
|
56
|
-
position_handle
|
57
|
-
@handle.recalculate
|
58
|
-
@handle.update_background
|
59
|
-
|
60
|
-
update_background
|
61
|
-
end
|
62
|
-
|
63
|
-
def position_handle
|
64
|
-
@handle.x = @x + @style.padding_left + @style.border_thickness_left +
|
65
|
-
((content_width - @handle.outer_width) * (@value - @range.min) / (@range.max - @range.min).to_f)
|
66
|
-
|
67
|
-
@handle.y = @y + @style.border_thickness_top + @style.padding_top
|
68
|
-
end
|
69
|
-
|
70
|
-
def draw
|
71
|
-
super
|
72
|
-
|
73
|
-
@handle.draw
|
74
|
-
end
|
75
|
-
|
76
|
-
def update
|
77
|
-
super
|
78
|
-
|
79
|
-
@tip = value.to_s
|
80
|
-
@handle.tip = @tip
|
81
|
-
end
|
82
|
-
|
83
|
-
def holding_left_mouse_button(_sender, x, y)
|
84
|
-
handle_dragged_to(x, y)
|
85
|
-
|
86
|
-
:handled
|
87
|
-
end
|
88
|
-
|
89
|
-
def handle_dragged_to(x, _y)
|
90
|
-
@ratio = ((x - @handle.width / 2) - @x) / (content_width - @handle.outer_width)
|
91
|
-
|
92
|
-
self.value = @ratio.clamp(0.0, 1.0) * (@range.max - @range.min) + @range.min
|
93
|
-
end
|
94
|
-
|
95
|
-
def value=(n)
|
96
|
-
@value = n
|
97
|
-
position_handle
|
98
|
-
@handle.recalculate
|
99
|
-
|
100
|
-
publish(:changed, @value)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Element
|
3
|
+
class Slider < Container
|
4
|
+
class Handle < Button
|
5
|
+
def initialize(*args)
|
6
|
+
super(*args)
|
7
|
+
|
8
|
+
event(:begin_drag)
|
9
|
+
event(:drag_update)
|
10
|
+
event(:end_drag)
|
11
|
+
|
12
|
+
subscribe :begin_drag do |_sender, x, y, _button|
|
13
|
+
@drag_start_pos = Vector.new(x, y)
|
14
|
+
|
15
|
+
:handled
|
16
|
+
end
|
17
|
+
|
18
|
+
subscribe :drag_update do |_sender, x, y, _button|
|
19
|
+
@parent.handle_dragged_to(x, y)
|
20
|
+
|
21
|
+
:handled
|
22
|
+
end
|
23
|
+
|
24
|
+
subscribe :end_drag do
|
25
|
+
@drag_start_pos = nil
|
26
|
+
|
27
|
+
:handled
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def draggable?(button)
|
32
|
+
button == :left
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_reader :range, :step_size, :value
|
37
|
+
|
38
|
+
def initialize(options = {}, block = nil)
|
39
|
+
super(options, block)
|
40
|
+
|
41
|
+
@range = @options[:range] || (0.0..1.0)
|
42
|
+
@step_size = @options[:step] || 0.1
|
43
|
+
@value = @options[:value] || (@range.first + @range.last) / 2
|
44
|
+
|
45
|
+
@handle = Handle.new("", parent: self, width: 8, height: 1.0) { close }
|
46
|
+
add(@handle)
|
47
|
+
end
|
48
|
+
|
49
|
+
def recalculate
|
50
|
+
_width = dimensional_size(@style.width, :width)
|
51
|
+
_height = dimensional_size(@style.height, :height)
|
52
|
+
|
53
|
+
@width = _width
|
54
|
+
@height = _height
|
55
|
+
|
56
|
+
position_handle
|
57
|
+
@handle.recalculate
|
58
|
+
@handle.update_background
|
59
|
+
|
60
|
+
update_background
|
61
|
+
end
|
62
|
+
|
63
|
+
def position_handle
|
64
|
+
@handle.x = @x + @style.padding_left + @style.border_thickness_left +
|
65
|
+
((content_width - @handle.outer_width) * (@value - @range.min) / (@range.max - @range.min).to_f)
|
66
|
+
|
67
|
+
@handle.y = @y + @style.border_thickness_top + @style.padding_top
|
68
|
+
end
|
69
|
+
|
70
|
+
def draw
|
71
|
+
super
|
72
|
+
|
73
|
+
@handle.draw
|
74
|
+
end
|
75
|
+
|
76
|
+
def update
|
77
|
+
super
|
78
|
+
|
79
|
+
@tip = value.to_s
|
80
|
+
@handle.tip = @tip
|
81
|
+
end
|
82
|
+
|
83
|
+
def holding_left_mouse_button(_sender, x, y)
|
84
|
+
handle_dragged_to(x, y)
|
85
|
+
|
86
|
+
:handled
|
87
|
+
end
|
88
|
+
|
89
|
+
def handle_dragged_to(x, _y)
|
90
|
+
@ratio = ((x - @handle.width / 2) - @x) / (content_width - @handle.outer_width)
|
91
|
+
|
92
|
+
self.value = @ratio.clamp(0.0, 1.0) * (@range.max - @range.min) + @range.min
|
93
|
+
end
|
94
|
+
|
95
|
+
def value=(n)
|
96
|
+
@value = n
|
97
|
+
position_handle
|
98
|
+
@handle.recalculate
|
99
|
+
|
100
|
+
publish(:changed, @value)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Element
|
3
|
-
class Stack < Container
|
4
|
-
def layout
|
5
|
-
@children.each do |child|
|
6
|
-
move_to_next_line(child)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Element
|
3
|
+
class Stack < Container
|
4
|
+
def layout
|
5
|
+
@children.each do |child|
|
6
|
+
move_to_next_line(child)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|