minigl 2.0.15 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22d1f8116b124e88af0f118061d03fdec42e53e699adb6b941873ea4111f777a
4
- data.tar.gz: 8c1baf3090485e58fcec0cbde92d1be87d29269facce261156a021f2452da553
3
+ metadata.gz: b8bdac633885e2a5c5e8deef33bfa5b513653952c275beb5bb589ee9c438f46a
4
+ data.tar.gz: aad3320fae8b1b1636f1ec14158727017e0fcc34a89ad36f041bbd0d93cf8fc3
5
5
  SHA512:
6
- metadata.gz: d7cd5d8f4d85825ce2797b9f9cda4016a2f135b74f319b09f6fd3f96d26ab4715d57544ed730077c703961b2813d4f97d49b1e7772f4cc11079f0d1ea693ff5c
7
- data.tar.gz: 17582310ae650eeb9b4269893985a252be3839b5c80803aaa6c32ba89df35a94da64dd4202b402697529cb6d89f78851ac6c97b23963e767b7cdddc90acaa8ef
6
+ metadata.gz: bfae3ced224c32373951cc043ce7f879f62643ed6db78da0e0afc2bdf9d9f862cc613b4f21128f0083d0443ad44cc52a2507a04b2bd7a0e096fcae1f1565efd3
7
+ data.tar.gz: e9591dc3f17d163cddcc67873e561a9f11bcb39531268128b4aeb702e91e595b7cf7bd334e876c3cf3c77bf4fd73c9381c2d0a7437e07482dac3b45b81a30ccd
data/README.md CHANGED
@@ -29,6 +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.0.15
32
+ ## Version 2.1.0
33
33
 
34
- * Added the `retro_images` global option to `Res` and the `retro` option to `Res::img`, `Res::imgs` and `Res::tileset`.
34
+ * Added the missing documentation for the `retro` option in `Res.img`, `Res.imgs` and `Res.tileset`.
35
+ * Added the `retro`, `scale_x` and `scale_y` options to the constructors of all form controls.
36
+ * Added color options to the `draw` methods of all form controls.
@@ -89,6 +89,11 @@ module MiniGL
89
89
  # @action.call @params
90
90
  # Note that this doesn't force you to declare a block that takes
91
91
  # parameters.
92
+ # [retro] Whether the image should be loaded with the 'retro' option set
93
+ # (see +Gosu::Image+ for details). If the value is omitted, the
94
+ # +Res.retro_images+ value will be used.
95
+ # [scale_x] Horizontal scale to draw the component with.
96
+ # [scale_y] Vertical scale to draw the component with.
92
97
  # [action] The block of code executed when the button is clicked (or by
93
98
  # calling the +click+ method).
94
99
  #
@@ -97,7 +102,8 @@ module MiniGL
97
102
  # provided, and vice-versa).
98
103
  def initialize(x, y = nil, font = nil, text = nil, img = nil,
99
104
  text_color = 0, disabled_text_color = 0, over_text_color = 0, down_text_color = 0,
100
- center_x = true, center_y = true, margin_x = 0, margin_y = 0, width = nil, height = nil, params = nil, &action)
105
+ center_x = true, center_y = true, margin_x = 0, margin_y = 0, width = nil, height = nil,
106
+ params = nil, retro = nil, scale_x = 1, scale_y = 1, &action)
101
107
  if x.is_a? Hash
102
108
  y = x[:y]
103
109
  font = x[:font]
@@ -114,25 +120,31 @@ module MiniGL
114
120
  width = x.fetch(:width, nil)
115
121
  height = x.fetch(:height, nil)
116
122
  params = x.fetch(:params, nil)
123
+ retro = x.fetch(:retro, nil)
124
+ scale_x = x.fetch(:scale_x, 1)
125
+ scale_y = x.fetch(:scale_y, 1)
117
126
  x = x[:x]
118
127
  end
119
128
 
120
129
  super x, y, font, text, text_color, disabled_text_color
121
130
  @over_text_color = over_text_color
122
131
  @down_text_color = down_text_color
132
+ retro = Res.retro_images if retro.nil?
133
+ @scale_x = scale_x
134
+ @scale_y = scale_y
123
135
  @img =
124
- if img; Res.imgs img, 1, 4, true
136
+ if img; Res.imgs img, 1, 4, true, '.png', retro
125
137
  else; nil; end
126
138
  @w =
127
- if img; @img[0].width
128
- else; width; end
139
+ if img; @img[0].width * @scale_x
140
+ else; width * @scale_x; end
129
141
  @h =
130
- if img; @img[0].height
131
- else; height; end
142
+ if img; @img[0].height * @scale_y
143
+ else; height * @scale_y; end
132
144
  if center_x; @text_x = x + @w / 2 if @w
133
- else; @text_x = x + margin_x; end
145
+ else; @text_x = x + margin_x * @scale_x; end
134
146
  if center_y; @text_y = y + @h / 2 if @h
135
- else; @text_y = y + margin_y; end
147
+ else; @text_y = y + margin_y * @scale_y; end
136
148
  @center_x = center_x
137
149
  @center_y = center_y
138
150
  @action = action
@@ -217,10 +229,11 @@ module MiniGL
217
229
  # vary between 0 (fully transparent) and 255 (fully opaque).
218
230
  # [z_index] The z-order to draw the object. Objects with larger z-orders
219
231
  # will be drawn on top of the ones with smaller z-orders.
220
- def draw(alpha = 0xff, z_index = 0)
232
+ # [color] Color to apply a filter to the image.
233
+ def draw(alpha = 0xff, z_index = 0, color = 0xffffff)
221
234
  return unless @visible
222
235
 
223
- color = (alpha << 24) | 0xffffff
236
+ color = (alpha << 24) | color
224
237
  text_color =
225
238
  if @enabled
226
239
  if @state == :down
@@ -232,14 +245,14 @@ module MiniGL
232
245
  @disabled_text_color
233
246
  end
234
247
  text_color = (alpha << 24) | text_color
235
- @img[@img_index].draw @x, @y, z_index, 1, 1, color if @img
248
+ @img[@img_index].draw @x, @y, z_index, @scale_x, @scale_y, color if @img
236
249
  if @text
237
250
  if @center_x or @center_y
238
251
  rel_x = @center_x ? 0.5 : 0
239
252
  rel_y = @center_y ? 0.5 : 0
240
- @font.draw_rel @text, @text_x, @text_y, z_index, rel_x, rel_y, 1, 1, text_color
253
+ @font.draw_rel @text, @text_x, @text_y, z_index, rel_x, rel_y, @scale_x, @scale_y, text_color
241
254
  else
242
- @font.draw @text, @text_x, @text_y, z_index, 1, 1, text_color
255
+ @font.draw @text, @text_x, @text_y, z_index, @scale_x, @scale_y, text_color
243
256
  end
244
257
  end
245
258
  end
@@ -277,7 +290,8 @@ module MiniGL
277
290
  # provided, and vice-versa).
278
291
  def initialize(x, y = nil, font = nil, text = nil, img = nil, checked = false,
279
292
  text_color = 0, disabled_text_color = 0, over_text_color = 0, down_text_color = 0,
280
- center_x = true, center_y = true, margin_x = 0, margin_y = 0, width = nil, height = nil, params = nil, &action)
293
+ center_x = true, center_y = true, margin_x = 0, margin_y = 0, width = nil, height = nil,
294
+ params = nil, retro = nil, scale_x = 1, scale_y = 1, &action)
281
295
  if x.is_a? Hash
282
296
  y = x[:y]
283
297
  font = x[:font]
@@ -295,20 +309,23 @@ module MiniGL
295
309
  width = x.fetch(:width, nil)
296
310
  height = x.fetch(:height, nil)
297
311
  params = x.fetch(:params, nil)
312
+ retro = x.fetch(:retro, nil)
313
+ scale_x = x.fetch(:scale_x, 1)
314
+ scale_y = x.fetch(:scale_y, 1)
298
315
  x = x[:x]
299
316
  end
300
317
 
301
318
  super x, y, font, text, nil, text_color, disabled_text_color, over_text_color, down_text_color,
302
- center_x, center_y, margin_x, margin_y, width, height, params, &action
319
+ center_x, center_y, margin_x, margin_y, 0, 0, params, retro, scale_x, scale_y, &action
303
320
  @img =
304
- if img; Res.imgs img, 2, 4, true
321
+ if img; Res.imgs img, 2, 4, true, '.png', retro
305
322
  else; nil; end
306
323
  @w =
307
- if img; @img[0].width
308
- else; width; end
324
+ if img; @img[0].width * @scale_x
325
+ else; width * @scale_x; end
309
326
  @h =
310
- if img; @img[0].height
311
- else; height; end
327
+ if img; @img[0].height * @scale_y
328
+ else; height * @scale_y; end
312
329
  @text_x = x + @w / 2 if center_x
313
330
  @text_y = y + @h / 2 if center_y
314
331
  @checked = checked
@@ -402,6 +419,11 @@ module MiniGL
402
419
  # @on_text_changed.call @text, @params
403
420
  # Thus, +params+ will be the second parameter. Note that this
404
421
  # doesn't force you to declare a block that takes parameters.
422
+ # [retro] Whether the images should be loaded with the 'retro' option set
423
+ # (see +Gosu::Image+ for details). If the value is omitted, the
424
+ # +Res.retro_images+ value will be used.
425
+ # [scale_x] Horizontal scale to draw the component with.
426
+ # [scale_y] Vertical scale to draw the component with.
405
427
  # [on_text_changed] The block of code executed when the text in the text
406
428
  # field is changed, either by user input or by calling
407
429
  # +text=+. The new text is passed as a first parameter
@@ -411,7 +433,8 @@ module MiniGL
411
433
  # +img+ are mandatory.
412
434
  def initialize(x, y = nil, font = nil, img = nil, cursor_img = nil, disabled_img = nil, margin_x = 0, margin_y = 0,
413
435
  max_length = 100, active = false, text = '', allowed_chars = nil,
414
- text_color = 0, disabled_text_color = 0, selection_color = 0, locale = 'en-us', params = nil, &on_text_changed)
436
+ text_color = 0, disabled_text_color = 0, selection_color = 0, locale = 'en-us',
437
+ params = nil, retro = nil, scale_x = 1, scale_y = 1, &on_text_changed)
415
438
  if x.is_a? Hash
416
439
  y = x[:y]
417
440
  font = x[:font]
@@ -429,22 +452,28 @@ module MiniGL
429
452
  selection_color = x.fetch(:selection_color, 0)
430
453
  locale = x.fetch(:locale, 'en-us')
431
454
  params = x.fetch(:params, nil)
455
+ retro = x.fetch(:retro, nil)
456
+ scale_x = x.fetch(:scale_x, 1)
457
+ scale_y = x.fetch(:scale_y, 1)
432
458
  x = x[:x]
433
459
  end
434
460
 
435
461
  super x, y, font, text, text_color, disabled_text_color
436
- @img = Res.img img
437
- @w = @img.width
438
- @h = @img.height
439
- @cursor_img = Res.img(cursor_img) if cursor_img
440
- @disabled_img = Res.img(disabled_img) if disabled_img
462
+ retro = Res.retro_images if retro.nil?
463
+ @scale_x = scale_x
464
+ @scale_y = scale_y
465
+ @img = Res.img img, false, false, '.png', retro
466
+ @w = @img.width * @scale_x
467
+ @h = @img.height * @scale_y
468
+ @cursor_img = Res.img(cursor_img, false, false, '.png', retro) if cursor_img
469
+ @disabled_img = Res.img(disabled_img, false, false, '.png', retro) if disabled_img
441
470
  @max_length = max_length
442
471
  @active = active
443
- @text_x = x + margin_x
444
- @text_y = y + margin_y
472
+ @text_x = x + margin_x * @scale_x
473
+ @text_y = y + margin_y * @scale_y
445
474
  @selection_color = selection_color
446
475
 
447
- @nodes = [x + margin_x]
476
+ @nodes = [x + margin_x * @scale_x]
448
477
  @cur_node = 0
449
478
  @cursor_visible = false
450
479
  @cursor_timer = 0
@@ -653,7 +682,7 @@ module MiniGL
653
682
  @nodes.clear; @nodes << @text_x
654
683
  x = @nodes[0]
655
684
  @text.chars.each { |char|
656
- x += @font.text_width char
685
+ x += @font.text_width(char) * @scale_x
657
686
  @nodes << x
658
687
  }
659
688
  @cur_node = @nodes.size - 1
@@ -727,14 +756,17 @@ module MiniGL
727
756
  # values vary between 0 (fully transparent) and 255 (fully opaque).
728
757
  # [z_index] The z-order to draw the object. Objects with larger z-orders
729
758
  # will be drawn on top of the ones with smaller z-orders.
730
- def draw(alpha = 0xff, z_index = 0)
759
+ # [color] Color to apply a filter to the image.
760
+ # [disabled_color] Color to apply a filter to the image when the field is
761
+ # disabled.
762
+ def draw(alpha = 0xff, z_index = 0, color = 0xffffff, disabled_color = 0x808080)
731
763
  return unless @visible
732
764
 
733
- color = (alpha << 24) | ((@enabled or @disabled_img) ? 0xffffff : 0x808080)
765
+ color = (alpha << 24) | ((@enabled or @disabled_img) ? color : disabled_color)
734
766
  text_color = (alpha << 24) | (@enabled ? @text_color : @disabled_text_color)
735
767
  img = ((@enabled or @disabled_img.nil?) ? @img : @disabled_img)
736
- img.draw @x, @y, z_index, 1, 1, color
737
- @font.draw @text, @text_x, @text_y, z_index, 1, 1, text_color
768
+ img.draw @x, @y, z_index, @scale_x, @scale_y, color
769
+ @font.draw @text, @text_x, @text_y, z_index, @scale_x, @scale_y, text_color
738
770
 
739
771
  if @anchor1 and @anchor2
740
772
  selection_color = ((alpha / 2) << 24) | @selection_color
@@ -746,13 +778,13 @@ module MiniGL
746
778
 
747
779
  if @cursor_visible
748
780
  if @cursor_img
749
- @cursor_img.draw @nodes[@cur_node] - @cursor_img.width / 2, @text_y, z_index
781
+ @cursor_img.draw @nodes[@cur_node] - (@cursor_img.width * @scale_x) / 2, @text_y, z_index, @scale_x, @scale_y
750
782
  else
751
783
  cursor_color = alpha << 24
752
784
  G.window.draw_quad @nodes[@cur_node], @text_y, cursor_color,
753
785
  @nodes[@cur_node] + 1, @text_y, cursor_color,
754
- @nodes[@cur_node] + 1, @text_y + @font.height, cursor_color,
755
- @nodes[@cur_node], @text_y + @font.height, cursor_color, z_index
786
+ @nodes[@cur_node] + 1, @text_y + @font.height * @scale_y, cursor_color,
787
+ @nodes[@cur_node], @text_y + @font.height * @scale_y, cursor_color, z_index
756
788
  end
757
789
  end
758
790
  end
@@ -792,9 +824,9 @@ module MiniGL
792
824
  def insert_char(char)
793
825
  return unless @allowed_chars.index char and @text.length < @max_length
794
826
  @text.insert @cur_node, char
795
- @nodes.insert @cur_node + 1, @nodes[@cur_node] + @font.text_width(char)
827
+ @nodes.insert @cur_node + 1, @nodes[@cur_node] + @font.text_width(char) * @scale_x
796
828
  for i in (@cur_node + 2)..(@nodes.size - 1)
797
- @nodes[i] += @font.text_width(char)
829
+ @nodes[i] += @font.text_width(char) * @scale_x
798
830
  end
799
831
  @cur_node += 1
800
832
  set_cursor_visible
@@ -806,7 +838,7 @@ module MiniGL
806
838
  max = min == @anchor1 ? @anchor2 : @anchor1
807
839
  interval_width = 0
808
840
  for i in min...max
809
- interval_width += @font.text_width(@text[i])
841
+ interval_width += @font.text_width(@text[i]) * @scale_x
810
842
  @nodes.delete_at min + 1
811
843
  end
812
844
  @text[min...max] = ''
@@ -822,7 +854,7 @@ module MiniGL
822
854
 
823
855
  def remove_char(back)
824
856
  @cur_node -= 1 if back
825
- char_width = @font.text_width(@text[@cur_node])
857
+ char_width = @font.text_width(@text[@cur_node]) * @scale_x
826
858
  @text[@cur_node] = ''
827
859
  @nodes.delete_at @cur_node + 1
828
860
  for i in (@cur_node + 1)..(@nodes.size - 1)
@@ -850,7 +882,8 @@ module MiniGL
850
882
  # [y] The y-coordinate of the progress bar on the screen.
851
883
  # [w] Width of the progress bar, in pixels. This is the maximum space the
852
884
  # bar foreground can occupy. Note that the width of the foreground image
853
- # (+fg+) can be less than this.
885
+ # (+fg+) can be less than this, in which case the image will be
886
+ # horizontally repeated to fill all the needed space.
854
887
  # [h] Height of the progress bar. This will be the height of the bar
855
888
  # foreground when +fg+ is a color (when it is an image, the height of
856
889
  # the image will be kept).
@@ -870,12 +903,17 @@ module MiniGL
870
903
  # [text_color] Color of the text.
871
904
  # [format] Format to display the value. Specify '%' for a percentage and
872
905
  # anything else for absolute values (current/maximum).
906
+ # [retro] Whether the images should be loaded with the 'retro' option set
907
+ # (see +Gosu::Image+ for details). If the value is omitted, the
908
+ # +Res.retro_images+ value will be used.
909
+ # [scale_x] Horizontal scale to draw the component with.
910
+ # [scale_y] Vertical scale to draw the component with.
873
911
  #
874
912
  # *Obs.:* This method accepts named parameters, but +x+, +y+, +w+, +h+, +bg+
875
913
  # and +fg+ are mandatory.
876
914
  def initialize(x, y = nil, w = nil, h = nil, bg = nil, fg = nil,
877
- max_value = 100, value = 100, fg_margin_x = 0, fg_margin_y = 0, #fg_left = nil, fg_right = nil,
878
- font = nil, text_color = 0, format = nil)
915
+ max_value = 100, value = 100, fg_margin_x = 0, fg_margin_y = 0, # fg_left = nil, fg_right = nil,
916
+ font = nil, text_color = 0, format = nil, retro = nil, scale_x = 1, scale_y = 1)
879
917
  if x.is_a? Hash
880
918
  y = x[:y]
881
919
  w = x[:w]
@@ -889,31 +927,37 @@ module MiniGL
889
927
  font = x.fetch(:font, nil)
890
928
  text_color = x.fetch(:text_color, 0)
891
929
  format = x.fetch(:format, nil)
930
+ retro = x.fetch(:retro, nil)
931
+ scale_x = x.fetch(:scale_x, 1)
932
+ scale_y = x.fetch(:scale_y, 1)
892
933
  x = x[:x]
893
934
  end
894
935
 
895
936
  super x, y, font, '', text_color, text_color
896
- @w = w
897
- @h = h
937
+ @scale_x = scale_x
938
+ @scale_y = scale_y
939
+ @w = w * @scale_x
940
+ @h = h * @scale_y
941
+ retro = Res.retro_images if retro.nil?
898
942
  if bg.is_a? Integer
899
943
  @bg_color = bg
900
944
  else # String or Symbol
901
- @bg = Res.img bg
945
+ @bg = Res.img bg, false, false, '.png', retro
902
946
  end
903
947
  if fg.is_a? Integer
904
948
  @fg_color = fg
905
949
  else # String or Symbol
906
- @fg = Res.img fg
950
+ @fg = Res.img fg, false, false, '.png', retro
907
951
  @fg_path = "#{Res.prefix}#{Res.img_dir}#{fg.to_s.gsub(Res.separator, '/')}.png"
908
- puts @fg_path
909
952
  end
910
- @fg_margin_x = fg_margin_x
911
- @fg_margin_y = fg_margin_y
953
+ @fg_margin_x = fg_margin_x * @scale_x
954
+ @fg_margin_y = fg_margin_y * @scale_y
912
955
  # @fg_left = fg_left
913
956
  # @fg_right = fg_right
914
957
  @max_value = max_value
915
958
  self.value = value
916
959
  @format = format
960
+ @retro = retro
917
961
  end
918
962
 
919
963
  # Increases the current value of the progress bar by the given amount.
@@ -968,12 +1012,13 @@ module MiniGL
968
1012
  # opaque).
969
1013
  # [z_index] (+Fixnum+) The z-order to draw the object. Objects with larger
970
1014
  # z-orders will be drawn on top of the ones with smaller z-orders.
971
- def draw(alpha = 0xff, z_index = 0)
1015
+ # [color] Color to apply a filter to the images (when these are provided).
1016
+ def draw(alpha = 0xff, z_index = 0, color = 0xffffff)
972
1017
  return unless @visible
973
1018
 
974
1019
  if @bg
975
- c = (alpha << 24) | 0xffffff
976
- @bg.draw @x, @y, z_index, 1, 1, c
1020
+ c = (alpha << 24) | color
1021
+ @bg.draw @x, @y, z_index, @scale_x, @scale_y, c
977
1022
  else
978
1023
  c = (alpha << 24) | @bg_color
979
1024
  G.window.draw_quad @x, @y, c,
@@ -982,18 +1027,18 @@ module MiniGL
982
1027
  @x, @y + @h, c, z_index
983
1028
  end
984
1029
  if @fg
985
- c = (alpha << 24) | 0xffffff
986
- w1 = @fg.width
1030
+ c = (alpha << 24) | color
1031
+ w1 = @fg.width * @scale_x
987
1032
  w2 = (@value.to_f / @max_value * @w).round
988
1033
  x0 = @x + @fg_margin_x
989
1034
  x = 0
990
1035
  while x <= w2 - w1
991
- @fg.draw x0 + x, @y + @fg_margin_y, z_index, 1, 1, c
1036
+ @fg.draw x0 + x, @y + @fg_margin_y, z_index, @scale_x, @scale_y, c
992
1037
  x += w1
993
1038
  end
994
1039
  if w2 - x > 0
995
- img = Gosu::Image.new(G.window, @fg_path, true, 0, 0, w2 - x, @fg.height)
996
- img.draw x0 + x, @y + @fg_margin_y, z_index, 1, 1, c
1040
+ img = Gosu::Image.new(@fg_path, tileable: true, retro: @retro, rect: [0, 0, ((w2 - x) / @scale_x).round, @fg.height])
1041
+ img.draw x0 + x, @y + @fg_margin_y, z_index, @scale_x, @scale_y, c
997
1042
  end
998
1043
  else
999
1044
  c = (alpha << 24) | @fg_color
@@ -1006,7 +1051,7 @@ module MiniGL
1006
1051
  if @font
1007
1052
  c = (alpha << 24) | @text_color
1008
1053
  @text = @format == '%' ? "#{(@value.to_f / @max_value * 100).round}%" : "#{@value}/#{@max_value}"
1009
- @font.draw_rel @text, @x + @fg_margin_x + @w / 2, @y + @fg_margin_y + @h / 2, 0, 0.5, 0.5, 1, 1, c
1054
+ @font.draw_rel @text, @x + @fg_margin_x + @w / 2, @y + @fg_margin_y + @h / 2, 0, 0.5, 0.5, @scale_x, @scale_y, c
1010
1055
  end
1011
1056
  end
1012
1057
  end
@@ -1041,6 +1086,11 @@ module MiniGL
1041
1086
  # [disabled_text_color] Analogous to +text_color+.
1042
1087
  # [over_text_color] Same as above.
1043
1088
  # [down_text_color] Same as above.
1089
+ # [retro] Whether the images should be loaded with the 'retro' option set
1090
+ # (see +Gosu::Image+ for details). If the value is omitted, the
1091
+ # +Res.retro_images+ value will be used.
1092
+ # [scale_x] Horizontal scale to draw the component with.
1093
+ # [scale_y] Vertical scale to draw the component with.
1044
1094
  # [on_changed] Action performed when the value of the dropdown is changed.
1045
1095
  # It must be a block with two parameters, which will receive
1046
1096
  # the old and the new value, respectively.
@@ -1050,7 +1100,8 @@ module MiniGL
1050
1100
  # +width+ and +height+ are not provided, and vice-versa).
1051
1101
  def initialize(x, y = nil, font = nil, img = nil, opt_img = nil, options = nil,
1052
1102
  option = 0, text_margin = 0, width = nil, height = nil,
1053
- text_color = 0, disabled_text_color = 0, over_text_color = 0, down_text_color = 0, &on_changed)
1103
+ text_color = 0, disabled_text_color = 0, over_text_color = 0, down_text_color = 0,
1104
+ retro = nil, scale_x = 1, scale_y = 1, &on_changed)
1054
1105
  if x.is_a? Hash
1055
1106
  y = x[:y]
1056
1107
  font = x[:font]
@@ -1065,6 +1116,9 @@ module MiniGL
1065
1116
  disabled_text_color = x.fetch(:disabled_text_color, 0)
1066
1117
  over_text_color = x.fetch(:over_text_color, 0)
1067
1118
  down_text_color = x.fetch(:down_text_color, 0)
1119
+ retro = x.fetch(:retro, nil)
1120
+ scale_x = x.fetch(:scale_x, 1)
1121
+ scale_y = x.fetch(:scale_y, 1)
1068
1122
  x = x[:x]
1069
1123
  end
1070
1124
 
@@ -1077,15 +1131,20 @@ module MiniGL
1077
1131
  @buttons = []
1078
1132
  @buttons.push(
1079
1133
  Button.new(x, y, font, @value, img, text_color, disabled_text_color, over_text_color, down_text_color,
1080
- false, true, text_margin, 0, width, height) {
1134
+ false, true, text_margin, 0, width, height, nil, retro, scale_x, scale_y) {
1081
1135
  toggle
1082
1136
  }
1083
1137
  )
1138
+
1139
+ @scale_x = scale_x
1140
+ @scale_y = scale_y
1084
1141
  @w = @buttons[0].w
1085
1142
  @h = @buttons[0].h
1143
+ @max_h = (@options.size + 1) * @h
1144
+
1086
1145
  @options.each_with_index do |o, i|
1087
1146
  b = Button.new(x, y + (i+1) * @h, font, o, opt_img, text_color, disabled_text_color, over_text_color, down_text_color,
1088
- false, true, text_margin, 0, @w, @h) {
1147
+ false, true, text_margin, 0, width, height, nil, retro, scale_x, scale_y) {
1089
1148
  old = @value
1090
1149
  @value = @buttons[0].text = o
1091
1150
  @on_changed.call(old, o) if @on_changed
@@ -1094,7 +1153,6 @@ module MiniGL
1094
1153
  b.visible = false
1095
1154
  @buttons.push b
1096
1155
  end
1097
- @max_h = (@options.size + 1) * @h
1098
1156
 
1099
1157
  @on_changed = on_changed
1100
1158
  end
@@ -1133,24 +1191,28 @@ module MiniGL
1133
1191
  # (fully opaque).
1134
1192
  # [z_index] (+Fixnum+) The z-order to draw the object. Objects with larger
1135
1193
  # z-orders will be drawn on top of the ones with smaller z-orders.
1136
- def draw(alpha = 0xff, z_index = 0)
1194
+ # [color] Color of the buttons, if no image was provided, or color to apply
1195
+ # a filter to the images.
1196
+ # [over_color] Color of the buttons when the mouse is over them (when no
1197
+ # image was provided).
1198
+ def draw(alpha = 0xff, z_index = 0, color = 0xffffff, over_color = 0xcccccc)
1137
1199
  return unless @visible
1138
1200
  unless @img
1139
- bottom = @open ? @y + @max_h + 1 : @y + @h + 1
1201
+ bottom = @y + (@open ? @max_h : @h) + @scale_y
1140
1202
  b_color = (alpha << 24)
1141
- G.window.draw_quad @x - 1, @y - 1, b_color,
1142
- @x + @w + 1, @y - 1, b_color,
1143
- @x + @w + 1, bottom, b_color,
1144
- @x - 1, bottom, b_color, z_index
1203
+ G.window.draw_quad @x - @scale_x, @y - @scale_y, b_color,
1204
+ @x + @w + @scale_x, @y - @scale_y, b_color,
1205
+ @x + @w + @scale_x, bottom, b_color,
1206
+ @x - @scale_x, bottom, b_color, z_index
1145
1207
  @buttons.each do |b|
1146
- color = (alpha << 24) | (b.state == :over ? 0xcccccc : 0xffffff)
1147
- G.window.draw_quad b.x, b.y, color,
1148
- b.x + b.w, b.y, color,
1149
- b.x + b.w, b.y + b.h, color,
1150
- b.x, b.y + b.h, color, z_index if b.visible
1208
+ c = (alpha << 24) | (b.state == :over ? over_color : color)
1209
+ G.window.draw_quad b.x, b.y, c,
1210
+ b.x + b.w, b.y, c,
1211
+ b.x + b.w, b.y + b.h, c,
1212
+ b.x, b.y + b.h, c, z_index if b.visible
1151
1213
  end
1152
1214
  end
1153
- @buttons.each { |b| b.draw alpha, z_index }
1215
+ @buttons.each { |b| b.draw alpha, z_index, color }
1154
1216
  end
1155
1217
 
1156
1218
  private
@@ -585,6 +585,9 @@ module MiniGL
585
585
  # continuous composition.
586
586
  # [ext] The extension of the file being loaded. Specify only if it is
587
587
  # other than '.png'.
588
+ # [retro] Whether the image should be loaded with the 'retro' option set
589
+ # (see +Gosu::Image+ for details). If the value is omitted, the
590
+ # +Res.retro_images+ value will be used.
588
591
  def img(id, global = false, tileable = false, ext = '.png', retro = nil)
589
592
  a = global ? @global_imgs : @imgs
590
593
  return a[id] if a[id]
@@ -609,6 +612,9 @@ module MiniGL
609
612
  # released when you call +clear+.
610
613
  # [ext] The extension of the file being loaded. Specify only if it is
611
614
  # other than ".png".
615
+ # [retro] Whether the image should be loaded with the 'retro' option set
616
+ # (see +Gosu::Image+ for details). If the value is omitted, the
617
+ # +Res.retro_images+ value will be used.
612
618
  def imgs(id, sprite_cols, sprite_rows, global = false, ext = '.png', retro = nil)
613
619
  a = global ? @global_imgs : @imgs
614
620
  return a[id] if a[id]
@@ -634,6 +640,9 @@ module MiniGL
634
640
  # released when you call +clear+.
635
641
  # [ext] The extension of the file being loaded. Specify only if it is
636
642
  # other than ".png".
643
+ # [retro] Whether the image should be loaded with the 'retro' option set
644
+ # (see +Gosu::Image+ for details). If the value is omitted, the
645
+ # +Res.retro_images+ value will be used.
637
646
  def tileset(id, tile_width = 32, tile_height = 32, global = false, ext = '.png', retro = nil)
638
647
  a = global ? @global_tilesets : @tilesets
639
648
  return a[id] if a[id]
@@ -19,17 +19,17 @@ 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, false, 0, 4, 0, 0, 'friends') { |x| puts "hello #{x}" }
22
+ @btn = Button.new(10, 560, @font1, 'Test', :btn, 0x008000, 0x808080, 0xffffff, 0xff9980, true, true, 0, 4, 0, 0, 'friends', nil, 2, 2) { |x| puts "hello #{x}" }
23
23
  @btn.enabled = false
24
24
  @chk =
25
- ToggleButton.new(x: 40, y: 300, font: @font1, text: 'Click me', img: :check, center_x: false, margin_x: 36, params: 'friends') { |c, x|
25
+ ToggleButton.new(x: 40, y: 300, font: @font1, text: 'Click me', img: :check, center_x: false, margin_x: 36, params: 'friends', scale_x: 2.3, scale_y: 1.4) { |c, x|
26
26
  puts "hello #{x}, checked: #{c}"
27
27
  }
28
- @txt = TextField.new(x: 10, y: 520, font: @font1, img: :text, margin_x: 15, margin_y: 5, max_length: 16, locale: 'PT-BR')
28
+ @txt = TextField.new(x: 10, y: 520, font: @font1, img: :text, margin_x: 15, margin_y: 5, max_length: 16, locale: 'PT-BR', scale_x: 1.2, scale_y: 0.8)
29
29
  @txt.visible = false
30
30
 
31
- @pb = ProgressBar.new(5, 240, 200, 20, 0xff0000, 0x00ff00, 3456, 70, 0, 0, @font1, 0xff000080)
32
- @ddl = DropDownList.new(5, 270, @font1, nil, nil, ['olá amigos', 'opção 2', 'terceira'], 0, 3, 150, 25, 0, 0x808080, 0xffffff, 0xffff00) { |a, b|
31
+ @pb = ProgressBar.new(5, 240, 200, 20, :barbg, :barfg, 3456, 70, 2, 2, @font1, 0xff000080, nil, nil, 1.8, 2)
32
+ @ddl = DropDownList.new(5, 270, @font1, nil, nil, ['olá amigos', 'opção 2', 'terceira'], 0, 3, 150, 25, 0, 0x808080, 0xffffff, 0xffff00, nil, 2, 2.5) { |a, b|
33
33
  puts "mudou de #{a} para #{b}"
34
34
  }
35
35
 
@@ -113,8 +113,8 @@ class MyGame < GameWindow
113
113
  'Furthermore, the text must be right-aligned.',
114
114
  780, 450, 300, :right, 0xff0000, 255, 1
115
115
 
116
- @ddl.draw 0x80, 1
117
- @btn.draw 0xcc
116
+ @ddl.draw 0x80, 1, 0xff8080
117
+ @btn.draw 0xcc, 1, 0x33ff33
118
118
  @chk.draw
119
119
  @txt.draw
120
120
  @pb.draw 0x66
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.0.15
4
+ version: 2.1.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: 2018-07-21 00:00:00.000000000 Z
11
+ date: 2018-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu