minigl 1.3.9 → 1.3.10
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 +5 -5
- data/lib/minigl/forms.rb +48 -52
- data/test/game.rb +9 -9
- 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: 3638cd0876552f96b482a2b5986581916a27a5f9
|
4
|
+
data.tar.gz: a6e059c49297f45b360e225394b687bb2650a0a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ac542ef6d3fe0140636b591b26336c23ed4b8fe1c7188c751f89e439a7099c2e0baaaff1e7fdae65f9d1529a73757792c9c147282e2f83418ac8e00254dad13
|
7
|
+
data.tar.gz: 68dbca5b83d9600c2d2b75c11b4c69aabd536a9a41722e0f1e1235af27e7bf195cad88809571770a9e91d61e025e777df13ed479dc8eb6e0f814c8e48d588530
|
data/README.md
CHANGED
@@ -32,10 +32,10 @@ this [working game example](https://github.com/victords/aventura-do-saber).
|
|
32
32
|
* An auxiliary, tutorial-like documentation is under construction
|
33
33
|
[here](https://github.com/victords/minigl/wiki).
|
34
34
|
|
35
|
-
**Version 1.3.
|
35
|
+
**Version 1.3.10**
|
36
36
|
|
37
|
-
*
|
37
|
+
* Split the `center` parameter in `Button` and `ToggleButton` constructors
|
38
|
+
into `center_x` and `center_y` (see doc. for details).
|
38
39
|
|
39
|
-
**P.S.**
|
40
|
-
|
41
|
-
small errors uncorrected.
|
40
|
+
**P.S.** This version can cause incompatibility because of the parameter order
|
41
|
+
in the constructors of `Button` and `ToggleButton`.
|
data/lib/minigl/forms.rb
CHANGED
@@ -19,7 +19,7 @@ module AGL
|
|
19
19
|
|
20
20
|
# This constructor is for internal use of the subclasses only. Do not
|
21
21
|
# instantiate objects of this class.
|
22
|
-
def initialize
|
22
|
+
def initialize(x, y, font, text, text_color, disabled_text_color)
|
23
23
|
@x = x
|
24
24
|
@y = y
|
25
25
|
@font = font
|
@@ -49,9 +49,12 @@ module AGL
|
|
49
49
|
# [text_color] Color of the button text, in hexadecimal RRGGBB format.
|
50
50
|
# [disabled_text_color] Color of the button text, when it's disabled, in
|
51
51
|
# hexadecimal RRGGBB format.
|
52
|
-
# [
|
53
|
-
#
|
54
|
-
#
|
52
|
+
# [center_x] Whether the button text should be horizontally centered in its
|
53
|
+
# area (the area is defined by the image size, if an image is
|
54
|
+
# given, or by the +width+ and +height+ parameters, otherwise).
|
55
|
+
# [center_y] Whether the button text should be vertically centered in its
|
56
|
+
# area (the area is defined by the image size, if an image is
|
57
|
+
# given, or by the +width+ and +height+ parameters, otherwise).
|
55
58
|
# [margin_x] The x offset, from the button x-coordinate, to draw the text.
|
56
59
|
# This parameter is used only if +center+ is false.
|
57
60
|
# [margin_y] The y offset, from the button y-coordinate, to draw the text.
|
@@ -68,8 +71,8 @@ module AGL
|
|
68
71
|
# parameters.
|
69
72
|
# [action] The block of code executed when the button is clicked (or by
|
70
73
|
# calling the +click+ method).
|
71
|
-
def initialize
|
72
|
-
width = nil, height = nil, params = nil, &action
|
74
|
+
def initialize(x, y, font, text, img, text_color = 0, disabled_text_color = 0, center_x = true, center_y = true,
|
75
|
+
margin_x = 0, margin_y = 0, width = nil, height = nil, params = nil, &action)
|
73
76
|
super x, y, font, text, text_color, disabled_text_color
|
74
77
|
@img =
|
75
78
|
if img; Res.imgs img, 1, 4, true
|
@@ -80,14 +83,12 @@ module AGL
|
|
80
83
|
@h =
|
81
84
|
if img; @img[0].height
|
82
85
|
else; height; end
|
83
|
-
if
|
84
|
-
|
85
|
-
|
86
|
-
else
|
87
|
-
|
88
|
-
|
89
|
-
end
|
90
|
-
@center = center
|
86
|
+
if center_x; @text_x = x + @w / 2 if @w
|
87
|
+
else; @text_x = x + margin_x; end
|
88
|
+
if center_y; @text_y = y + @h / 2 if @h
|
89
|
+
else; @text_y = y + margin_y; end
|
90
|
+
@center_x = center_x
|
91
|
+
@center_y = center_y
|
91
92
|
@action = action
|
92
93
|
@params = params
|
93
94
|
|
@@ -155,17 +156,12 @@ module AGL
|
|
155
156
|
# Parameters:
|
156
157
|
# [x] The new x-coordinate for the button.
|
157
158
|
# [y] The new y-coordinate for the button.
|
158
|
-
def set_position
|
159
|
-
|
160
|
-
|
159
|
+
def set_position(x, y)
|
160
|
+
if @center_x; @text_x = x + @w / 2
|
161
|
+
else; @text_x += x - @x; end
|
162
|
+
if @center_y; @text_y = y + @h / 2
|
163
|
+
else; @text_y += y - @y; end
|
161
164
|
@x = x; @y = y
|
162
|
-
if @center
|
163
|
-
@text_x = x + @w / 2
|
164
|
-
@text_y = y + @h / 2
|
165
|
-
else
|
166
|
-
@text_x += d_x
|
167
|
-
@text_y += d_y
|
168
|
-
end
|
169
165
|
end
|
170
166
|
|
171
167
|
# Draws the button in the screen.
|
@@ -175,22 +171,24 @@ module AGL
|
|
175
171
|
# vary between 0 (fully transparent) and 255 (fully opaque).
|
176
172
|
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
177
173
|
# will be drawn on top of the ones with smaller z-orders.
|
178
|
-
def draw
|
174
|
+
def draw(alpha = 0xff, z_index = 0)
|
179
175
|
return unless @visible
|
180
176
|
|
181
177
|
color = (alpha << 24) | 0xffffff
|
182
178
|
text_color = (alpha << 24) | (@enabled ? @text_color : @disabled_text_color)
|
183
179
|
@img[@img_index].draw @x, @y, z_index, 1, 1, color if @img
|
184
180
|
if @text
|
185
|
-
if @
|
186
|
-
|
181
|
+
if @center_x or @center_y
|
182
|
+
rel_x = @center_x ? 0.5 : 0
|
183
|
+
rel_y = @center_y ? 0.5 : 0
|
184
|
+
@font.draw_rel @text, @text_x, @text_y, z_index, rel_x, rel_y, 1, 1, text_color
|
187
185
|
else
|
188
186
|
@font.draw @text, @text_x, @text_y, z_index, 1, 1, text_color
|
189
187
|
end
|
190
188
|
end
|
191
189
|
end
|
192
190
|
|
193
|
-
def enabled=
|
191
|
+
def enabled=(value) # :nodoc:
|
194
192
|
@enabled = value
|
195
193
|
@state = :up
|
196
194
|
@img_index = 3
|
@@ -217,9 +215,9 @@ module AGL
|
|
217
215
|
# puts "button was checked" if checked
|
218
216
|
# # do something with params
|
219
217
|
# }
|
220
|
-
def initialize
|
221
|
-
width = nil, height = nil, params = nil, &action
|
222
|
-
super x, y, font, text, nil, text_color, disabled_text_color,
|
218
|
+
def initialize(x, y, font, text, img, checked = false, text_color = 0, disabled_text_color = 0, center_x = true, center_y = true,
|
219
|
+
margin_x = 0, margin_y = 0, width = nil, height = nil, params = nil, &action)
|
220
|
+
super x, y, font, text, nil, text_color, disabled_text_color, center_x, center_y, margin_x, margin_y, width, height, params, &action
|
223
221
|
@img =
|
224
222
|
if img; Res.imgs img, 2, 4, true
|
225
223
|
else; nil; end
|
@@ -229,10 +227,8 @@ module AGL
|
|
229
227
|
@h =
|
230
228
|
if img; @img[0].height
|
231
229
|
else; height; end
|
232
|
-
if
|
233
|
-
|
234
|
-
@text_y = y + @h / 2
|
235
|
-
end
|
230
|
+
@text_x = x + @w / 2 if center_x
|
231
|
+
@text_y = y + @h / 2 if center_y
|
236
232
|
@checked = checked
|
237
233
|
end
|
238
234
|
|
@@ -258,12 +254,12 @@ module AGL
|
|
258
254
|
#
|
259
255
|
# Parameters:
|
260
256
|
# [value] The state to be set (+true+ for checked, +false+ for unchecked).
|
261
|
-
def checked=
|
257
|
+
def checked=(value)
|
262
258
|
click if value != @checked
|
263
259
|
@checked = value
|
264
260
|
end
|
265
261
|
|
266
|
-
def enabled=
|
262
|
+
def enabled=(value) # :nodoc:
|
267
263
|
@enabled = value
|
268
264
|
@state = :up
|
269
265
|
@img_index = @checked ? 7 : 6
|
@@ -320,8 +316,8 @@ module AGL
|
|
320
316
|
# field is changed, either by user input or by calling
|
321
317
|
# +text=+. The new text is passed as a first parameter
|
322
318
|
# to this block, followed by +params+. Can be +nil+.
|
323
|
-
def initialize
|
324
|
-
allowed_chars = nil, text_color = 0, disabled_text_color = 0, selection_color = 0, params = nil, &on_text_changed
|
319
|
+
def initialize(x, y, font, img, cursor_img = nil, disabled_img = nil, margin_x = 0, margin_y = 0, max_length = 100, active = false, text = '',
|
320
|
+
allowed_chars = nil, text_color = 0, disabled_text_color = 0, selection_color = 0, params = nil, &on_text_changed)
|
325
321
|
super x, y, font, text, text_color, disabled_text_color
|
326
322
|
@img = Res.img img
|
327
323
|
@w = @img.width
|
@@ -417,10 +413,10 @@ module AGL
|
|
417
413
|
end
|
418
414
|
|
419
415
|
############################### Keyboard ##############################
|
420
|
-
shift = (
|
421
|
-
if
|
416
|
+
shift = (KB.key_down?(@k[53]) or KB.key_down?(@k[54]))
|
417
|
+
if KB.key_pressed?(@k[53]) or KB.key_pressed?(@k[54]) # shift
|
422
418
|
@anchor1 = @cur_node if @anchor1.nil?
|
423
|
-
elsif
|
419
|
+
elsif KB.key_released?(@k[53]) or KB.key_released?(@k[54])
|
424
420
|
@anchor1 = nil if @anchor2.nil?
|
425
421
|
end
|
426
422
|
inserted = false
|
@@ -530,7 +526,7 @@ module AGL
|
|
530
526
|
# [value] The new text to be set. If it's longer than the +max_length+
|
531
527
|
# parameter used in the constructor, it will be truncated to
|
532
528
|
# +max_length+ characters.
|
533
|
-
def text=
|
529
|
+
def text=(value)
|
534
530
|
@text = value[0...@max_length]
|
535
531
|
@nodes.clear; @nodes << @text_x
|
536
532
|
x = @nodes[0]
|
@@ -547,7 +543,7 @@ module AGL
|
|
547
543
|
|
548
544
|
# Returns the currently selected text.
|
549
545
|
def selected_text
|
550
|
-
return
|
546
|
+
return '' if @anchor2.nil?
|
551
547
|
min = @anchor1 < @anchor2 ? @anchor1 : @anchor2
|
552
548
|
max = min == @anchor1 ? @anchor2 : @anchor1
|
553
549
|
@text[min..max]
|
@@ -572,7 +568,7 @@ module AGL
|
|
572
568
|
# Parameters:
|
573
569
|
# [x] The new x-coordinate for the text field.
|
574
570
|
# [y] The new y-coordinate for the text field.
|
575
|
-
def set_position
|
571
|
+
def set_position(x, y)
|
576
572
|
d_x = x - @x
|
577
573
|
d_y = y - @y
|
578
574
|
@x = x; @y = y
|
@@ -590,7 +586,7 @@ module AGL
|
|
590
586
|
# values vary between 0 (fully transparent) and 255 (fully opaque).
|
591
587
|
# [z_index] The z-order to draw the object. Objects with larger z-orders
|
592
588
|
# will be drawn on top of the ones with smaller z-orders.
|
593
|
-
def draw
|
589
|
+
def draw(alpha = 0xff, z_index = 0)
|
594
590
|
return unless @visible
|
595
591
|
|
596
592
|
color = (alpha << 24) | ((@enabled or @disabled_img) ? 0xffffff : 0x808080)
|
@@ -620,12 +616,12 @@ module AGL
|
|
620
616
|
end
|
621
617
|
end
|
622
618
|
|
623
|
-
def enabled=
|
619
|
+
def enabled=(value) # :nodoc:
|
624
620
|
@enabled = value
|
625
621
|
unfocus unless @enabled
|
626
622
|
end
|
627
623
|
|
628
|
-
def visible=
|
624
|
+
def visible=(value) # :nodoc:
|
629
625
|
@visible = value
|
630
626
|
unfocus unless @visible
|
631
627
|
end
|
@@ -652,7 +648,7 @@ module AGL
|
|
652
648
|
@cur_node = index
|
653
649
|
end
|
654
650
|
|
655
|
-
def insert_char
|
651
|
+
def insert_char(char)
|
656
652
|
return unless @allowed_chars.index char and @text.length < @max_length
|
657
653
|
@text.insert @cur_node, char
|
658
654
|
@nodes.insert @cur_node + 1, @nodes[@cur_node] + @font.text_width(char)
|
@@ -664,7 +660,7 @@ module AGL
|
|
664
660
|
@on_text_changed.call @text, @params if @on_text_changed
|
665
661
|
end
|
666
662
|
|
667
|
-
def remove_interval
|
663
|
+
def remove_interval(will_insert = false)
|
668
664
|
min = @anchor1 < @anchor2 ? @anchor1 : @anchor2
|
669
665
|
max = min == @anchor1 ? @anchor2 : @anchor1
|
670
666
|
interval_width = 0
|
@@ -683,10 +679,10 @@ module AGL
|
|
683
679
|
@on_text_changed.call @text, @params if @on_text_changed and not will_insert
|
684
680
|
end
|
685
681
|
|
686
|
-
def remove_char
|
682
|
+
def remove_char(back)
|
687
683
|
@cur_node -= 1 if back
|
688
684
|
char_width = @font.text_width(@text[@cur_node])
|
689
|
-
@text[@cur_node] =
|
685
|
+
@text[@cur_node] = ''
|
690
686
|
@nodes.delete_at @cur_node + 1
|
691
687
|
for i in (@cur_node + 1)..(@nodes.size - 1)
|
692
688
|
@nodes[i] -= char_width
|
data/test/game.rb
CHANGED
@@ -5,21 +5,21 @@ class MyGame < Gosu::Window
|
|
5
5
|
def initialize
|
6
6
|
super 800, 600, false # creating a 800 x 600 window, not full screen
|
7
7
|
Game.initialize self, Vector.new(0, 1), 10, 2
|
8
|
-
|
8
|
+
|
9
9
|
@obj1 = GameObject.new 10, 10, 80, 80, :img1, Vector.new(-10, -10)
|
10
10
|
@obj2 = Sprite.new 400, 0, :img1
|
11
|
-
|
11
|
+
|
12
12
|
@font = Res.font :font1, 20
|
13
13
|
@writer = TextHelper.new @font, 5
|
14
|
-
@btn = Button.new(10, 560, @font,
|
14
|
+
@btn = Button.new(10, 560, @font, 'Test', :btn, 0x008000, 0x808080, true, false, 0, 4, 0, 0, 'friends') { |x| puts "hello #{x}" }
|
15
15
|
@btn.enabled = false
|
16
|
-
@chk = ToggleButton.new(
|
16
|
+
@chk = ToggleButton.new(40, 300, @font, 'Click me', :check, false, 0xffffff, 0x808080, false, true, 36, 0, 0, 0, 'friends') { |c, x|
|
17
17
|
puts "hello #{x}, checked: #{c}"
|
18
18
|
}
|
19
|
-
@txt = TextField.new(10, 520, @font, :text, nil, nil, 15, 5, 16, false,
|
19
|
+
@txt = TextField.new(10, 520, @font, :text, nil, nil, 15, 5, 16, false, '', nil, 0, 0, 0x0000ff, 'test') { |t, x| puts "field #{x}, text: #{t}" }
|
20
20
|
@txt.visible = false
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def needs_cursor?
|
24
24
|
true
|
25
25
|
end
|
@@ -36,13 +36,13 @@ class MyGame < Gosu::Window
|
|
36
36
|
@chk.enabled = !@chk.enabled if KB.key_pressed? Gosu::KbRightControl
|
37
37
|
@txt.visible = !@txt.visible if KB.key_pressed? Gosu::KbReturn
|
38
38
|
@txt.enabled = !@txt.enabled if KB.key_pressed? Gosu::KbLeftAlt
|
39
|
-
|
39
|
+
|
40
40
|
Mouse.update
|
41
41
|
if Mouse.double_click? :left
|
42
42
|
@obj1.x = Mouse.x + 10
|
43
43
|
@obj1.y = Mouse.y + 10
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
@btn.update
|
47
47
|
@chk.update
|
48
48
|
@txt.update
|
@@ -55,7 +55,7 @@ class MyGame < Gosu::Window
|
|
55
55
|
"across multiple lines, respecting a limit width. "\
|
56
56
|
"Furthermore, the text must be right-aligned.",
|
57
57
|
780, 300, 300, :right, 0xff0000, 255, 1
|
58
|
-
|
58
|
+
|
59
59
|
@btn.draw 0xcc
|
60
60
|
@chk.draw
|
61
61
|
@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: 1.3.
|
4
|
+
version: 1.3.10
|
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: 2014-
|
11
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|