minigl 2.0.2 → 2.0.3
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 +26 -6
- data/lib/minigl/forms.rb +132 -19
- data/lib/minigl/game_object.rb +55 -12
- data/lib/minigl/global.rb +29 -4
- data/lib/minigl/movement.rb +2 -2
- data/lib/minigl/text.rb +21 -4
- data/test/game.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fda5e695d12ea20cd3a5a85554b55f8fd1bb29e7
|
4
|
+
data.tar.gz: f864987fbf4fe1a042a4a48191ac2b12625e4602
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8850221370b6f6a77412059b6743a341adefbc5f91bbcffff09b24ce351eaa1782c3f1f440d2aba17cf1ed326710ea906a1cac6cac5ed81da79ec5cef188348
|
7
|
+
data.tar.gz: 2629a2fe8113011548014bfb651afb2b408e921d188a6ab2abd03c352a867000cf39f4f723a52d8cc24cbcf5d98c44c186b51e99b295bc67b19850d05bbfba6c
|
data/README.md
CHANGED
@@ -32,9 +32,29 @@ examples provided with the gem.
|
|
32
32
|
* An auxiliary, tutorial-like documentation is under construction
|
33
33
|
[here](https://github.com/victords/minigl/wiki/How-To).
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
*
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
## Version 2.0.3
|
36
|
+
|
37
|
+
* Flexibilization of various methods and constructors with named parameters.
|
38
|
+
Please note I haven't used the "official" Ruby syntax for named parameters, but
|
39
|
+
the "first parameter as hash" technique (in order to keep the positional call
|
40
|
+
available), so you will need to be careful to include all the mandatory
|
41
|
+
parameters in your hash, or you could face some strange errors (you can find out
|
42
|
+
the mandatory parameters in the documentation). Here is the list of flexibilized
|
43
|
+
methods:
|
44
|
+
* `GameWindow::new`
|
45
|
+
* `Sprite#draw`
|
46
|
+
* `GameObject#draw`
|
47
|
+
* `TextHelper#write_line`
|
48
|
+
* `Button::new`
|
49
|
+
* `ToggleButton::new`
|
50
|
+
* `TextField::new`
|
51
|
+
* `ProgressBar::new`
|
52
|
+
* `DropDownList::new`
|
53
|
+
* Flexibilization of `Mouse::over?` with the possibility of passing a single
|
54
|
+
parameter (a `Rectangle` object) instead of four coordinates.
|
55
|
+
* Passing of the `set_animation` method from `GameObject` to `Sprite`, so the
|
56
|
+
sprites also support it (`GameObject` still supports because it inherits from
|
57
|
+
`Sprite`).
|
58
|
+
* Change of the parameter order in `TextHelper#write_line`, so that `alpha`
|
59
|
+
comes right after `color`, and not after all the `effect_...` parameters. **This
|
60
|
+
could generate incompatibility.**
|
data/lib/minigl/forms.rb
CHANGED
@@ -29,9 +29,7 @@ module MiniGL
|
|
29
29
|
# for each specific component class.
|
30
30
|
attr_accessor :params
|
31
31
|
|
32
|
-
|
33
|
-
# instantiate objects of this class.
|
34
|
-
def initialize(x, y, font, text, text_color, disabled_text_color)
|
32
|
+
def initialize(x, y, font, text, text_color, disabled_text_color) # :nodoc:
|
35
33
|
@x = x
|
36
34
|
@y = y
|
37
35
|
@font = font
|
@@ -93,8 +91,32 @@ module MiniGL
|
|
93
91
|
# parameters.
|
94
92
|
# [action] The block of code executed when the button is clicked (or by
|
95
93
|
# calling the +click+ method).
|
96
|
-
|
94
|
+
#
|
95
|
+
# *Obs.:* This method accepts named parameters, but +x+ and +y+ are
|
96
|
+
# mandatory (also, +img+ is mandatory when +width+ and +height+ are not
|
97
|
+
# provided, and vice-versa).
|
98
|
+
def initialize(x, y = nil, font = nil, text = nil, img = nil,
|
99
|
+
text_color = 0, disabled_text_color = 0, over_text_color = 0, down_text_color = 0,
|
97
100
|
center_x = true, center_y = true, margin_x = 0, margin_y = 0, width = nil, height = nil, params = nil, &action)
|
101
|
+
if x.is_a? Hash
|
102
|
+
y = x[:y]
|
103
|
+
font = x[:font]
|
104
|
+
text = x[:text]
|
105
|
+
img = x[:img]
|
106
|
+
text_color = x.fetch(:text_color, 0)
|
107
|
+
disabled_text_color = x.fetch(:disabled_text_color, 0)
|
108
|
+
over_text_color = x.fetch(:over_text_color, 0)
|
109
|
+
down_text_color = x.fetch(:down_text_color, 0)
|
110
|
+
center_x = x.fetch(:center_x, true)
|
111
|
+
center_y = x.fetch(:center_y, true)
|
112
|
+
margin_x = x.fetch(:margin_x, 0)
|
113
|
+
margin_y = x.fetch(:margin_y, 0)
|
114
|
+
width = x.fetch(:width, nil)
|
115
|
+
height = x.fetch(:height, nil)
|
116
|
+
params = x.fetch(:params, nil)
|
117
|
+
x = x[:x]
|
118
|
+
end
|
119
|
+
|
98
120
|
super x, y, font, text, text_color, disabled_text_color
|
99
121
|
@over_text_color = over_text_color
|
100
122
|
@down_text_color = down_text_color
|
@@ -249,8 +271,33 @@ module MiniGL
|
|
249
271
|
# puts "button was checked" if checked
|
250
272
|
# # do something with params
|
251
273
|
# }
|
252
|
-
|
274
|
+
#
|
275
|
+
# *Obs.:* This method accepts named parameters, but +x+ and +y+ are
|
276
|
+
# mandatory (also, +img+ is mandatory when +width+ and +height+ are not
|
277
|
+
# provided, and vice-versa).
|
278
|
+
def initialize(x, y = nil, font = nil, text = nil, img = nil, checked = false,
|
279
|
+
text_color = 0, disabled_text_color = 0, over_text_color = 0, down_text_color = 0,
|
253
280
|
center_x = true, center_y = true, margin_x = 0, margin_y = 0, width = nil, height = nil, params = nil, &action)
|
281
|
+
if x.is_a? Hash
|
282
|
+
y = x[:y]
|
283
|
+
font = x[:font]
|
284
|
+
text = x[:text]
|
285
|
+
img = x[:img]
|
286
|
+
checked = x.fetch(:checked, false)
|
287
|
+
text_color = x.fetch(:text_color, 0)
|
288
|
+
disabled_text_color = x.fetch(:disabled_text_color, 0)
|
289
|
+
over_text_color = x.fetch(:over_text_color, 0)
|
290
|
+
down_text_color = x.fetch(:down_text_color, 0)
|
291
|
+
center_x = x.fetch(:center_x, true)
|
292
|
+
center_y = x.fetch(:center_y, true)
|
293
|
+
margin_x = x.fetch(:margin_x, 0)
|
294
|
+
margin_y = x.fetch(:margin_y, 0)
|
295
|
+
width = x.fetch(:width, nil)
|
296
|
+
height = x.fetch(:height, nil)
|
297
|
+
params = x.fetch(:params, nil)
|
298
|
+
x = x[:x]
|
299
|
+
end
|
300
|
+
|
254
301
|
super x, y, font, text, nil, text_color, disabled_text_color, over_text_color, down_text_color,
|
255
302
|
center_x, center_y, margin_x, margin_y, width, height, params, &action
|
256
303
|
@img =
|
@@ -359,8 +406,32 @@ module MiniGL
|
|
359
406
|
# field is changed, either by user input or by calling
|
360
407
|
# +text=+. The new text is passed as a first parameter
|
361
408
|
# to this block, followed by +params+. Can be +nil+.
|
362
|
-
|
363
|
-
|
409
|
+
#
|
410
|
+
# *Obs.:* This method accepts named parameters, but +x+, +y+, +font+ and
|
411
|
+
# +img+ are mandatory.
|
412
|
+
def initialize(x, y = nil, font = nil, img = nil, cursor_img = nil, disabled_img = nil, margin_x = 0, margin_y = 0,
|
413
|
+
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)
|
415
|
+
if x.is_a? Hash
|
416
|
+
y = x[:y]
|
417
|
+
font = x[:font]
|
418
|
+
img = x[:img]
|
419
|
+
cursor_img = x.fetch(:cursor_img, nil)
|
420
|
+
disabled_img = x.fetch(:disabled_img, nil)
|
421
|
+
margin_x = x.fetch(:margin_x, 0)
|
422
|
+
margin_y = x.fetch(:margin_y, 0)
|
423
|
+
max_length = x.fetch(:max_length, 100)
|
424
|
+
active = x.fetch(:active, false)
|
425
|
+
text = x.fetch(:text, '')
|
426
|
+
allowed_chars = x.fetch(:allowed_chars, nil)
|
427
|
+
text_color = x.fetch(:text_color, 0)
|
428
|
+
disabled_text_color = x.fetch(:disabled_text_color, 0)
|
429
|
+
selection_color = x.fetch(:selection_color, 0)
|
430
|
+
locale = x.fetch(:locale, 'en-us')
|
431
|
+
params = x.fetch(:params, nil)
|
432
|
+
x = x[:x]
|
433
|
+
end
|
434
|
+
|
364
435
|
super x, y, font, text, text_color, disabled_text_color
|
365
436
|
@img = Res.img img
|
366
437
|
@w = @img.width
|
@@ -598,17 +669,17 @@ module MiniGL
|
|
598
669
|
def locale=(value)
|
599
670
|
@locale = value.downcase
|
600
671
|
@chars =
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
672
|
+
case @locale
|
673
|
+
when 'en-us' then "abcdefghijklmnopqrstuvwxyz1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ`-=[]\\;',./~_+{}|:\"<>?!@#$%^&*()+-*/"
|
674
|
+
when 'pt-br' then "abcdefghijklmnopqrstuvwxyz1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ'-=/[]ç~,.;\"_+?{}Ç^<>:!@#$%¨&*()+-*/"
|
675
|
+
else '###################################################################################################'
|
676
|
+
end
|
606
677
|
@allowed_chars =
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
678
|
+
if @user_allowed_chars
|
679
|
+
@user_allowed_chars
|
680
|
+
else
|
681
|
+
@chars
|
682
|
+
end
|
612
683
|
end
|
613
684
|
|
614
685
|
# Returns the currently selected text.
|
@@ -799,8 +870,28 @@ module MiniGL
|
|
799
870
|
# [text_color] Color of the text.
|
800
871
|
# [format] Format to display the value. Specify '%' for a percentage and
|
801
872
|
# anything else for absolute values (current/maximum).
|
802
|
-
|
873
|
+
#
|
874
|
+
# *Obs.:* This method accepts named parameters, but +x+, +y+, +w+, +h+, +bg+
|
875
|
+
# and +fg+ are mandatory.
|
876
|
+
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,
|
803
878
|
font = nil, text_color = 0, format = nil)
|
879
|
+
if x.is_a? Hash
|
880
|
+
y = x[:y]
|
881
|
+
w = x[:w]
|
882
|
+
h = x[:h]
|
883
|
+
bg = x[:bg]
|
884
|
+
fg = x[:fg]
|
885
|
+
max_value = x.fetch(:max_value, 100)
|
886
|
+
value = x.fetch(:value, 100)
|
887
|
+
fg_margin_x = x.fetch(:fg_margin_x, 0)
|
888
|
+
fg_margin_y = x.fetch(:fg_margin_y, 0)
|
889
|
+
font = x.fetch(:font, nil)
|
890
|
+
text_color = x.fetch(:text_color, 0)
|
891
|
+
format = x.fetch(:format, nil)
|
892
|
+
x = x[:x]
|
893
|
+
end
|
894
|
+
|
804
895
|
super x, y, font, '', text_color, text_color
|
805
896
|
@w = w
|
806
897
|
@h = h
|
@@ -950,8 +1041,30 @@ module MiniGL
|
|
950
1041
|
# [disabled_text_color] Analogous to +text_color+.
|
951
1042
|
# [over_text_color] Same as above.
|
952
1043
|
# [down_text_color] Same as above.
|
953
|
-
|
1044
|
+
#
|
1045
|
+
# *Obs.:* This method accepts named parameters, but +x+, +y+, +font+ and
|
1046
|
+
# +options+ are mandatory (also, +img+ and +opt_img+ are mandatory when
|
1047
|
+
# +width+ and +height+ are not provided, and vice-versa).
|
1048
|
+
def initialize(x, y = nil, font = nil, img = nil, opt_img = nil, options = nil,
|
1049
|
+
option = 0, text_margin = 0, width = nil, height = nil,
|
954
1050
|
text_color = 0, disabled_text_color = 0, over_text_color = 0, down_text_color = 0)
|
1051
|
+
if x.is_a? Hash
|
1052
|
+
y = x[:y]
|
1053
|
+
font = x[:font]
|
1054
|
+
img = x[:img]
|
1055
|
+
opt_img = x[:opt_img]
|
1056
|
+
options = x[:options]
|
1057
|
+
option = x.fetch(:option, 0)
|
1058
|
+
text_margin = x.fetch(:text_margin, 0)
|
1059
|
+
width = x.fetch(:width, nil)
|
1060
|
+
height = x.fetch(:height, nil)
|
1061
|
+
text_color = x.fetch(:text_color, 0)
|
1062
|
+
disabled_text_color = x.fetch(:disabled_text_color, 0)
|
1063
|
+
over_text_color = x.fetch(:over_text_color, 0)
|
1064
|
+
down_text_color = x.fetch(:down_text_color, 0)
|
1065
|
+
x = x[:x]
|
1066
|
+
end
|
1067
|
+
|
955
1068
|
super x, y, font, options[option], text_color, disabled_text_color
|
956
1069
|
@img = img
|
957
1070
|
@opt_img = opt_img
|
data/lib/minigl/game_object.rb
CHANGED
@@ -66,6 +66,17 @@ module MiniGL
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
# Resets the animation timer and immediately changes the image index to
|
70
|
+
# the specified value.
|
71
|
+
#
|
72
|
+
# Parameters:
|
73
|
+
# [index] The image index to be set.
|
74
|
+
def set_animation(index)
|
75
|
+
@anim_counter = 0
|
76
|
+
@img_index = index
|
77
|
+
@index_index = 0
|
78
|
+
end
|
79
|
+
|
69
80
|
# Draws the sprite in the screen
|
70
81
|
#
|
71
82
|
# Parameters:
|
@@ -87,7 +98,20 @@ module MiniGL
|
|
87
98
|
# to draw it vertically flipped.
|
88
99
|
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
89
100
|
# will be drawn on top of the ones with smaller z-orders.
|
101
|
+
#
|
102
|
+
# *Obs.:* This method accepts named parameters.
|
90
103
|
def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, flip = nil, z_index = 0)
|
104
|
+
if map.is_a? Hash
|
105
|
+
scale_x = map.fetch(:scale_x, 1)
|
106
|
+
scale_y = map.fetch(:scale_y, 1)
|
107
|
+
alpha = map.fetch(:alpha, 0xff)
|
108
|
+
color = map.fetch(:color, 0xffffff)
|
109
|
+
angle = map.fetch(:angle, nil)
|
110
|
+
flip = map.fetch(:flip, nil)
|
111
|
+
z_index = map.fetch(:z_index, 0)
|
112
|
+
map = map.fetch(:map, nil)
|
113
|
+
end
|
114
|
+
|
91
115
|
color = (alpha << 24) | color
|
92
116
|
if angle
|
93
117
|
@img[@img_index].draw_rot @x.round - (map ? map.cam.x : 0) + (flip == :horiz ? scale_x * @img[0].width : 0),
|
@@ -154,17 +178,6 @@ module MiniGL
|
|
154
178
|
@stored_forces = Vector.new 0, 0
|
155
179
|
end
|
156
180
|
|
157
|
-
# Resets the animation timer and immediately changes the image index to
|
158
|
-
# the specified value.
|
159
|
-
#
|
160
|
-
# Parameters:
|
161
|
-
# [index] The image index to be set.
|
162
|
-
def set_animation(index)
|
163
|
-
@anim_counter = 0
|
164
|
-
@img_index = index
|
165
|
-
@index_index = 0
|
166
|
-
end
|
167
|
-
|
168
181
|
# Draws the game object in the screen.
|
169
182
|
#
|
170
183
|
# Parameters:
|
@@ -186,7 +199,20 @@ module MiniGL
|
|
186
199
|
# to draw it vertically flipped.
|
187
200
|
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
188
201
|
# will be drawn on top of the ones with smaller z-orders.
|
202
|
+
#
|
203
|
+
# *Obs.:* This method accepts named parameters.
|
189
204
|
def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, flip = nil, z_index = 0)
|
205
|
+
if map.is_a? Hash
|
206
|
+
scale_x = map.fetch(:scale_x, 1)
|
207
|
+
scale_y = map.fetch(:scale_y, 1)
|
208
|
+
alpha = map.fetch(:alpha, 0xff)
|
209
|
+
color = map.fetch(:color, 0xffffff)
|
210
|
+
angle = map.fetch(:angle, nil)
|
211
|
+
flip = map.fetch(:flip, nil)
|
212
|
+
z_index = map.fetch(:z_index, 0)
|
213
|
+
map = map.fetch(:map, nil)
|
214
|
+
end
|
215
|
+
|
190
216
|
color = (alpha << 24) | color
|
191
217
|
if angle
|
192
218
|
@img[@img_index].draw_rot @x.round + (flip == :horiz ? -1 : 1) * @img_gap.x - (map ? map.cam.x : 0) + (flip == :horiz ? scale_x * @w : 0),
|
@@ -247,8 +273,25 @@ module MiniGL
|
|
247
273
|
# '.wav'.
|
248
274
|
# [sound_volume] The volume (from 0 to 1) to play the sound, if any. Default
|
249
275
|
# is 1.
|
250
|
-
|
276
|
+
#
|
277
|
+
# *Obs.:* This method accepts named parameters, but +x+, +y+ and +img+ are
|
278
|
+
# mandatory.
|
279
|
+
def initialize(x, y = nil, img = nil, sprite_cols = nil, sprite_rows = nil, interval = 10, indices = nil, lifetime = nil,
|
251
280
|
sound = nil, sound_ext = '.wav', sound_volume = 1)
|
281
|
+
if x.is_a? Hash
|
282
|
+
y = x[:y]
|
283
|
+
img = x[:img]
|
284
|
+
sprite_cols = x.fetch(:sprite_cols, nil)
|
285
|
+
sprite_rows = x.fetch(:sprite_rows, nil)
|
286
|
+
interval = x.fetch(:interval, 10)
|
287
|
+
indices = x.fetch(:indices, nil)
|
288
|
+
lifetime = x.fetch(:lifetime, nil)
|
289
|
+
sound = x.fetch(:sound, nil)
|
290
|
+
sound_ext = x.fetch(:sound_ext, '.wav')
|
291
|
+
sound_volume = x.fetch(:sound_volume, 1)
|
292
|
+
x = x[:x]
|
293
|
+
end
|
294
|
+
|
252
295
|
super x, y, img, sprite_cols, sprite_rows
|
253
296
|
@timer = 0
|
254
297
|
if indices
|
data/lib/minigl/global.rb
CHANGED
@@ -193,10 +193,27 @@ module MiniGL
|
|
193
193
|
# [double_click_delay] The maximum interval, in frames, between two
|
194
194
|
# clicks, to trigger the "double click" event
|
195
195
|
# (checked with <code>Mouse.double_click?</code>).
|
196
|
-
|
196
|
+
#
|
197
|
+
# *Obs.:* This method accepts named parameters, but +scr_w+ and +scr_h+ are
|
198
|
+
# mandatory.
|
199
|
+
def initialize(scr_w, scr_h = nil, fullscreen = true,
|
197
200
|
gravity = Vector.new(0, 1), min_speed = Vector.new(0.01, 0.01),
|
198
|
-
ramp_contact_threshold = 4, ramp_slip_threshold = 1.
|
201
|
+
ramp_contact_threshold = 4, ramp_slip_threshold = 1.1, ramp_slip_force = 0.1,
|
199
202
|
kb_held_delay = 40, kb_held_interval = 5, double_click_delay = 8)
|
203
|
+
if scr_w.is_a? Hash
|
204
|
+
scr_h = scr_w[:scr_h]
|
205
|
+
fullscreen = scr_w.fetch(:fullscreen, true)
|
206
|
+
gravity = scr_w.fetch(:gravity, Vector.new(0, 1))
|
207
|
+
min_speed = scr_w.fetch(:min_speed, Vector.new(0.01, 0.01))
|
208
|
+
ramp_contact_threshold = scr_w.fetch(:ramp_contact_threshold, 4)
|
209
|
+
ramp_slip_threshold = scr_w.fetch(:ramp_slip_threshold, 1.1)
|
210
|
+
ramp_slip_force = scr_w.fetch(:ramp_slip_force, 0.1)
|
211
|
+
kb_held_delay = scr_w.fetch(:kb_held_delay, 40)
|
212
|
+
kb_held_interval = scr_w.fetch(:kb_held_interval, 5)
|
213
|
+
double_click_delay = scr_w.fetch(:double_click_delay, 8)
|
214
|
+
scr_w = scr_w[:scr_w]
|
215
|
+
end
|
216
|
+
|
200
217
|
super scr_w, scr_h, fullscreen
|
201
218
|
G.window = self
|
202
219
|
G.gravity = gravity
|
@@ -435,8 +452,16 @@ module MiniGL
|
|
435
452
|
# [y] The y-coordinate of the top left corner of the area.
|
436
453
|
# [w] The width of the area.
|
437
454
|
# [h] The height of the area.
|
438
|
-
|
439
|
-
|
455
|
+
#
|
456
|
+
# <b>Alternate syntax</b>
|
457
|
+
#
|
458
|
+
# <code>over?(rectangle)</code>
|
459
|
+
#
|
460
|
+
# Parameters:
|
461
|
+
# [rectangle] A rectangle representing the area to be checked.
|
462
|
+
def over?(x, y = nil, w = nil, h = nil)
|
463
|
+
return @x >= x.x && @x < x.x + x.w && @y >= x.y && @y < x.y + x.h if x.is_a? Rectangle
|
464
|
+
@x >= x && @x < x + w && @y >= y && @y < y + h
|
440
465
|
end
|
441
466
|
end
|
442
467
|
end
|
data/lib/minigl/movement.rb
CHANGED
@@ -30,8 +30,8 @@ module MiniGL
|
|
30
30
|
# [h] The height of the bounding box.
|
31
31
|
# [passable] Whether a moving object can pass through this block when
|
32
32
|
# coming from below. This is a common feature of platforms in platform
|
33
|
-
# games.
|
34
|
-
def initialize(x, y, w, h, passable)
|
33
|
+
# games. Default is +false+.
|
34
|
+
def initialize(x, y, w, h, passable = false)
|
35
35
|
@x = x; @y = y; @w = w; @h = h
|
36
36
|
@passable = passable
|
37
37
|
end
|
data/lib/minigl/text.rb
CHANGED
@@ -27,6 +27,8 @@ module MiniGL
|
|
27
27
|
# [mode] The alignment of the text. Valid values are +:left+, +:right+ and
|
28
28
|
# +:center+.
|
29
29
|
# [color] The color of the text, in hexadecimal RRGGBB format.
|
30
|
+
# [alpha] The opacity of the text. Valid values vary from 0 (fully
|
31
|
+
# transparent) to 255 (fully opaque).
|
30
32
|
# [effect] Effect to add to the text. It can be either +nil+, for no effect,
|
31
33
|
# +:border+ for bordered text, or +:shadow+ for shadowed text (the
|
32
34
|
# shadow is always placed below and to the right of the text).
|
@@ -38,13 +40,28 @@ module MiniGL
|
|
38
40
|
# distance between the text and the shadow.
|
39
41
|
# [effect_alpha] Opacity of the effect, if any. For shadows, it is usual to
|
40
42
|
# provide less than 255.
|
41
|
-
# [alpha] The opacity of the text. Valid values vary from 0 (fully
|
42
|
-
# transparent) to 255 (fully opaque).
|
43
43
|
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
44
44
|
# will be drawn on top of the ones with smaller z-orders.
|
45
|
-
|
45
|
+
#
|
46
|
+
# *Obs.:* This method accepts named parameters, but +text+, +x+ and +y+ are
|
47
|
+
# mandatory.
|
48
|
+
def write_line(text, x = nil, y = nil, mode = :left, color = 0, alpha = 0xff,
|
46
49
|
effect = nil, effect_color = 0, effect_size = 1, effect_alpha = 0xff,
|
47
|
-
|
50
|
+
z_index = 0)
|
51
|
+
if text.is_a? Hash
|
52
|
+
x = text[:x]
|
53
|
+
y = text[:y]
|
54
|
+
mode = text.fetch(:mode, :left)
|
55
|
+
color = text.fetch(:color, 0)
|
56
|
+
alpha = text.fetch(:alpha, 0xff)
|
57
|
+
effect = text.fetch(:effect, nil)
|
58
|
+
effect_color = text.fetch(:effect_color, 0)
|
59
|
+
effect_size = text.fetch(:effect_size, 1)
|
60
|
+
effect_alpha = text.fetch(:effect_alpha, 0xff)
|
61
|
+
z_index = text.fetch(:z_index, 0)
|
62
|
+
text = text[:text]
|
63
|
+
end
|
64
|
+
|
48
65
|
color = (alpha << 24) | color
|
49
66
|
rel =
|
50
67
|
case mode
|
data/test/game.rb
CHANGED
@@ -18,10 +18,10 @@ class MyGame < GameWindow
|
|
18
18
|
@btn = Button.new(10, 560, @font1, 'Test', :btn, 0x008000, 0x808080, 0xffffff, 0xff9980, true, false, 0, 4, 0, 0, 'friends') { |x| puts "hello #{x}" }
|
19
19
|
@btn.enabled = false
|
20
20
|
@chk =
|
21
|
-
ToggleButton.new(40, 300, @font1, 'Click me', :check,
|
21
|
+
ToggleButton.new(x: 40, y: 300, font: @font1, text: 'Click me', img: :check, center_x: false, margin_x: 36, params: 'friends') { |c, x|
|
22
22
|
puts "hello #{x}, checked: #{c}"
|
23
23
|
}
|
24
|
-
@txt = TextField.new(10, 520, @font1, :text,
|
24
|
+
@txt = TextField.new(x: 10, y: 520, font: @font1, img: :text, margin_x: 15, margin_y: 5, max_length: 16, locale: 'PT-BR')
|
25
25
|
@txt.visible = false
|
26
26
|
|
27
27
|
@pb = ProgressBar.new(5, 240, 200, 20, 0xff0000, 0x00ff00, 3456, 70, 0, 0, @font1, 0xff000080)
|
@@ -83,11 +83,11 @@ class MyGame < GameWindow
|
|
83
83
|
clear 0xabcdef
|
84
84
|
|
85
85
|
@obj1.draw nil, 1, 1, 255, 0x33ff33, 30, 1
|
86
|
-
@obj2.draw
|
87
|
-
@obj3.draw
|
88
|
-
@writer1.write_line 'Testing effect 1', 400, 260, :
|
89
|
-
@writer2.write_line 'Second effect test', 400, 280, :center, 0xffffff, :border, 0xff0000, 2
|
90
|
-
@writer2.write_line 'Text with shadow!!', 400, 340, :center, 0xffff00, :shadow, 0, 2, 0x80
|
86
|
+
@obj2.draw flip: :vert, scale_x: 0.5, scale_y: 1.4
|
87
|
+
@obj3.draw flip: @flip
|
88
|
+
@writer1.write_line text: 'Testing effect 1', x: 400, y: 260, color: 0xffffff, effect: :border
|
89
|
+
@writer2.write_line 'Second effect test', 400, 280, :center, 0xffffff, 255, :border, 0xff0000, 2
|
90
|
+
@writer2.write_line 'Text with shadow!!', 400, 340, :center, 0xffff00, 255, :shadow, 0, 2, 0x80
|
91
91
|
@writer1.write_breaking "Testing multiple line text.\nThis should draw text "\
|
92
92
|
'across multiple lines, respecting a limit width. '\
|
93
93
|
'Furthermore, the text must be right-aligned.',
|
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.
|
4
|
+
version: 2.0.3
|
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: 2015-03-
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|