cyberarm_engine 0.18.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cyberarm_engine/animator.rb +165 -2
- data/lib/cyberarm_engine/background_nine_slice.rb +51 -34
- data/lib/cyberarm_engine/builtin/intro_state.rb +10 -7
- data/lib/cyberarm_engine/common.rb +14 -2
- data/lib/cyberarm_engine/console/command.rb +158 -0
- data/lib/cyberarm_engine/console/commands/help_command.rb +43 -0
- data/lib/cyberarm_engine/console/subcommand.rb +100 -0
- data/lib/cyberarm_engine/console.rb +248 -0
- data/lib/cyberarm_engine/model.rb +6 -1
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +2 -2
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +9 -0
- data/lib/cyberarm_engine/text.rb +72 -45
- data/lib/cyberarm_engine/ui/element.rb +60 -11
- data/lib/cyberarm_engine/ui/elements/container.rb +2 -0
- data/lib/cyberarm_engine/ui/elements/text_block.rb +10 -1
- data/lib/cyberarm_engine/ui/event.rb +9 -2
- data/lib/cyberarm_engine/ui/gui_state.rb +1 -1
- data/lib/cyberarm_engine/ui/theme.rb +5 -1
- data/lib/cyberarm_engine/version.rb +1 -1
- data/lib/cyberarm_engine.rb +6 -0
- metadata +6 -2
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CyberarmEngine
|
4
|
+
class Console
|
5
|
+
class Command
|
6
|
+
class SubCommand
|
7
|
+
def initialize(parent, command, type)
|
8
|
+
@parent = parent
|
9
|
+
@command = command
|
10
|
+
@type = type
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :command
|
14
|
+
|
15
|
+
def handle(arguments, console)
|
16
|
+
if arguments.size > 1
|
17
|
+
console.stdin("to many arguments for #{Style.highlight(command.to_s)}, got #{Style.error(arguments.size)} expected #{Style.notice(1)}.")
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
21
|
+
case @type
|
22
|
+
when :boolean
|
23
|
+
case arguments.last
|
24
|
+
when "", nil
|
25
|
+
var = @parent.get(command.to_sym) || false
|
26
|
+
console.stdin("#{command}: #{Style.highlight(var)}")
|
27
|
+
when "on"
|
28
|
+
var = @parent.set(command.to_sym, true)
|
29
|
+
console.stdin("#{command} => #{Style.highlight(var)}")
|
30
|
+
when "off"
|
31
|
+
var = @parent.set(command.to_sym, false)
|
32
|
+
console.stdin("#{command} => #{Style.highlight(var)}")
|
33
|
+
else
|
34
|
+
console.stdin("Invalid argument for #{Style.highlight(command.to_s)}, got #{Style.error(arguments.last)} expected #{Style.notice('on')}, or #{Style.notice('off')}.")
|
35
|
+
end
|
36
|
+
when :string
|
37
|
+
case arguments.last
|
38
|
+
when "", nil
|
39
|
+
var = @parent.get(command.to_sym) || "\"\""
|
40
|
+
console.stdin("#{command}: #{Style.highlight(var)}")
|
41
|
+
else
|
42
|
+
var = @parent.set(command.to_sym, arguments.last)
|
43
|
+
console.stdin("#{command} => #{Style.highlight(var)}")
|
44
|
+
end
|
45
|
+
when :integer
|
46
|
+
case arguments.last
|
47
|
+
when "", nil
|
48
|
+
var = @parent.get(command.to_sym) || "nil"
|
49
|
+
console.stdin("#{command}: #{Style.highlight(var)}")
|
50
|
+
else
|
51
|
+
begin
|
52
|
+
var = @parent.set(command.to_sym, Integer(arguments.last))
|
53
|
+
console.stdin("#{command} => #{Style.highlight(var)}")
|
54
|
+
rescue ArgumentError
|
55
|
+
console.stdin("Error: #{Style.error("Expected an integer, got '#{arguments.last}'")}")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
when :decimal
|
59
|
+
case arguments.last
|
60
|
+
when "", nil
|
61
|
+
var = @parent.get(command.to_sym) || "nil"
|
62
|
+
console.stdin("#{command}: #{Style.highlight(var)}")
|
63
|
+
else
|
64
|
+
begin
|
65
|
+
var = @parent.set(command.to_sym, Float(arguments.last))
|
66
|
+
console.stdin("#{command} => #{Style.highlight(var)}")
|
67
|
+
rescue ArgumentError
|
68
|
+
console.stdin("Error: #{Style.error("Expected a decimal or integer, got '#{arguments.last}'")}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
else
|
72
|
+
raise RuntimeError
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def values
|
77
|
+
case @type
|
78
|
+
when :boolean
|
79
|
+
%w[on off]
|
80
|
+
else
|
81
|
+
[]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def usage
|
86
|
+
case @type
|
87
|
+
when :boolean
|
88
|
+
"#{Style.highlight(command)} #{Style.notice('[on|off]')}"
|
89
|
+
when :string
|
90
|
+
"#{Style.highlight(command)} #{Style.notice('[string]')}"
|
91
|
+
when :integer
|
92
|
+
"#{Style.highlight(command)} #{Style.notice('[0]')}"
|
93
|
+
when :decimal
|
94
|
+
"#{Style.highlight(command)} #{Style.notice('[0.0]')}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,248 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CyberarmEngine
|
4
|
+
class Console
|
5
|
+
Z = 100_000
|
6
|
+
PADDING = 2
|
7
|
+
include Common
|
8
|
+
|
9
|
+
attr_reader :text_input
|
10
|
+
|
11
|
+
def initialize(font: Gosu.default_font_name)
|
12
|
+
@text_input = Gosu::TextInput.new
|
13
|
+
@width = window.width / 4 * 3
|
14
|
+
@height = window.height / 4 * 3
|
15
|
+
|
16
|
+
@input = Text.new("", x: 4, y: @height - (PADDING * 2), z: Console::Z + 1, font: font)
|
17
|
+
@input.y -= @input.height
|
18
|
+
|
19
|
+
@history = Text.new("", x: 4, z: Console::Z + 1, font: font, border: true, border_color: Gosu::Color::BLACK)
|
20
|
+
update_history_y
|
21
|
+
|
22
|
+
@command_history = []
|
23
|
+
@command_history_index = 0
|
24
|
+
|
25
|
+
@memory = ""
|
26
|
+
|
27
|
+
@background_color = Gosu::Color.rgba(0, 0, 0, 200)
|
28
|
+
@foreground_color = Gosu::Color.rgba(100, 100, 100, 100)
|
29
|
+
@input_color = Gosu::Color.rgba(100, 100, 100, 200)
|
30
|
+
|
31
|
+
@showing_cursor = false
|
32
|
+
@active_text_input = nil
|
33
|
+
|
34
|
+
@show_caret = true
|
35
|
+
@caret_last_change = Gosu.milliseconds
|
36
|
+
@caret_interval = 250
|
37
|
+
@caret_color = Gosu::Color::WHITE
|
38
|
+
@selection_color = Gosu::Color.new(0x5522ff22)
|
39
|
+
end
|
40
|
+
|
41
|
+
def draw
|
42
|
+
# Background/Border
|
43
|
+
draw_rect(0, 0, @width, @height, @background_color, Console::Z)
|
44
|
+
# Foregound/History
|
45
|
+
draw_rect(PADDING, PADDING, @width - (PADDING * 2), @height - (PADDING * 2), @foreground_color, Console::Z)
|
46
|
+
# Text bar
|
47
|
+
draw_rect(2, @input.y, @width - (PADDING * 2), @input.height, @input_color, Console::Z)
|
48
|
+
|
49
|
+
@history.draw
|
50
|
+
@input.draw
|
51
|
+
# Caret
|
52
|
+
if @show_caret
|
53
|
+
draw_rect(@input.x + caret_from_left, @input.y, Console::PADDING, @input.height, @caret_color, Console::Z + 2)
|
54
|
+
end
|
55
|
+
# Caret selection
|
56
|
+
if caret_start != caret_end
|
57
|
+
if caret_start < @text_input.selection_start
|
58
|
+
draw_rect(@input.x + caret_from_left, @input.y, caret_selection_width, @input.height, @selection_color, Console::Z)
|
59
|
+
else
|
60
|
+
draw_rect((@input.x + caret_from_left) - caret_selection_width, @input.y, caret_selection_width, @input.height, @selection_color, Console::Z)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def caret_from_left
|
66
|
+
return 0 if @text_input.caret_pos.zero?
|
67
|
+
|
68
|
+
@input.textobject.text_width(@text_input.text[0..@text_input.caret_pos - 1])
|
69
|
+
end
|
70
|
+
|
71
|
+
def caret_selection_width
|
72
|
+
@input.textobject.text_width(@text_input.text[caret_start..(caret_end - 1)])
|
73
|
+
end
|
74
|
+
|
75
|
+
def caret_pos
|
76
|
+
@text_input.caret_pos
|
77
|
+
end
|
78
|
+
|
79
|
+
def caret_start
|
80
|
+
@text_input.selection_start < @text_input.caret_pos ? @text_input.selection_start : @text_input.caret_pos
|
81
|
+
end
|
82
|
+
|
83
|
+
def caret_end
|
84
|
+
@text_input.selection_start > @text_input.caret_pos ? @text_input.selection_start : @text_input.caret_pos
|
85
|
+
end
|
86
|
+
|
87
|
+
def update
|
88
|
+
if Gosu.milliseconds - @caret_last_change >= @caret_interval
|
89
|
+
@caret_last_change = Gosu.milliseconds
|
90
|
+
@show_caret = !@show_caret
|
91
|
+
end
|
92
|
+
|
93
|
+
if @width != window.width || @height != @height
|
94
|
+
@width = window.width / 4 * 3
|
95
|
+
@height = window.height / 4 * 3
|
96
|
+
|
97
|
+
@input.y = @height - (PADDING * 2 + @input.height)
|
98
|
+
update_history_y
|
99
|
+
end
|
100
|
+
|
101
|
+
@input.text = @text_input.text
|
102
|
+
end
|
103
|
+
|
104
|
+
def button_down(id)
|
105
|
+
case id
|
106
|
+
when Gosu::KbEnter, Gosu::KbReturn
|
107
|
+
return unless @text_input.text.length.positive?
|
108
|
+
|
109
|
+
@history.text += "\n<c=999999>> #{@text_input.text}</c>"
|
110
|
+
@command_history << @text_input.text
|
111
|
+
@command_history_index = @command_history.size
|
112
|
+
update_history_y
|
113
|
+
handle_command
|
114
|
+
@text_input.text = ""
|
115
|
+
|
116
|
+
when Gosu::KbUp
|
117
|
+
@command_history_index -= 1
|
118
|
+
@command_history_index = 0 if @command_history_index.negative?
|
119
|
+
@text_input.text = @command_history[@command_history_index]
|
120
|
+
|
121
|
+
when Gosu::KbDown
|
122
|
+
@command_history_index += 1
|
123
|
+
if @command_history_index > @command_history.size - 1
|
124
|
+
@text_input.text = "" unless @command_history_index > @command_history.size
|
125
|
+
@command_history_index = @command_history.size
|
126
|
+
else
|
127
|
+
@text_input.text = @command_history[@command_history_index]
|
128
|
+
end
|
129
|
+
|
130
|
+
when Gosu::KbTab
|
131
|
+
split = @text_input.text.split(" ")
|
132
|
+
|
133
|
+
if !@text_input.text.end_with?(" ") && split.size == 1
|
134
|
+
list = abbrev_search(Console::Command.list_commands.map { |cmd| cmd.command.to_s }, @text_input.text)
|
135
|
+
|
136
|
+
if list.size == 1
|
137
|
+
@text_input.text = "#{list.first} "
|
138
|
+
elsif list.size.positive?
|
139
|
+
stdin("\n#{list.map { |cmd| Console::Style.highlight(cmd) }.join(', ')}")
|
140
|
+
end
|
141
|
+
elsif split.size.positive? && cmd = Console::Command.find(split.first)
|
142
|
+
cmd.autocomplete(self)
|
143
|
+
end
|
144
|
+
|
145
|
+
when Gosu::KbBacktick
|
146
|
+
# Remove backtick character from input
|
147
|
+
@text_input.text = if @text_input.text.size > 1
|
148
|
+
@text_input.text[0..@text_input.text.size - 2]
|
149
|
+
else
|
150
|
+
""
|
151
|
+
end
|
152
|
+
|
153
|
+
# Copy
|
154
|
+
when Gosu::KbC
|
155
|
+
if control_down? && shift_down?
|
156
|
+
@memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
|
157
|
+
p @memory
|
158
|
+
elsif control_down?
|
159
|
+
@text_input.text = ""
|
160
|
+
end
|
161
|
+
|
162
|
+
# Paste
|
163
|
+
when Gosu::KbV
|
164
|
+
if control_down? && shift_down?
|
165
|
+
string = @text_input.text.chars.insert(caret_pos, @memory).join
|
166
|
+
_caret_pos = caret_pos
|
167
|
+
@text_input.text = string
|
168
|
+
@text_input.caret_pos = _caret_pos + @memory.length
|
169
|
+
@text_input.selection_start = _caret_pos + @memory.length
|
170
|
+
end
|
171
|
+
|
172
|
+
# Cut
|
173
|
+
when Gosu::KbX
|
174
|
+
if control_down? && shift_down?
|
175
|
+
@memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
|
176
|
+
string = @text_input.text.chars
|
177
|
+
Array(caret_start..caret_end - 1).each_with_index do |i, j|
|
178
|
+
string.delete_at(i - j)
|
179
|
+
end
|
180
|
+
|
181
|
+
@text_input.text = string.join
|
182
|
+
end
|
183
|
+
|
184
|
+
# Delete word to left of caret
|
185
|
+
when Gosu::KbW
|
186
|
+
if control_down?
|
187
|
+
split = @text_input.text.split(" ")
|
188
|
+
split.delete(split.last)
|
189
|
+
@text_input.text = split.join(" ")
|
190
|
+
end
|
191
|
+
|
192
|
+
# Clear history
|
193
|
+
when Gosu::KbL
|
194
|
+
@history.text = "" if control_down?
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def button_up(id)
|
199
|
+
end
|
200
|
+
|
201
|
+
def update_history_y
|
202
|
+
@history.y = @height - (PADDING * 2) - @input.height - (@history.text.lines.count * @history.textobject.height)
|
203
|
+
end
|
204
|
+
|
205
|
+
def handle_command
|
206
|
+
string = @text_input.text
|
207
|
+
split = string.split(" ")
|
208
|
+
command = split.first
|
209
|
+
arguments = split.length.positive? ? split[1..split.length - 1] : []
|
210
|
+
|
211
|
+
CyberarmEngine::Console::Command.use(command, arguments, self)
|
212
|
+
end
|
213
|
+
|
214
|
+
def abbrev_search(array, text)
|
215
|
+
return [] unless text.length.positive?
|
216
|
+
|
217
|
+
list = []
|
218
|
+
Abbrev.abbrev(array).each do |abbrev, value|
|
219
|
+
next unless abbrev&.start_with?(text)
|
220
|
+
|
221
|
+
list << value
|
222
|
+
end
|
223
|
+
|
224
|
+
list.uniq
|
225
|
+
end
|
226
|
+
|
227
|
+
def stdin(string)
|
228
|
+
@history.text += "\n#{string}"
|
229
|
+
update_history_y
|
230
|
+
end
|
231
|
+
|
232
|
+
def focus
|
233
|
+
@active_text_input = window.text_input
|
234
|
+
window.text_input = @text_input
|
235
|
+
|
236
|
+
@showing_cursor = window.needs_cursor
|
237
|
+
window.needs_cursor = true
|
238
|
+
|
239
|
+
@show_caret = true
|
240
|
+
@caret_last_change = Gosu.milliseconds
|
241
|
+
end
|
242
|
+
|
243
|
+
def blur
|
244
|
+
window.text_input = @active_text_input
|
245
|
+
window.needs_cursor = @showing_cursor
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
@@ -3,7 +3,8 @@ module CyberarmEngine
|
|
3
3
|
attr_accessor :objects, :materials, :vertices, :uvs, :texures, :normals, :faces, :colors, :bones, :material_file,
|
4
4
|
:current_material, :current_object, :vertex_count, :smoothing
|
5
5
|
attr_reader :position, :bounding_box, :textured_material, :file_path, :positions_buffer_id, :colors_buffer_id,
|
6
|
-
:normals_buffer_id, :uvs_buffer_id, :textures_buffer_id, :vertex_array_id, :aabb_tree
|
6
|
+
:normals_buffer_id, :uvs_buffer_id, :textures_buffer_id, :vertex_array_id, :aabb_tree,
|
7
|
+
:vertices_count
|
7
8
|
|
8
9
|
def initialize(file_path:)
|
9
10
|
@file_path = file_path
|
@@ -23,6 +24,8 @@ module CyberarmEngine
|
|
23
24
|
@bones = []
|
24
25
|
@smoothing = 0
|
25
26
|
|
27
|
+
@vertices_count = 0
|
28
|
+
|
26
29
|
@bounding_box = BoundingBox.new
|
27
30
|
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
28
31
|
|
@@ -32,6 +35,8 @@ module CyberarmEngine
|
|
32
35
|
|
33
36
|
parse(parser)
|
34
37
|
|
38
|
+
@vertices_count = @vertices.size
|
39
|
+
|
35
40
|
@has_texture = false
|
36
41
|
|
37
42
|
@materials.each do |_key, material|
|
@@ -3,8 +3,8 @@ module CyberarmEngine
|
|
3
3
|
attr_accessor :position, :orientation, :aspect_ratio, :field_of_view,
|
4
4
|
:min_view_distance, :max_view_distance
|
5
5
|
|
6
|
-
def initialize(position:, aspect_ratio:, orientation: Vector.new(0, 0,
|
7
|
-
|
6
|
+
def initialize(position:, aspect_ratio:, orientation: Vector.new(0, 0, 0),
|
7
|
+
field_of_view: 70.0, min_view_distance: 0.1, max_view_distance: 1024.0)
|
8
8
|
@position = position
|
9
9
|
@orientation = orientation
|
10
10
|
|
@@ -3,12 +3,15 @@ module CyberarmEngine
|
|
3
3
|
@@immediate_mode_warning = false
|
4
4
|
|
5
5
|
attr_accessor :show_wireframe
|
6
|
+
attr_reader :number_of_vertices
|
6
7
|
|
7
8
|
def initialize(width:, height:, show_wireframe: false)
|
8
9
|
@width = width
|
9
10
|
@height = height
|
10
11
|
@show_wireframe = show_wireframe
|
11
12
|
|
13
|
+
@number_of_vertices = 0
|
14
|
+
|
12
15
|
@g_buffer = GBuffer.new(width: @width, height: @height)
|
13
16
|
end
|
14
17
|
|
@@ -20,6 +23,8 @@ module CyberarmEngine
|
|
20
23
|
end
|
21
24
|
|
22
25
|
def render(camera, lights, entities)
|
26
|
+
@number_of_vertices = 0
|
27
|
+
|
23
28
|
glViewport(0, 0, @width, @height)
|
24
29
|
glEnable(GL_DEPTH_TEST)
|
25
30
|
|
@@ -44,6 +49,8 @@ module CyberarmEngine
|
|
44
49
|
gl_error?
|
45
50
|
draw_model(entity.model, shader)
|
46
51
|
entity.draw
|
52
|
+
|
53
|
+
@number_of_vertices += entity.model.vertices_count
|
47
54
|
end
|
48
55
|
end
|
49
56
|
|
@@ -90,6 +97,8 @@ module CyberarmEngine
|
|
90
97
|
draw_mesh(entity.model)
|
91
98
|
entity.draw
|
92
99
|
glPopMatrix
|
100
|
+
|
101
|
+
@number_of_vertices += entity.model.vertices_count
|
93
102
|
end
|
94
103
|
end
|
95
104
|
|
data/lib/cyberarm_engine/text.rb
CHANGED
@@ -3,7 +3,9 @@ module CyberarmEngine
|
|
3
3
|
CACHE = {}
|
4
4
|
|
5
5
|
attr_accessor :x, :y, :z, :size, :options
|
6
|
-
attr_reader :text, :textobject, :factor_x, :factor_y, :color,
|
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
|
7
9
|
|
8
10
|
def initialize(text, options = {})
|
9
11
|
@text = text.to_s || ""
|
@@ -15,16 +17,25 @@ module CyberarmEngine
|
|
15
17
|
@z = options[:z] || 1025
|
16
18
|
@factor_x = options[:factor_x] || 1
|
17
19
|
@factor_y = options[:factor_y] || 1
|
18
|
-
|
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
|
19
25
|
@mode = options[:mode] || :default
|
20
26
|
@alignment = options[:alignment] || nil
|
21
|
-
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@
|
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]
|
33
|
+
|
34
|
+
@shadow = options[:shadow]
|
35
|
+
@shadow_size = options[:shadow_size] || 2
|
26
36
|
@shadow_alpha = options[:shadow_alpha] || 30
|
27
37
|
@shadow_color = options[:shadow_color]
|
38
|
+
|
28
39
|
@textobject = check_cache(@size, @font)
|
29
40
|
|
30
41
|
if @alignment
|
@@ -37,8 +48,6 @@ module CyberarmEngine
|
|
37
48
|
@x = $window.width - BUTTON_PADDING - @textobject.text_width(@text)
|
38
49
|
end
|
39
50
|
end
|
40
|
-
|
41
|
-
self
|
42
51
|
end
|
43
52
|
|
44
53
|
def check_cache(size, font_name)
|
@@ -75,82 +84,100 @@ module CyberarmEngine
|
|
75
84
|
end
|
76
85
|
|
77
86
|
def text=(string)
|
78
|
-
@
|
87
|
+
@rendered_border = nil
|
79
88
|
@text = string
|
80
89
|
end
|
81
90
|
|
82
91
|
def factor_x=(n)
|
83
|
-
@
|
92
|
+
@rendered_border = nil
|
84
93
|
@factor_x = n
|
85
94
|
end
|
86
95
|
|
87
96
|
def factor_y=(n)
|
88
|
-
@
|
97
|
+
@rendered_border = nil
|
89
98
|
@factor_y = n
|
90
99
|
end
|
91
100
|
|
92
101
|
def color=(color)
|
93
|
-
@
|
94
|
-
|
102
|
+
@rendered_border = nil
|
103
|
+
if color
|
104
|
+
@color = color.is_a?(Gosu::Color) ? color : Gosu::Color.new(color)
|
105
|
+
else
|
106
|
+
raise "color cannot be nil"
|
107
|
+
end
|
95
108
|
end
|
96
109
|
|
97
|
-
def
|
98
|
-
@
|
99
|
-
@
|
110
|
+
def border=(boolean)
|
111
|
+
@rendered_border = nil
|
112
|
+
@border = boolean
|
100
113
|
end
|
101
114
|
|
102
|
-
def
|
103
|
-
@
|
104
|
-
@
|
115
|
+
def border_size=(n)
|
116
|
+
@rendered_border = nil
|
117
|
+
@border_size = n
|
105
118
|
end
|
106
119
|
|
107
|
-
def
|
108
|
-
@
|
109
|
-
@
|
120
|
+
def border_alpha=(n)
|
121
|
+
@rendered_border = nil
|
122
|
+
@border_alpha = n
|
110
123
|
end
|
111
124
|
|
112
|
-
def
|
113
|
-
@
|
114
|
-
@
|
125
|
+
def border_color=(n)
|
126
|
+
@rendered_border = nil
|
127
|
+
@border_color = n
|
115
128
|
end
|
116
129
|
|
117
130
|
def width(text = @text)
|
118
|
-
|
131
|
+
markup_width(text)
|
132
|
+
end
|
133
|
+
|
134
|
+
def text_width(text = @text)
|
135
|
+
textobject.text_width(text) + @border_size + @shadow_size
|
119
136
|
end
|
120
137
|
|
121
138
|
def markup_width(text = @text)
|
122
|
-
textobject.markup_width(text)
|
139
|
+
textobject.markup_width(text) + @border_size + @shadow_size
|
123
140
|
end
|
124
141
|
|
125
142
|
def height(text = @text)
|
126
|
-
text.lines.count > 0
|
143
|
+
if text.lines.count > 0
|
144
|
+
text.lines.count * textobject.height + @border_size + @shadow_size
|
145
|
+
else
|
146
|
+
@textobject.height + @border_size + @shadow_size
|
147
|
+
end
|
127
148
|
end
|
128
149
|
|
129
150
|
def draw(method = :draw_markup)
|
130
|
-
if @
|
131
|
-
|
132
|
-
|
133
|
-
|
151
|
+
if @border && !ARGV.join.include?("--no-border")
|
152
|
+
border_alpha = @color.alpha <= 30 ? @color.alpha : @border_alpha
|
153
|
+
border_color = @border_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue,
|
154
|
+
border_alpha)
|
134
155
|
white = Gosu::Color::WHITE
|
135
156
|
|
136
|
-
_x = @
|
137
|
-
_y = @
|
157
|
+
_x = @border_size
|
158
|
+
_y = @border_size
|
159
|
+
_width = method == :draw_markup ? text_width : markup_width
|
138
160
|
|
139
|
-
@
|
140
|
-
@textobject.send(method, @text, _x - @
|
141
|
-
@textobject.send(method, @text, _x - @
|
161
|
+
@rendered_border ||= Gosu.render((_width + (border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
|
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)
|
142
164
|
|
143
|
-
@textobject.send(method, @text, _x, _y - @
|
144
|
-
@textobject.send(method, @text, _x + @
|
165
|
+
@textobject.send(method, @text, _x, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
166
|
+
@textobject.send(method, @text, _x + @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
145
167
|
|
146
|
-
@textobject.send(method, @text, _x, _y + @
|
147
|
-
@textobject.send(method, @text, _x - @
|
168
|
+
@textobject.send(method, @text, _x, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
169
|
+
@textobject.send(method, @text, _x - @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
148
170
|
|
149
|
-
@textobject.send(method, @text, _x + @
|
150
|
-
@textobject.send(method, @text, _x + @
|
171
|
+
@textobject.send(method, @text, _x + @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
|
172
|
+
@textobject.send(method, @text, _x + @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
151
173
|
end
|
152
174
|
|
153
|
-
@
|
175
|
+
@rendered_border.draw(@x - @border_size, @y - @border_size, @z, @factor_x, @factor_y, border_color)
|
176
|
+
end
|
177
|
+
|
178
|
+
if @shadow
|
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)
|
154
181
|
end
|
155
182
|
|
156
183
|
@textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode)
|