minigl 2.3.6 → 2.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/minigl/forms.rb +56 -39
- data/lib/minigl/game_object.rb +20 -6
- data/lib/minigl/global.rb +61 -12
- data/lib/minigl/text.rb +25 -3
- data/test/game.rb +12 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff7475dd66f98076ad86cc143943c75f186e6b696aba46083b71727ad69e95b0
|
4
|
+
data.tar.gz: 87bec4f94e32553a70ea4ca4318357bbadb71ffc6600859a8c63ec772e708137
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09094e3898b3a19939f39acf33ba4514db24bb1771b7795769a632e7f7230874058f921609d0760ea5958b42ca70e0a5b2224c974c5d3a80b4f1d2d1e59ad4cc'
|
7
|
+
data.tar.gz: ad1fc0475cee6c71ec019e5f8516b077da8ba4f37fbd95136137acb4716f83fe3fff42f68a5c458841c80732e8117776ac14c696c70b776d06c8b73860b379f5
|
data/README.md
CHANGED
@@ -14,6 +14,14 @@ It provides the following features:
|
|
14
14
|
More functionalities are coming. Feel free to contribute! You can send feedback
|
15
15
|
to victordavidsantos@gmail.com.
|
16
16
|
|
17
|
+
## Made with MiniGL
|
18
|
+
|
19
|
+
Below are two full games built with MiniGL, both available for free download and also open source.
|
20
|
+
* [Super Bombinhas](https://github.com/victords/super-bombinhas)
|
21
|
+
* [ConnecMan](https://github.com/victords/connecman)
|
22
|
+
|
23
|
+
If you create a project using MiniGL, feel free to open a PR to include it in this list.
|
24
|
+
|
17
25
|
## Installing
|
18
26
|
|
19
27
|
MiniGL was built on top of the Gosu gem. This gem has its own dependencies for
|
@@ -29,9 +37,10 @@ After installing the Gosu dependencies, you can just `gem install minigl`.
|
|
29
37
|
* The [wiki](https://github.com/victords/minigl/wiki) is a work in progress with tutorials and examples.
|
30
38
|
* Test package and examples aren't complete!
|
31
39
|
|
32
|
-
## Version 2.3.
|
40
|
+
## Version 2.3.9
|
33
41
|
|
34
|
-
*
|
42
|
+
* Fixed click detection for very short clicks.
|
43
|
+
* Allow combining `center` and `margin` for `Button` text.
|
35
44
|
|
36
45
|
## Contributing
|
37
46
|
|
data/lib/minigl/forms.rb
CHANGED
@@ -98,6 +98,9 @@ module MiniGL
|
|
98
98
|
# Gets or sets whether the panel (and thus all components inside it) are visible.
|
99
99
|
attr_accessor :visible
|
100
100
|
|
101
|
+
# The components contained in this panel.
|
102
|
+
attr_reader :controls
|
103
|
+
|
101
104
|
# Creates a new Panel.
|
102
105
|
# Parameters:
|
103
106
|
# [x] The horizontal coordinate of the top-left corner of the panel, or the horizontal offset from the anchor, if provided.
|
@@ -314,12 +317,12 @@ module MiniGL
|
|
314
317
|
super x, y, font, text, text_color, disabled_text_color
|
315
318
|
@over_text_color = over_text_color
|
316
319
|
@down_text_color = down_text_color
|
317
|
-
if center_x; @text_x = x + @w / 2 if @w
|
318
|
-
else; @text_x = x + margin_x * @scale_x; end
|
319
|
-
if center_y; @text_y = y + @h / 2 if @h
|
320
|
-
else; @text_y = y + margin_y * @scale_y; end
|
321
320
|
@center_x = center_x
|
322
321
|
@center_y = center_y
|
322
|
+
@margin_x = margin_x
|
323
|
+
@margin_y = margin_y
|
324
|
+
set_position(x, y)
|
325
|
+
|
323
326
|
@action = action
|
324
327
|
@params = params
|
325
328
|
|
@@ -348,8 +351,10 @@ module MiniGL
|
|
348
351
|
@img_index = 0
|
349
352
|
@state = :up
|
350
353
|
elsif mouse_press
|
351
|
-
@
|
352
|
-
|
354
|
+
Mouse.add_click(@z_index || 0, lambda do
|
355
|
+
@img_index = 2
|
356
|
+
@state = :down
|
357
|
+
end)
|
353
358
|
else
|
354
359
|
@img_index = 1
|
355
360
|
end
|
@@ -360,7 +365,7 @@ module MiniGL
|
|
360
365
|
elsif mouse_rel
|
361
366
|
@img_index = 1
|
362
367
|
@state = :over
|
363
|
-
|
368
|
+
Mouse.add_click(@z_index || 0, method(:perform_action))
|
364
369
|
else
|
365
370
|
@img_index = 2
|
366
371
|
end
|
@@ -379,7 +384,7 @@ module MiniGL
|
|
379
384
|
|
380
385
|
# Executes the button click action.
|
381
386
|
def click
|
382
|
-
|
387
|
+
perform_action
|
383
388
|
end
|
384
389
|
|
385
390
|
# Sets the position of the button in the screen.
|
@@ -388,10 +393,10 @@ module MiniGL
|
|
388
393
|
# [x] The new x-coordinate for the button.
|
389
394
|
# [y] The new y-coordinate for the button.
|
390
395
|
def set_position(x, y)
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
396
|
+
@text_x = @center_x ? x + @w / 2 : x
|
397
|
+
@text_y = @center_y ? y + @h / 2 : y
|
398
|
+
@text_x += @margin_x
|
399
|
+
@text_y += @margin_y
|
395
400
|
@x = x; @y = y
|
396
401
|
end
|
397
402
|
|
@@ -404,6 +409,7 @@ module MiniGL
|
|
404
409
|
# will be drawn on top of the ones with smaller z-orders.
|
405
410
|
# [color] Color to apply a filter to the image.
|
406
411
|
def draw(alpha = 0xff, z_index = 0, color = 0xffffff)
|
412
|
+
@z_index = z_index
|
407
413
|
return unless @visible
|
408
414
|
|
409
415
|
color = (alpha << 24) | color
|
@@ -435,6 +441,12 @@ module MiniGL
|
|
435
441
|
@state = :up
|
436
442
|
@img_index = 3
|
437
443
|
end
|
444
|
+
|
445
|
+
private
|
446
|
+
|
447
|
+
def perform_action
|
448
|
+
@action.call(@params) if @action
|
449
|
+
end
|
438
450
|
end
|
439
451
|
|
440
452
|
# This class represents a toggle button, which can be also interpreted as a
|
@@ -502,8 +514,6 @@ module MiniGL
|
|
502
514
|
else; height * @scale_y; end
|
503
515
|
_, x, y = FormUtils.check_anchor(anchor, @anchor_offset_x, @anchor_offset_y, @w, @h)
|
504
516
|
set_position(x, y)
|
505
|
-
@text_x = x + @w / 2 if center_x
|
506
|
-
@text_y = y + @h / 2 if center_y
|
507
517
|
@checked = checked
|
508
518
|
end
|
509
519
|
|
@@ -517,20 +527,12 @@ module MiniGL
|
|
517
527
|
@img_index += 1 if @checked
|
518
528
|
end
|
519
529
|
|
520
|
-
# Executes the button click action, and toggles its state. The +action+
|
521
|
-
# block always receives as a first parameter +true+, if the button has
|
522
|
-
# been changed to checked, or +false+, otherwise.
|
523
|
-
def click
|
524
|
-
@checked = !@checked
|
525
|
-
@action.call @checked, @params if @action
|
526
|
-
end
|
527
|
-
|
528
530
|
# Sets the state of the button to the value given.
|
529
531
|
#
|
530
532
|
# Parameters:
|
531
533
|
# [value] The state to be set (+true+ for checked, +false+ for unchecked).
|
532
534
|
def checked=(value)
|
533
|
-
|
535
|
+
@action.call(value, @params) if @action && value != @checked
|
534
536
|
@checked = value
|
535
537
|
end
|
536
538
|
|
@@ -539,6 +541,13 @@ module MiniGL
|
|
539
541
|
@state = :up
|
540
542
|
@img_index = @checked ? 7 : 6
|
541
543
|
end
|
544
|
+
|
545
|
+
private
|
546
|
+
|
547
|
+
def perform_action
|
548
|
+
@checked = !@checked
|
549
|
+
@action.call(@checked, @params) if @action
|
550
|
+
end
|
542
551
|
end
|
543
552
|
|
544
553
|
# This class represents a text field (input).
|
@@ -547,6 +556,9 @@ module MiniGL
|
|
547
556
|
# INCOMPLETE!
|
548
557
|
attr_reader :locale
|
549
558
|
|
559
|
+
# Whether the text field is focused (accepting input)
|
560
|
+
attr_reader :focused
|
561
|
+
|
550
562
|
# Creates a new text field.
|
551
563
|
#
|
552
564
|
# Parameters:
|
@@ -566,9 +578,9 @@ module MiniGL
|
|
566
578
|
# [margin_x] The x offset, from the field x-coordinate, to draw the text.
|
567
579
|
# [margin_y] The y offset, from the field y-coordinate, to draw the text.
|
568
580
|
# [max_length] The maximum length of the text inside the field.
|
569
|
-
# [
|
570
|
-
#
|
571
|
-
#
|
581
|
+
# [focused] Whether the text field must be focused by default. If +false+,
|
582
|
+
# focus can be granted by clicking inside the text field or by
|
583
|
+
# calling the +focus+ method.
|
572
584
|
# [text] The starting text. Must not be +nil+.
|
573
585
|
# [allowed_chars] A string containing all characters that can be typed
|
574
586
|
# inside the text field. The complete set of supported
|
@@ -606,7 +618,7 @@ module MiniGL
|
|
606
618
|
# *Obs.:* This method accepts named parameters, but +x+, +y+, +font+ and
|
607
619
|
# +img+ are mandatory.
|
608
620
|
def initialize(x, y = nil, font = nil, img = nil, cursor_img = nil, disabled_img = nil, margin_x = 0, margin_y = 0,
|
609
|
-
max_length = 100,
|
621
|
+
max_length = 100, focused = false, text = '', allowed_chars = nil,
|
610
622
|
text_color = 0, disabled_text_color = 0, selection_color = 0, locale = 'en-us',
|
611
623
|
params = nil, retro = nil, scale_x = 1, scale_y = 1, anchor = nil, &on_text_changed)
|
612
624
|
if x.is_a? Hash
|
@@ -618,7 +630,7 @@ module MiniGL
|
|
618
630
|
margin_x = x.fetch(:margin_x, 0)
|
619
631
|
margin_y = x.fetch(:margin_y, 0)
|
620
632
|
max_length = x.fetch(:max_length, 100)
|
621
|
-
|
633
|
+
focused = x.fetch(:focused, false)
|
622
634
|
text = x.fetch(:text, '')
|
623
635
|
allowed_chars = x.fetch(:allowed_chars, nil)
|
624
636
|
text_color = x.fetch(:text_color, 0)
|
@@ -647,7 +659,7 @@ module MiniGL
|
|
647
659
|
@cursor_img = Res.img(cursor_img, false, false, '.png', retro) if cursor_img
|
648
660
|
@disabled_img = Res.img(disabled_img, false, false, '.png', retro) if disabled_img
|
649
661
|
@max_length = max_length
|
650
|
-
@
|
662
|
+
@focused = focused
|
651
663
|
@text_x = x + margin_x * @scale_x
|
652
664
|
@text_y = y + margin_y * @scale_y
|
653
665
|
@selection_color = selection_color
|
@@ -690,14 +702,14 @@ module MiniGL
|
|
690
702
|
|
691
703
|
################################ Mouse ################################
|
692
704
|
if Mouse.over? @x, @y, @w, @h
|
693
|
-
if not @
|
694
|
-
focus
|
705
|
+
if not @focused and Mouse.button_pressed? :left
|
706
|
+
Mouse.add_click(@z_index || 0, method(:focus))
|
695
707
|
end
|
696
708
|
elsif Mouse.button_pressed? :left
|
697
709
|
unfocus
|
698
710
|
end
|
699
711
|
|
700
|
-
return unless @
|
712
|
+
return unless @focused
|
701
713
|
|
702
714
|
if Mouse.double_click? :left
|
703
715
|
if @nodes.size > 1
|
@@ -708,11 +720,7 @@ module MiniGL
|
|
708
720
|
end
|
709
721
|
set_cursor_visible
|
710
722
|
elsif Mouse.button_pressed? :left
|
711
|
-
|
712
|
-
@anchor1 = @cur_node
|
713
|
-
@anchor2 = nil
|
714
|
-
@double_clicked = false
|
715
|
-
set_cursor_visible
|
723
|
+
Mouse.add_click(@z_index || 0, method(:focus))
|
716
724
|
elsif Mouse.button_down? :left
|
717
725
|
if @anchor1 and not @double_clicked
|
718
726
|
set_node_by_mouse
|
@@ -902,7 +910,12 @@ module MiniGL
|
|
902
910
|
|
903
911
|
# Grants focus to the text field, so that it allows keyboard input.
|
904
912
|
def focus
|
905
|
-
@
|
913
|
+
@focused = true
|
914
|
+
set_node_by_mouse
|
915
|
+
@anchor1 = @cur_node
|
916
|
+
@anchor2 = nil
|
917
|
+
@double_clicked = false
|
918
|
+
set_cursor_visible
|
906
919
|
end
|
907
920
|
|
908
921
|
# Removes focus from the text field, so that no keyboard input will be
|
@@ -911,7 +924,7 @@ module MiniGL
|
|
911
924
|
@anchor1 = @anchor2 = nil
|
912
925
|
@cursor_visible = false
|
913
926
|
@cursor_timer = 0
|
914
|
-
@
|
927
|
+
@focused = false
|
915
928
|
end
|
916
929
|
|
917
930
|
# Sets the position of the text field in the screen.
|
@@ -941,6 +954,7 @@ module MiniGL
|
|
941
954
|
# [disabled_color] Color to apply a filter to the image when the field is
|
942
955
|
# disabled.
|
943
956
|
def draw(alpha = 0xff, z_index = 0, color = 0xffffff, disabled_color = 0x808080)
|
957
|
+
@z_index = z_index
|
944
958
|
return unless @visible
|
945
959
|
|
946
960
|
color = (alpha << 24) | ((@enabled or @disabled_img) ? color : disabled_color)
|
@@ -1250,6 +1264,9 @@ module MiniGL
|
|
1250
1264
|
# The selected value in the drop-down list. This is one of the +options+.
|
1251
1265
|
attr_reader :value
|
1252
1266
|
|
1267
|
+
# Whether the list of options is currently visible.
|
1268
|
+
attr_reader :open
|
1269
|
+
|
1253
1270
|
# An array containing all the options (each of them +String+s) that can be
|
1254
1271
|
# selected in the drop-down list.
|
1255
1272
|
attr_accessor :options
|
data/lib/minigl/game_object.rb
CHANGED
@@ -304,6 +304,14 @@ module MiniGL
|
|
304
304
|
# This is +true+ when the effect's lifetime has already passed.
|
305
305
|
attr_reader :dead
|
306
306
|
|
307
|
+
# The lifetime of the effect, in updates, i.e., how many calls to +update+
|
308
|
+
# must happen before the effect is marked as +dead+, since its creation.
|
309
|
+
attr_reader :lifetime
|
310
|
+
|
311
|
+
# The number of times +update+ has been called for this effect, while it
|
312
|
+
# was still active (not +dead+).
|
313
|
+
attr_reader :elapsed_time
|
314
|
+
|
307
315
|
# Creates a new Effect.
|
308
316
|
#
|
309
317
|
# Parameters:
|
@@ -352,7 +360,7 @@ module MiniGL
|
|
352
360
|
end
|
353
361
|
|
354
362
|
super x, y, img, sprite_cols, sprite_rows
|
355
|
-
@
|
363
|
+
@elapsed_time = 0
|
356
364
|
if indices
|
357
365
|
@indices = indices
|
358
366
|
else
|
@@ -369,15 +377,21 @@ module MiniGL
|
|
369
377
|
|
370
378
|
# Updates the effect, animating and counting its remaining lifetime.
|
371
379
|
def update
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
380
|
+
return if @dead
|
381
|
+
|
382
|
+
animate(@indices, @interval)
|
383
|
+
@elapsed_time += 1
|
384
|
+
@dead = true if @elapsed_time == @lifetime
|
377
385
|
end
|
378
386
|
|
379
387
|
def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, z_index = 0)
|
380
388
|
super unless @dead
|
381
389
|
end
|
390
|
+
|
391
|
+
# The remaining number of calls to +update+ until the effect is marked
|
392
|
+
# +dead+.
|
393
|
+
def time_left
|
394
|
+
@lifetime - @elapsed_time
|
395
|
+
end
|
382
396
|
end
|
383
397
|
end
|
data/lib/minigl/global.rb
CHANGED
@@ -245,6 +245,16 @@ module MiniGL
|
|
245
245
|
def toggle_fullscreen
|
246
246
|
self.fullscreen = !fullscreen?
|
247
247
|
end
|
248
|
+
|
249
|
+
def button_down(id)
|
250
|
+
super
|
251
|
+
Mouse.register_button_down(id)
|
252
|
+
end
|
253
|
+
|
254
|
+
def button_up(id)
|
255
|
+
super
|
256
|
+
Mouse.register_button_up(id)
|
257
|
+
end
|
248
258
|
end
|
249
259
|
|
250
260
|
# Exposes methods for controlling keyboard and gamepad events.
|
@@ -387,6 +397,7 @@ module MiniGL
|
|
387
397
|
def initialize
|
388
398
|
@down = {}
|
389
399
|
@prev_down = {}
|
400
|
+
@next_down = {}
|
390
401
|
@dbl_click = {}
|
391
402
|
@dbl_click_timer = {}
|
392
403
|
end
|
@@ -394,23 +405,29 @@ module MiniGL
|
|
394
405
|
# Updates the mouse position and the state of all buttons.
|
395
406
|
def update
|
396
407
|
@prev_down = @down.clone
|
397
|
-
@down.
|
408
|
+
@down = @next_down.clone
|
409
|
+
@next_down.delete_if { |_, v| v.zero? }
|
398
410
|
@dbl_click.clear
|
399
411
|
|
412
|
+
if @click
|
413
|
+
@click[:action].call
|
414
|
+
@click = nil
|
415
|
+
end
|
416
|
+
|
400
417
|
@dbl_click_timer.each do |k, v|
|
401
|
-
if v < G.double_click_delay
|
402
|
-
|
418
|
+
if v < G.double_click_delay
|
419
|
+
@dbl_click_timer[k] += 1
|
420
|
+
else
|
421
|
+
@dbl_click_timer.delete(k)
|
422
|
+
end
|
403
423
|
end
|
404
424
|
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
@
|
411
|
-
@dbl_click_timer.delete k2[i]
|
412
|
-
elsif @prev_down[k2[i]]
|
413
|
-
@dbl_click_timer[k2[i]] = 0
|
425
|
+
%i[left middle right].each do |key|
|
426
|
+
if @down[key]
|
427
|
+
@dbl_click[key] = true if @dbl_click_timer[key]
|
428
|
+
@dbl_click_timer.delete(key)
|
429
|
+
elsif @prev_down[key]
|
430
|
+
@dbl_click_timer[key] = 0
|
414
431
|
end
|
415
432
|
end
|
416
433
|
|
@@ -474,6 +491,38 @@ module MiniGL
|
|
474
491
|
return @x >= x.x && @x < x.x + x.w && @y >= x.y && @y < x.y + x.h if x.is_a? Rectangle
|
475
492
|
@x >= x && @x < x + w && @y >= y && @y < y + h
|
476
493
|
end
|
494
|
+
|
495
|
+
# :nodoc:
|
496
|
+
def add_click(z_index, action)
|
497
|
+
return if @click && @click[:z_index] > z_index
|
498
|
+
|
499
|
+
@click = { z_index: z_index, action: action }
|
500
|
+
end
|
501
|
+
|
502
|
+
# :nodoc:
|
503
|
+
def register_button_down(id)
|
504
|
+
key = key_from_id(id)
|
505
|
+
@next_down[key] = 1 if key
|
506
|
+
end
|
507
|
+
|
508
|
+
# :nodoc:
|
509
|
+
def register_button_up(id)
|
510
|
+
key = key_from_id(id)
|
511
|
+
@next_down[key] = 0 if key && @next_down[key]
|
512
|
+
end
|
513
|
+
|
514
|
+
private
|
515
|
+
|
516
|
+
def key_from_id(id)
|
517
|
+
case id
|
518
|
+
when Gosu::MS_LEFT
|
519
|
+
:left
|
520
|
+
when Gosu::MS_RIGHT
|
521
|
+
:right
|
522
|
+
when Gosu::MS_MIDDLE
|
523
|
+
:middle
|
524
|
+
end
|
525
|
+
end
|
477
526
|
end
|
478
527
|
end
|
479
528
|
|
data/lib/minigl/text.rb
CHANGED
@@ -11,9 +11,18 @@ module MiniGL
|
|
11
11
|
# if a character fits in the current line it must not be placed in the next
|
12
12
|
# one. In the last line there can be any amount of free space at the end.
|
13
13
|
class ImageFont
|
14
|
+
# A string containing the characters supported by this font.
|
15
|
+
attr_reader :chars
|
16
|
+
|
14
17
|
# The height of this font in pixels.
|
15
18
|
attr_reader :height
|
16
19
|
|
20
|
+
# The width of the white space character in this font, in pixels.
|
21
|
+
attr_reader :space_width
|
22
|
+
|
23
|
+
# The spacing between characters, in pixels (can be a decimal number).
|
24
|
+
attr_reader :char_spacing
|
25
|
+
|
17
26
|
# Creates an +ImageFont+.
|
18
27
|
#
|
19
28
|
# Parameters:
|
@@ -26,16 +35,19 @@ module MiniGL
|
|
26
35
|
# as they appear in the +chars+ string.
|
27
36
|
# [height] The height of the lines in the image (see description above).
|
28
37
|
# [space_width] The width of the white space character in this font.
|
38
|
+
# [char_spacing] The spacing between non-white-space characters when writing text with
|
39
|
+
# this font. It can be a decimal number, useful when scaling the text up.
|
29
40
|
# [global] Parameter that will be passed to +Res.img+ when loading the image.
|
30
41
|
# [ext] Parameter that will be passed to +Res.img+ when loading the image.
|
31
42
|
# [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)
|
43
|
+
def initialize(img_path, chars, widths, height, space_width, char_spacing = 0, global = true, ext = '.png', retro = nil)
|
33
44
|
retro = Res.retro_images if retro.nil?
|
34
45
|
img = Res.img(img_path, global, false, ext, retro)
|
35
46
|
@chars = chars
|
36
47
|
@images = []
|
37
48
|
@height = height
|
38
49
|
@space_width = space_width
|
50
|
+
@char_spacing = char_spacing
|
39
51
|
wa = widths.is_a?(Array)
|
40
52
|
if wa && widths.length != chars.length
|
41
53
|
raise 'Wrong widths array size!'
|
@@ -60,7 +72,17 @@ module MiniGL
|
|
60
72
|
# Parameters:
|
61
73
|
# [text] The string to be measured
|
62
74
|
def markup_width(text)
|
63
|
-
|
75
|
+
w = 0
|
76
|
+
text.chars.each_with_index do |c, i|
|
77
|
+
if c == ' '
|
78
|
+
w += @space_width
|
79
|
+
else
|
80
|
+
idx = @chars.index(c)
|
81
|
+
w += idx ? @images[idx].width : 0
|
82
|
+
w += @char_spacing if i < text.chars.size - 1
|
83
|
+
end
|
84
|
+
end
|
85
|
+
w
|
64
86
|
end
|
65
87
|
|
66
88
|
# See <code>Gosu::Font#draw_markup_rel</code> for details.
|
@@ -82,7 +104,7 @@ module MiniGL
|
|
82
104
|
i = @chars.index(c)
|
83
105
|
next if i.nil?
|
84
106
|
@images[i].draw(x, y, z, scale_x, scale_y, color)
|
85
|
-
x += scale_x * @images[i].width
|
107
|
+
x += (scale_x * (@images[i].width + @char_spacing)).round
|
86
108
|
end
|
87
109
|
end
|
88
110
|
|
data/test/game.rb
CHANGED
@@ -19,7 +19,7 @@ class MyGame < GameWindow
|
|
19
19
|
@font2 = Res.font :font1, 50
|
20
20
|
@writer1 = TextHelper.new @font1, 5
|
21
21
|
@writer2 = TextHelper.new @font2, 5
|
22
|
-
@btn = Button.new(10, 560, @font1, 'Test', :btn, 0x008000, 0x808080, 0xffffff, 0xff9980, true,
|
22
|
+
@btn = Button.new(10, 560, @font1, 'Test', :btn, 0x008000, 0x808080, 0xffffff, 0xff9980, true, false, -10, 4, 0, 0, 'friends', nil, 2, 2) { |x| puts "hello #{x}" }
|
23
23
|
@btn.enabled = false
|
24
24
|
@chk =
|
25
25
|
ToggleButton.new(x: 0, y: 30, font: @font1, text: 'Click me', img: :check, center_x: false, margin_x: 36, params: 'friends', anchor: :south) { |c, x|
|
@@ -32,11 +32,12 @@ class MyGame < GameWindow
|
|
32
32
|
@ddl = DropDownList.new(0, 10, @font1, nil, nil, ['olá amigos', 'opção 2', 'terceira'], 0, 3, 150, 25, 0, 0x808080, 0xffffff, 0xffff00, nil, 2, 2.5, :north) { |a, b|
|
33
33
|
puts "mudou de #{a} para #{b}"
|
34
34
|
}
|
35
|
+
@btn2 = Button.new(x: 0, y: 80, font: @font1, text: 'Below', img: :btn, anchor: :north) { puts 'Below the dropdown' }
|
35
36
|
|
36
37
|
@panel = Panel.new(10, 10, 720, 520, [
|
37
|
-
|
38
|
+
TextField.new(x: 5, y: 5, font: @font1, text: 'Opa', img: :text, margin_x: 5, margin_y: 5, anchor: :top_left),
|
39
|
+
Button.new(x: 5, y: 5, font: @font1, text: 'Teste', img: :btn) { puts 'top left' },
|
38
40
|
@lbl = Label.new(0, 70, @font1, 'Teste de label', 0, 0x666666, 1, 1, :north),
|
39
|
-
TextField.new(x: 5, y: 40, font: @font1, text: 'Opa', img: :text, margin_x: 5, margin_y: 5, anchor: :top_left),
|
40
41
|
Button.new(x: 0, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :top),
|
41
42
|
DropDownList.new(x: 0, y: 40, width: 150, height: 25, font: @font1, options: ['olá amigos', 'opção 2', 'terceira'], anchor: :north),
|
42
43
|
Button.new(x: 5, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :northeast),
|
@@ -44,7 +45,7 @@ class MyGame < GameWindow
|
|
44
45
|
Button.new(x: 0, y: 0, font: @font1, text: 'Teste', img: :btn, anchor: :center),
|
45
46
|
Button.new(x: 5, y: 0, font: @font1, text: 'Teste', img: :btn, anchor: :right),
|
46
47
|
ToggleButton.new(x: 5, y: 40, img: :check, center_x: false, margin_x: 36, anchor: :east),
|
47
|
-
Button.new(x: 5, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :southwest),
|
48
|
+
Button.new(x: 5, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :southwest) { @lbl.visible = !@lbl.visible },
|
48
49
|
Button.new(x: 0, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :south),
|
49
50
|
ProgressBar.new(0, 40, 200, 20, :barbg, :barfg, 3456, 70, 2, 2, @font1, 0xff000080, nil, nil, 1, 1, :bottom)
|
50
51
|
], :text, :tiled, true, 2, 2, :bottom_right)
|
@@ -80,7 +81,11 @@ class MyGame < GameWindow
|
|
80
81
|
@panel.enabled = !@panel.enabled if KB.key_pressed? Gosu::KbN
|
81
82
|
@panel.visible = !@panel.visible if KB.key_pressed? Gosu::KbM
|
82
83
|
|
83
|
-
|
84
|
+
if KB.key_pressed?(Gosu::KbB)
|
85
|
+
@panel.add_component(Button.new(x: 5, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :southeast) {
|
86
|
+
puts 'new button added'
|
87
|
+
})
|
88
|
+
end
|
84
89
|
@lbl.text = 'Test of changed text' if KB.key_pressed?(Gosu::KB_C)
|
85
90
|
@lbl2.text = 'Shorter text' if KB.key_pressed?(Gosu::KB_X)
|
86
91
|
|
@@ -112,6 +117,7 @@ class MyGame < GameWindow
|
|
112
117
|
@chk.update
|
113
118
|
@txt.update
|
114
119
|
@ddl.update
|
120
|
+
@btn2.update
|
115
121
|
|
116
122
|
@panel.update
|
117
123
|
|
@@ -145,6 +151,7 @@ class MyGame < GameWindow
|
|
145
151
|
780, 450, 300, :right, 0xff0000, 255, 1
|
146
152
|
|
147
153
|
@ddl.draw 0x80, 1, 0xff8080
|
154
|
+
@btn2.draw
|
148
155
|
@btn.draw 0xcc, 1, 0x33ff33
|
149
156
|
@chk.draw
|
150
157
|
@txt.draw
|
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.3.
|
4
|
+
version: 2.3.9
|
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: 2022-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|