cyberarm_engine 0.24.3 → 0.24.5
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 +8 -8
- data/.rubocop.yml +7 -7
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/Gemfile.lock +24 -0
- data/LICENSE.txt +21 -21
- data/README.md +74 -74
- data/Rakefile +10 -10
- data/assets/shaders/fragment/g_buffer.glsl +30 -30
- data/assets/shaders/fragment/lighting.glsl +115 -69
- data/assets/shaders/include/light_struct.glsl +11 -11
- data/assets/shaders/include/material_struct.glsl +16 -16
- data/assets/shaders/vertex/g_buffer.glsl +28 -28
- data/assets/shaders/vertex/lighting.glsl +24 -24
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cyberarm_engine.gemspec +36 -36
- data/lib/cyberarm_engine/animator.rb +219 -219
- data/lib/cyberarm_engine/background.rb +180 -179
- data/lib/cyberarm_engine/background_image.rb +93 -93
- 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 +123 -123
- data/lib/cyberarm_engine/cache.rb +4 -4
- data/lib/cyberarm_engine/common.rb +128 -128
- 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 +244 -244
- data/lib/cyberarm_engine/game_state.rb +124 -124
- data/lib/cyberarm_engine/gosu_ext/draw_arc.rb +97 -97
- data/lib/cyberarm_engine/gosu_ext/draw_circle.rb +30 -30
- data/lib/cyberarm_engine/gosu_ext/draw_path.rb +17 -17
- data/lib/cyberarm_engine/model/material.rb +21 -21
- data/lib/cyberarm_engine/model/{model_object.rb → mesh.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 +216 -213
- data/lib/cyberarm_engine/model_cache.rb +31 -31
- data/lib/cyberarm_engine/notification.rb +82 -82
- data/lib/cyberarm_engine/notification_manager.rb +241 -241
- data/lib/cyberarm_engine/opengl/light.rb +52 -50
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +41 -38
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +167 -165
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +307 -304
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +33 -33
- data/lib/cyberarm_engine/opengl/shader.rb +408 -406
- data/lib/cyberarm_engine/opengl/texture.rb +69 -69
- data/lib/cyberarm_engine/opengl.rb +53 -40
- data/lib/cyberarm_engine/ray.rb +56 -56
- data/lib/cyberarm_engine/stats.rb +200 -200
- data/lib/cyberarm_engine/text.rb +260 -260
- data/lib/cyberarm_engine/timer.rb +23 -23
- data/lib/cyberarm_engine/transform.rb +296 -296
- data/lib/cyberarm_engine/trees/aabb_node.rb +126 -0
- data/lib/cyberarm_engine/trees/aabb_tree.rb +55 -0
- data/lib/cyberarm_engine/trees/aabb_tree_debug.rb +29 -0
- data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
- data/lib/cyberarm_engine/ui/dsl.rb +142 -142
- data/lib/cyberarm_engine/ui/element.rb +662 -662
- data/lib/cyberarm_engine/ui/elements/button.rb +100 -100
- data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
- data/lib/cyberarm_engine/ui/elements/container.rb +404 -410
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +297 -297
- 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 +79 -79
- data/lib/cyberarm_engine/ui/elements/menu.rb +27 -27
- data/lib/cyberarm_engine/ui/elements/menu_item.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/progress.rb +93 -93
- data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/slider.rb +107 -107
- data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
- data/lib/cyberarm_engine/ui/elements/text_block.rb +216 -216
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +67 -67
- data/lib/cyberarm_engine/ui/event.rb +54 -54
- data/lib/cyberarm_engine/ui/gui_state.rb +321 -321
- data/lib/cyberarm_engine/ui/style.rb +50 -50
- data/lib/cyberarm_engine/ui/theme.rb +225 -225
- data/lib/cyberarm_engine/vector.rb +312 -312
- data/lib/cyberarm_engine/version.rb +4 -4
- data/lib/cyberarm_engine/window.rb +195 -195
- data/lib/cyberarm_engine.rb +70 -78
- data/mrbgem.rake +29 -29
- metadata +8 -7
data/lib/cyberarm_engine/text.rb
CHANGED
@@ -1,260 +1,260 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Text
|
3
|
-
CACHE = {}
|
4
|
-
|
5
|
-
attr_accessor :x, :y, :z, :size, :options
|
6
|
-
attr_reader :text, :textobject, :factor_x, :factor_y, :color,
|
7
|
-
:border, :border_size, :border_alpha, :border_color,
|
8
|
-
:shadow, :shadow_size, :shadow_alpha, :shadow_color
|
9
|
-
|
10
|
-
def initialize(text, options = {})
|
11
|
-
@text = text.to_s || ""
|
12
|
-
@options = options
|
13
|
-
@size = options[:size] || 18
|
14
|
-
@font = options[:font] || Gosu.default_font_name
|
15
|
-
@x = options[:x] || 0
|
16
|
-
@y = options[:y] || 0
|
17
|
-
@z = options[:z] || 1025
|
18
|
-
@factor_x = options[:factor_x] || 1
|
19
|
-
@factor_y = options[:factor_y] || 1
|
20
|
-
if options[:color]
|
21
|
-
@color = options[:color].is_a?(Gosu::Color) ? options[:color] : Gosu::Color.new(options[:color])
|
22
|
-
else
|
23
|
-
@color = Gosu::Color::WHITE
|
24
|
-
end
|
25
|
-
@mode = options[:mode] || :default
|
26
|
-
@alignment = options[:alignment] || nil
|
27
|
-
|
28
|
-
@border = options[:border]
|
29
|
-
@border = true if options[:border].nil?
|
30
|
-
@border_size = options[:border_size] || 1
|
31
|
-
@border_alpha = options[:border_alpha] || 30
|
32
|
-
@border_color = options[:border_color] || Gosu::Color::BLACK
|
33
|
-
|
34
|
-
@shadow = options[:shadow]
|
35
|
-
@shadow_size = options[:shadow_size] || 2
|
36
|
-
@shadow_alpha = options[:shadow_alpha] || 30
|
37
|
-
@shadow_color = options[:shadow_color] || Gosu::Color::BLACK
|
38
|
-
|
39
|
-
@static = options[:static] || (options[:static].nil? || options[:static] == false ? false : true)
|
40
|
-
|
41
|
-
@textobject = check_cache(@size, @font)
|
42
|
-
|
43
|
-
if @alignment
|
44
|
-
case @alignment
|
45
|
-
when :left
|
46
|
-
@x = 0 + BUTTON_PADDING
|
47
|
-
when :center
|
48
|
-
@x = (CyberarmEngine::Window.instance.width / 2) - (@textobject.text_width(@text) / 2)
|
49
|
-
when :right
|
50
|
-
@x = CyberarmEngine::Window.instance.width - BUTTON_PADDING - @textobject.text_width(@text)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def check_cache(size, font_name)
|
56
|
-
available = false
|
57
|
-
font = nil
|
58
|
-
|
59
|
-
if CACHE[size]
|
60
|
-
if CACHE[size][font_name]
|
61
|
-
font = CACHE[size][font_name]
|
62
|
-
available = true
|
63
|
-
else
|
64
|
-
available = false
|
65
|
-
end
|
66
|
-
else
|
67
|
-
available = false
|
68
|
-
end
|
69
|
-
|
70
|
-
unless available
|
71
|
-
font = Gosu::Font.new(@size, name: @font)
|
72
|
-
CACHE[@size] = {} unless CACHE[@size].is_a?(Hash)
|
73
|
-
CACHE[@size][@font] = font
|
74
|
-
end
|
75
|
-
|
76
|
-
font
|
77
|
-
end
|
78
|
-
|
79
|
-
def swap_font(size, font_name = @font)
|
80
|
-
if @size != size || @font != font_name
|
81
|
-
@size = size
|
82
|
-
@font = font_name
|
83
|
-
|
84
|
-
invalidate_cache!
|
85
|
-
@textobject = check_cache(size, font_name)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def text=(string)
|
90
|
-
invalidate_cache! if @text != string
|
91
|
-
@text = string
|
92
|
-
end
|
93
|
-
|
94
|
-
def factor_x=(n)
|
95
|
-
invalidate_cache! if @factor_x != n
|
96
|
-
@factor_x = n
|
97
|
-
end
|
98
|
-
|
99
|
-
def factor_y=(n)
|
100
|
-
invalidate_cache! if @factor_y != n
|
101
|
-
@factor_y = n
|
102
|
-
end
|
103
|
-
|
104
|
-
def color=(color)
|
105
|
-
old_color = @color
|
106
|
-
|
107
|
-
if color
|
108
|
-
@color = color.is_a?(Gosu::Color) ? color : Gosu::Color.new(color)
|
109
|
-
else
|
110
|
-
raise "color cannot be nil"
|
111
|
-
end
|
112
|
-
|
113
|
-
invalidate_cache! if old_color != color
|
114
|
-
end
|
115
|
-
|
116
|
-
def border=(boolean)
|
117
|
-
invalidate_cache! if @border != boolean
|
118
|
-
@border = boolean
|
119
|
-
end
|
120
|
-
|
121
|
-
def border_size=(n)
|
122
|
-
invalidate_cache! if @border_size != n
|
123
|
-
@border_size = n
|
124
|
-
end
|
125
|
-
|
126
|
-
def border_alpha=(n)
|
127
|
-
invalidate_cache! if @border_alpha != n
|
128
|
-
@border_alpha = n
|
129
|
-
end
|
130
|
-
|
131
|
-
def border_color=(n)
|
132
|
-
invalidate_cache! if @border_color != n
|
133
|
-
@border_color = n
|
134
|
-
end
|
135
|
-
|
136
|
-
def width(text = @text)
|
137
|
-
markup_width(text)
|
138
|
-
end
|
139
|
-
|
140
|
-
def text_width(text = @text)
|
141
|
-
spacing = 0
|
142
|
-
spacing += @border_size if @border
|
143
|
-
spacing += @shadow_size if @shadow
|
144
|
-
|
145
|
-
if text == @text && @static && @gosu_cached_text_image
|
146
|
-
@gosu_cached_text_image&.width + spacing
|
147
|
-
else
|
148
|
-
textobject.text_width(text) + spacing
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def markup_width(text = @text)
|
153
|
-
text = text.to_s
|
154
|
-
|
155
|
-
spacing = 0
|
156
|
-
spacing += @border_size if @border
|
157
|
-
spacing += @shadow_size if @shadow
|
158
|
-
|
159
|
-
if text == @text && @static && @gosu_cached_text_image
|
160
|
-
@gosu_cached_text_image&.width + spacing
|
161
|
-
else
|
162
|
-
textobject.markup_width(text) + spacing
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def height(text = @text)
|
167
|
-
if text.lines.count > 0
|
168
|
-
text.lines.count * textobject.height + @border_size + @shadow_size
|
169
|
-
else
|
170
|
-
@textobject.height + @border_size + @shadow_size
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def draw(method = :draw_markup)
|
175
|
-
if @static
|
176
|
-
if @border && !@cached_text_border_image
|
177
|
-
_x = @border_size
|
178
|
-
_y = @border_size
|
179
|
-
_width = method == :draw_markup ? text_width : markup_width
|
180
|
-
img = Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font)
|
181
|
-
|
182
|
-
@cached_text_border_image = Gosu.render((_width + (@border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
|
183
|
-
img.draw(-_x, 0, @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(0, -_y, @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(_x, 0, @z, @factor_x, @factor_y, @border_color, @mode)
|
190
|
-
img.draw(_x, _y, @z, @factor_x, @factor_y, @border_color, @mode)
|
191
|
-
|
192
|
-
img.draw(0, _y, @z, @factor_x, @factor_y, @border_color, @mode)
|
193
|
-
img.draw(-_x, _y, @z, @factor_x, @factor_y, @border_color, @mode)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
@cached_text_shadow_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font) if @shadow
|
198
|
-
|
199
|
-
@gosu_cached_text_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font)
|
200
|
-
|
201
|
-
@cached_text_border_image.draw(@x, @y, @z, @factor_x, @factor_y, @border_color, @mode) if @border
|
202
|
-
|
203
|
-
@cached_text_shadow_image.draw(@x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, @shadow_color, @mode) if @shadow
|
204
|
-
|
205
|
-
@gosu_cached_text_image.draw(@x, @y, @z, @factor_x, @factor_y, @color, @mode)
|
206
|
-
else
|
207
|
-
if @border && !ARGV.join.include?("--no-border")
|
208
|
-
border_alpha = @color.alpha <= 30 ? @color.alpha : @border_alpha
|
209
|
-
border_color = @border_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue,
|
210
|
-
border_alpha)
|
211
|
-
white = Gosu::Color::WHITE
|
212
|
-
|
213
|
-
_x = @border_size
|
214
|
-
_y = @border_size
|
215
|
-
_width = method == :draw_markup ? text_width : markup_width
|
216
|
-
|
217
|
-
@cached_text_border_image ||= Gosu.render((_width + (border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
|
218
|
-
@textobject.send(method, @text, _x - @border_size, _y, @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, _y + @border_size, @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
|
-
|
227
|
-
@textobject.send(method, @text, _x + @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
|
228
|
-
@textobject.send(method, @text, _x + @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
229
|
-
end
|
230
|
-
|
231
|
-
@cached_text_border_image.draw(@x - @border_size, @y - @border_size, @z, @factor_x, @factor_y, border_color)
|
232
|
-
end
|
233
|
-
|
234
|
-
if @shadow
|
235
|
-
shadow_color = @shadow_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha)
|
236
|
-
@textobject.send(method, @text, @x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, shadow_color, @mode)
|
237
|
-
end
|
238
|
-
|
239
|
-
@textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode)
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
def alpha=(n)
|
244
|
-
@color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, n)
|
245
|
-
end
|
246
|
-
|
247
|
-
def alpha
|
248
|
-
@color.alpha
|
249
|
-
end
|
250
|
-
|
251
|
-
def update
|
252
|
-
end
|
253
|
-
|
254
|
-
def invalidate_cache!
|
255
|
-
@cached_text_border_image = nil
|
256
|
-
@cached_text_shadow_image = nil
|
257
|
-
@gosu_cached_text_image = nil
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Text
|
3
|
+
CACHE = {}
|
4
|
+
|
5
|
+
attr_accessor :x, :y, :z, :size, :options
|
6
|
+
attr_reader :text, :textobject, :factor_x, :factor_y, :color,
|
7
|
+
:border, :border_size, :border_alpha, :border_color,
|
8
|
+
:shadow, :shadow_size, :shadow_alpha, :shadow_color
|
9
|
+
|
10
|
+
def initialize(text, options = {})
|
11
|
+
@text = text.to_s || ""
|
12
|
+
@options = options
|
13
|
+
@size = options[:size] || 18
|
14
|
+
@font = options[:font] || Gosu.default_font_name
|
15
|
+
@x = options[:x] || 0
|
16
|
+
@y = options[:y] || 0
|
17
|
+
@z = options[:z] || 1025
|
18
|
+
@factor_x = options[:factor_x] || 1
|
19
|
+
@factor_y = options[:factor_y] || 1
|
20
|
+
if options[:color]
|
21
|
+
@color = options[:color].is_a?(Gosu::Color) ? options[:color] : Gosu::Color.new(options[:color])
|
22
|
+
else
|
23
|
+
@color = Gosu::Color::WHITE
|
24
|
+
end
|
25
|
+
@mode = options[:mode] || :default
|
26
|
+
@alignment = options[:alignment] || nil
|
27
|
+
|
28
|
+
@border = options[:border]
|
29
|
+
@border = true if options[:border].nil?
|
30
|
+
@border_size = options[:border_size] || 1
|
31
|
+
@border_alpha = options[:border_alpha] || 30
|
32
|
+
@border_color = options[:border_color] || Gosu::Color::BLACK
|
33
|
+
|
34
|
+
@shadow = options[:shadow]
|
35
|
+
@shadow_size = options[:shadow_size] || 2
|
36
|
+
@shadow_alpha = options[:shadow_alpha] || 30
|
37
|
+
@shadow_color = options[:shadow_color] || Gosu::Color::BLACK
|
38
|
+
|
39
|
+
@static = options[:static] || (options[:static].nil? || options[:static] == false ? false : true)
|
40
|
+
|
41
|
+
@textobject = check_cache(@size, @font)
|
42
|
+
|
43
|
+
if @alignment
|
44
|
+
case @alignment
|
45
|
+
when :left
|
46
|
+
@x = 0 + BUTTON_PADDING
|
47
|
+
when :center
|
48
|
+
@x = (CyberarmEngine::Window.instance.width / 2) - (@textobject.text_width(@text) / 2)
|
49
|
+
when :right
|
50
|
+
@x = CyberarmEngine::Window.instance.width - BUTTON_PADDING - @textobject.text_width(@text)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def check_cache(size, font_name)
|
56
|
+
available = false
|
57
|
+
font = nil
|
58
|
+
|
59
|
+
if CACHE[size]
|
60
|
+
if CACHE[size][font_name]
|
61
|
+
font = CACHE[size][font_name]
|
62
|
+
available = true
|
63
|
+
else
|
64
|
+
available = false
|
65
|
+
end
|
66
|
+
else
|
67
|
+
available = false
|
68
|
+
end
|
69
|
+
|
70
|
+
unless available
|
71
|
+
font = Gosu::Font.new(@size, name: @font)
|
72
|
+
CACHE[@size] = {} unless CACHE[@size].is_a?(Hash)
|
73
|
+
CACHE[@size][@font] = font
|
74
|
+
end
|
75
|
+
|
76
|
+
font
|
77
|
+
end
|
78
|
+
|
79
|
+
def swap_font(size, font_name = @font)
|
80
|
+
if @size != size || @font != font_name
|
81
|
+
@size = size
|
82
|
+
@font = font_name
|
83
|
+
|
84
|
+
invalidate_cache!
|
85
|
+
@textobject = check_cache(size, font_name)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def text=(string)
|
90
|
+
invalidate_cache! if @text != string
|
91
|
+
@text = string
|
92
|
+
end
|
93
|
+
|
94
|
+
def factor_x=(n)
|
95
|
+
invalidate_cache! if @factor_x != n
|
96
|
+
@factor_x = n
|
97
|
+
end
|
98
|
+
|
99
|
+
def factor_y=(n)
|
100
|
+
invalidate_cache! if @factor_y != n
|
101
|
+
@factor_y = n
|
102
|
+
end
|
103
|
+
|
104
|
+
def color=(color)
|
105
|
+
old_color = @color
|
106
|
+
|
107
|
+
if color
|
108
|
+
@color = color.is_a?(Gosu::Color) ? color : Gosu::Color.new(color)
|
109
|
+
else
|
110
|
+
raise "color cannot be nil"
|
111
|
+
end
|
112
|
+
|
113
|
+
invalidate_cache! if old_color != color
|
114
|
+
end
|
115
|
+
|
116
|
+
def border=(boolean)
|
117
|
+
invalidate_cache! if @border != boolean
|
118
|
+
@border = boolean
|
119
|
+
end
|
120
|
+
|
121
|
+
def border_size=(n)
|
122
|
+
invalidate_cache! if @border_size != n
|
123
|
+
@border_size = n
|
124
|
+
end
|
125
|
+
|
126
|
+
def border_alpha=(n)
|
127
|
+
invalidate_cache! if @border_alpha != n
|
128
|
+
@border_alpha = n
|
129
|
+
end
|
130
|
+
|
131
|
+
def border_color=(n)
|
132
|
+
invalidate_cache! if @border_color != n
|
133
|
+
@border_color = n
|
134
|
+
end
|
135
|
+
|
136
|
+
def width(text = @text)
|
137
|
+
markup_width(text)
|
138
|
+
end
|
139
|
+
|
140
|
+
def text_width(text = @text)
|
141
|
+
spacing = 0
|
142
|
+
spacing += @border_size if @border
|
143
|
+
spacing += @shadow_size if @shadow
|
144
|
+
|
145
|
+
if text == @text && @static && @gosu_cached_text_image
|
146
|
+
@gosu_cached_text_image&.width + spacing
|
147
|
+
else
|
148
|
+
textobject.text_width(text) + spacing
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def markup_width(text = @text)
|
153
|
+
text = text.to_s
|
154
|
+
|
155
|
+
spacing = 0
|
156
|
+
spacing += @border_size if @border
|
157
|
+
spacing += @shadow_size if @shadow
|
158
|
+
|
159
|
+
if text == @text && @static && @gosu_cached_text_image
|
160
|
+
@gosu_cached_text_image&.width + spacing
|
161
|
+
else
|
162
|
+
textobject.markup_width(text) + spacing
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def height(text = @text)
|
167
|
+
if text.lines.count > 0
|
168
|
+
text.lines.count * textobject.height + @border_size + @shadow_size
|
169
|
+
else
|
170
|
+
@textobject.height + @border_size + @shadow_size
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def draw(method = :draw_markup)
|
175
|
+
if @static
|
176
|
+
if @border && !@cached_text_border_image
|
177
|
+
_x = @border_size
|
178
|
+
_y = @border_size
|
179
|
+
_width = method == :draw_markup ? text_width : markup_width
|
180
|
+
img = Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font)
|
181
|
+
|
182
|
+
@cached_text_border_image = Gosu.render((_width + (@border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
|
183
|
+
img.draw(-_x, 0, @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(0, -_y, @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(_x, 0, @z, @factor_x, @factor_y, @border_color, @mode)
|
190
|
+
img.draw(_x, _y, @z, @factor_x, @factor_y, @border_color, @mode)
|
191
|
+
|
192
|
+
img.draw(0, _y, @z, @factor_x, @factor_y, @border_color, @mode)
|
193
|
+
img.draw(-_x, _y, @z, @factor_x, @factor_y, @border_color, @mode)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
@cached_text_shadow_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font) if @shadow
|
198
|
+
|
199
|
+
@gosu_cached_text_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font)
|
200
|
+
|
201
|
+
@cached_text_border_image.draw(@x, @y, @z, @factor_x, @factor_y, @border_color, @mode) if @border
|
202
|
+
|
203
|
+
@cached_text_shadow_image.draw(@x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, @shadow_color, @mode) if @shadow
|
204
|
+
|
205
|
+
@gosu_cached_text_image.draw(@x, @y, @z, @factor_x, @factor_y, @color, @mode)
|
206
|
+
else
|
207
|
+
if @border && !ARGV.join.include?("--no-border")
|
208
|
+
border_alpha = @color.alpha <= 30 ? @color.alpha : @border_alpha
|
209
|
+
border_color = @border_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue,
|
210
|
+
border_alpha)
|
211
|
+
white = Gosu::Color::WHITE
|
212
|
+
|
213
|
+
_x = @border_size
|
214
|
+
_y = @border_size
|
215
|
+
_width = method == :draw_markup ? text_width : markup_width
|
216
|
+
|
217
|
+
@cached_text_border_image ||= Gosu.render((_width + (border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
|
218
|
+
@textobject.send(method, @text, _x - @border_size, _y, @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, _y + @border_size, @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
|
+
|
227
|
+
@textobject.send(method, @text, _x + @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
|
228
|
+
@textobject.send(method, @text, _x + @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
229
|
+
end
|
230
|
+
|
231
|
+
@cached_text_border_image.draw(@x - @border_size, @y - @border_size, @z, @factor_x, @factor_y, border_color)
|
232
|
+
end
|
233
|
+
|
234
|
+
if @shadow
|
235
|
+
shadow_color = @shadow_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha)
|
236
|
+
@textobject.send(method, @text, @x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, shadow_color, @mode)
|
237
|
+
end
|
238
|
+
|
239
|
+
@textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def alpha=(n)
|
244
|
+
@color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, n)
|
245
|
+
end
|
246
|
+
|
247
|
+
def alpha
|
248
|
+
@color.alpha
|
249
|
+
end
|
250
|
+
|
251
|
+
def update
|
252
|
+
end
|
253
|
+
|
254
|
+
def invalidate_cache!
|
255
|
+
@cached_text_border_image = nil
|
256
|
+
@cached_text_shadow_image = nil
|
257
|
+
@gosu_cached_text_image = nil
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Timer
|
3
|
-
def initialize(interval, looping = true, &block)
|
4
|
-
@interval = interval
|
5
|
-
@looping = looping
|
6
|
-
@block = block
|
7
|
-
|
8
|
-
@last_interval = Gosu.milliseconds
|
9
|
-
@triggered = false
|
10
|
-
end
|
11
|
-
|
12
|
-
def update
|
13
|
-
return if !@looping && @triggered
|
14
|
-
|
15
|
-
if Gosu.milliseconds >= @last_interval + @interval
|
16
|
-
@last_interval = Gosu.milliseconds
|
17
|
-
@triggered = true
|
18
|
-
|
19
|
-
@block.call if @block
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Timer
|
3
|
+
def initialize(interval, looping = true, &block)
|
4
|
+
@interval = interval
|
5
|
+
@looping = looping
|
6
|
+
@block = block
|
7
|
+
|
8
|
+
@last_interval = Gosu.milliseconds
|
9
|
+
@triggered = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def update
|
13
|
+
return if !@looping && @triggered
|
14
|
+
|
15
|
+
if Gosu.milliseconds >= @last_interval + @interval
|
16
|
+
@last_interval = Gosu.milliseconds
|
17
|
+
@triggered = true
|
18
|
+
|
19
|
+
@block.call if @block
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|