cyberarm_engine 0.21.0 → 0.22.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/cyberarm_engine.gemspec +0 -1
- data/lib/cyberarm_engine/common.rb +5 -2
- data/lib/cyberarm_engine/text.rb +97 -37
- data/lib/cyberarm_engine/ui/element.rb +18 -10
- data/lib/cyberarm_engine/ui/elements/container.rb +31 -9
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +53 -25
- data/lib/cyberarm_engine/ui/elements/list_box.rb +3 -1
- data/lib/cyberarm_engine/ui/elements/slider.rb +3 -3
- data/lib/cyberarm_engine/ui/elements/text_block.rb +15 -1
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +1 -1
- data/lib/cyberarm_engine/ui/gui_state.rb +8 -2
- data/lib/cyberarm_engine/ui/theme.rb +7 -1
- data/lib/cyberarm_engine/version.rb +1 -1
- data/lib/cyberarm_engine/window.rb +0 -6
- data/lib/cyberarm_engine.rb +0 -1
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '084b65265f65a631e6a27bf59c7dfd738af16aeb86b3298c30503d4560a87f58'
|
4
|
+
data.tar.gz: c73cf6b9f66780c230f331409ef5256d7364cf1b6d05e515bf638b8fa3722417
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40fd281091cbf5fa84c6f166ab9bdb24e893fd29f987309e2f1fa812737281dbee1612ef12a6b18bd7677bf50b69916f7379976871f78014dd8e49376c789023
|
7
|
+
data.tar.gz: 7884dc297c81d0add9fdd77cf38fad94765010502944f59cb31ed47cd54bf9e3f85746f488ffdc66d2e555656a7ab3d2b9c0780277593d05b0dea4f5aa5c17b8
|
data/cyberarm_engine.gemspec
CHANGED
@@ -27,7 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = %w[lib assets]
|
29
29
|
|
30
|
-
spec.add_dependency "clipboard", "~> 1.3"
|
31
30
|
spec.add_dependency "excon", "~> 0.88"
|
32
31
|
spec.add_dependency "gosu", "~> 1.1"
|
33
32
|
spec.add_dependency "gosu_more_drawables", "~> 0.3"
|
@@ -8,8 +8,11 @@ module CyberarmEngine
|
|
8
8
|
window.current_state
|
9
9
|
end
|
10
10
|
|
11
|
-
def previous_state
|
12
|
-
|
11
|
+
def previous_state(state = nil)
|
12
|
+
raise "Only available for CyberarmEngine::GameState and subclasses" unless is_a?(CyberarmEngine::GameState) || state.is_a?(CyberarmEngine::GameState)
|
13
|
+
|
14
|
+
i = window.states.index(state || self)
|
15
|
+
window.states[i - 1] unless (i - 1).negative?
|
13
16
|
end
|
14
17
|
|
15
18
|
def pop_state
|
data/lib/cyberarm_engine/text.rb
CHANGED
@@ -22,19 +22,21 @@ module CyberarmEngine
|
|
22
22
|
else
|
23
23
|
@color = Gosu::Color::WHITE
|
24
24
|
end
|
25
|
-
@mode
|
25
|
+
@mode = options[:mode] || :default
|
26
26
|
@alignment = options[:alignment] || nil
|
27
27
|
|
28
28
|
@border = options[:border]
|
29
29
|
@border = true if options[:border].nil?
|
30
30
|
@border_size = options[:border_size] || 1
|
31
31
|
@border_alpha = options[:border_alpha] || 30
|
32
|
-
@border_color = options[:border_color]
|
32
|
+
@border_color = options[:border_color] || Gosu::Color::BLACK
|
33
33
|
|
34
34
|
@shadow = options[:shadow]
|
35
35
|
@shadow_size = options[:shadow_size] || 2
|
36
36
|
@shadow_alpha = options[:shadow_alpha] || 30
|
37
|
-
@shadow_color = options[:shadow_color]
|
37
|
+
@shadow_color = options[:shadow_color] || Gosu::Color::BLACK
|
38
|
+
|
39
|
+
@static = options[:static] || (options[:static].nil? || options[:static] == false ? false : true)
|
38
40
|
|
39
41
|
@textobject = check_cache(@size, @font)
|
40
42
|
|
@@ -84,46 +86,49 @@ module CyberarmEngine
|
|
84
86
|
end
|
85
87
|
|
86
88
|
def text=(string)
|
87
|
-
@
|
89
|
+
invalidate_cache! if @text != string
|
88
90
|
@text = string
|
89
91
|
end
|
90
92
|
|
91
93
|
def factor_x=(n)
|
92
|
-
@
|
94
|
+
invalidate_cache! if @factor_x != n
|
93
95
|
@factor_x = n
|
94
96
|
end
|
95
97
|
|
96
98
|
def factor_y=(n)
|
97
|
-
@
|
99
|
+
invalidate_cache! if @factor_y != n
|
98
100
|
@factor_y = n
|
99
101
|
end
|
100
102
|
|
101
103
|
def color=(color)
|
102
|
-
|
104
|
+
old_color = @color
|
105
|
+
|
103
106
|
if color
|
104
107
|
@color = color.is_a?(Gosu::Color) ? color : Gosu::Color.new(color)
|
105
108
|
else
|
106
109
|
raise "color cannot be nil"
|
107
110
|
end
|
111
|
+
|
112
|
+
invalidate_cache! if old_color != color
|
108
113
|
end
|
109
114
|
|
110
115
|
def border=(boolean)
|
111
|
-
@
|
116
|
+
invalidate_cache! if @border != boolean
|
112
117
|
@border = boolean
|
113
118
|
end
|
114
119
|
|
115
120
|
def border_size=(n)
|
116
|
-
@
|
121
|
+
invalidate_cache! if @border_size != n
|
117
122
|
@border_size = n
|
118
123
|
end
|
119
124
|
|
120
125
|
def border_alpha=(n)
|
121
|
-
@
|
126
|
+
invalidate_cache! if @border_alpha != n
|
122
127
|
@border_alpha = n
|
123
128
|
end
|
124
129
|
|
125
130
|
def border_color=(n)
|
126
|
-
@
|
131
|
+
invalidate_cache! if @border_color != n
|
127
132
|
@border_color = n
|
128
133
|
end
|
129
134
|
|
@@ -132,11 +137,27 @@ module CyberarmEngine
|
|
132
137
|
end
|
133
138
|
|
134
139
|
def text_width(text = @text)
|
135
|
-
|
140
|
+
spacing = 0
|
141
|
+
spacing += @border_size if @border
|
142
|
+
spacing += @shadow_size if @shadow
|
143
|
+
|
144
|
+
if text == @text && @static && @gosu_cached_text_image
|
145
|
+
@gosu_cached_text_image&.width + spacing
|
146
|
+
else
|
147
|
+
textobject.text_width(text) + spacing
|
148
|
+
end
|
136
149
|
end
|
137
150
|
|
138
151
|
def markup_width(text = @text)
|
139
|
-
|
152
|
+
spacing = 0
|
153
|
+
spacing += @border_size if @border
|
154
|
+
spacing += @shadow_size if @shadow
|
155
|
+
|
156
|
+
if text == @text && @static && @gosu_cached_text_image
|
157
|
+
@gosu_cached_text_image&.width + spacing
|
158
|
+
else
|
159
|
+
textobject.markup_width(text) + spacing
|
160
|
+
end
|
140
161
|
end
|
141
162
|
|
142
163
|
def height(text = @text)
|
@@ -148,39 +169,72 @@ module CyberarmEngine
|
|
148
169
|
end
|
149
170
|
|
150
171
|
def draw(method = :draw_markup)
|
151
|
-
if @
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
172
|
+
if @static
|
173
|
+
if @border && !@cached_text_border_image
|
174
|
+
_x = @border_size
|
175
|
+
_y = @border_size
|
176
|
+
_width = method == :draw_markup ? text_width : markup_width
|
177
|
+
img = Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font)
|
178
|
+
|
179
|
+
@cached_text_border_image = Gosu.render((_width + (@border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
|
180
|
+
img.draw(-_x, 0, @z, @factor_x, @factor_y, @border_color, @mode)
|
181
|
+
img.draw(-_x, -_y, @z, @factor_x, @factor_y, @border_color, @mode)
|
182
|
+
|
183
|
+
img.draw(0, -_y, @z, @factor_x, @factor_y, @border_color, @mode)
|
184
|
+
img.draw(_x, -_y, @z, @factor_x, @factor_y, @border_color, @mode)
|
185
|
+
|
186
|
+
img.draw(_x, 0, @z, @factor_x, @factor_y, @border_color, @mode)
|
187
|
+
img.draw(_x, _y, @z, @factor_x, @factor_y, @border_color, @mode)
|
188
|
+
|
189
|
+
img.draw(0, _y, @z, @factor_x, @factor_y, @border_color, @mode)
|
190
|
+
img.draw(-_x, _y, @z, @factor_x, @factor_y, @border_color, @mode)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
@cached_text_shadow_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font) if @shadow
|
156
195
|
|
157
|
-
|
158
|
-
_y = @border_size
|
159
|
-
_width = method == :draw_markup ? text_width : markup_width
|
196
|
+
@gosu_cached_text_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font)
|
160
197
|
|
161
|
-
@
|
162
|
-
@textobject.send(method, @text, _x - @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
|
163
|
-
@textobject.send(method, @text, _x - @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
198
|
+
@cached_text_border_image.draw(@x, @y, @z, @factor_x, @factor_y, @border_color, @mode) if @border
|
164
199
|
|
165
|
-
|
166
|
-
@textobject.send(method, @text, _x + @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
200
|
+
@cached_text_shadow_image.draw(@x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, @shadow_color, @mode) if @shadow
|
167
201
|
|
168
|
-
|
169
|
-
|
202
|
+
@gosu_cached_text_image.draw(@x, @y, @z, @factor_x, @factor_y, @color, @mode)
|
203
|
+
else
|
204
|
+
if @border && !ARGV.join.include?("--no-border")
|
205
|
+
border_alpha = @color.alpha <= 30 ? @color.alpha : @border_alpha
|
206
|
+
border_color = @border_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue,
|
207
|
+
border_alpha)
|
208
|
+
white = Gosu::Color::WHITE
|
209
|
+
|
210
|
+
_x = @border_size
|
211
|
+
_y = @border_size
|
212
|
+
_width = method == :draw_markup ? text_width : markup_width
|
213
|
+
|
214
|
+
@cached_text_border_image ||= Gosu.render((_width + (border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
|
215
|
+
@textobject.send(method, @text, _x - @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
|
216
|
+
@textobject.send(method, @text, _x - @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
217
|
+
|
218
|
+
@textobject.send(method, @text, _x, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
219
|
+
@textobject.send(method, @text, _x + @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
220
|
+
|
221
|
+
@textobject.send(method, @text, _x, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
222
|
+
@textobject.send(method, @text, _x - @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
223
|
+
|
224
|
+
@textobject.send(method, @text, _x + @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
|
225
|
+
@textobject.send(method, @text, _x + @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
226
|
+
end
|
170
227
|
|
171
|
-
@
|
172
|
-
@textobject.send(method, @text, _x + @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
228
|
+
@cached_text_border_image.draw(@x - @border_size, @y - @border_size, @z, @factor_x, @factor_y, border_color)
|
173
229
|
end
|
174
230
|
|
175
|
-
|
176
|
-
|
231
|
+
if @shadow
|
232
|
+
shadow_color = @shadow_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha)
|
233
|
+
@textobject.send(method, @text, @x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, shadow_color, @mode)
|
234
|
+
end
|
177
235
|
|
178
|
-
|
179
|
-
shadow_color = @shadow_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha)
|
180
|
-
@textobject.send(method, @text, @x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, shadow_color, @mode)
|
236
|
+
@textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode)
|
181
237
|
end
|
182
|
-
|
183
|
-
@textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode)
|
184
238
|
end
|
185
239
|
|
186
240
|
def alpha=(n)
|
@@ -193,5 +247,11 @@ module CyberarmEngine
|
|
193
247
|
|
194
248
|
def update
|
195
249
|
end
|
250
|
+
|
251
|
+
def invalidate_cache!
|
252
|
+
@cached_text_border_image = nil
|
253
|
+
@cached_text_shadow_image = nil
|
254
|
+
@gosu_cached_text_image = nil
|
255
|
+
end
|
196
256
|
end
|
197
257
|
end
|
@@ -447,29 +447,37 @@ module CyberarmEngine
|
|
447
447
|
end
|
448
448
|
|
449
449
|
if @parent && @style.fill # Handle fill behavior
|
450
|
-
fill_siblings = @parent.children.select { |c| c.style.fill }.count.to_f # include self since we're dividing
|
451
|
-
|
452
450
|
if dimension == :width && @parent.is_a?(Flow)
|
453
|
-
space_available_width = ((@parent.content_width - (@parent.children.reject { |c| c.style.fill }).map(&:outer_width).sum) / fill_siblings)
|
454
|
-
space_available_width = space_available_width.nan? ? 0 : space_available_width.floor # The parent element might not have its dimensions, yet.
|
455
|
-
|
456
451
|
return space_available_width - noncontent_width
|
457
452
|
|
458
453
|
elsif dimension == :height && @parent.is_a?(Stack)
|
459
|
-
space_available_height = ((@parent.content_height - (@parent.children.reject { |c| c.style.fill }).map(&:outer_height).sum) / fill_siblings)
|
460
|
-
space_available_height = space_available_height.nan? ? 0 : space_available_height.floor # The parent element might not have its dimensions, yet.
|
461
|
-
|
462
454
|
return space_available_height - noncontent_height
|
463
455
|
end
|
464
456
|
|
465
457
|
else # Handle min_width/height and max_width/height
|
466
|
-
return @style.send(:"min_#{dimension}") if @style.send(:"min_#{dimension}") && new_size < @style.send(:"min_#{dimension}")
|
467
|
-
return @style.send(:"max_#{dimension}") if @style.send(:"max_#{dimension}") && new_size > @style.send(:"max_#{dimension}")
|
458
|
+
return @style.send(:"min_#{dimension}") if @style.send(:"min_#{dimension}") && new_size.to_f < @style.send(:"min_#{dimension}")
|
459
|
+
return @style.send(:"max_#{dimension}") if @style.send(:"max_#{dimension}") && new_size.to_f > @style.send(:"max_#{dimension}")
|
468
460
|
end
|
469
461
|
|
470
462
|
new_size
|
471
463
|
end
|
472
464
|
|
465
|
+
def space_available_width
|
466
|
+
# TODO: This may get expensive if there are a lot of children, probably should cache it somehow
|
467
|
+
fill_siblings = @parent.children.select { |c| c.style.fill }.count.to_f # include self since we're dividing
|
468
|
+
|
469
|
+
available_space = ((@parent.content_width - (@parent.children.reject { |c| c.style.fill }).map(&:outer_width).sum) / fill_siblings)
|
470
|
+
(available_space.nan? || available_space.infinite?) ? 0 : available_space.floor # The parent element might not have its dimensions, yet.
|
471
|
+
end
|
472
|
+
|
473
|
+
def space_available_height
|
474
|
+
# TODO: This may get expensive if there are a lot of children, probably should cache it somehow
|
475
|
+
fill_siblings = @parent.children.select { |c| c.style.fill }.count.to_f # include self since we're dividing
|
476
|
+
|
477
|
+
available_space = ((@parent.content_height - (@parent.children.reject { |c| c.style.fill }).map(&:outer_height).sum) / fill_siblings)
|
478
|
+
(available_space.nan? || available_space.infinite?) ? 0 : available_space.floor # The parent element might not have its dimensions, yet.
|
479
|
+
end
|
480
|
+
|
473
481
|
def background=(_background)
|
474
482
|
@style.background_canvas.background = _background
|
475
483
|
update_background
|
@@ -136,7 +136,31 @@ module CyberarmEngine
|
|
136
136
|
@height = _height || (@children.map { |c| c.y + c.outer_height }.max || 0).floor
|
137
137
|
end
|
138
138
|
|
139
|
-
#
|
139
|
+
# FIXME: Correctly handle alignment when element has siblings
|
140
|
+
# FIXME: Enable alignment for any element, not just containers
|
141
|
+
if @style.v_align
|
142
|
+
space = space_available_height
|
143
|
+
|
144
|
+
case @style.v_align
|
145
|
+
when :center
|
146
|
+
@y = parent.height / 2 - height / 2
|
147
|
+
when :bottom
|
148
|
+
@y = parent.height - height
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
if @style.h_align
|
153
|
+
space = space_available_width
|
154
|
+
|
155
|
+
case @style.h_align
|
156
|
+
when :center
|
157
|
+
@x = parent.width / 2 - width / 2
|
158
|
+
when :right
|
159
|
+
@x = parent.width - width
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# Move children to parent after positioning
|
140
164
|
@children.each do |child|
|
141
165
|
child.x += (@x + @style.border_thickness_left) - style.margin_left
|
142
166
|
child.y += (@y + @style.border_thickness_top) - style.margin_top
|
@@ -172,7 +196,6 @@ module CyberarmEngine
|
|
172
196
|
end
|
173
197
|
|
174
198
|
def fits_on_line?(element) # Flow
|
175
|
-
p [@options[:id], @width] if @options[:id]
|
176
199
|
@current_position.x + element.outer_width <= max_width &&
|
177
200
|
@current_position.x + element.outer_width <= window.width
|
178
201
|
end
|
@@ -182,7 +205,6 @@ module CyberarmEngine
|
|
182
205
|
element.y = element.style.margin_top + @current_position.y
|
183
206
|
|
184
207
|
@current_position.x += element.outer_width
|
185
|
-
@current_position.x = @style.margin_left if @current_position.x >= max_width
|
186
208
|
end
|
187
209
|
|
188
210
|
def tallest_neighbor(querier, _y_position) # Flow
|
@@ -195,14 +217,14 @@ module CyberarmEngine
|
|
195
217
|
response
|
196
218
|
end
|
197
219
|
|
198
|
-
def position_on_next_line(
|
199
|
-
@current_position.x = @style.margin_left
|
200
|
-
@current_position.y += tallest_neighbor(
|
220
|
+
def position_on_next_line(element) # Flow
|
221
|
+
@current_position.x = @style.margin_left + @style.padding_left
|
222
|
+
@current_position.y += tallest_neighbor(element, @current_position.y).outer_height
|
201
223
|
|
202
|
-
|
203
|
-
|
224
|
+
element.x = element.style.margin_left + @current_position.x
|
225
|
+
element.y = element.style.margin_top + @current_position.y
|
204
226
|
|
205
|
-
@current_position.x +=
|
227
|
+
@current_position.x += element.outer_width
|
206
228
|
end
|
207
229
|
|
208
230
|
def move_to_next_line(element) # Stack
|
@@ -1,6 +1,20 @@
|
|
1
1
|
module CyberarmEngine
|
2
2
|
class Element
|
3
3
|
class EditLine < Button
|
4
|
+
class TextInput < Gosu::TextInput
|
5
|
+
def filter=(filter)
|
6
|
+
@filter = filter
|
7
|
+
end
|
8
|
+
|
9
|
+
def filter(text_in)
|
10
|
+
if @filter
|
11
|
+
@filter.call(text_in)
|
12
|
+
else
|
13
|
+
text_in
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
4
18
|
def initialize(text, options = {}, block = nil)
|
5
19
|
@filter = options.delete(:filter)
|
6
20
|
super(text, options, block)
|
@@ -14,17 +28,11 @@ module CyberarmEngine
|
|
14
28
|
@caret_last_interval = Gosu.milliseconds
|
15
29
|
@show_caret = true
|
16
30
|
|
17
|
-
@text_input =
|
31
|
+
@text_input = TextInput.new
|
32
|
+
@text_input.filter = @filter
|
18
33
|
@text_input.text = text
|
19
34
|
@last_text_value = text
|
20
|
-
|
21
|
-
if @filter && @filter.respond_to?(:call)
|
22
|
-
@text_input.instance_variable_set(:@filter, @filter)
|
23
|
-
|
24
|
-
def @text_input.filter(text_in)
|
25
|
-
@filter.call(text_in)
|
26
|
-
end
|
27
|
-
end
|
35
|
+
@last_caret_position = @text_input.caret_pos
|
28
36
|
|
29
37
|
@offset_x = 0
|
30
38
|
@offset_y = 0
|
@@ -75,6 +83,12 @@ module CyberarmEngine
|
|
75
83
|
publish(:changed, value)
|
76
84
|
end
|
77
85
|
|
86
|
+
if @last_caret_position != @text_input.caret_pos
|
87
|
+
@last_caret_position = @text_input.caret_pos
|
88
|
+
@show_caret = true
|
89
|
+
@caret_last_interval = Gosu.milliseconds
|
90
|
+
end
|
91
|
+
|
78
92
|
if Gosu.milliseconds >= @caret_last_interval + @caret_interval
|
79
93
|
@caret_last_interval = Gosu.milliseconds
|
80
94
|
|
@@ -98,20 +112,20 @@ module CyberarmEngine
|
|
98
112
|
@text_input.caret_pos = @text_input.text.length
|
99
113
|
|
100
114
|
when Gosu::KB_C
|
101
|
-
if @text_input.selection_start < @text_input.caret_pos
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
115
|
+
Gosu.clipboard = if @text_input.selection_start < @text_input.caret_pos
|
116
|
+
@text_input.text[@text_input.selection_start...@text_input.caret_pos]
|
117
|
+
else
|
118
|
+
@text_input.text[@text_input.caret_pos...@text_input.selection_start]
|
119
|
+
end
|
106
120
|
|
107
121
|
when Gosu::KB_X
|
108
122
|
chars = @text_input.text.chars
|
109
123
|
|
110
124
|
if @text_input.selection_start < @text_input.caret_pos
|
111
|
-
|
125
|
+
Gosu.clipboard = @text_input.text[@text_input.selection_start...@text_input.caret_pos]
|
112
126
|
chars.slice!(@text_input.selection_start, @text_input.caret_pos)
|
113
127
|
else
|
114
|
-
|
128
|
+
Gosu.clipboard = @text_input.text[@text_input.caret_pos...@text_input.selection_start]
|
115
129
|
chars.slice!(@text_input.caret_pos, @text_input.selection_start)
|
116
130
|
end
|
117
131
|
|
@@ -119,10 +133,9 @@ module CyberarmEngine
|
|
119
133
|
|
120
134
|
when Gosu::KB_V
|
121
135
|
if instance_of?(EditLine) # EditLine assumes a single line of text
|
122
|
-
@text_input.
|
123
|
-
Clipboard.paste.encode("UTF-8").gsub("\n", ""))
|
136
|
+
@text_input.insert_text(Gosu.clipboard.gsub("\n", ""))
|
124
137
|
else
|
125
|
-
@text_input.
|
138
|
+
@text_input.insert_text(Gosu.clipboard)
|
126
139
|
end
|
127
140
|
end
|
128
141
|
end
|
@@ -180,7 +193,7 @@ module CyberarmEngine
|
|
180
193
|
if @type == :password
|
181
194
|
@text.x + @text.width(default(:password_character) * @text_input.text[0...@text_input.send(method)].length)
|
182
195
|
else
|
183
|
-
@text.x + @text.width(@text_input.text[0...@text_input.send(method)])
|
196
|
+
@text.x + @text.width(@text_input.text[0...@text_input.send(method)]) - @style.border_thickness_left
|
184
197
|
end
|
185
198
|
end
|
186
199
|
|
@@ -197,20 +210,35 @@ module CyberarmEngine
|
|
197
210
|
end
|
198
211
|
|
199
212
|
def focus(sender)
|
200
|
-
|
201
|
-
|
213
|
+
@focus = true
|
202
214
|
window.text_input = @text_input
|
203
215
|
@text_input.caret_pos = @text_input.selection_start = @text_input.text.length
|
204
216
|
|
217
|
+
update_styles(:active)
|
218
|
+
|
205
219
|
:handled
|
206
220
|
end
|
207
221
|
|
208
222
|
def enter(sender)
|
209
|
-
|
223
|
+
if @enabled && @focus
|
224
|
+
update_styles(:active)
|
225
|
+
elsif @enabled && !@focus
|
226
|
+
update_styles(:hover)
|
227
|
+
else
|
228
|
+
update_styles(:disabled)
|
229
|
+
end
|
210
230
|
|
211
|
-
|
231
|
+
:handled
|
232
|
+
end
|
212
233
|
|
213
|
-
|
234
|
+
def leave(sender)
|
235
|
+
if @enabled && @focus
|
236
|
+
update_styles(:active)
|
237
|
+
elsif @enabled && !@focus
|
238
|
+
update_styles
|
239
|
+
else
|
240
|
+
update_styles(:disabled)
|
241
|
+
end
|
214
242
|
|
215
243
|
:handled
|
216
244
|
end
|
@@ -13,7 +13,7 @@ module CyberarmEngine
|
|
13
13
|
@style.background_canvas.background = default(:background)
|
14
14
|
|
15
15
|
# TODO: "Clean Up" into own class?
|
16
|
-
@menu = Stack.new(parent:
|
16
|
+
@menu = Stack.new(parent: self, theme: @options[:theme])
|
17
17
|
@menu.define_singleton_method(:recalculate_menu) do
|
18
18
|
@x = @__list_box.x
|
19
19
|
@y = @__list_box.y + @__list_box.height
|
@@ -64,6 +64,8 @@ module CyberarmEngine
|
|
64
64
|
def show_menu
|
65
65
|
@menu.clear
|
66
66
|
|
67
|
+
@menu.style.width = width
|
68
|
+
|
67
69
|
@items.each do |item|
|
68
70
|
next if item == self.value
|
69
71
|
|
@@ -42,7 +42,7 @@ module CyberarmEngine
|
|
42
42
|
@step_size = @options[:step] || 0.1
|
43
43
|
@value = @options[:value] || (@range.first + @range.last) / 2
|
44
44
|
|
45
|
-
@handle = Handle.new("", parent: self, width: 8, height: 1.0) { close }
|
45
|
+
@handle = Handle.new("", parent: self, theme: options[:theme], width: 8, height: 1.0) { close }
|
46
46
|
add(@handle)
|
47
47
|
end
|
48
48
|
|
@@ -61,10 +61,10 @@ module CyberarmEngine
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def position_handle
|
64
|
-
@handle.x = @x + @style.padding_left + @style.border_thickness_left +
|
64
|
+
@handle.x = @x + @handle.style.margin_left + @style.padding_left + @style.border_thickness_left +
|
65
65
|
((content_width - @handle.outer_width) * (@value - @range.min) / (@range.max - @range.min).to_f)
|
66
66
|
|
67
|
-
@handle.y = @y + @style.border_thickness_top + @style.padding_top
|
67
|
+
@handle.y = @y + @handle.style.margin_top + @style.border_thickness_top + @style.padding_top
|
68
68
|
end
|
69
69
|
|
70
70
|
def draw
|
@@ -7,6 +7,7 @@ module CyberarmEngine
|
|
7
7
|
@text = Text.new(
|
8
8
|
text, font: @options[:font], z: @z, color: @options[:color],
|
9
9
|
size: @options[:text_size], shadow: @options[:text_shadow],
|
10
|
+
static: @options[:text_static],
|
10
11
|
shadow_size: @options[:text_shadow_size],
|
11
12
|
shadow_color: @options[:text_shadow_color],
|
12
13
|
border: @options[:text_border],
|
@@ -49,7 +50,7 @@ module CyberarmEngine
|
|
49
50
|
@text.y = @style.border_thickness_top + @style.padding_top + @y
|
50
51
|
@text.z = @z + 3
|
51
52
|
|
52
|
-
if (text_alignment = @options[:text_align])
|
53
|
+
if (text_alignment = @options[:text_align] || @options[:text_h_align])
|
53
54
|
case text_alignment
|
54
55
|
when :left
|
55
56
|
@text.x = @style.border_thickness_left + @style.padding_left + @x
|
@@ -64,6 +65,19 @@ module CyberarmEngine
|
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
68
|
+
if (vertical_alignment = @options[:text_v_align])
|
69
|
+
case vertical_alignment
|
70
|
+
when :center
|
71
|
+
@text.y = if @text.height <= height
|
72
|
+
@y + height / 2 - @text.height / 2
|
73
|
+
else
|
74
|
+
@style.border_thickness_top + @style.padding_top + @y
|
75
|
+
end
|
76
|
+
when :bottom
|
77
|
+
@text.y = @y + outer_height - (@text.height + @style.border_thickness_bottom + @style.padding_bottom)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
67
81
|
update_background
|
68
82
|
end
|
69
83
|
|
@@ -5,7 +5,7 @@ module CyberarmEngine
|
|
5
5
|
|
6
6
|
def initialize(options, block = nil)
|
7
7
|
if options.dig(:theme, :ToggleButton, :checkmark_image)
|
8
|
-
options[:theme][:ToggleButton][:image_width] ||= options[:theme][:
|
8
|
+
options[:theme][:ToggleButton][:image_width] ||= options[:theme][:TextBlock][:text_size]
|
9
9
|
super(get_image(options.dig(:theme, :ToggleButton, :checkmark_image)), options, block)
|
10
10
|
|
11
11
|
@_image = @image
|
@@ -171,6 +171,9 @@ module CyberarmEngine
|
|
171
171
|
end
|
172
172
|
|
173
173
|
@focus.button_up(id) if @focus.respond_to?(:button_up)
|
174
|
+
|
175
|
+
# Prevents menu from popping back up if the listbox is clicked to hide it.
|
176
|
+
@hid_menu_for = nil
|
174
177
|
end
|
175
178
|
|
176
179
|
def tool_tip_delay
|
@@ -185,7 +188,7 @@ module CyberarmEngine
|
|
185
188
|
@focus = nil
|
186
189
|
end
|
187
190
|
|
188
|
-
if @mouse_over
|
191
|
+
if @mouse_over && @hid_menu_for != @mouse_over
|
189
192
|
@mouse_down_position[button] = Vector.new(window.mouse_x, window.mouse_y)
|
190
193
|
@mouse_down_on[button] = @mouse_over
|
191
194
|
|
@@ -199,7 +202,7 @@ module CyberarmEngine
|
|
199
202
|
def redirect_released_mouse_button(button)
|
200
203
|
hide_menu if @menu && (@menu == @mouse_over) || (@mouse_over&.parent == @menu)
|
201
204
|
|
202
|
-
if @mouse_over
|
205
|
+
if @mouse_over && @hid_menu_for != @mouse_over
|
203
206
|
@mouse_over.publish(:"released_#{button}_mouse_button", window.mouse_x, window.mouse_y)
|
204
207
|
if @mouse_over == @mouse_down_on[button]
|
205
208
|
@mouse_over.publish(:"clicked_#{button}_mouse_button", window.mouse_x,
|
@@ -255,6 +258,9 @@ module CyberarmEngine
|
|
255
258
|
end
|
256
259
|
|
257
260
|
def hide_menu
|
261
|
+
return unless @menu
|
262
|
+
|
263
|
+
@hid_menu_for = @menu.parent
|
258
264
|
@menu = nil
|
259
265
|
end
|
260
266
|
|
@@ -76,6 +76,7 @@ module CyberarmEngine
|
|
76
76
|
border_radius: 0,
|
77
77
|
background: ["ffc75e61".to_i(16), "ffe26623".to_i(16)],
|
78
78
|
text_align: :center,
|
79
|
+
text_v_align: :center,
|
79
80
|
text_wrap: :none,
|
80
81
|
|
81
82
|
hover: {
|
@@ -102,7 +103,12 @@ module CyberarmEngine
|
|
102
103
|
caret_color: Gosu::Color::WHITE,
|
103
104
|
caret_interval: 500,
|
104
105
|
selection_color: Gosu::Color.rgba(255, 128, 50, 200),
|
105
|
-
text_align: :left
|
106
|
+
text_align: :left,
|
107
|
+
text_static: false # static text causes issues correctly displaying caret position
|
108
|
+
},
|
109
|
+
|
110
|
+
EditBox: { # < EditLine
|
111
|
+
text_v_align: :top
|
106
112
|
},
|
107
113
|
|
108
114
|
Image: { # < Element
|
data/lib/cyberarm_engine.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyberarm_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyberarm
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: clipboard
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.3'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.3'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: excon
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -211,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
197
|
- !ruby/object:Gem::Version
|
212
198
|
version: '0'
|
213
199
|
requirements: []
|
214
|
-
rubygems_version: 3.3.
|
200
|
+
rubygems_version: 3.3.15
|
215
201
|
signing_key:
|
216
202
|
specification_version: 4
|
217
203
|
summary: Make games quickly and easily with gosu
|