cyberarm_engine 0.25.1 → 0.30.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/.gitignore +1 -0
- data/Gemfile.lock +20 -8
- data/README.md +1 -1
- data/assets/textures/ui/circle.png +0 -0
- data/assets/textures/ui/circle_small.png +0 -0
- data/assets/textures/ui/rounded.png +0 -0
- data/assets/textures/ui/rounded_bottom.png +0 -0
- data/assets/textures/ui/rounded_left.png +0 -0
- data/assets/textures/ui/rounded_left_bottom.png +0 -0
- data/assets/textures/ui/rounded_left_top.png +0 -0
- data/assets/textures/ui/rounded_right.png +0 -0
- data/assets/textures/ui/rounded_right_bottom.png +0 -0
- data/assets/textures/ui/rounded_right_top.png +0 -0
- data/assets/textures/ui/rounded_small.png +0 -0
- data/assets/textures/ui/rounded_tiny.png +0 -0
- data/assets/textures/ui/rounded_top.png +0 -0
- data/assets/textures/ui/square.png +0 -0
- data/cyberarm_engine.gemspec +1 -2
- data/lib/cyberarm_engine/background.rb +16 -18
- data/lib/cyberarm_engine/background_nine_slice.rb +62 -22
- data/lib/cyberarm_engine/common.rb +2 -0
- data/lib/cyberarm_engine/event_bus.rb +39 -0
- data/lib/cyberarm_engine/game_state.rb +11 -1
- data/lib/cyberarm_engine/pathfinding/graph.rb +64 -0
- data/lib/cyberarm_engine/pathfinding/graph_search.rb +6 -0
- data/lib/cyberarm_engine/pathfinding/graph_searches/astar_search.rb +6 -0
- data/lib/cyberarm_engine/pathfinding/graph_searches/breadth_first_search.rb +27 -0
- data/lib/cyberarm_engine/pathfinding/graph_searches/dijkstra_search.rb +6 -0
- data/lib/cyberarm_engine/pathfinding/graphs/grid.rb +52 -0
- data/lib/cyberarm_engine/result.rb +1 -2
- data/lib/cyberarm_engine/text.rb +54 -26
- data/lib/cyberarm_engine/timer.rb +4 -0
- data/lib/cyberarm_engine/ui/border_canvas.rb +16 -16
- data/lib/cyberarm_engine/ui/dialog.rb +24 -0
- data/lib/cyberarm_engine/ui/dsl.rb +29 -1
- data/lib/cyberarm_engine/ui/element.rb +132 -130
- data/lib/cyberarm_engine/ui/elements/button.rb +12 -13
- data/lib/cyberarm_engine/ui/elements/check_box.rb +5 -1
- data/lib/cyberarm_engine/ui/elements/container.rb +52 -46
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +30 -9
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +4 -2
- data/lib/cyberarm_engine/ui/elements/image.rb +9 -3
- data/lib/cyberarm_engine/ui/elements/list_box.rb +3 -3
- data/lib/cyberarm_engine/ui/elements/menu.rb +3 -3
- data/lib/cyberarm_engine/ui/elements/progress.rb +8 -6
- data/lib/cyberarm_engine/ui/elements/slider.rb +7 -3
- data/lib/cyberarm_engine/ui/elements/text_block.rb +31 -17
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +5 -1
- data/lib/cyberarm_engine/ui/elements/widget.rb +45 -0
- data/lib/cyberarm_engine/ui/event.rb +1 -1
- data/lib/cyberarm_engine/ui/gui_state.rb +86 -10
- data/lib/cyberarm_engine/ui/page.rb +39 -0
- data/lib/cyberarm_engine/ui/style.rb +48 -15
- data/lib/cyberarm_engine/ui/theme.rb +17 -5
- data/lib/cyberarm_engine/version.rb +1 -1
- data/lib/cyberarm_engine/window.rb +40 -1
- data/lib/cyberarm_engine.rb +11 -0
- metadata +28 -4
|
@@ -18,6 +18,7 @@ module CyberarmEngine
|
|
|
18
18
|
@visible = !@options.key?(:visible) ? true : @options[:visible]
|
|
19
19
|
@tip = @options[:tip] || ""
|
|
20
20
|
|
|
21
|
+
@debug = @options[:debug].nil? ? nil : @options[:debug]
|
|
21
22
|
@debug_color = @options[:debug_color].nil? ? Gosu::Color::RED : @options[:debug_color]
|
|
22
23
|
|
|
23
24
|
@style = Style.new(options)
|
|
@@ -35,15 +36,15 @@ module CyberarmEngine
|
|
|
35
36
|
@width = 0
|
|
36
37
|
@height = 0
|
|
37
38
|
|
|
38
|
-
@style.width = default(:width)
|
|
39
|
+
@style.width = default(:width) || nil
|
|
39
40
|
@style.height = default(:height) || nil
|
|
40
41
|
|
|
41
|
-
@
|
|
42
|
-
@
|
|
43
|
-
@
|
|
44
|
-
@
|
|
42
|
+
@background_canvas = nil # Background.new
|
|
43
|
+
@background_nine_slice_canvas = nil # BackgroundNineSlice.new
|
|
44
|
+
@background_image_canvas = nil # BackgroundImage.new
|
|
45
|
+
@border_canvas = nil # BorderCanvas.new(element: self)
|
|
45
46
|
|
|
46
|
-
@style_event = :default
|
|
47
|
+
@style_event = enabled? ? :default : :disabled
|
|
47
48
|
|
|
48
49
|
stylize
|
|
49
50
|
|
|
@@ -52,33 +53,52 @@ module CyberarmEngine
|
|
|
52
53
|
root.gui_state.request_focus(self) if @options[:autofocus]
|
|
53
54
|
end
|
|
54
55
|
|
|
56
|
+
def resolution_scaled(n)
|
|
57
|
+
return n unless @style.design_width
|
|
58
|
+
|
|
59
|
+
((Gosu.screen_width(window).to_f / @style.design_width) * n).floor
|
|
60
|
+
end
|
|
61
|
+
|
|
55
62
|
def stylize
|
|
63
|
+
@style_event = :disabled unless enabled?
|
|
64
|
+
|
|
56
65
|
set_static_position
|
|
57
66
|
|
|
58
67
|
set_color
|
|
59
68
|
set_font
|
|
60
69
|
|
|
61
|
-
set_padding
|
|
62
|
-
set_margin
|
|
63
|
-
|
|
64
70
|
set_background
|
|
65
71
|
set_background_nine_slice
|
|
66
72
|
set_background_image
|
|
67
73
|
|
|
68
|
-
|
|
69
|
-
set_border_color
|
|
74
|
+
set_border
|
|
70
75
|
|
|
71
76
|
root.gui_state.request_repaint
|
|
72
77
|
end
|
|
73
78
|
|
|
79
|
+
def styled(key)
|
|
80
|
+
case key
|
|
81
|
+
when :border_color_bottom, :border_color_left, :border_color_right, :border_color_top
|
|
82
|
+
safe_style_fetch(key, :border_color)
|
|
83
|
+
when :border_thickness_bottom, :border_thickness_left, :border_thickness_right, :border_thickness_top
|
|
84
|
+
visible? ? safe_style_fetch(key, :border_thickness) : 0
|
|
85
|
+
when :margin_bottom, :margin_left, :margin_right, :margin_top
|
|
86
|
+
visible? ? safe_style_fetch(key, :margin) : 0
|
|
87
|
+
when :padding_bottom, :padding_left, :padding_right, :padding_top
|
|
88
|
+
visible? ? safe_style_fetch(key, :padding) : 0
|
|
89
|
+
else
|
|
90
|
+
safe_style_fetch(key)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
74
94
|
def safe_style_fetch(key, fallback_key = nil)
|
|
75
95
|
# Attempt to return value for requested key
|
|
76
|
-
v = @style.
|
|
96
|
+
v = @style.send(@style_event)&.send(key) || @style.send(key)
|
|
77
97
|
return v if v
|
|
78
98
|
|
|
79
99
|
# Attempt to return overriding value
|
|
80
100
|
if fallback_key
|
|
81
|
-
v = @style.
|
|
101
|
+
v = @style.send(@style_event)&.send(fallback_key) || @style.send(fallback_key)
|
|
82
102
|
return v if v
|
|
83
103
|
end
|
|
84
104
|
|
|
@@ -92,84 +112,71 @@ module CyberarmEngine
|
|
|
92
112
|
end
|
|
93
113
|
|
|
94
114
|
def set_color
|
|
95
|
-
@
|
|
96
|
-
@text&.color = @style.color
|
|
115
|
+
@text&.color = safe_style_fetch(:color)
|
|
97
116
|
end
|
|
98
117
|
|
|
99
118
|
def set_font
|
|
100
|
-
@text&.swap_font(safe_style_fetch(:text_size), safe_style_fetch(:font))
|
|
119
|
+
@text&.swap_font(resolution_scaled(safe_style_fetch(:text_size)), safe_style_fetch(:font))
|
|
101
120
|
end
|
|
102
121
|
|
|
103
122
|
def set_background
|
|
104
|
-
|
|
123
|
+
return unless bg = safe_style_fetch(:background)
|
|
105
124
|
|
|
106
|
-
@
|
|
125
|
+
@background_canvas ||= Background.new
|
|
126
|
+
@background_canvas.background = bg
|
|
107
127
|
end
|
|
108
128
|
|
|
109
129
|
def set_background_nine_slice
|
|
110
|
-
|
|
130
|
+
return unless img = safe_style_fetch(:background_nine_slice)
|
|
111
131
|
|
|
112
|
-
@
|
|
113
|
-
@style.background_nine_slice_color = safe_style_fetch(:background_nine_slice_color) || Gosu::Color::WHITE
|
|
114
|
-
@style.background_nine_slice_canvas.color = @style.background_nine_slice_color
|
|
132
|
+
@background_nine_slice_canvas ||= BackgroundNineSlice.new
|
|
115
133
|
|
|
116
|
-
@
|
|
134
|
+
@background_nine_slice_canvas.image = img
|
|
117
135
|
|
|
118
|
-
@
|
|
119
|
-
@
|
|
120
|
-
@
|
|
121
|
-
@
|
|
122
|
-
|
|
136
|
+
@background_nine_slice_canvas.x = @x + styled(:margin_left)
|
|
137
|
+
@background_nine_slice_canvas.y = @y + styled(:margin_top)
|
|
138
|
+
@background_nine_slice_canvas.z = @z
|
|
139
|
+
@background_nine_slice_canvas.width = width
|
|
140
|
+
@background_nine_slice_canvas.height = height
|
|
123
141
|
|
|
124
|
-
|
|
125
|
-
@style.background_image = safe_style_fetch(:background_image)
|
|
126
|
-
@style.background_image_mode = safe_style_fetch(:background_image_mode) || :stretch
|
|
127
|
-
@style.background_image_color = safe_style_fetch(:background_image_color) || Gosu::Color::WHITE
|
|
128
|
-
@style.background_image_canvas.mode = @style.background_image_mode
|
|
129
|
-
@style.background_image_canvas.color = @style.background_image_color
|
|
130
|
-
end
|
|
142
|
+
@background_nine_slice_canvas.mode = safe_style_fetch(:background_nine_slice_mode) || :stretch
|
|
131
143
|
|
|
132
|
-
|
|
133
|
-
@style.border_thickness = safe_style_fetch(:border_thickness)
|
|
144
|
+
@background_nine_slice_canvas.color = safe_style_fetch(:background_nine_slice_color) || Gosu::Color::WHITE
|
|
134
145
|
|
|
135
|
-
@
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
146
|
+
@background_nine_slice_canvas.set_edges(
|
|
147
|
+
left: safe_style_fetch(:background_nine_slice_left, :background_nine_slice_from_edge) || 1,
|
|
148
|
+
top: safe_style_fetch(:background_nine_slice_top, :background_nine_slice_from_edge) || 1,
|
|
149
|
+
right: safe_style_fetch(:background_nine_slice_right, :background_nine_slice_from_edge) || 1,
|
|
150
|
+
bottom: safe_style_fetch(:background_nine_slice_bottom, :background_nine_slice_from_edge) || 1
|
|
151
|
+
)
|
|
139
152
|
end
|
|
140
153
|
|
|
141
|
-
def
|
|
142
|
-
|
|
154
|
+
def set_background_image
|
|
155
|
+
return unless img = safe_style_fetch(:background_image)
|
|
143
156
|
|
|
144
|
-
@
|
|
145
|
-
@style.border_color_right = safe_style_fetch(:border_color_right, :border_color)
|
|
146
|
-
@style.border_color_top = safe_style_fetch(:border_color_top, :border_color)
|
|
147
|
-
@style.border_color_bottom = safe_style_fetch(:border_color_bottom, :border_color)
|
|
157
|
+
@background_image_canvas ||= BackgroundImage.new
|
|
148
158
|
|
|
149
|
-
@
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
@style.border_color_bottom,
|
|
153
|
-
@style.border_color_left
|
|
154
|
-
]
|
|
159
|
+
@background_image_canvas.image = img
|
|
160
|
+
@background_image_canvas.mode = safe_style_fetch(:background_image_mode) || :stretch
|
|
161
|
+
@background_image_canvas.color = safe_style_fetch(:background_image_color) || Gosu::Color::WHITE
|
|
155
162
|
end
|
|
156
163
|
|
|
157
|
-
def
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
end
|
|
164
|
+
def set_border
|
|
165
|
+
return unless [
|
|
166
|
+
safe_style_fetch(:border_thickness_bottom, :border_thickness),
|
|
167
|
+
safe_style_fetch(:border_thickness_left, :border_thickness),
|
|
168
|
+
safe_style_fetch(:border_thickness_right, :border_thickness),
|
|
169
|
+
safe_style_fetch(:border_thickness_top, :border_thickness),
|
|
170
|
+
].any?(&:positive?)
|
|
165
171
|
|
|
166
|
-
|
|
167
|
-
@style.margin = safe_style_fetch(:margin)
|
|
172
|
+
@border_canvas ||= BorderCanvas.new(element: self)
|
|
168
173
|
|
|
169
|
-
@
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
@border_canvas&.color = [
|
|
175
|
+
styled(:border_color_top),
|
|
176
|
+
styled(:border_color_right),
|
|
177
|
+
styled(:border_color_bottom),
|
|
178
|
+
styled(:border_color_left)
|
|
179
|
+
]
|
|
173
180
|
end
|
|
174
181
|
|
|
175
182
|
def update_styles(event = :default)
|
|
@@ -208,6 +215,7 @@ module CyberarmEngine
|
|
|
208
215
|
event(:blur)
|
|
209
216
|
|
|
210
217
|
event(:changed)
|
|
218
|
+
event(:size_changed)
|
|
211
219
|
end
|
|
212
220
|
|
|
213
221
|
def enter(_sender)
|
|
@@ -215,7 +223,7 @@ module CyberarmEngine
|
|
|
215
223
|
|
|
216
224
|
if !@enabled
|
|
217
225
|
update_styles(:disabled)
|
|
218
|
-
elsif @focus
|
|
226
|
+
elsif @focus && !@style.active.empty?
|
|
219
227
|
update_styles(:active)
|
|
220
228
|
else
|
|
221
229
|
update_styles(:hover)
|
|
@@ -230,7 +238,7 @@ module CyberarmEngine
|
|
|
230
238
|
unless @enabled
|
|
231
239
|
update_styles(:disabled)
|
|
232
240
|
else
|
|
233
|
-
update_styles(:active)
|
|
241
|
+
update_styles(:active) unless @style.active.empty?
|
|
234
242
|
end
|
|
235
243
|
|
|
236
244
|
window.current_state.focus = self
|
|
@@ -276,6 +284,7 @@ module CyberarmEngine
|
|
|
276
284
|
root.gui_state.request_repaint if @enabled != boolean
|
|
277
285
|
|
|
278
286
|
@enabled = boolean
|
|
287
|
+
@style_event = :default if boolean && @style_event == :disabled
|
|
279
288
|
|
|
280
289
|
recalculate
|
|
281
290
|
|
|
@@ -322,15 +331,16 @@ module CyberarmEngine
|
|
|
322
331
|
return unless visible?
|
|
323
332
|
return unless element_visible?
|
|
324
333
|
|
|
325
|
-
@
|
|
326
|
-
@
|
|
327
|
-
@
|
|
328
|
-
@
|
|
334
|
+
@background_canvas&.draw
|
|
335
|
+
@background_nine_slice_canvas&.draw
|
|
336
|
+
@background_image_canvas&.draw
|
|
337
|
+
@border_canvas&.draw
|
|
329
338
|
|
|
330
339
|
render
|
|
331
340
|
end
|
|
332
341
|
|
|
333
342
|
def debug_draw
|
|
343
|
+
return if @debug == false || !CyberarmEngine::GUI_DEBUG # allow elements to opt out of debug drawing, makes debugging some things easier.
|
|
334
344
|
return if CyberarmEngine.const_defined?("GUI_DEBUG_ONLY_ELEMENT") && self.class == GUI_DEBUG_ONLY_ELEMENT
|
|
335
345
|
|
|
336
346
|
Gosu.draw_line(
|
|
@@ -357,6 +367,11 @@ module CyberarmEngine
|
|
|
357
367
|
|
|
358
368
|
def update
|
|
359
369
|
recalculate_if_size_changed
|
|
370
|
+
|
|
371
|
+
if @style.dirty?
|
|
372
|
+
@style.mark_clean!
|
|
373
|
+
stylize
|
|
374
|
+
end
|
|
360
375
|
end
|
|
361
376
|
|
|
362
377
|
def button_down(id)
|
|
@@ -373,13 +388,13 @@ module CyberarmEngine
|
|
|
373
388
|
end
|
|
374
389
|
|
|
375
390
|
def hit?(x, y)
|
|
376
|
-
x.between?(@x, @x + width) &&
|
|
377
|
-
y.between?(@y, @y + height)
|
|
391
|
+
x.between?(@x + styled(:margin_left), @x + styled(:margin_left) + width) &&
|
|
392
|
+
y.between?(@y + styled(:margin_top), @y + styled(:margin_top) + height)
|
|
378
393
|
end
|
|
379
394
|
|
|
380
395
|
def width
|
|
381
396
|
if visible?
|
|
382
|
-
inner_width +
|
|
397
|
+
inner_width + content_width
|
|
383
398
|
else
|
|
384
399
|
0
|
|
385
400
|
end
|
|
@@ -394,16 +409,16 @@ module CyberarmEngine
|
|
|
394
409
|
end
|
|
395
410
|
|
|
396
411
|
def outer_width
|
|
397
|
-
|
|
412
|
+
styled(:margin_left) + width + styled(:margin_right)
|
|
398
413
|
end
|
|
399
414
|
|
|
400
415
|
def inner_width
|
|
401
|
-
(
|
|
416
|
+
(styled(:border_thickness_left) + styled(:padding_left)) + (styled(:padding_right) + styled(:border_thickness_right))
|
|
402
417
|
end
|
|
403
418
|
|
|
404
419
|
def height
|
|
405
420
|
if visible?
|
|
406
|
-
inner_height +
|
|
421
|
+
inner_height + content_height
|
|
407
422
|
else
|
|
408
423
|
0
|
|
409
424
|
end
|
|
@@ -418,11 +433,11 @@ module CyberarmEngine
|
|
|
418
433
|
end
|
|
419
434
|
|
|
420
435
|
def outer_height
|
|
421
|
-
|
|
436
|
+
styled(:margin_top) + height + styled(:margin_bottom)
|
|
422
437
|
end
|
|
423
438
|
|
|
424
439
|
def inner_height
|
|
425
|
-
(
|
|
440
|
+
(styled(:border_thickness_top) + styled(:padding_top)) + (styled(:padding_bottom) + styled(:border_thickness_bottom))
|
|
426
441
|
end
|
|
427
442
|
|
|
428
443
|
def scroll_width
|
|
@@ -454,9 +469,9 @@ module CyberarmEngine
|
|
|
454
469
|
|
|
455
470
|
pairs_ << a_ unless pairs_.last == a_
|
|
456
471
|
|
|
457
|
-
@cached_scroll_height = pairs_.sum { |pair|
|
|
472
|
+
@cached_scroll_height = pairs_.sum { |pair| pair.map(&:outer_height).max } + noncontent_height
|
|
458
473
|
else
|
|
459
|
-
@cached_scroll_height =
|
|
474
|
+
@cached_scroll_height = noncontent_height + @children.sum(&:outer_height)
|
|
460
475
|
end
|
|
461
476
|
end
|
|
462
477
|
|
|
@@ -473,84 +488,67 @@ module CyberarmEngine
|
|
|
473
488
|
|
|
474
489
|
new_size = if size.is_a?(Float) && size.between?(0.0, 1.0)
|
|
475
490
|
(@parent.send(:"content_#{dimension}") * size).floor - send(:"noncontent_#{dimension}").floor
|
|
491
|
+
elsif size.is_a?(Numeric)
|
|
492
|
+
(size - send(:"noncontent_#{dimension}")).floor
|
|
476
493
|
else
|
|
477
494
|
size
|
|
478
495
|
end
|
|
479
496
|
|
|
480
497
|
# Handle fill behavior
|
|
481
|
-
if @parent &&
|
|
498
|
+
if @parent && styled(:fill) &&
|
|
482
499
|
(dimension == :width && @parent.is_a?(Flow) ||
|
|
483
500
|
dimension == :height && @parent.is_a?(Stack))
|
|
484
501
|
new_size = space_available_width - noncontent_width if dimension == :width && @parent.is_a?(Flow)
|
|
485
502
|
new_size = space_available_height - noncontent_height if dimension == :height && @parent.is_a?(Stack)
|
|
486
503
|
end
|
|
487
504
|
|
|
488
|
-
return
|
|
489
|
-
return
|
|
505
|
+
return styled(:"min_#{dimension}") if styled(:"min_#{dimension}") && new_size.to_f < styled(:"min_#{dimension}")
|
|
506
|
+
return styled(:"max_#{dimension}") if styled(:"max_#{dimension}") && new_size.to_f > styled(:"max_#{dimension}")
|
|
490
507
|
|
|
491
508
|
new_size
|
|
492
509
|
end
|
|
493
510
|
|
|
494
511
|
def space_available_width
|
|
495
512
|
# TODO: This may get expensive if there are a lot of children, probably should cache it somehow
|
|
496
|
-
fill_siblings = @parent.children.select { |c| c.
|
|
513
|
+
fill_siblings = @parent.children.select { |c| c.styled(:fill) }.count.to_f # include self since we're dividing
|
|
497
514
|
|
|
498
|
-
available_space = ((@parent.content_width - (@parent.children.reject { |c| c.
|
|
515
|
+
available_space = ((@parent.content_width - (@parent.children.reject { |c| c.styled(:fill) }).map(&:outer_width).sum) / fill_siblings)
|
|
499
516
|
(available_space.nan? || available_space.infinite?) ? 0 : available_space.floor # The parent element might not have its dimensions, yet.
|
|
500
517
|
end
|
|
501
518
|
|
|
502
519
|
def space_available_height
|
|
503
520
|
# TODO: This may get expensive if there are a lot of children, probably should cache it somehow
|
|
504
|
-
fill_siblings = @parent.children.select { |c| c.
|
|
521
|
+
fill_siblings = @parent.children.select { |c| c.styled(:fill) && c.visible? }.count.to_f # include self since we're dividing
|
|
505
522
|
|
|
506
|
-
available_space = ((@parent.content_height - (@parent.children.reject { |c| c.
|
|
523
|
+
available_space = ((@parent.content_height - (@parent.children.reject { |c| c.styled(:fill) }).map(&:outer_height).sum) / fill_siblings)
|
|
507
524
|
(available_space.nan? || available_space.infinite?) ? 0 : available_space.floor # The parent element might not have its dimensions, yet.
|
|
508
525
|
end
|
|
509
526
|
|
|
510
527
|
def background=(_background)
|
|
511
528
|
root.gui_state.request_repaint
|
|
512
529
|
|
|
513
|
-
@
|
|
530
|
+
@background_canvas.background = _background
|
|
514
531
|
update_background
|
|
515
532
|
end
|
|
516
533
|
|
|
517
534
|
def update_background
|
|
518
|
-
@
|
|
519
|
-
@
|
|
520
|
-
@
|
|
521
|
-
@
|
|
522
|
-
@
|
|
523
|
-
|
|
524
|
-
@
|
|
525
|
-
|
|
535
|
+
@background_canvas&.x = @x + styled(:margin_left)
|
|
536
|
+
@background_canvas&.y = @y + styled(:margin_top)
|
|
537
|
+
@background_canvas&.z = @z
|
|
538
|
+
@background_canvas&.width = width
|
|
539
|
+
@background_canvas&.height = height
|
|
540
|
+
|
|
541
|
+
@background_canvas&.update
|
|
542
|
+
set_background_nine_slice
|
|
526
543
|
update_background_image
|
|
527
|
-
@
|
|
544
|
+
@border_canvas&.update
|
|
528
545
|
end
|
|
529
546
|
|
|
530
547
|
def background_nine_slice=(_image_path)
|
|
531
548
|
root.gui_state.request_repaint
|
|
532
549
|
|
|
533
|
-
@
|
|
534
|
-
|
|
535
|
-
end
|
|
536
|
-
|
|
537
|
-
def update_background_nine_slice
|
|
538
|
-
@style.background_nine_slice_canvas.x = @x
|
|
539
|
-
@style.background_nine_slice_canvas.y = @y
|
|
540
|
-
@style.background_nine_slice_canvas.z = @z
|
|
541
|
-
@style.background_nine_slice_canvas.width = width
|
|
542
|
-
@style.background_nine_slice_canvas.height = height
|
|
543
|
-
|
|
544
|
-
@style.background_nine_slice_canvas.mode = @style.background_nine_slice_mode
|
|
545
|
-
|
|
546
|
-
@style.background_nine_slice_canvas.color = @style.background_nine_slice_color
|
|
547
|
-
|
|
548
|
-
@style.background_nine_slice_canvas.left = @style.background_nine_slice_left
|
|
549
|
-
@style.background_nine_slice_canvas.top = @style.background_nine_slice_top
|
|
550
|
-
@style.background_nine_slice_canvas.right = @style.background_nine_slice_right
|
|
551
|
-
@style.background_nine_slice_canvas.bottom = @style.background_nine_slice_bottom
|
|
552
|
-
|
|
553
|
-
@style.background_nine_slice_canvas.image = @style.background_nine_slice
|
|
550
|
+
@background_nine_slice_canvas.image = _image_path
|
|
551
|
+
set_background_nine_slice
|
|
554
552
|
end
|
|
555
553
|
|
|
556
554
|
def background_image=(image_path)
|
|
@@ -561,16 +559,18 @@ module CyberarmEngine
|
|
|
561
559
|
end
|
|
562
560
|
|
|
563
561
|
def update_background_image
|
|
564
|
-
|
|
565
|
-
@style.background_image_canvas.y = @y
|
|
566
|
-
@style.background_image_canvas.z = @z
|
|
567
|
-
@style.background_image_canvas.width = width
|
|
568
|
-
@style.background_image_canvas.height = height
|
|
562
|
+
return unless @background_image_canvas
|
|
569
563
|
|
|
570
|
-
@
|
|
571
|
-
@
|
|
564
|
+
@background_image_canvas.x = @x + styled(:margin_left)
|
|
565
|
+
@background_image_canvas.y = @y + styled(:margin_top)
|
|
566
|
+
@background_image_canvas.z = @z
|
|
567
|
+
@background_image_canvas.width = width
|
|
568
|
+
@background_image_canvas.height = height
|
|
572
569
|
|
|
573
|
-
@
|
|
570
|
+
@background_image_canvas.mode = safe_style_fetch(:background_image_mode) || :stretch
|
|
571
|
+
@background_image_canvas.color = safe_style_fetch(:background_image_color) || Gosu::Color::WHITE
|
|
572
|
+
|
|
573
|
+
@background_image_canvas.image = safe_style_fetch(:background_image)
|
|
574
574
|
end
|
|
575
575
|
|
|
576
576
|
def recalculate_if_size_changed
|
|
@@ -579,6 +579,8 @@ module CyberarmEngine
|
|
|
579
579
|
|
|
580
580
|
@old_width = width
|
|
581
581
|
@old_height = height
|
|
582
|
+
|
|
583
|
+
publish(:size_changed)
|
|
582
584
|
end
|
|
583
585
|
end
|
|
584
586
|
|
|
@@ -634,7 +636,7 @@ module CyberarmEngine
|
|
|
634
636
|
root.gui_state.request_recalculate if @parent && !is_a?(ToolTip) && (width != old_width || height != old_height)
|
|
635
637
|
root.gui_state.request_repaint if width != old_width || height != old_height
|
|
636
638
|
|
|
637
|
-
root.gui_state.
|
|
639
|
+
root.gui_state.active_menu.recalculate if root.gui_state.active_menu && root.gui_state.active_menu.parent == self
|
|
638
640
|
end
|
|
639
641
|
|
|
640
642
|
def layout
|
|
@@ -10,7 +10,7 @@ module CyberarmEngine
|
|
|
10
10
|
|
|
11
11
|
super(text_or_image, options, block)
|
|
12
12
|
|
|
13
|
-
@
|
|
13
|
+
@background_canvas.background = styled(:background)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def render
|
|
@@ -23,8 +23,8 @@ module CyberarmEngine
|
|
|
23
23
|
|
|
24
24
|
def draw_image
|
|
25
25
|
@image.draw(
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
styled(:border_thickness_left) + styled(:margin_left) + styled(:padding_left) + @x,
|
|
27
|
+
styled(:border_thickness_top) + styled(:margin_top) + styled(:padding_top) + @y,
|
|
28
28
|
@z + 2,
|
|
29
29
|
@scale_x, @scale_y, @text.color
|
|
30
30
|
)
|
|
@@ -35,20 +35,15 @@ module CyberarmEngine
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def layout
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
@text.color = @style.disabled[:color]
|
|
41
|
-
else
|
|
42
|
-
@style.background_canvas.background = @style.background
|
|
43
|
-
@text.color = @style.color
|
|
44
|
-
end
|
|
38
|
+
@background_canvas.background = styled(:background)
|
|
39
|
+
@text.color = styled(:color)
|
|
45
40
|
|
|
46
41
|
if @image
|
|
47
42
|
@width = 0
|
|
48
43
|
@height = 0
|
|
49
44
|
|
|
50
|
-
_width = dimensional_size(
|
|
51
|
-
_height = dimensional_size(
|
|
45
|
+
_width = dimensional_size(styled(:image_width), :width)
|
|
46
|
+
_height = dimensional_size(styled(:image_height), :height)
|
|
52
47
|
|
|
53
48
|
if _width && _height
|
|
54
49
|
@scale_x = _width.to_f / @image.width
|
|
@@ -78,6 +73,8 @@ module CyberarmEngine
|
|
|
78
73
|
end
|
|
79
74
|
|
|
80
75
|
def value=(value)
|
|
76
|
+
old_value = self.value
|
|
77
|
+
|
|
81
78
|
if value.is_a?(Gosu::Image)
|
|
82
79
|
@image = value
|
|
83
80
|
else
|
|
@@ -93,7 +90,9 @@ module CyberarmEngine
|
|
|
93
90
|
recalculate
|
|
94
91
|
end
|
|
95
92
|
|
|
96
|
-
publish(:changed, self.value)
|
|
93
|
+
publish(:changed, self.value) if value != old_value
|
|
94
|
+
|
|
95
|
+
self.value
|
|
97
96
|
end
|
|
98
97
|
end
|
|
99
98
|
end
|