minigl 2.2.6 → 2.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c160807a14f043a9e5bffd7de36b8c0085a50c9b383144b6db7c86a066d7ace
4
- data.tar.gz: a107f24295cbacc47a25069672301f085ee81fd7e3998e97a2ea47d9c7cc345b
3
+ metadata.gz: 01f5acaeb5e8ec1f22e2ffcd206b34a65bdd10215bbf11905d81d669c016c966
4
+ data.tar.gz: 27e794b64224d12c5e9d839f811b98832a3f033d15dd8589b202d9813d1155fb
5
5
  SHA512:
6
- metadata.gz: cbfbdaa66ae480738b129a9944cad90b2225d974479a18ec1e30a9f742856c5750036bff8a4bc9d499c6ad3eec4ba993b236a7e5184d6ac3e35f623de1db2f53
7
- data.tar.gz: 58ade56420bfe2ee57481efadca47d0af79f55bdf34abf11da86f49f2680fa3459a5c48f3f5d1df4b37883942dd1ab4ea6827542fba9e5a3c1c0e1cac910f776
6
+ metadata.gz: 2b3fc964c0a8fd8cebbbbef53b8e04724ff598a1dcc3239ee80c3416e1280653e1a8afa78f0d733809376d057ec918c62dc6973ed7f9b91395dd237b96607e55
7
+ data.tar.gz: dd1bd674701076bc3fb1c9e1c4ea935cd5aa40288bfd440712bf08fd2d3156c5b3bd1c580a565dc8a842af1c9238bc34158c0d04ee9067b114c27c1568318d40
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, sounds, ...)
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,7 +29,13 @@ 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.2.6
32
+ ## Version 2.3.1
33
33
 
34
- * Made the `text` readable in all form components.
35
- * Added the `text=` method to `Label`.
34
+ * Fix bug in `Movement#move_carrying`.
35
+ * Fix `ImageFont#draw_markup_rel` for different values of `rel_x` and `rel_y`.
36
+ * Add missing documentation in `TextHelper` methods.
37
+
38
+ ## Contributing
39
+
40
+ Contributions are very welcome. Feel free to fork and send pull requests.
41
+ Also, you can support my work by donating bitcoins to this wallet: bc1qsp7mypdqvkt88xtnarmaytt0etxfccxr5pt5tk
@@ -247,9 +247,7 @@ module MiniGL
247
247
  end
248
248
  end
249
249
 
250
- #class JSHelper
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 = []
@@ -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
- # [obstacles] An array of obstacles to be considered in the collision
364
- # checking, and carried along when colliding from above.
365
- # Obstacles must be instances of Block (or derived classes),
366
- # or objects that <code>include Movement</code>.
367
- # [obst_obstacles] Obstacles that should be considered when moving objects
368
- # from the +obstacles+ array, i.e., these obstacles won't
369
- # interfere in the elevator's movement, but in the movement
370
- # of the objects being carried.
371
- # [obst_ramps] Ramps to consider when moving objects from the +obstacles+
372
- # array, as described for +obst_obstacles+.
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,14 @@ module MiniGL
382
381
 
383
382
  @speed.x = 1.0 * x_d * speed / distance
384
383
  @speed.y = 1.0 * y_d * speed / distance
384
+ x_aim = @x + @speed.x; y_aim = @y + @speed.y
385
385
  else
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
386
+ x_aim = @x + @speed.x + G.gravity.x + arg.x
387
+ y_aim = @y + @speed.y + G.gravity.y + arg.y
392
388
  end
393
389
 
394
- x_aim = @x + @speed.x; y_aim = @y + @speed.y
395
390
  passengers = []
396
- obstacles.each do |o|
391
+ carried_objs.each do |o|
397
392
  if @x + @w > o.x && o.x + o.w > @x
398
393
  foot = o.y + o.h
399
394
  if foot.round(6) == @y.round(6) || @speed.y < 0 && foot < @y && foot > y_aim
@@ -415,25 +410,30 @@ module MiniGL
415
410
  @y = y_aim
416
411
  end
417
412
  else
418
- @x = x_aim; @y = y_aim
413
+ move(arg, obstacles, ramps)
419
414
  end
420
415
 
421
416
  forces = Vector.new @x - prev_x, @y - prev_y
422
417
  prev_g = G.gravity.clone
423
418
  G.gravity.x = G.gravity.y = 0
424
419
  passengers.each do |p|
425
- prev_speed = p.speed.clone
426
- prev_forces = p.stored_forces.clone
427
- prev_bottom = p.bottom
428
- p.speed.x = p.speed.y = 0
429
- p.stored_forces.x = p.stored_forces.y = 0
430
- p.instance_exec { @bottom = nil }
431
- p.move forces * p.mass, obst_obstacles, obst_ramps
432
- p.speed.x = prev_speed.x
433
- p.speed.y = prev_speed.y
434
- p.stored_forces.x = prev_forces.x
435
- p.stored_forces.y = prev_forces.y
436
- p.instance_exec(prev_bottom) { |b| @bottom = b }
420
+ if p.class.included_modules.include?(Movement)
421
+ prev_speed = p.speed.clone
422
+ prev_forces = p.stored_forces.clone
423
+ prev_bottom = p.bottom
424
+ p.speed.x = p.speed.y = 0
425
+ p.stored_forces.x = p.stored_forces.y = 0
426
+ p.instance_exec { @bottom = nil }
427
+ p.move(forces * p.mass, obstacles, ramps)
428
+ p.speed.x = prev_speed.x
429
+ p.speed.y = prev_speed.y
430
+ p.stored_forces.x = prev_forces.x
431
+ p.stored_forces.y = prev_forces.y
432
+ p.instance_exec(prev_bottom) { |b| @bottom = b }
433
+ else
434
+ p.x += forces.x
435
+ p.y += forces.y
436
+ end
437
437
  end
438
438
  G.gravity = prev_g
439
439
  end
@@ -504,16 +504,32 @@ module MiniGL
504
504
  # of the objects being carried.
505
505
  # [obst_ramps] Ramps to consider when moving objects from the +obstacles+
506
506
  # array, as described for +obst_obstacles+.
507
- def cycle(points, speed, obstacles = nil, obst_obstacles = nil, obst_ramps = nil)
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
507
+ # [stop_time] Optional stop time (in frames) when the object reaches each of
508
+ # the points.
509
+ def cycle(points, speed, obstacles = nil, obst_obstacles = nil, obst_ramps = nil, stop_time = 0)
510
+ unless @cycle_setup
511
+ @cur_point = 0 if @cur_point.nil?
512
+ if obstacles
513
+ move_carrying points[@cur_point], speed, obstacles, obst_obstacles, obst_ramps
514
+ else
515
+ move_free points[@cur_point], speed
516
+ end
513
517
  end
514
518
  if @speed.x == 0 and @speed.y == 0
515
- if @cur_point == points.length - 1; @cur_point = 0
516
- else; @cur_point += 1; end
519
+ unless @cycle_setup
520
+ @cycle_timer = 0
521
+ @cycle_setup = true
522
+ end
523
+ if @cycle_timer >= stop_time
524
+ if @cur_point == points.length - 1
525
+ @cur_point = 0
526
+ else
527
+ @cur_point += 1
528
+ end
529
+ @cycle_setup = false
530
+ else
531
+ @cycle_timer += 1
532
+ end
517
533
  end
518
534
  end
519
535
 
@@ -1,23 +1,127 @@
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. Moreover, this class can be passed to the
5
+ # +TextHelper+ constructor as if it was a +Gosu::Font+.
6
+ #
7
+ # The image used to load the font must meet these criteria:
8
+ # * The characters should be laid out in lines of the same height in pixels.
9
+ # * The full image must have a height that is a multiple of that line height.
10
+ # * The characters should occupy the maximum available space in each line, i.e.,
11
+ # if a character fits in the current line it must not be placed in the next
12
+ # one. In the last line there can be any amount of free space at the end.
13
+ class ImageFont
14
+ # The height of this font in pixels.
15
+ attr_reader :height
16
+
17
+ # Creates an +ImageFont+.
18
+ #
19
+ # Parameters:
20
+ # [img_path] Identifier of an image fitting the description in the class documentation,
21
+ # as used in +Res.img+.
22
+ # [chars] A string containing all characters that will be present in the image, in the
23
+ # same order as they appear in the image. Do not include white space.
24
+ # [widths] An integer representing the width of the chars in pixels, if this is a fixed
25
+ # width font, or an array containing the width of each char, in the same order
26
+ # as they appear in the +chars+ string.
27
+ # [height] The height of the lines in the image (see description above).
28
+ # [space_width] The width of the white space character in this font.
29
+ # [global] Parameter that will be passed to +Res.img+ when loading the image.
30
+ # [ext] Parameter that will be passed to +Res.img+ when loading the image.
31
+ # [retro] Parameter that will be passed to +Res.img+ when loading the image.
32
+ def initialize(img_path, chars, widths, height, space_width, global = true, ext = '.png', retro = nil)
33
+ retro = Res.retro_images if retro.nil?
34
+ img = Res.img(img_path, global, false, ext, retro)
35
+ @chars = chars
36
+ @images = []
37
+ @height = height
38
+ @space_width = space_width
39
+ wa = widths.is_a?(Array)
40
+ if wa && widths.length != chars.length
41
+ raise 'Wrong widths array size!'
42
+ end
43
+ x = y = 0
44
+ (0...chars.length).each do |i|
45
+ @images.push(img.subimage(x, y, wa ? widths[i] : widths, height))
46
+ new_x = x + (wa ? widths[i] : widths)
47
+ if i < chars.length - 1 && new_x + (wa ? widths[i+1] : widths) > img.width
48
+ x = 0
49
+ y += height
50
+ else
51
+ x = new_x
52
+ end
53
+ end
54
+ end
55
+
56
+ # Returns the width, in pixels, of a given string written by this font.
57
+ # Note: Markup is not supported, this method is named this way to match
58
+ # <code>Gosu::Font</code>'s signature.
59
+ #
60
+ # Parameters:
61
+ # [text] The string to be measured
62
+ def markup_width(text)
63
+ text.chars.reduce(0) { |w, c| if c == ' '; w += @space_width; else; i = @chars.index(c); w += i ? @images[i].width : 0; end }
64
+ end
65
+
66
+ # See <code>Gosu::Font#draw_markup_rel</code> for details.
67
+ # Note: Markup is not supported, this method is named this way to match
68
+ # <code>Gosu::Font</code>'s signature.
69
+ def draw_markup_rel(text, x, y, z, rel_x, rel_y, scale_x, scale_y, color)
70
+ text = text.to_s unless text.is_a?(String)
71
+ if rel_x != 0
72
+ x -= scale_x * markup_width(text) * rel_x
73
+ end
74
+ if rel_y != 0
75
+ y -= scale_y * @height * rel_y
76
+ end
77
+ text.each_char do |c|
78
+ if c == ' '
79
+ x += scale_x * @space_width
80
+ next
81
+ end
82
+ i = @chars.index(c)
83
+ next if i.nil?
84
+ @images[i].draw(x, y, z, scale_x, scale_y, color)
85
+ x += scale_x * @images[i].width
86
+ end
87
+ end
88
+
89
+ # See <code>Gosu::Font#draw_markup</code> for details.
90
+ # Note: Markup is not supported, this method is named this way to match
91
+ # <code>Gosu::Font</code>'s signature.
92
+ def draw_markup(text, x, y, z, scale_x, scale_y, color)
93
+ draw_markup_rel(text, x, y, z, 0, 0, scale_x, scale_y, color)
94
+ end
95
+
96
+ alias :draw_text_rel :draw_markup_rel
97
+ alias :draw_text :draw_markup
98
+ alias :text_width :markup_width
99
+ end
100
+
2
101
  # This class provides methods for easily drawing one or multiple lines of
3
102
  # text, with control over the text alignment and coloring.
4
103
  class TextHelper
5
104
  # Creates a TextHelper.
6
105
  #
7
106
  # Parameters:
8
- # [font] A <code>Gosu::Font</code> that will be used to draw the text.
9
- # [line_spacing] When drawing multiple lines, the distance, in pixels,
10
- # between each line.
11
- def initialize(font, line_spacing = 0)
107
+ # [font] A <code>Gosu::Font</code> or <code>ImageFont</code> that will
108
+ # be used to draw the text.
109
+ # [line_spacing] When drawing multiple lines, the default distance, in
110
+ # pixels, between each line.
111
+ # [scale_x] The default horizontal scale of the font.
112
+ # [scale_y] The default vertical scale of the font.
113
+ def initialize(font, line_spacing = 0, scale_x = 1, scale_y = 1)
12
114
  @font = font
13
115
  @line_spacing = line_spacing
116
+ @scale_x = scale_x
117
+ @scale_y = scale_y
14
118
  end
15
119
 
16
120
  # Draws a single line of text.
17
121
  #
18
122
  # Parameters:
19
123
  # [text] The text to be drawn. No line breaks are allowed. You can use the
20
- # `<b>` tag for bold, `<i>` for italic and `<c=rrggbb>` for colors.
124
+ # `<b>` tag for bold, `<i>` for italic and `<c=rrggbb>` for colors.
21
125
  # [x] The horizontal reference for drawing the text. If +mode+ is +:left+,
22
126
  # all text will be drawn from this point to the right; if +mode+ is
23
127
  # +:right+, all text will be drawn from this point to the left; and if
@@ -43,12 +147,16 @@ module MiniGL
43
147
  # provide less than 255.
44
148
  # [z_index] The z-order to draw the object. Objects with larger z-orders
45
149
  # will be drawn on top of the ones with smaller z-orders.
150
+ # [scale_x] The horizontal scaling of the text. If +nil+, this instance's
151
+ # +@scale_x+ value will be used.
152
+ # [scale_y] The vertical scaling of the text. If +nil+, this instance's
153
+ # +@scale_y+ value will be used.
46
154
  #
47
155
  # *Obs.:* This method accepts named parameters, but +text+, +x+ and +y+ are
48
156
  # mandatory.
49
157
  def write_line(text, x = nil, y = nil, mode = :left, color = 0, alpha = 0xff,
50
158
  effect = nil, effect_color = 0, effect_size = 1, effect_alpha = 0xff,
51
- z_index = 0)
159
+ z_index = 0, scale_x = nil, scale_y = nil)
52
160
  if text.is_a? Hash
53
161
  x = text[:x]
54
162
  y = text[:y]
@@ -60,9 +168,13 @@ module MiniGL
60
168
  effect_size = text.fetch(:effect_size, 1)
61
169
  effect_alpha = text.fetch(:effect_alpha, 0xff)
62
170
  z_index = text.fetch(:z_index, 0)
171
+ scale_x = text.fetch(:scale_x, nil)
172
+ scale_y = text.fetch(:scale_y, nil)
63
173
  text = text[:text]
64
174
  end
65
175
 
176
+ scale_x = @scale_x if scale_x.nil?
177
+ scale_y = @scale_y if scale_y.nil?
66
178
  color = (alpha << 24) | color
67
179
  rel =
68
180
  case mode
@@ -74,19 +186,19 @@ module MiniGL
74
186
  if effect
75
187
  effect_color = (effect_alpha << 24) | effect_color
76
188
  if effect == :border
77
- @font.draw_markup_rel text, x - effect_size, y - effect_size, z_index, rel, 0, 1, 1, effect_color
78
- @font.draw_markup_rel text, x, y - effect_size, z_index, rel, 0, 1, 1, effect_color
79
- @font.draw_markup_rel text, x + effect_size, y - effect_size, z_index, rel, 0, 1, 1, effect_color
80
- @font.draw_markup_rel text, x + effect_size, y, z_index, rel, 0, 1, 1, effect_color
81
- @font.draw_markup_rel text, x + effect_size, y + effect_size, z_index, rel, 0, 1, 1, effect_color
82
- @font.draw_markup_rel text, x, y + effect_size, z_index, rel, 0, 1, 1, effect_color
83
- @font.draw_markup_rel text, x - effect_size, y + effect_size, z_index, rel, 0, 1, 1, effect_color
84
- @font.draw_markup_rel text, x - effect_size, y, z_index, rel, 0, 1, 1, effect_color
189
+ @font.draw_markup_rel text, x - effect_size, y - effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
190
+ @font.draw_markup_rel text, x, y - effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
191
+ @font.draw_markup_rel text, x + effect_size, y - effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
192
+ @font.draw_markup_rel text, x + effect_size, y, z_index, rel, 0, scale_x, scale_y, effect_color
193
+ @font.draw_markup_rel text, x + effect_size, y + effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
194
+ @font.draw_markup_rel text, x, y + effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
195
+ @font.draw_markup_rel text, x - effect_size, y + effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
196
+ @font.draw_markup_rel text, x - effect_size, y, z_index, rel, 0, scale_x, scale_y, effect_color
85
197
  elsif effect == :shadow
86
- @font.draw_markup_rel text, x + effect_size, y + effect_size, z_index, rel, 0, 1, 1, effect_color
198
+ @font.draw_markup_rel text, x + effect_size, y + effect_size, z_index, rel, 0, scale_x, scale_y, effect_color
87
199
  end
88
200
  end
89
- @font.draw_markup_rel text, x, y, z_index, rel, 0, 1, 1, color
201
+ @font.draw_markup_rel text, x, y, z_index, rel, 0, scale_x, scale_y, color
90
202
  end
91
203
 
92
204
  # Draws text, breaking lines when needed and when explicitly caused by the
@@ -94,7 +206,7 @@ module MiniGL
94
206
  #
95
207
  # Parameters:
96
208
  # [text] The text to be drawn. Line breaks are allowed. You can use the
97
- # `<b>` tag for bold, `<i>` for italic and `<c=rrggbb>` for colors.
209
+ # `<b>` tag for bold, `<i>` for italic and `<c=rrggbb>` for colors.
98
210
  # [x] The horizontal reference for drawing the text. Works like in
99
211
  # +write_line+ for the +:left+, +:right+ and +:center+ modes. For the
100
212
  # +:justified+ mode, works the same as for +:left+.
@@ -109,11 +221,20 @@ module MiniGL
109
221
  # transparent) to 255 (fully opaque).
110
222
  # [z_index] The z-order to draw the object. Objects with larger z-orders
111
223
  # 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)
224
+ # [scale_x] The horizontal scaling of the text. If +nil+, this instance's
225
+ # +@scale_x+ value will be used.
226
+ # [scale_y] The vertical scaling of the text. If +nil+, this instance's
227
+ # +@scale_y+ value will be used.
228
+ # [line_spacing] The spacing between lines, in pixels. If +nil+, this
229
+ # instance's +@line_spacing+ value will be used.
230
+ 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)
231
+ line_spacing = @line_spacing if line_spacing.nil?
232
+ scale_x = @scale_x if scale_x.nil?
233
+ scale_y = @scale_y if scale_y.nil?
113
234
  color = (alpha << 24) | color
114
235
  text.split("\n").each do |p|
115
236
  if mode == :justified
116
- y = write_paragraph_justified p, x, y, width, color, z_index
237
+ y = write_paragraph_justified p, x, y, width, color, z_index, scale_x, scale_y, line_spacing
117
238
  else
118
239
  rel =
119
240
  case mode
@@ -122,40 +243,40 @@ module MiniGL
122
243
  when :right then 1
123
244
  else 0
124
245
  end
125
- y = write_paragraph p, x, y, width, rel, color, z_index
246
+ y = write_paragraph p, x, y, width, rel, color, z_index, scale_x, scale_y, line_spacing
126
247
  end
127
248
  end
128
249
  end
129
250
 
130
251
  private
131
252
 
132
- def write_paragraph(text, x, y, width, rel, color, z_index)
253
+ def write_paragraph(text, x, y, width, rel, color, z_index, scale_x, scale_y, line_spacing)
133
254
  line = ''
134
255
  line_width = 0
135
256
  text.split(' ').each do |word|
136
- w = @font.markup_width word
137
- if line_width + w > width
138
- @font.draw_markup_rel line.chop, x, y, z_index, rel, 0, 1, 1, color
257
+ w = @font.markup_width(word)
258
+ if line_width + w * scale_x > width
259
+ @font.draw_markup_rel line.chop, x, y, z_index, rel, 0, scale_x, scale_y, color
139
260
  line = ''
140
261
  line_width = 0
141
- y += @font.height + @line_spacing
262
+ y += (@font.height + line_spacing) * scale_y
142
263
  end
143
264
  line += "#{word} "
144
- line_width += @font.markup_width "#{word} "
265
+ line_width += @font.markup_width("#{word} ") * scale_x
145
266
  end
146
- @font.draw_markup_rel line.chop, x, y, z_index, rel, 0, 1, 1, color unless line.empty?
147
- y + @font.height + @line_spacing
267
+ @font.draw_markup_rel line.chop, x, y, z_index, rel, 0, scale_x, scale_y, color unless line.empty?
268
+ y + (@font.height + line_spacing) * scale_y
148
269
  end
149
270
 
150
- def write_paragraph_justified(text, x, y, width, color, z_index)
151
- space_width = @font.text_width ' '
271
+ def write_paragraph_justified(text, x, y, width, color, z_index, scale_x, scale_y, line_spacing)
272
+ space_width = @font.text_width(' ') * scale_x
152
273
  spaces = [[]]
153
274
  line_index = 0
154
275
  new_x = x
155
276
  words = text.split(' ')
156
277
  words.each do |word|
157
- w = @font.markup_width word
158
- if new_x + w > x + width
278
+ w = @font.markup_width(word)
279
+ if new_x + w * scale_x > x + width
159
280
  space = x + width - new_x + space_width
160
281
  index = 0
161
282
  while space > 0
@@ -170,7 +291,7 @@ module MiniGL
170
291
 
171
292
  new_x = x
172
293
  end
173
- new_x += @font.markup_width(word) + space_width
294
+ new_x += @font.markup_width(word) * scale_x + space_width
174
295
  spaces[line_index] << space_width
175
296
  end
176
297
 
@@ -178,11 +299,11 @@ module MiniGL
178
299
  spaces.each do |line|
179
300
  new_x = x
180
301
  line.each do |s|
181
- @font.draw_markup words[index], new_x, y, z_index, 1, 1, color
182
- new_x += @font.markup_width(words[index]) + s
302
+ @font.draw_markup(words[index], new_x, y, z_index, scale_x, scale_y, color)
303
+ new_x += @font.markup_width(words[index]) * scale_x + s
183
304
  index += 1
184
305
  end
185
- y += @font.height + @line_spacing
306
+ y += (@font.height + line_spacing) * scale_y
186
307
  end
187
308
  y
188
309
  end
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.2.6
4
+ version: 2.3.1
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: 2019-07-21 00:00:00.000000000 Z
11
+ date: 2020-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -93,43 +93,42 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 2.7.8
96
+ rubygems_version: 3.1.2
98
97
  signing_key:
99
98
  specification_version: 4
100
99
  summary: MiniGL
101
100
  test_files:
101
+ - test/vector_tests.rb
102
102
  - test/res_tests.rb
103
- - test/iso_game.rb
104
103
  - test/mov_game.rb
104
+ - test/movement_tests.rb
105
105
  - test/map_tests.rb
106
- - test/game.rb
106
+ - test/iso_game.rb
107
107
  - test/game_object_tests.rb
108
- - test/vector_tests.rb
109
- - test/movement_tests.rb
108
+ - test/game.rb
110
109
  - test/test.png
110
+ - test/data/tileset/tileset1.png
111
111
  - test/data/font/font1.ttf
112
+ - test/data/sound/1.wav
113
+ - test/data/img/check.png
112
114
  - test/data/img/square.svg
113
- - test/data/img/barbg.png
114
- - test/data/img/img1.png
115
- - test/data/img/tile1.png
116
- - test/data/img/tile2b.png
117
- - test/data/img/text.png
118
- - test/data/img/btn.png
119
- - test/data/img/square2.svg
120
- - test/data/img/square2.png
115
+ - test/data/img/tile2.svg
121
116
  - test/data/img/barfg.png
122
- - test/data/img/tile1b.png
123
117
  - test/data/img/tile2.png
124
- - test/data/img/check.png
125
- - test/data/img/tile2.svg
126
- - test/data/img/square3.png
118
+ - test/data/img/tile1.svg
127
119
  - test/data/img/square3.svg
120
+ - test/data/img/text.png
121
+ - test/data/img/square2.svg
128
122
  - test/data/img/image.png
129
- - test/data/img/tile1.svg
130
- - test/data/img/square.png
123
+ - test/data/img/img1.png
124
+ - test/data/img/square2.png
131
125
  - test/data/img/barbg.svg
132
126
  - test/data/img/barfg.svg
133
- - test/data/tileset/tileset1.png
134
- - test/data/sound/1.wav
127
+ - test/data/img/tile1b.png
128
+ - test/data/img/barbg.png
129
+ - test/data/img/square.png
130
+ - test/data/img/btn.png
131
+ - test/data/img/square3.png
132
+ - test/data/img/tile2b.png
133
+ - test/data/img/tile1.png
135
134
  - test/data/img/sub/image.png