cyberarm_engine 0.8.1 → 0.9.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.
- checksums.yaml +4 -4
- data/lib/cyberarm_engine.rb +11 -10
- data/lib/cyberarm_engine/background.rb +12 -1
- data/lib/cyberarm_engine/engine.rb +1 -1
- data/lib/cyberarm_engine/ui/dsl.rb +17 -8
- data/lib/cyberarm_engine/ui/element.rb +27 -7
- data/lib/cyberarm_engine/ui/elements/button.rb +55 -0
- data/lib/cyberarm_engine/ui/elements/check_box.rb +59 -0
- data/lib/cyberarm_engine/ui/elements/container.rb +159 -0
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +92 -0
- data/lib/cyberarm_engine/ui/elements/flow.rb +17 -0
- data/lib/cyberarm_engine/ui/elements/image.rb +50 -0
- data/lib/cyberarm_engine/ui/elements/label.rb +45 -0
- data/lib/cyberarm_engine/ui/elements/progress.rb +50 -0
- data/lib/cyberarm_engine/ui/elements/stack.rb +13 -0
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +54 -0
- data/lib/cyberarm_engine/ui/gui_state.rb +20 -2
- data/lib/cyberarm_engine/ui/theme.rb +28 -3
- data/lib/cyberarm_engine/version.rb +1 -1
- metadata +13 -12
- data/lib/cyberarm_engine/ui/button.rb +0 -53
- data/lib/cyberarm_engine/ui/check_box.rb +0 -60
- data/lib/cyberarm_engine/ui/container.rb +0 -146
- data/lib/cyberarm_engine/ui/edit_line.rb +0 -90
- data/lib/cyberarm_engine/ui/flow.rb +0 -15
- data/lib/cyberarm_engine/ui/image.rb +0 -46
- data/lib/cyberarm_engine/ui/label.rb +0 -43
- data/lib/cyberarm_engine/ui/stack.rb +0 -11
- data/lib/cyberarm_engine/ui/toggle_button.rb +0 -49
@@ -1,53 +0,0 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Button < Label
|
3
|
-
def initialize(text, options = {}, block = nil)
|
4
|
-
super(text, options, block)
|
5
|
-
|
6
|
-
@style.background_canvas.background = default(:background)
|
7
|
-
end
|
8
|
-
|
9
|
-
def render
|
10
|
-
draw_text
|
11
|
-
end
|
12
|
-
|
13
|
-
def draw_text
|
14
|
-
@text.draw
|
15
|
-
end
|
16
|
-
|
17
|
-
def enter(sender)
|
18
|
-
@focus = false unless window.button_down?(Gosu::MsLeft)
|
19
|
-
|
20
|
-
if @focus
|
21
|
-
@style.background_canvas.background = default(:active, :background)
|
22
|
-
@text.color = default(:active, :color)
|
23
|
-
else
|
24
|
-
@style.background_canvas.background = default(:hover, :background)
|
25
|
-
@text.color = default(:hover, :color)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def left_mouse_button(sender, x, y)
|
30
|
-
@focus = true
|
31
|
-
@style.background_canvas.background = default(:active, :background)
|
32
|
-
window.current_state.focus = self
|
33
|
-
@text.color = default(:active, :color)
|
34
|
-
end
|
35
|
-
|
36
|
-
def released_left_mouse_button(sender,x, y)
|
37
|
-
enter(sender)
|
38
|
-
end
|
39
|
-
|
40
|
-
def clicked_left_mouse_button(sender, x, y)
|
41
|
-
@block.call(self) if @block
|
42
|
-
end
|
43
|
-
|
44
|
-
def leave(sender)
|
45
|
-
@style.background_canvas.background = default(:background)
|
46
|
-
@text.color = default(:color)
|
47
|
-
end
|
48
|
-
|
49
|
-
def blur(sender)
|
50
|
-
@focus = false
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class CheckBox < Flow
|
3
|
-
def initialize(text, options, block = nil)
|
4
|
-
super({}, block = nil)
|
5
|
-
options[:toggled] = options[:checked]
|
6
|
-
|
7
|
-
@toggle_button = ToggleButton.new(options)
|
8
|
-
@label = Label.new(text, options)
|
9
|
-
|
10
|
-
define_label_singletons
|
11
|
-
|
12
|
-
add(@toggle_button)
|
13
|
-
add(@label)
|
14
|
-
|
15
|
-
@style.width = @toggle_button.width + @label.width
|
16
|
-
@style.height = @toggle_button.height + @label.height
|
17
|
-
end
|
18
|
-
|
19
|
-
def text=(text)
|
20
|
-
@label.text = text
|
21
|
-
recalculate
|
22
|
-
end
|
23
|
-
|
24
|
-
def value
|
25
|
-
@toggle_button.value
|
26
|
-
end
|
27
|
-
|
28
|
-
def value=(bool)
|
29
|
-
@toggle_button.vlaue = bool
|
30
|
-
end
|
31
|
-
|
32
|
-
def define_label_singletons
|
33
|
-
@label.define_singleton_method(:_toggle_button) do |button|
|
34
|
-
@_toggle_button = button
|
35
|
-
end
|
36
|
-
|
37
|
-
@label._toggle_button(@toggle_button)
|
38
|
-
|
39
|
-
@label.define_singleton_method(:holding_left_mouse_button) do |sender, x, y|
|
40
|
-
@_toggle_button.left_mouse_button(sender, x, y)
|
41
|
-
end
|
42
|
-
|
43
|
-
@label.define_singleton_method(:released_left_mouse_button) do |sender, x, y|
|
44
|
-
@_toggle_button.released_left_mouse_button(sender, x, y)
|
45
|
-
end
|
46
|
-
|
47
|
-
@label.define_singleton_method(:clicked_left_mouse_button) do |sender, x, y|
|
48
|
-
@_toggle_button.clicked_left_mouse_button(sender, x, y)
|
49
|
-
end
|
50
|
-
|
51
|
-
@label.define_singleton_method(:enter) do |sender|
|
52
|
-
@_toggle_button.enter(sender)
|
53
|
-
end
|
54
|
-
|
55
|
-
@label.define_singleton_method(:leave) do |sender|
|
56
|
-
@_toggle_button.leave(sender)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,146 +0,0 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Container < Element
|
3
|
-
include Common
|
4
|
-
|
5
|
-
attr_accessor :stroke_color, :fill_color
|
6
|
-
attr_reader :children
|
7
|
-
attr_reader :scroll_x, :scroll_y
|
8
|
-
|
9
|
-
def initialize(options = {}, block = nil)
|
10
|
-
super
|
11
|
-
|
12
|
-
@scroll_x, @scroll_y = 0, 0
|
13
|
-
@scroll_speed = 10
|
14
|
-
|
15
|
-
@text_color = options[:color]
|
16
|
-
|
17
|
-
@children = []
|
18
|
-
end
|
19
|
-
|
20
|
-
def build
|
21
|
-
@block.call(self) if @block
|
22
|
-
|
23
|
-
recalculate
|
24
|
-
end
|
25
|
-
|
26
|
-
def add(element)
|
27
|
-
@children << element
|
28
|
-
|
29
|
-
recalculate
|
30
|
-
end
|
31
|
-
|
32
|
-
def render
|
33
|
-
@children.each(&:draw)
|
34
|
-
end
|
35
|
-
|
36
|
-
def update
|
37
|
-
@children.each(&:update)
|
38
|
-
end
|
39
|
-
|
40
|
-
def hit_element?(x, y)
|
41
|
-
@children.reverse_each do |child|
|
42
|
-
case child
|
43
|
-
when Container
|
44
|
-
if element = child.hit_element?(x, y)
|
45
|
-
return element
|
46
|
-
end
|
47
|
-
else
|
48
|
-
return child if child.hit?(x, y)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
self if hit?(x, y)
|
53
|
-
end
|
54
|
-
|
55
|
-
def recalculate
|
56
|
-
@current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
|
57
|
-
return unless visible?
|
58
|
-
stylize
|
59
|
-
|
60
|
-
layout
|
61
|
-
|
62
|
-
@style.width = @max_width ? @max_width : (@children.map {|c| c.x + c.outer_width }.max || 0).round
|
63
|
-
@style.height = @max_height ? @max_height : (@children.map {|c| c.y + c.outer_height}.max || 0).round
|
64
|
-
|
65
|
-
# Move child to parent after positioning
|
66
|
-
@children.each do |child|
|
67
|
-
child.x += @x
|
68
|
-
child.y += @y
|
69
|
-
|
70
|
-
child.stylize
|
71
|
-
child.recalculate
|
72
|
-
child.reposition # TODO: Implement top,bottom,left,center, and right positioning
|
73
|
-
end
|
74
|
-
|
75
|
-
update_background
|
76
|
-
end
|
77
|
-
|
78
|
-
def layout
|
79
|
-
raise "Not overridden"
|
80
|
-
end
|
81
|
-
|
82
|
-
def max_width
|
83
|
-
@max_width ? @max_width : window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
|
84
|
-
end
|
85
|
-
|
86
|
-
def fits_on_line?(element) # Flow
|
87
|
-
@current_position.x + element.outer_width <= max_width &&
|
88
|
-
@current_position.x + element.outer_width <= window.width
|
89
|
-
end
|
90
|
-
|
91
|
-
def position_on_current_line(element) # Flow
|
92
|
-
element.x = element.style.margin_left + @current_position.x
|
93
|
-
element.y = element.style.margin_top + @current_position.y
|
94
|
-
|
95
|
-
element.recalculate
|
96
|
-
|
97
|
-
@current_position.x += element.outer_width
|
98
|
-
@current_position.x = @style.margin_left if @current_position.x >= max_width
|
99
|
-
end
|
100
|
-
|
101
|
-
def tallest_neighbor(querier, y_position) # Flow
|
102
|
-
response = querier
|
103
|
-
@children.each do |child|
|
104
|
-
response = child if child.outer_height > response.outer_height
|
105
|
-
break if child == querier
|
106
|
-
end
|
107
|
-
|
108
|
-
return response
|
109
|
-
end
|
110
|
-
|
111
|
-
def position_on_next_line(child) # Flow
|
112
|
-
@current_position.x = @style.margin_left
|
113
|
-
@current_position.y += tallest_neighbor(child, @current_position.y).outer_height
|
114
|
-
|
115
|
-
child.x = child.style.margin_left + @current_position.x
|
116
|
-
child.y = child.style.margin_top + @current_position.y
|
117
|
-
|
118
|
-
child.recalculate
|
119
|
-
|
120
|
-
@current_position.x += child.outer_width
|
121
|
-
end
|
122
|
-
|
123
|
-
def move_to_next_line(element) # Stack
|
124
|
-
element.x = element.style.margin_left + @current_position.x
|
125
|
-
element.y = element.style.margin_top + @current_position.y
|
126
|
-
|
127
|
-
element.recalculate
|
128
|
-
|
129
|
-
@current_position.y += element.outer_height
|
130
|
-
end
|
131
|
-
|
132
|
-
# def mouse_wheel_up(sender, x, y)
|
133
|
-
# @children.each {|c| c.y -= @scroll_speed}
|
134
|
-
# @children.each {|c| c.recalculate}
|
135
|
-
# end
|
136
|
-
|
137
|
-
# def mouse_wheel_down(sender, x, y)
|
138
|
-
# @children.each {|c| c.y += @scroll_speed}
|
139
|
-
# @children.each {|c| c.recalculate}
|
140
|
-
# end
|
141
|
-
|
142
|
-
def value
|
143
|
-
@children.map {|c| c.class}.join(", ")
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class EditLine < Button
|
3
|
-
def initialize(text, options = {}, block = nil)
|
4
|
-
super(text, options, block)
|
5
|
-
|
6
|
-
@type = default(:type)
|
7
|
-
|
8
|
-
@caret_width = default(:caret_width)
|
9
|
-
@caret_height= @text.height
|
10
|
-
@caret_color = default(:caret_color)
|
11
|
-
@caret_interval = default(:caret_interval)
|
12
|
-
@caret_last_interval = Gosu.milliseconds
|
13
|
-
@show_caret = true
|
14
|
-
|
15
|
-
@text_input = Gosu::TextInput.new
|
16
|
-
@text_input.text = text
|
17
|
-
|
18
|
-
return self
|
19
|
-
end
|
20
|
-
|
21
|
-
def render
|
22
|
-
Gosu.clip_to(@text.x, @text.y, @style.width, @text.height) do
|
23
|
-
draw_text
|
24
|
-
Gosu.draw_rect(caret_position, @text.y, @caret_width, @caret_height, @caret_color, @z + 40) if @focus && @show_caret
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def update
|
29
|
-
if @type == :password
|
30
|
-
@text.text = default(:password_character) * @text_input.text.length
|
31
|
-
else
|
32
|
-
@text.text = @text_input.text
|
33
|
-
end
|
34
|
-
|
35
|
-
if Gosu.milliseconds >= @caret_last_interval + @caret_interval
|
36
|
-
@caret_last_interval = Gosu.milliseconds
|
37
|
-
|
38
|
-
@show_caret = !@show_caret
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def left_mouse_button(sender, x, y)
|
43
|
-
super
|
44
|
-
window.text_input = @text_input
|
45
|
-
end
|
46
|
-
|
47
|
-
def enter(sender)
|
48
|
-
if @focus
|
49
|
-
@style.background_canvas.background = default(:active, :background)
|
50
|
-
@text.color = default(:active, :color)
|
51
|
-
else
|
52
|
-
@style.background_canvas.background = default(:hover, :background)
|
53
|
-
@text.color = default(:hover, :color)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def leave(sender)
|
58
|
-
unless @focus
|
59
|
-
super
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def blur(sender)
|
64
|
-
@focus = false
|
65
|
-
@style.background_canvas.background = default(:background)
|
66
|
-
@text.color = default(:color)
|
67
|
-
window.text_input = nil
|
68
|
-
end
|
69
|
-
|
70
|
-
# TODO: Fix caret rendering in wrong position unless caret_pos is at end of text
|
71
|
-
def caret_position
|
72
|
-
if @type == :password
|
73
|
-
@text.x + @text.textobject.text_width(default(:password_character) * @text_input.text[0..@text_input.caret_pos-1].length)
|
74
|
-
else
|
75
|
-
@text.x + @text.textobject.text_width(@text_input.text[0..@text_input.caret_pos-1])
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def recalculate
|
80
|
-
super
|
81
|
-
|
82
|
-
@style.width = default(:width)
|
83
|
-
update_background
|
84
|
-
end
|
85
|
-
|
86
|
-
def value
|
87
|
-
@text_input.text
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Image < Element
|
3
|
-
def initialize(path, options = {}, block = nil)
|
4
|
-
super(options, block)
|
5
|
-
@path = path
|
6
|
-
|
7
|
-
@image = Gosu::Image.new(path, retro: @options[:image_retro])
|
8
|
-
if @options[:width] && @options[:height]
|
9
|
-
@scale_x = @options[:width].to_f / @image.width
|
10
|
-
@scale_y = @options[:height].to_f / @image.height
|
11
|
-
elsif @options[:width]
|
12
|
-
@scale_x = @options[:width].to_f / @image.width
|
13
|
-
@scale_y = @scale_x
|
14
|
-
elsif @options[:height]
|
15
|
-
@scale_y = @options[:height].to_f / @image.height
|
16
|
-
@scale_x = @scale_y
|
17
|
-
else
|
18
|
-
@scale_x, @scale_y = 1, 1
|
19
|
-
end
|
20
|
-
|
21
|
-
raise "Scale X" unless @scale_x.is_a?(Numeric)
|
22
|
-
raise "Scale Y" unless @scale_y.is_a?(Numeric)
|
23
|
-
end
|
24
|
-
|
25
|
-
def render
|
26
|
-
@image.draw(
|
27
|
-
@style.border_thickness_left + @style.padding_left + @x,
|
28
|
-
@style.border_thickness_top + @style.padding_top + @y,
|
29
|
-
@z + 2,
|
30
|
-
@scale_x, @scale_y) # TODO: Add color support?
|
31
|
-
end
|
32
|
-
|
33
|
-
def clicked_left_mouse_button(sender, x, y)
|
34
|
-
@block.call(self) if @block
|
35
|
-
end
|
36
|
-
|
37
|
-
def recalculate
|
38
|
-
@style.width = @image.width * @scale_x
|
39
|
-
@style.height = @image.height * @scale_y
|
40
|
-
end
|
41
|
-
|
42
|
-
def value
|
43
|
-
@path
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Label < Element
|
3
|
-
def initialize(text, options = {}, block = nil)
|
4
|
-
super(options, block)
|
5
|
-
|
6
|
-
@text = Text.new(text, font: @options[:font], z: @z, color: @options[:color], size: @options[:text_size], shadow: @options[:text_shadow])
|
7
|
-
|
8
|
-
return self
|
9
|
-
end
|
10
|
-
|
11
|
-
def render
|
12
|
-
@text.draw
|
13
|
-
end
|
14
|
-
|
15
|
-
def clicked_left_mouse_button(sender, x, y)
|
16
|
-
@block.call(self) if @block
|
17
|
-
end
|
18
|
-
|
19
|
-
def recalculate
|
20
|
-
@style.width = @text.width.round
|
21
|
-
@style.height= @text.height.round
|
22
|
-
|
23
|
-
@text.x = @style.border_thickness_left + @style.padding_left + @x
|
24
|
-
@text.y = @style.border_thickness_top + @style.padding_top + @y
|
25
|
-
@text.z = @z + 3
|
26
|
-
|
27
|
-
update_background
|
28
|
-
end
|
29
|
-
|
30
|
-
def value
|
31
|
-
@text.text
|
32
|
-
end
|
33
|
-
|
34
|
-
def value=(value)
|
35
|
-
@text.text = value
|
36
|
-
|
37
|
-
old_width, old_height = width, height
|
38
|
-
recalculate
|
39
|
-
|
40
|
-
root.recalculate if old_width != width || old_height != height
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|