minigl 2.2.0 → 2.2.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/lib/minigl/forms.rb +82 -7
  4. data/test/game.rb +4 -4
  5. metadata +21 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf74cda701aadb5941c6b9e7a35c1ef534fcb55608bfc6cf9e2614fce53e48c5
4
- data.tar.gz: 53ba4be1ad4f60c97ba926986d8909df7f7db2eb9706f25a7a62f3f1c91ed68c
3
+ metadata.gz: a7d451a982c58c436b84bd5de4bf52f2f6762d69d7275043aadf330b60d8ba63
4
+ data.tar.gz: 1d699e8182002420b17beac84e0d5601ddbca86cbd17c3425e09f73aa00bd819
5
5
  SHA512:
6
- metadata.gz: 97699a40a88821a6506e4bf8861d0917c71753424b94131bcbecd7e7355ba484575114df951a423d0998307cfed731f18f80e6551de9bd2f539618a1bf562ddf
7
- data.tar.gz: 79ebb0b3647c2e80bb43d1927c42f6ba027970d6fe11c273aba72bc2747cf9207c6cfc2868928bdd772b7eee7296e388d1a58924c03290e13c659a56bb08e34b
6
+ metadata.gz: 941b9be8b09c005054527c571a9adfda1cdbe76090b974ee518b40f51ab9bf38fb3515a2874d2647abe68db2ccb87a07fbbbc944eb276560d972132f41556488
7
+ data.tar.gz: 37c59f05e5b10d8f8728a2c612e5bf132875946ca0a673de9a7e0176c3302a61cde07743a8a8b3b4c435ab54daaf3a2ab7ce44013a2645d393f295154be84614
data/README.md CHANGED
@@ -29,8 +29,8 @@ 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.0
32
+ ## Version 2.2.1
33
33
 
34
- * Added the `tileable` option to `Res::imgs`.
35
- * Added the `anchor` option to all form components.
36
- * Added the `Panel` class, to easily group form components - take a look at the docs!
34
+ * Added the `Label` class.
35
+ * Made the `x`, `y`, `w` and `h` of `Panel`s accessible.
36
+ * Fixed bug in `TextField` with starting text.
data/lib/minigl/forms.rb CHANGED
@@ -23,7 +23,7 @@ module MiniGL
23
23
  end
24
24
 
25
25
  # This class is an abstract ancestor for all form components (Button,
26
- # ToggleButton and TextField).
26
+ # ToggleButton, TextField, DropDownList and ProgressBar).
27
27
  class Component
28
28
  # The horizontal coordinate of the component
29
29
  attr_reader :x
@@ -75,6 +75,18 @@ module MiniGL
75
75
 
76
76
  # Represents a container of form components.
77
77
  class Panel
78
+ # The horizontal position of the panel from the top left corner of the window.
79
+ attr_reader :x
80
+
81
+ # The vertical position of the panel from the top left corner of the window.
82
+ attr_reader :y
83
+
84
+ # The width of the panel in pixels.
85
+ attr_reader :w
86
+
87
+ # The height of the panel in pixels.
88
+ attr_reader :h
89
+
78
90
  # Whether the components inside this panel are enabled.
79
91
  attr_reader :enabled
80
92
 
@@ -636,7 +648,9 @@ module MiniGL
636
648
  @text_y = y + margin_y * @scale_y
637
649
  @selection_color = selection_color
638
650
 
639
- @nodes = [x + margin_x * @scale_x]
651
+ @nodes = [@text_x]
652
+ send(:text=, text, false) if text
653
+
640
654
  @cur_node = 0
641
655
  @cursor_visible = false
642
656
  @cursor_timer = 0
@@ -840,7 +854,7 @@ module MiniGL
840
854
  # [value] The new text to be set. If it's longer than the +max_length+
841
855
  # parameter used in the constructor, it will be truncated to
842
856
  # +max_length+ characters.
843
- def text=(value)
857
+ def text=(value, trigger_changed = true)
844
858
  @text = value[0...@max_length]
845
859
  @nodes.clear; @nodes << @text_x
846
860
  x = @nodes[0]
@@ -852,7 +866,7 @@ module MiniGL
852
866
  @anchor1 = nil
853
867
  @anchor2 = nil
854
868
  set_cursor_visible
855
- @on_text_changed.call @text, @params if @on_text_changed
869
+ @on_text_changed.call @text, @params if trigger_changed && @on_text_changed
856
870
  end
857
871
 
858
872
  # Sets the locale used by the text field to detect keys. Only 'en-us' and
@@ -1241,7 +1255,7 @@ module MiniGL
1241
1255
  # Parameters:
1242
1256
  # [x] The x-coordinate of the object.
1243
1257
  # [y] The y-coordinate of the object.
1244
- # [font] Font to be used by the buttons that compose the drop-donwn list.
1258
+ # [font] Font to be used by the buttons that compose the drop-down list.
1245
1259
  # [img] Image of the main button, i.e., the one at the top, that toggles
1246
1260
  # visibility of the other buttons (the "option" buttons).
1247
1261
  # [opt_img] Image for the "option" buttons, as described above.
@@ -1389,10 +1403,11 @@ module MiniGL
1389
1403
  G.window.draw_quad b.x, b.y, c,
1390
1404
  b.x + b.w, b.y, c,
1391
1405
  b.x + b.w, b.y + b.h, c,
1392
- b.x, b.y + b.h, c, z_index if b.visible
1406
+ b.x, b.y + b.h, c, z_index + 1 if b.visible
1393
1407
  end
1394
1408
  end
1395
- @buttons.each { |b| b.draw alpha, z_index, color }
1409
+ @buttons[0].draw(alpha, z_index, color)
1410
+ @buttons[1..-1].each { |b| b.draw alpha, z_index + 1, color }
1396
1411
  end
1397
1412
 
1398
1413
  private
@@ -1407,4 +1422,64 @@ module MiniGL
1407
1422
  end
1408
1423
  end
1409
1424
  end
1425
+
1426
+ # This class represents a label.
1427
+ class Label < Component
1428
+ # Creates a new label.
1429
+ #
1430
+ # Parameters:
1431
+ # [x] The x-coordinate of the label.
1432
+ # [y] The x-coordinate of the label.
1433
+ # [font] Font that will be used to draw the label's text.
1434
+ # [text] The label's text.
1435
+ # [text_color] The default text color.
1436
+ # [disabled_text_color] The text color when the label is disabled.
1437
+ # [scale_x] The horizontal scale factor.
1438
+ # [scale_y] The vertical scale factor.
1439
+ # [anchor] See parameter with the same name in <code>Panel#initialize</code> for details.
1440
+ def initialize(x, y = nil, font = nil, text = nil, text_color = 0, disabled_text_color = 0, scale_x = 1, scale_y = 1, anchor = nil)
1441
+ if x.is_a? Hash
1442
+ y = x[:y]
1443
+ font = x[:font]
1444
+ text = x[:text]
1445
+ text_color = x.fetch(:text_color, 0)
1446
+ disabled_text_color = x.fetch(:disabled_text_color, 0)
1447
+ scale_x = x.fetch(:scale_x, 1)
1448
+ scale_y = x.fetch(:scale_y, 1)
1449
+ anchor = x.fetch(:anchor, nil)
1450
+ x = x[:x]
1451
+ end
1452
+
1453
+ @scale_x = scale_x
1454
+ @scale_y = scale_y
1455
+ @w = font.text_width(text) * scale_x
1456
+ @h = font.height * scale_y
1457
+ @anchor_offset_x = x; @anchor_offset_y = y
1458
+ @anchor, x, y = FormUtils.check_anchor(anchor, x, y, @w, @h)
1459
+ super(x, y, font, text, text_color, disabled_text_color)
1460
+ end
1461
+
1462
+ # Draws the label.
1463
+ #
1464
+ # Parameters:
1465
+ # [alpha] The opacity with which the label will be drawn. Allowed values
1466
+ # vary between 0 (fully transparent) and 255 (fully opaque).
1467
+ # [z_index] The z-order to draw the object. Objects with larger z-orders
1468
+ # will be drawn on top of the ones with smaller z-orders.
1469
+ # [color] Color to apply a filter to the text.
1470
+ def draw(alpha = 255, z_index = 0, color = 0xffffff)
1471
+ c = @enabled ? @text_color : @disabled_text_color
1472
+ r1 = c >> 16
1473
+ g1 = (c & 0xff00) >> 8
1474
+ b1 = (c & 0xff)
1475
+ r2 = color >> 16
1476
+ g2 = (color & 0xff00) >> 8
1477
+ b2 = (color & 0xff)
1478
+ r1 *= r2; r1 /= 255
1479
+ g1 *= g2; g1 /= 255
1480
+ b1 *= b2; b1 /= 255
1481
+ color = (alpha << 24) | (r1 << 16) | (g1 << 8) | b1
1482
+ @font.draw(@text, @x, @y, z_index, @scale_x, @scale_y, color)
1483
+ end
1484
+ end
1410
1485
  end
data/test/game.rb CHANGED
@@ -33,9 +33,10 @@ class MyGame < GameWindow
33
33
  puts "mudou de #{a} para #{b}"
34
34
  }
35
35
 
36
- @panel = Panel.new(10, 10,720, 520, [
36
+ @panel = Panel.new(10, 10, 720, 520, [
37
37
  Button.new(x: 5, y: 5, font: @font1, text: 'Teste', img: :btn),
38
- TextField.new(x: 5, y: 40, font: @font1, img: :text, margin_x: 5, margin_y: 5, anchor: :top_left),
38
+ Label.new(0, 70, @font1, 'Teste de label', 0xcccccc, 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),
39
40
  Button.new(x: 0, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :top),
40
41
  DropDownList.new(x: 0, y: 40, width: 150, height: 25, font: @font1, options: ['olá amigos', 'opção 2', 'terceira'], anchor: :north),
41
42
  Button.new(x: 5, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :northeast),
@@ -45,8 +46,7 @@ class MyGame < GameWindow
45
46
  ToggleButton.new(x: 5, y: 40, img: :check, center_x: false, margin_x: 36, anchor: :east),
46
47
  Button.new(x: 5, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :southwest),
47
48
  Button.new(x: 0, y: 5, font: @font1, text: 'Teste', img: :btn, anchor: :south),
48
- ProgressBar.new(0, 40, 200, 20, :barbg, :barfg, 3456, 70, 2, 2, @font1, 0xff000080, nil, nil, 1, 1, :bottom),
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
52
  @eff = Effect.new(100, 100, :check, 2, 4, 10, nil, nil, '1')
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.0
4
+ version: 2.2.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: 2018-11-20 00:00:00.000000000 Z
11
+ date: 2018-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -94,42 +94,42 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
- rubygems_version: 2.7.7
97
+ rubygems_version: 2.7.8
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: MiniGL
101
101
  test_files:
102
- - test/game_object_tests.rb
103
- - test/vector_tests.rb
104
- - test/movement_tests.rb
105
102
  - test/res_tests.rb
106
103
  - test/iso_game.rb
107
104
  - test/mov_game.rb
108
105
  - test/map_tests.rb
109
106
  - test/game.rb
107
+ - test/game_object_tests.rb
108
+ - test/vector_tests.rb
109
+ - test/movement_tests.rb
110
110
  - test/test.png
111
111
  - test/data/font/font1.ttf
112
112
  - test/data/img/square.svg
113
- - test/data/img/btn.png
114
- - test/data/img/square3.svg
115
- - test/data/img/image.png
116
- - test/data/img/tile2.svg
117
- - test/data/img/tile2.png
113
+ - test/data/img/barbg.png
114
+ - test/data/img/img1.png
118
115
  - test/data/img/tile1.png
119
- - test/data/img/check.png
120
- - test/data/img/barbg.svg
121
- - test/data/img/barfg.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
122
120
  - test/data/img/square2.png
123
- - test/data/img/square.png
121
+ - test/data/img/barfg.png
124
122
  - test/data/img/tile1b.png
125
- - test/data/img/img1.png
123
+ - test/data/img/tile2.png
124
+ - test/data/img/check.png
125
+ - test/data/img/tile2.svg
126
126
  - test/data/img/square3.png
127
+ - test/data/img/square3.svg
128
+ - test/data/img/image.png
127
129
  - test/data/img/tile1.svg
128
- - test/data/img/barbg.png
129
- - test/data/img/square2.svg
130
- - test/data/img/text.png
130
+ - test/data/img/square.png
131
+ - test/data/img/barbg.svg
131
132
  - test/data/img/barfg.svg
132
- - test/data/img/tile2b.png
133
- - test/data/sound/1.wav
134
133
  - test/data/tileset/tileset1.png
134
+ - test/data/sound/1.wav
135
135
  - test/data/img/sub/image.png