minigl 2.2.5 → 2.3.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/README.md +11 -5
- data/lib/minigl/forms.rb +22 -3
- data/lib/minigl/game_object.rb +4 -1
- data/lib/minigl/global.rb +22 -4
- data/lib/minigl/movement.rb +54 -41
- data/lib/minigl/text.rb +137 -32
- data/test/game.rb +6 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0362df674b485b64cd44d6b167377b2d46d6c33fd9b2d65428fe75e8de9e027
|
4
|
+
data.tar.gz: d91ae820bfc76cb9895f43227646028b23927cffe2e4b226f3b2b14779fe08a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70af1a521abd0f23110b62b2c88a1de5f1fd94aeb664fc8c9e4ca8cd414a024c0ac93037889b9b8431598c7e63cf11e62b00f657213f5eb68957da70ca4fdfc5
|
7
|
+
data.tar.gz: 685115af1a42dc3662af276580771b0be33eae0348fd54e1f11f679c2de26a10f8d158a9d00cf0e67ae42ae5bab2af4841adbf466aca38b46b6e75665ca3b773
|
data/README.md
CHANGED
@@ -5,9 +5,9 @@ top of the [Gosu](http://www.libgosu.org/) gem.
|
|
5
5
|
|
6
6
|
It provides the following features:
|
7
7
|
|
8
|
-
* Resource management (images,
|
9
|
-
* Input manipulation (keyboard, mouse,
|
10
|
-
* UI (text, buttons, text fields,
|
8
|
+
* Resource management (images, sound effects, songs, tilesets, fonts)
|
9
|
+
* Input manipulation (keyboard, mouse, joystick)
|
10
|
+
* UI (text, buttons, text fields, drop-down lists, progress bars)
|
11
11
|
* Basic physics and collision checking
|
12
12
|
* Animated objects
|
13
13
|
|
@@ -29,6 +29,12 @@ After installing the Gosu dependencies, you can just `gem install minigl`.
|
|
29
29
|
* The [wiki](https://github.com/victords/minigl/wiki) is a work in progress with tutorials and examples.
|
30
30
|
* Test package and examples aren't complete!
|
31
31
|
|
32
|
-
## Version 2.
|
32
|
+
## Version 2.3.0
|
33
33
|
|
34
|
-
*
|
34
|
+
* Added the `ImageFont` class.
|
35
|
+
* Added scale and line spacing options to `TextHelper` methods.
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Contributions are very welcome. Feel free to fork and send pull requests.
|
40
|
+
Also, you can support my work by donating bitcoins to this wallet: bc1qsp7mypdqvkt88xtnarmaytt0etxfccxr5pt5tk
|
data/lib/minigl/forms.rb
CHANGED
@@ -37,6 +37,9 @@ module MiniGL
|
|
37
37
|
# The height of the component
|
38
38
|
attr_reader :h
|
39
39
|
|
40
|
+
# The text of the component
|
41
|
+
attr_reader :text
|
42
|
+
|
40
43
|
attr_reader :anchor, :anchor_offset_x, :anchor_offset_y # :nodoc:
|
41
44
|
|
42
45
|
# Determines whether the control is enabled, i.e., will process user input.
|
@@ -52,6 +55,8 @@ module MiniGL
|
|
52
55
|
# for each specific component class.
|
53
56
|
attr_accessor :params
|
54
57
|
|
58
|
+
attr_accessor :panel # :nodoc:
|
59
|
+
|
55
60
|
def initialize(x, y, font, text, text_color, disabled_text_color) # :nodoc:
|
56
61
|
@x = x
|
57
62
|
@y = y
|
@@ -127,6 +132,7 @@ module MiniGL
|
|
127
132
|
controls.each do |c|
|
128
133
|
_, x, y = FormUtils.check_anchor(c.anchor, c.anchor_offset_x, c.anchor_offset_y, c.w, c.h, @w, @h)
|
129
134
|
c.set_position(@x + x, @y + y)
|
135
|
+
c.panel = self
|
130
136
|
end
|
131
137
|
|
132
138
|
if img
|
@@ -537,9 +543,6 @@ module MiniGL
|
|
537
543
|
|
538
544
|
# This class represents a text field (input).
|
539
545
|
class TextField < Component
|
540
|
-
# The current text inside the text field.
|
541
|
-
attr_reader :text
|
542
|
-
|
543
546
|
# The current 'locale' used for detecting the keys. THIS FEATURE IS
|
544
547
|
# INCOMPLETE!
|
545
548
|
attr_reader :locale
|
@@ -1460,6 +1463,22 @@ module MiniGL
|
|
1460
1463
|
super(x, y, font, text, text_color, disabled_text_color)
|
1461
1464
|
end
|
1462
1465
|
|
1466
|
+
# Changes the label's text.
|
1467
|
+
#
|
1468
|
+
# Parameters:
|
1469
|
+
# [new_text] The new text to show in the label.
|
1470
|
+
def text=(new_text)
|
1471
|
+
@text = new_text
|
1472
|
+
@w = @font.text_width(@text) * @scale_x
|
1473
|
+
x = @anchor_offset_x; y = @anchor_offset_y
|
1474
|
+
_, x, y = FormUtils.check_anchor(@anchor, x, y, @w, @h, panel ? panel.w : G.window.width, panel ? panel.h : G.window.height)
|
1475
|
+
if panel
|
1476
|
+
set_position(panel.x + x, panel.y + y)
|
1477
|
+
else
|
1478
|
+
set_position(x, y)
|
1479
|
+
end
|
1480
|
+
end
|
1481
|
+
|
1463
1482
|
# Draws the label.
|
1464
1483
|
#
|
1465
1484
|
# Parameters:
|
data/lib/minigl/game_object.rb
CHANGED
@@ -82,7 +82,10 @@ module MiniGL
|
|
82
82
|
# [interval] The amount of frames between each change in the image index.
|
83
83
|
# See +animate+ for details.
|
84
84
|
def animate_once(indices, interval)
|
85
|
-
|
85
|
+
if @animate_once_control == 2
|
86
|
+
return if indices == @animate_once_indices && interval == @animate_once_interval
|
87
|
+
@animate_once_control = 0
|
88
|
+
end
|
86
89
|
|
87
90
|
unless @animate_once_control == 1
|
88
91
|
@anim_counter = 0
|
data/lib/minigl/global.rb
CHANGED
@@ -247,9 +247,7 @@ module MiniGL
|
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
250
|
-
#
|
251
|
-
|
252
|
-
# Exposes methods for controlling keyboard events.
|
250
|
+
# Exposes methods for controlling keyboard and gamepad events.
|
253
251
|
module KB
|
254
252
|
class << self
|
255
253
|
# This is called by <code>GameWindow.initialize</code>. Don't call it
|
@@ -278,7 +276,27 @@ module MiniGL
|
|
278
276
|
Gosu::KB_PAGE_UP, Gosu::KB_PERIOD, Gosu::KB_RETURN, Gosu::KB_RIGHT,
|
279
277
|
Gosu::KB_RIGHT_ALT, Gosu::KB_RIGHT_BRACKET, Gosu::KB_RIGHT_CONTROL,
|
280
278
|
Gosu::KB_RIGHT_META, Gosu::KB_RIGHT_SHIFT, Gosu::KB_SEMICOLON,
|
281
|
-
Gosu::KB_SLASH, Gosu::KB_SPACE, Gosu::KB_TAB, Gosu::KB_UP
|
279
|
+
Gosu::KB_SLASH, Gosu::KB_SPACE, Gosu::KB_TAB, Gosu::KB_UP,
|
280
|
+
Gosu::GP_0_BUTTON_0, Gosu::GP_0_BUTTON_1, Gosu::GP_0_BUTTON_2, Gosu::GP_0_BUTTON_3,
|
281
|
+
Gosu::GP_0_BUTTON_4, Gosu::GP_0_BUTTON_5, Gosu::GP_0_BUTTON_6, Gosu::GP_0_BUTTON_7,
|
282
|
+
Gosu::GP_0_BUTTON_8, Gosu::GP_0_BUTTON_9, Gosu::GP_0_BUTTON_10, Gosu::GP_0_BUTTON_11,
|
283
|
+
Gosu::GP_0_BUTTON_12, Gosu::GP_0_BUTTON_13, Gosu::GP_0_BUTTON_14, Gosu::GP_0_BUTTON_15,
|
284
|
+
Gosu::GP_0_DOWN, Gosu::GP_0_LEFT, Gosu::GP_0_RIGHT, Gosu::GP_0_UP,
|
285
|
+
Gosu::GP_1_BUTTON_0, Gosu::GP_1_BUTTON_1, Gosu::GP_1_BUTTON_2, Gosu::GP_1_BUTTON_3,
|
286
|
+
Gosu::GP_1_BUTTON_4, Gosu::GP_1_BUTTON_5, Gosu::GP_1_BUTTON_6, Gosu::GP_1_BUTTON_7,
|
287
|
+
Gosu::GP_1_BUTTON_8, Gosu::GP_1_BUTTON_9, Gosu::GP_1_BUTTON_10, Gosu::GP_1_BUTTON_11,
|
288
|
+
Gosu::GP_1_BUTTON_12, Gosu::GP_1_BUTTON_13, Gosu::GP_1_BUTTON_14, Gosu::GP_1_BUTTON_15,
|
289
|
+
Gosu::GP_1_DOWN, Gosu::GP_1_LEFT, Gosu::GP_1_RIGHT, Gosu::GP_1_UP,
|
290
|
+
Gosu::GP_2_BUTTON_0, Gosu::GP_2_BUTTON_1, Gosu::GP_2_BUTTON_2, Gosu::GP_2_BUTTON_3,
|
291
|
+
Gosu::GP_2_BUTTON_4, Gosu::GP_2_BUTTON_5, Gosu::GP_2_BUTTON_6, Gosu::GP_2_BUTTON_7,
|
292
|
+
Gosu::GP_2_BUTTON_8, Gosu::GP_2_BUTTON_9, Gosu::GP_2_BUTTON_10, Gosu::GP_2_BUTTON_11,
|
293
|
+
Gosu::GP_2_BUTTON_12, Gosu::GP_2_BUTTON_13, Gosu::GP_2_BUTTON_14, Gosu::GP_2_BUTTON_15,
|
294
|
+
Gosu::GP_2_DOWN, Gosu::GP_2_LEFT, Gosu::GP_2_RIGHT, Gosu::GP_2_UP,
|
295
|
+
Gosu::GP_3_BUTTON_0, Gosu::GP_3_BUTTON_1, Gosu::GP_3_BUTTON_2, Gosu::GP_3_BUTTON_3,
|
296
|
+
Gosu::GP_3_BUTTON_4, Gosu::GP_3_BUTTON_5, Gosu::GP_3_BUTTON_6, Gosu::GP_3_BUTTON_7,
|
297
|
+
Gosu::GP_3_BUTTON_8, Gosu::GP_3_BUTTON_9, Gosu::GP_3_BUTTON_10, Gosu::GP_3_BUTTON_11,
|
298
|
+
Gosu::GP_3_BUTTON_12, Gosu::GP_3_BUTTON_13, Gosu::GP_3_BUTTON_14, Gosu::GP_3_BUTTON_15,
|
299
|
+
Gosu::GP_3_DOWN, Gosu::GP_3_LEFT, Gosu::GP_3_RIGHT, Gosu::GP_3_UP,
|
282
300
|
]
|
283
301
|
@down = []
|
284
302
|
@prev_down = []
|
data/lib/minigl/movement.rb
CHANGED
@@ -360,17 +360,16 @@ module MiniGL
|
|
360
360
|
# [speed] If the first argument is a forces vector, then this should be
|
361
361
|
# +nil+. If it is a point, then this is the constant speed at which
|
362
362
|
# the object will move (provided as a scalar, not a vector).
|
363
|
-
# [
|
364
|
-
#
|
365
|
-
#
|
366
|
-
#
|
367
|
-
#
|
368
|
-
#
|
369
|
-
#
|
370
|
-
#
|
371
|
-
#
|
372
|
-
|
373
|
-
def move_carrying(arg, speed, obstacles, obst_obstacles, obst_ramps)
|
363
|
+
# [carried_objs] An array of objects that can potentially be carried by
|
364
|
+
# this object while it moves. The objects must respond to
|
365
|
+
# +x+, +y+, +w+ and +h+.
|
366
|
+
# [obstacles] Obstacles that should be considered for collision checking
|
367
|
+
# with the carried objects, if they include the +Movement+
|
368
|
+
# module, and with this object too, if moving with forces.
|
369
|
+
# [ramps] Ramps that should be considered for the carried objects, if they
|
370
|
+
# include the +Movement+ module, and for this object too, if moving
|
371
|
+
# with forces.
|
372
|
+
def move_carrying(arg, speed, carried_objs, obstacles, ramps)
|
374
373
|
if speed
|
375
374
|
x_d = arg.x - @x; y_d = arg.y - @y
|
376
375
|
distance = Math.sqrt(x_d**2 + y_d**2)
|
@@ -382,18 +381,11 @@ module MiniGL
|
|
382
381
|
|
383
382
|
@speed.x = 1.0 * x_d * speed / distance
|
384
383
|
@speed.y = 1.0 * y_d * speed / distance
|
385
|
-
|
386
|
-
arg += G.gravity
|
387
|
-
@speed.x += arg.x / @mass; @speed.y += arg.y / @mass
|
388
|
-
@speed.x = 0 if @speed.x.abs < G.min_speed.x
|
389
|
-
@speed.y = 0 if @speed.y.abs < G.min_speed.y
|
390
|
-
@speed.x = (@speed.x <=> 0) * @max_speed.x if @speed.x.abs > @max_speed.x
|
391
|
-
@speed.y = (@speed.y <=> 0) * @max_speed.y if @speed.y.abs > @max_speed.y
|
384
|
+
x_aim = @x + @speed.x; y_aim = @y + @speed.y
|
392
385
|
end
|
393
386
|
|
394
|
-
x_aim = @x + @speed.x; y_aim = @y + @speed.y
|
395
387
|
passengers = []
|
396
|
-
|
388
|
+
carried_objs.each do |o|
|
397
389
|
if @x + @w > o.x && o.x + o.w > @x
|
398
390
|
foot = o.y + o.h
|
399
391
|
if foot.round(6) == @y.round(6) || @speed.y < 0 && foot < @y && foot > y_aim
|
@@ -415,25 +407,30 @@ module MiniGL
|
|
415
407
|
@y = y_aim
|
416
408
|
end
|
417
409
|
else
|
418
|
-
|
410
|
+
move(arg, obstacles, ramps)
|
419
411
|
end
|
420
412
|
|
421
413
|
forces = Vector.new @x - prev_x, @y - prev_y
|
422
414
|
prev_g = G.gravity.clone
|
423
415
|
G.gravity.x = G.gravity.y = 0
|
424
416
|
passengers.each do |p|
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
417
|
+
if p.class.included_modules.include?(Movement)
|
418
|
+
prev_speed = p.speed.clone
|
419
|
+
prev_forces = p.stored_forces.clone
|
420
|
+
prev_bottom = p.bottom
|
421
|
+
p.speed.x = p.speed.y = 0
|
422
|
+
p.stored_forces.x = p.stored_forces.y = 0
|
423
|
+
p.instance_exec { @bottom = nil }
|
424
|
+
p.move(forces * p.mass, obstacles, ramps)
|
425
|
+
p.speed.x = prev_speed.x
|
426
|
+
p.speed.y = prev_speed.y
|
427
|
+
p.stored_forces.x = prev_forces.x
|
428
|
+
p.stored_forces.y = prev_forces.y
|
429
|
+
p.instance_exec(prev_bottom) { |b| @bottom = b }
|
430
|
+
else
|
431
|
+
p.x += forces.x
|
432
|
+
p.y += forces.y
|
433
|
+
end
|
437
434
|
end
|
438
435
|
G.gravity = prev_g
|
439
436
|
end
|
@@ -504,16 +501,32 @@ module MiniGL
|
|
504
501
|
# of the objects being carried.
|
505
502
|
# [obst_ramps] Ramps to consider when moving objects from the +obstacles+
|
506
503
|
# array, as described for +obst_obstacles+.
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
504
|
+
# [stop_time] Optional stop time (in frames) when the object reaches each of
|
505
|
+
# the points.
|
506
|
+
def cycle(points, speed, obstacles = nil, obst_obstacles = nil, obst_ramps = nil, stop_time = 0)
|
507
|
+
unless @cycle_setup
|
508
|
+
@cur_point = 0 if @cur_point.nil?
|
509
|
+
if obstacles
|
510
|
+
move_carrying points[@cur_point], speed, obstacles, obst_obstacles, obst_ramps
|
511
|
+
else
|
512
|
+
move_free points[@cur_point], speed
|
513
|
+
end
|
513
514
|
end
|
514
515
|
if @speed.x == 0 and @speed.y == 0
|
515
|
-
|
516
|
-
|
516
|
+
unless @cycle_setup
|
517
|
+
@cycle_timer = 0
|
518
|
+
@cycle_setup = true
|
519
|
+
end
|
520
|
+
if @cycle_timer >= stop_time
|
521
|
+
if @cur_point == points.length - 1
|
522
|
+
@cur_point = 0
|
523
|
+
else
|
524
|
+
@cur_point += 1
|
525
|
+
end
|
526
|
+
@cycle_setup = false
|
527
|
+
else
|
528
|
+
@cycle_timer += 1
|
529
|
+
end
|
517
530
|
end
|
518
531
|
end
|
519
532
|
|
data/lib/minigl/text.rb
CHANGED
@@ -1,4 +1,100 @@
|
|
1
1
|
module MiniGL
|
2
|
+
# This class represents a font and exposes most of the methods from +Gosu::Font+,
|
3
|
+
# but allows the font to be created from an image, allowing for better customization
|
4
|
+
# and also using the +retro+ option.
|
5
|
+
#
|
6
|
+
# The image used to load the font must meet these criteria:
|
7
|
+
# * The characters should be laid out in lines of the same height in pixels.
|
8
|
+
# * The full image must have a height that is a multiple of that line height.
|
9
|
+
# * The characters should occupy the maximum available space in each line, i.e.,
|
10
|
+
# if a character fits in the current line it must not be placed in the next
|
11
|
+
# one. In the last line there can be any amount of free space at the end.
|
12
|
+
class ImageFont
|
13
|
+
# The height of this font in pixels.
|
14
|
+
attr_reader :height
|
15
|
+
|
16
|
+
# Creates an +ImageFont+.
|
17
|
+
#
|
18
|
+
# Parameters:
|
19
|
+
# [img_path] Identifier of an image fitting the description in the class documentation,
|
20
|
+
# as used in +Res.img+.
|
21
|
+
# [chars] A string containing all characters that will be present in the image, in the
|
22
|
+
# same order as they appear in the image. Do not include white space.
|
23
|
+
# [widths] An integer representing the width of the chars in pixels, if this is a fixed
|
24
|
+
# width font, or an array containing the width of each char, in the same order
|
25
|
+
# as they appear in the +chars+ string.
|
26
|
+
# [height] The height of the lines in the image (see description above).
|
27
|
+
# [space_width] The width of the white space character in this font.
|
28
|
+
# [global] Parameter that will be passed to +Res.img+ when loading the image.
|
29
|
+
# [ext] Parameter that will be passed to +Res.img+ when loading the image.
|
30
|
+
# [retro] Parameter that will be passed to +Res.img+ when loading the image.
|
31
|
+
def initialize(img_path, chars, widths, height, space_width, global = true, ext = '.png', retro = nil)
|
32
|
+
retro = Res.retro_images if retro.nil?
|
33
|
+
img = Res.img(img_path, global, false, ext, retro)
|
34
|
+
@chars = chars
|
35
|
+
@images = []
|
36
|
+
@height = height
|
37
|
+
@space_width = space_width
|
38
|
+
wa = widths.is_a?(Array)
|
39
|
+
if wa && widths.length != chars.length
|
40
|
+
raise 'Wrong widths array size!'
|
41
|
+
end
|
42
|
+
x = y = 0
|
43
|
+
(0...chars.length).each do |i|
|
44
|
+
@images.push(img.subimage(x, y, wa ? widths[i] : widths, height))
|
45
|
+
new_x = x + (wa ? widths[i] : widths)
|
46
|
+
if i < chars.length - 1 && new_x + (wa ? widths[i+1] : widths) > img.width
|
47
|
+
x = 0
|
48
|
+
y += height
|
49
|
+
else
|
50
|
+
x = new_x
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns the width, in pixels, of a given string written by this font.
|
56
|
+
#
|
57
|
+
# Parameters:
|
58
|
+
# [text] The string to be measured
|
59
|
+
def markup_width(text)
|
60
|
+
text.chars.reduce(0) { |w, c| if c == ' '; w += @space_width; else; i = @chars.index(c); w += i ? @images[i].width : 0; end }
|
61
|
+
end
|
62
|
+
|
63
|
+
# See <code>Gosu::Font#draw_markup_rel</code> for details.
|
64
|
+
def draw_markup_rel(text, x, y, z, rel_x, rel_y, scale_x, scale_y, color)
|
65
|
+
text = text.to_s unless text.is_a?(String)
|
66
|
+
if rel_x == 0.5
|
67
|
+
x -= scale_x * markup_width(text) / 2
|
68
|
+
elsif rel_x == 1
|
69
|
+
x -= scale_x * markup_width(text)
|
70
|
+
end
|
71
|
+
if rel_y == 0.5
|
72
|
+
y -= scale_y * @height / 2
|
73
|
+
elsif rel_y == 1
|
74
|
+
y -= scale_x * @height
|
75
|
+
end
|
76
|
+
text.each_char do |c|
|
77
|
+
if c == ' '
|
78
|
+
x += scale_x * @space_width
|
79
|
+
next
|
80
|
+
end
|
81
|
+
i = @chars.index(c)
|
82
|
+
next if i.nil?
|
83
|
+
@images[i].draw(x, y, z, scale_x, scale_y, color)
|
84
|
+
x += scale_x * @images[i].width
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# See <code>Gosu::Font#draw_markup</code> for details.
|
89
|
+
def draw_markup(text, x, y, z, scale_x, scale_y, color)
|
90
|
+
draw_markup_rel(text, x, y, z, 0, 0, scale_x, scale_y, color)
|
91
|
+
end
|
92
|
+
|
93
|
+
alias :draw_text_rel :draw_markup_rel
|
94
|
+
alias :draw_text :draw_markup
|
95
|
+
alias :text_width :markup_width
|
96
|
+
end
|
97
|
+
|
2
98
|
# This class provides methods for easily drawing one or multiple lines of
|
3
99
|
# text, with control over the text alignment and coloring.
|
4
100
|
class TextHelper
|
@@ -8,9 +104,11 @@ module MiniGL
|
|
8
104
|
# [font] A <code>Gosu::Font</code> that will be used to draw the text.
|
9
105
|
# [line_spacing] When drawing multiple lines, the distance, in pixels,
|
10
106
|
# between each line.
|
11
|
-
def initialize(font, line_spacing = 0)
|
107
|
+
def initialize(font, line_spacing = 0, scale_x = 1, scale_y = 1)
|
12
108
|
@font = font
|
13
109
|
@line_spacing = line_spacing
|
110
|
+
@scale_x = scale_x
|
111
|
+
@scale_y = scale_y
|
14
112
|
end
|
15
113
|
|
16
114
|
# Draws a single line of text.
|
@@ -48,7 +146,7 @@ module MiniGL
|
|
48
146
|
# mandatory.
|
49
147
|
def write_line(text, x = nil, y = nil, mode = :left, color = 0, alpha = 0xff,
|
50
148
|
effect = nil, effect_color = 0, effect_size = 1, effect_alpha = 0xff,
|
51
|
-
z_index = 0)
|
149
|
+
z_index = 0, scale_x = nil, scale_y = nil)
|
52
150
|
if text.is_a? Hash
|
53
151
|
x = text[:x]
|
54
152
|
y = text[:y]
|
@@ -60,9 +158,13 @@ module MiniGL
|
|
60
158
|
effect_size = text.fetch(:effect_size, 1)
|
61
159
|
effect_alpha = text.fetch(:effect_alpha, 0xff)
|
62
160
|
z_index = text.fetch(:z_index, 0)
|
161
|
+
scale_x = text.fetch(:scale_x, nil)
|
162
|
+
scale_y = text.fetch(:scale_y, nil)
|
63
163
|
text = text[:text]
|
64
164
|
end
|
65
165
|
|
166
|
+
scale_x = @scale_x if scale_x.nil?
|
167
|
+
scale_y = @scale_y if scale_y.nil?
|
66
168
|
color = (alpha << 24) | color
|
67
169
|
rel =
|
68
170
|
case mode
|
@@ -74,19 +176,19 @@ module MiniGL
|
|
74
176
|
if effect
|
75
177
|
effect_color = (effect_alpha << 24) | effect_color
|
76
178
|
if effect == :border
|
77
|
-
@font.draw_markup_rel text, x - effect_size, y - effect_size, z_index, rel, 0,
|
78
|
-
@font.draw_markup_rel text, x, y - effect_size, z_index, rel, 0,
|
79
|
-
@font.draw_markup_rel text, x + effect_size, y - effect_size, z_index, rel, 0,
|
80
|
-
@font.draw_markup_rel text, x + effect_size, y, z_index, rel, 0,
|
81
|
-
@font.draw_markup_rel text, x + effect_size, y + effect_size, z_index, rel, 0,
|
82
|
-
@font.draw_markup_rel text, x, y + effect_size, z_index, rel, 0,
|
83
|
-
@font.draw_markup_rel text, x - effect_size, y + effect_size, z_index, rel, 0,
|
84
|
-
@font.draw_markup_rel text, x - effect_size, y, z_index, rel, 0,
|
179
|
+
@font.draw_markup_rel text, x - effect_size, y - effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
|
180
|
+
@font.draw_markup_rel text, x, y - effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
|
181
|
+
@font.draw_markup_rel text, x + effect_size, y - effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
|
182
|
+
@font.draw_markup_rel text, x + effect_size, y, z_index, rel, 0, scale_x, scale_y, effect_color
|
183
|
+
@font.draw_markup_rel text, x + effect_size, y + effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
|
184
|
+
@font.draw_markup_rel text, x, y + effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
|
185
|
+
@font.draw_markup_rel text, x - effect_size, y + effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
|
186
|
+
@font.draw_markup_rel text, x - effect_size, y, z_index, rel, 0, scale_x, scale_y, effect_color
|
85
187
|
elsif effect == :shadow
|
86
|
-
@font.draw_markup_rel text, x + effect_size, y + effect_size, z_index, rel, 0,
|
188
|
+
@font.draw_markup_rel text, x + effect_size, y + effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
|
87
189
|
end
|
88
190
|
end
|
89
|
-
@font.draw_markup_rel text, x, y, z_index, rel, 0,
|
191
|
+
@font.draw_markup_rel text, x, y, z_index, rel, 0, scale_x, scale_y, color
|
90
192
|
end
|
91
193
|
|
92
194
|
# Draws text, breaking lines when needed and when explicitly caused by the
|
@@ -94,7 +196,7 @@ module MiniGL
|
|
94
196
|
#
|
95
197
|
# Parameters:
|
96
198
|
# [text] The text to be drawn. Line breaks are allowed. You can use the
|
97
|
-
|
199
|
+
# `<b>` tag for bold, `<i>` for italic and `<c=rrggbb>` for colors.
|
98
200
|
# [x] The horizontal reference for drawing the text. Works like in
|
99
201
|
# +write_line+ for the +:left+, +:right+ and +:center+ modes. For the
|
100
202
|
# +:justified+ mode, works the same as for +:left+.
|
@@ -109,11 +211,14 @@ module MiniGL
|
|
109
211
|
# transparent) to 255 (fully opaque).
|
110
212
|
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
111
213
|
# will be drawn on top of the ones with smaller z-orders.
|
112
|
-
def write_breaking(text, x, y, width, mode = :left, color = 0, alpha = 0xff, z_index = 0)
|
214
|
+
def write_breaking(text, x, y, width, mode = :left, color = 0, alpha = 0xff, z_index = 0, scale_x = nil, scale_y = nil, line_spacing = nil)
|
215
|
+
line_spacing = @line_spacing if line_spacing.nil?
|
216
|
+
scale_x = @scale_x if scale_x.nil?
|
217
|
+
scale_y = @scale_y if scale_y.nil?
|
113
218
|
color = (alpha << 24) | color
|
114
219
|
text.split("\n").each do |p|
|
115
220
|
if mode == :justified
|
116
|
-
y = write_paragraph_justified p, x, y, width, color, z_index
|
221
|
+
y = write_paragraph_justified p, x, y, width, color, z_index, scale_x, scale_y, line_spacing
|
117
222
|
else
|
118
223
|
rel =
|
119
224
|
case mode
|
@@ -122,40 +227,40 @@ module MiniGL
|
|
122
227
|
when :right then 1
|
123
228
|
else 0
|
124
229
|
end
|
125
|
-
y = write_paragraph p, x, y, width, rel, color, z_index
|
230
|
+
y = write_paragraph p, x, y, width, rel, color, z_index, scale_x, scale_y, line_spacing
|
126
231
|
end
|
127
232
|
end
|
128
233
|
end
|
129
234
|
|
130
235
|
private
|
131
236
|
|
132
|
-
def write_paragraph(text, x, y, width, rel, color, z_index)
|
237
|
+
def write_paragraph(text, x, y, width, rel, color, z_index, scale_x, scale_y, line_spacing)
|
133
238
|
line = ''
|
134
239
|
line_width = 0
|
135
240
|
text.split(' ').each do |word|
|
136
|
-
w = @font.markup_width
|
137
|
-
if line_width + w > width
|
138
|
-
@font.draw_markup_rel line.chop, x, y, z_index, rel, 0,
|
241
|
+
w = @font.markup_width(word)
|
242
|
+
if line_width + w * scale_x > width
|
243
|
+
@font.draw_markup_rel line.chop, x, y, z_index, rel, 0, scale_x, scale_y, color
|
139
244
|
line = ''
|
140
245
|
line_width = 0
|
141
|
-
y += @font.height +
|
246
|
+
y += (@font.height + line_spacing) * scale_y
|
142
247
|
end
|
143
248
|
line += "#{word} "
|
144
|
-
line_width += @font.markup_width
|
249
|
+
line_width += @font.markup_width("#{word} ") * scale_x
|
145
250
|
end
|
146
|
-
@font.draw_markup_rel line.chop, x, y, z_index, rel, 0,
|
147
|
-
y + @font.height +
|
251
|
+
@font.draw_markup_rel line.chop, x, y, z_index, rel, 0, scale_x, scale_y, color unless line.empty?
|
252
|
+
y + (@font.height + line_spacing) * scale_y
|
148
253
|
end
|
149
254
|
|
150
|
-
def write_paragraph_justified(text, x, y, width, color, z_index)
|
151
|
-
space_width = @font.text_width '
|
255
|
+
def write_paragraph_justified(text, x, y, width, color, z_index, scale_x, scale_y, line_spacing)
|
256
|
+
space_width = @font.text_width(' ') * scale_x
|
152
257
|
spaces = [[]]
|
153
258
|
line_index = 0
|
154
259
|
new_x = x
|
155
260
|
words = text.split(' ')
|
156
261
|
words.each do |word|
|
157
|
-
w = @font.markup_width
|
158
|
-
if new_x + w > x + width
|
262
|
+
w = @font.markup_width(word)
|
263
|
+
if new_x + w * scale_x > x + width
|
159
264
|
space = x + width - new_x + space_width
|
160
265
|
index = 0
|
161
266
|
while space > 0
|
@@ -170,7 +275,7 @@ module MiniGL
|
|
170
275
|
|
171
276
|
new_x = x
|
172
277
|
end
|
173
|
-
new_x += @font.markup_width(word) + space_width
|
278
|
+
new_x += @font.markup_width(word) * scale_x + space_width
|
174
279
|
spaces[line_index] << space_width
|
175
280
|
end
|
176
281
|
|
@@ -178,11 +283,11 @@ module MiniGL
|
|
178
283
|
spaces.each do |line|
|
179
284
|
new_x = x
|
180
285
|
line.each do |s|
|
181
|
-
@font.draw_markup
|
182
|
-
new_x += @font.markup_width(words[index]) + s
|
286
|
+
@font.draw_markup(words[index], new_x, y, z_index, scale_x, scale_y, color)
|
287
|
+
new_x += @font.markup_width(words[index]) * scale_x + s
|
183
288
|
index += 1
|
184
289
|
end
|
185
|
-
y += @font.height +
|
290
|
+
y += (@font.height + line_spacing) * scale_y
|
186
291
|
end
|
187
292
|
y
|
188
293
|
end
|
data/test/game.rb
CHANGED
@@ -35,7 +35,7 @@ class MyGame < GameWindow
|
|
35
35
|
|
36
36
|
@panel = Panel.new(10, 10, 720, 520, [
|
37
37
|
Button.new(x: 5, y: 5, font: @font1, text: 'Teste', img: :btn),
|
38
|
-
Label.new(0, 70, @font1, 'Teste de label',
|
38
|
+
@lbl = Label.new(0, 70, @font1, 'Teste de label', 0, 0x666666, 1, 1, :north),
|
39
39
|
TextField.new(x: 5, y: 40, font: @font1, text: 'Opa', img: :text, margin_x: 5, margin_y: 5, anchor: :top_left),
|
40
40
|
Button.new(x: 0, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :top),
|
41
41
|
DropDownList.new(x: 0, y: 40, width: 150, height: 25, font: @font1, options: ['olá amigos', 'opção 2', 'terceira'], anchor: :north),
|
@@ -49,6 +49,8 @@ class MyGame < GameWindow
|
|
49
49
|
ProgressBar.new(0, 40, 200, 20, :barbg, :barfg, 3456, 70, 2, 2, @font1, 0xff000080, nil, nil, 1, 1, :bottom)
|
50
50
|
], :text, :tiled, true, 2, 2, :bottom_right)
|
51
51
|
|
52
|
+
@lbl2 = Label.new(x: 5, y: 5, font: @font1, text: 'top-right corner label test', anchor: :top_right)
|
53
|
+
|
52
54
|
@eff = Effect.new(100, 100, :check, 2, 4, 10, nil, nil, '1')
|
53
55
|
|
54
56
|
@angle = 0
|
@@ -79,6 +81,8 @@ class MyGame < GameWindow
|
|
79
81
|
@panel.visible = !@panel.visible if KB.key_pressed? Gosu::KbM
|
80
82
|
|
81
83
|
@panel.add_component(Button.new(x: 5, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :southeast)) if KB.key_pressed?(Gosu::KbB)
|
84
|
+
@lbl.text = 'Test of changed text' if KB.key_pressed?(Gosu::KB_C)
|
85
|
+
@lbl2.text = 'Shorter text' if KB.key_pressed?(Gosu::KB_X)
|
82
86
|
|
83
87
|
@pb.increase 1 if KB.key_down? Gosu::KbD
|
84
88
|
@pb.decrease 1 if KB.key_down? Gosu::KbA
|
@@ -145,6 +149,7 @@ class MyGame < GameWindow
|
|
145
149
|
@chk.draw
|
146
150
|
@txt.draw
|
147
151
|
@pb.draw 0x66
|
152
|
+
@lbl2.draw
|
148
153
|
|
149
154
|
@panel.draw(204, 10)
|
150
155
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minigl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor David Santos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -93,8 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
|
-
|
97
|
-
rubygems_version: 2.7.6
|
96
|
+
rubygems_version: 3.1.2
|
98
97
|
signing_key:
|
99
98
|
specification_version: 4
|
100
99
|
summary: MiniGL
|