rubygame 2.5.3 → 2.6.0
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.
- data/CREDITS +6 -4
- data/NEWS +79 -0
- data/README +55 -72
- data/ROADMAP +20 -13
- data/doc/custom_sdl_load_paths.rdoc +79 -0
- data/doc/getting_started.rdoc +65 -36
- data/doc/keyboard_symbols.rdoc +243 -0
- data/doc/macosx_install.rdoc +49 -35
- data/doc/windows_install.rdoc +36 -108
- data/lib/rubygame.rb +62 -24
- data/lib/rubygame/audio.rb +147 -0
- data/lib/rubygame/clock.rb +164 -1
- data/lib/rubygame/color.rb +40 -7
- data/lib/rubygame/color/models/hsl.rb +1 -1
- data/lib/rubygame/color/models/hsv.rb +1 -1
- data/lib/rubygame/color/models/rgb.rb +1 -1
- data/lib/rubygame/color/palettes/css.rb +1 -3
- data/lib/rubygame/color/palettes/x11.rb +1 -2
- data/lib/rubygame/constants.rb +297 -0
- data/lib/rubygame/deprecated_mixer.rb +555 -0
- data/lib/rubygame/event.rb +122 -6
- data/lib/rubygame/event_handler.rb +3 -1
- data/lib/rubygame/event_hook.rb +6 -2
- data/lib/rubygame/event_triggers.rb +1 -1
- data/lib/rubygame/events.rb +416 -1
- data/lib/rubygame/ftor.rb +1 -7
- data/lib/rubygame/gfx.rb +583 -0
- data/lib/rubygame/gl.rb +107 -0
- data/lib/rubygame/image.rb +140 -0
- data/lib/rubygame/joystick.rb +184 -0
- data/lib/rubygame/main.rb +82 -0
- data/lib/rubygame/mediabag.rb +1 -1
- data/lib/rubygame/mixer.rb +30 -0
- data/lib/rubygame/music.rb +493 -0
- data/lib/rubygame/queue.rb +3 -1
- data/lib/rubygame/rect.rb +9 -9
- data/lib/rubygame/screen.rb +357 -0
- data/lib/rubygame/shared.rb +40 -4
- data/lib/rubygame/sound.rb +428 -0
- data/lib/rubygame/surface.rb +626 -0
- data/lib/rubygame/ttf.rb +311 -0
- data/samples/FreeSans.ttf +0 -0
- data/samples/README +6 -5
- data/samples/demo_draw.rb +1 -1
- data/samples/demo_gl.rb +3 -1
- data/samples/demo_gl_tex.rb +4 -2
- data/samples/demo_rubygame.rb +114 -105
- data/samples/demo_sfont.rb +1 -1
- data/samples/demo_ttf.rb +3 -1
- data/samples/demo_utf8.rb +1 -1
- data/samples/image_viewer.rb +118 -0
- data/samples/load_and_blit.rb +1 -1
- data/samples/rubygame.png +0 -0
- metadata +34 -40
- data/Rakefile +0 -537
- data/doc/extended_readme.rdoc +0 -49
- data/ext/body/rubygame_body.so +0 -0
- data/ext/rubygame/rubygame_clock.c +0 -301
- data/ext/rubygame/rubygame_clock.h +0 -32
- data/ext/rubygame/rubygame_event.c +0 -760
- data/ext/rubygame/rubygame_event.h +0 -48
- data/ext/rubygame/rubygame_event2.c +0 -661
- data/ext/rubygame/rubygame_event2.h +0 -29
- data/ext/rubygame/rubygame_gfx.c +0 -942
- data/ext/rubygame/rubygame_gfx.h +0 -101
- data/ext/rubygame/rubygame_gl.c +0 -154
- data/ext/rubygame/rubygame_gl.h +0 -32
- data/ext/rubygame/rubygame_image.c +0 -252
- data/ext/rubygame/rubygame_image.h +0 -41
- data/ext/rubygame/rubygame_joystick.c +0 -336
- data/ext/rubygame/rubygame_joystick.h +0 -41
- data/ext/rubygame/rubygame_main.c +0 -158
- data/ext/rubygame/rubygame_main.h +0 -36
- data/ext/rubygame/rubygame_mixer.c +0 -1024
- data/ext/rubygame/rubygame_mixer.h +0 -36
- data/ext/rubygame/rubygame_music.c +0 -1017
- data/ext/rubygame/rubygame_music.h +0 -29
- data/ext/rubygame/rubygame_screen.c +0 -572
- data/ext/rubygame/rubygame_screen.h +0 -45
- data/ext/rubygame/rubygame_shared.c +0 -269
- data/ext/rubygame/rubygame_shared.h +0 -69
- data/ext/rubygame/rubygame_sound.c +0 -863
- data/ext/rubygame/rubygame_sound.h +0 -29
- data/ext/rubygame/rubygame_surface.c +0 -1153
- data/ext/rubygame/rubygame_surface.h +0 -62
- data/ext/rubygame/rubygame_ttf.c +0 -599
- data/ext/rubygame/rubygame_ttf.h +0 -69
- data/samples/keys.rb +0 -52
data/lib/rubygame/ftor.rb
CHANGED
@@ -18,13 +18,6 @@
|
|
18
18
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
19
|
#++
|
20
20
|
|
21
|
-
require "rubygame"
|
22
|
-
|
23
|
-
#--
|
24
|
-
# Ftor is DEPRECATED and will be removed in Rubygame 3.0!
|
25
|
-
# Warn the user when this file is loaded.
|
26
|
-
#++
|
27
|
-
Rubygame.deprecated("Rubygame::Ftor", "3.0")
|
28
21
|
|
29
22
|
|
30
23
|
module Rubygame
|
@@ -87,6 +80,7 @@ class Ftor
|
|
87
80
|
# Create a new Ftor by specifying its x and y components. See also #new_am
|
88
81
|
# and #new_from_to.
|
89
82
|
def initialize(x,y)
|
83
|
+
Rubygame.deprecated("Rubygame::Ftor", "3.0")
|
90
84
|
@x, @y = x, y
|
91
85
|
end
|
92
86
|
|
data/lib/rubygame/gfx.rb
ADDED
@@ -0,0 +1,583 @@
|
|
1
|
+
#--
|
2
|
+
# Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
3
|
+
# Copyright (C) 2004-2009 John Croisant
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
#++
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require "ruby-sdl-ffi/gfx"
|
23
|
+
|
24
|
+
# SDL_gfx has no function to get the version number.
|
25
|
+
Rubygame::VERSIONS[:sdl_gfx] = [0, 0, 0]
|
26
|
+
|
27
|
+
|
28
|
+
class Rubygame::Surface
|
29
|
+
|
30
|
+
|
31
|
+
def _draw_line(pt1, pt2, color, smooth) # :nodoc:
|
32
|
+
x1, y1 = pt1.to_a.collect{|n| n.round}
|
33
|
+
x2, y2 = pt2.to_a.collect{|n| n.round}
|
34
|
+
|
35
|
+
r,g,b,a = Rubygame::Color.make_sdl_rgba( color )
|
36
|
+
|
37
|
+
if( y1 == y2 )
|
38
|
+
SDL::Gfx.hlineRGBA(@struct, x1, x2, y1, r,g,b,a)
|
39
|
+
elsif( x1 == x2 )
|
40
|
+
SDL::Gfx.vlineRGBA(@struct, x1, y1, y2, r,g,b,a)
|
41
|
+
else
|
42
|
+
if smooth
|
43
|
+
SDL::Gfx.aalineRGBA(@struct, x1, y1, x2, y2, r,g,b,a)
|
44
|
+
else
|
45
|
+
SDL::Gfx.lineRGBA(@struct, x1, y1, x2, y2, r,g,b,a)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private :_draw_line
|
51
|
+
|
52
|
+
|
53
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
54
|
+
# Your code should check "surface.respond_to?(:draw_line)" to see if
|
55
|
+
# you can use this method, or be prepared to rescue from NameError.
|
56
|
+
#
|
57
|
+
# Draw a line segment between two points on the Surface.
|
58
|
+
# See also #draw_line_a
|
59
|
+
#
|
60
|
+
# This method takes these arguments:
|
61
|
+
# point1:: the coordinates of one end of the line, [x1,y1].
|
62
|
+
# point2:: the coordinates of the other end of the line, [x2,y2].
|
63
|
+
# color:: the color of the shape. [r,g,b] or [r,g,b,a] (0-255),
|
64
|
+
# color name, or Rubygame::Color.
|
65
|
+
#
|
66
|
+
def draw_line( point1, point2, color )
|
67
|
+
_draw_line( point1, point2, color, false )
|
68
|
+
return self
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
73
|
+
# Your code should check "surface.respond_to?(:draw_line_a)" to see if
|
74
|
+
# you can use this method, or be prepared to rescue from NameError.
|
75
|
+
#
|
76
|
+
# Like #draw_line, but the line will be anti-aliased.
|
77
|
+
#
|
78
|
+
def draw_line_a( point1, point2, color )
|
79
|
+
_draw_line( point1, point2, color, true )
|
80
|
+
return self
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
def _draw_box(pt1, pt2, color, solid) # :nodoc:
|
86
|
+
x1, y1 = pt1.to_a.collect{|n| n.round}
|
87
|
+
x2, y2 = pt2.to_a.collect{|n| n.round}
|
88
|
+
|
89
|
+
r,g,b,a = Rubygame::Color.make_sdl_rgba( color )
|
90
|
+
|
91
|
+
if solid
|
92
|
+
SDL::Gfx.boxRGBA(@struct, x1, y1, x2, y2, r,g,b,a)
|
93
|
+
else
|
94
|
+
SDL::Gfx.rectangleRGBA(@struct, x1, y1, x2, y2, r,g,b,a)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
private :_draw_box
|
99
|
+
|
100
|
+
|
101
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
102
|
+
# Your code should check "surface.respond_to?(:draw_box)" to see if
|
103
|
+
# you can use this method, or be prepared to rescue from NameError.
|
104
|
+
#
|
105
|
+
# Draw a non-solid box (rectangle) on the Surface, given the
|
106
|
+
# coordinates of its top-left corner and bottom-right corner. See
|
107
|
+
# also #draw_box_s
|
108
|
+
#
|
109
|
+
# This method takes these arguments:
|
110
|
+
# point1:: the coordinates of top-left corner, [x1,y1].
|
111
|
+
# point2:: the coordinates of bottom-right corner, [x2,y2].
|
112
|
+
# color:: the color of the shape. [r,g,b] or [r,g,b,a] (0-255),
|
113
|
+
# color name, or Rubygame::Color.
|
114
|
+
#
|
115
|
+
def draw_box( point1, point2, color )
|
116
|
+
_draw_box( point1, point2, color, false )
|
117
|
+
return self
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
122
|
+
# Your code should check "surface.respond_to?(:draw_box_s)" to see
|
123
|
+
# if you can use this method, or be prepared to rescue from
|
124
|
+
# NameError.
|
125
|
+
#
|
126
|
+
# Like #draw_box, but the shape is solid, instead of an outline.
|
127
|
+
# (You may find using #fill to be more convenient and perhaps faster
|
128
|
+
# than this method.)
|
129
|
+
#
|
130
|
+
def draw_box_s( point1, point2, color )
|
131
|
+
_draw_box( point1, point2, color, true )
|
132
|
+
return self
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
def _draw_circle(center, radius, color, smooth, solid) # :nodoc:
|
138
|
+
x, y = center.to_a.collect{|n| n.round}
|
139
|
+
radius = radius.to_i
|
140
|
+
|
141
|
+
r,g,b,a = Rubygame::Color.make_sdl_rgba( color )
|
142
|
+
|
143
|
+
if solid
|
144
|
+
SDL::Gfx.filledCircleRGBA(@struct, x, y, radius, r,g,b,a)
|
145
|
+
elsif smooth
|
146
|
+
SDL::Gfx.aacircleRGBA(@struct, x, y, radius, r,g,b,a)
|
147
|
+
else
|
148
|
+
SDL::Gfx.circleRGBA(@struct, x, y, radius, r,g,b,a)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
private :_draw_circle
|
153
|
+
|
154
|
+
|
155
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
156
|
+
# Your code should check "surface.respond_to?(:draw_circle)" to see
|
157
|
+
# if you can use this method, or be prepared to rescue from
|
158
|
+
# NameError.
|
159
|
+
#
|
160
|
+
# Draw a non-solid circle on the Surface, given the coordinates of its
|
161
|
+
# center and its radius. See also #draw_circle_a and #draw_circle_s
|
162
|
+
#
|
163
|
+
# This method takes these arguments:
|
164
|
+
# center:: the coordinates of circle's center, [x,y].
|
165
|
+
# radius:: the radius (pixels) of the circle.
|
166
|
+
# color:: the color of the shape. [r,g,b] or [r,g,b,a] (0-255),
|
167
|
+
# color name, or Rubygame::Color.
|
168
|
+
#
|
169
|
+
def draw_circle( center, radius, color )
|
170
|
+
_draw_circle( center, radius, color, false, false )
|
171
|
+
return self
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
176
|
+
# Your code should check "surface.respond_to?(:draw_circle_a)" to see if
|
177
|
+
# you can use this method, or be prepared to rescue from NameError.
|
178
|
+
#
|
179
|
+
# Like #draw_circle, but the outline is anti-aliased.
|
180
|
+
#
|
181
|
+
def draw_circle_a( center, radius, color )
|
182
|
+
_draw_circle( center, radius, color, true, false )
|
183
|
+
return self
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
188
|
+
# Your code should check "surface.respond_to?(:draw_circle_s)" to
|
189
|
+
# see if you can use this method, or be prepared to rescue from
|
190
|
+
# NameError.
|
191
|
+
#
|
192
|
+
# Like #draw_circle, but the shape is solid, instead of an outline.
|
193
|
+
#
|
194
|
+
def draw_circle_s( center, radius, color )
|
195
|
+
_draw_circle( center, radius, color, false, true )
|
196
|
+
return self
|
197
|
+
end
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
def _draw_ellipse(center, radii, color, smooth, solid) # :nodoc:
|
202
|
+
x, y = center.to_a.collect{|n| n.round}
|
203
|
+
radx, rady = radii.to_a.collect{|n| n.round}
|
204
|
+
|
205
|
+
r,g,b,a = Rubygame::Color.make_sdl_rgba( color )
|
206
|
+
|
207
|
+
if solid
|
208
|
+
SDL::Gfx.filledEllipseRGBA(@struct, x, y, radx, rady, r,g,b,a)
|
209
|
+
elsif smooth
|
210
|
+
SDL::Gfx.aaellipseRGBA(@struct, x, y, radx, rady, r,g,b,a)
|
211
|
+
else
|
212
|
+
SDL::Gfx.ellipseRGBA(@struct, x, y, radx, rady, r,g,b,a)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
private :_draw_ellipse
|
217
|
+
|
218
|
+
|
219
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
220
|
+
# Your code should check "surface.respond_to?(:draw_ellipse)" to see
|
221
|
+
# if you can use this method, or be prepared to rescue from
|
222
|
+
# NameError.
|
223
|
+
#
|
224
|
+
# Draw a non-solid ellipse (oval) on the Surface, given the
|
225
|
+
# coordinates of its center and its horizontal and vertical radii.
|
226
|
+
# See also #draw_ellipse_a and #draw_ellipse_s
|
227
|
+
#
|
228
|
+
# This method takes these arguments:
|
229
|
+
# center:: the coordinates of ellipse's center, [x,y].
|
230
|
+
# radii:: the x and y radii (pixels), [rx,ry].
|
231
|
+
# color:: the color of the shape. [r,g,b] or [r,g,b,a] (0-255),
|
232
|
+
# color name, or Rubygame::Color.
|
233
|
+
#
|
234
|
+
def draw_ellipse( center, radii, color )
|
235
|
+
_draw_ellipse( center, radii, color, false, false )
|
236
|
+
return self
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
241
|
+
# Your code should check "surface.respond_to?(:draw_ellipse_a)" to see if
|
242
|
+
# you can use this method, or be prepared to rescue from NameError.
|
243
|
+
#
|
244
|
+
# Like #draw_ellipse, but the ellipse border is anti-aliased.
|
245
|
+
#
|
246
|
+
def draw_ellipse_a( center, radii, color )
|
247
|
+
_draw_ellipse( center, radii, color, true, false )
|
248
|
+
return self
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
253
|
+
# Your code should check "surface.respond_to?(:draw_ellipse_s)" to
|
254
|
+
# see if you can use this method, or be prepared to rescue from
|
255
|
+
# NameError.
|
256
|
+
#
|
257
|
+
# Like #draw_ellipse, but the shape is solid, instead of an outline.
|
258
|
+
#
|
259
|
+
def draw_ellipse_s( center, radii, color )
|
260
|
+
_draw_ellipse( center, radii, color, false, true )
|
261
|
+
return self
|
262
|
+
end
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
def _draw_arc(center, radius, angles, color, solid) # :nodoc:
|
267
|
+
x, y = center.to_a.collect{|n| n.round}
|
268
|
+
radius = radius.round
|
269
|
+
ang1, ang2 = angles.to_a.collect{|n| n.round}
|
270
|
+
|
271
|
+
r,g,b,a = Rubygame::Color.make_sdl_rgba( color )
|
272
|
+
|
273
|
+
if solid
|
274
|
+
SDL::Gfx.filledPieRGBA(@struct, x, y, radius, ang1, ang2, r,g,b,a)
|
275
|
+
else
|
276
|
+
SDL::Gfx.pieRGBA(@struct, x, y, radius, ang1, ang2, r,g,b,a)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
private :_draw_arc
|
281
|
+
|
282
|
+
|
283
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
284
|
+
# Your code should check "surface.respond_to?(:draw_arc)" to see if
|
285
|
+
# you can use this method, or be prepared to rescue from NameError.
|
286
|
+
#
|
287
|
+
# Draw a non-solid arc (part of a circle), given the coordinates of
|
288
|
+
# its center, radius, and starting/ending angles.
|
289
|
+
# See also #draw_arc_s
|
290
|
+
#
|
291
|
+
# This method takes these arguments:
|
292
|
+
# center:: the coordinates of circle's center, [x,y].
|
293
|
+
# radius:: the radius (pixels) of the circle.
|
294
|
+
# angles:: the start and end angles (in degrees) of the arc, [start,end].
|
295
|
+
# Angles are given *CLOCKWISE* from the positive x
|
296
|
+
# (remember that the positive Y direction is down, rather than up).
|
297
|
+
# color:: the color of the shape. [r,g,b] or [r,g,b,a] (0-255),
|
298
|
+
# color name, or Rubygame::Color.
|
299
|
+
#
|
300
|
+
def draw_arc( center, radius, angles, color )
|
301
|
+
_draw_arc( center, radius, angles, color, false )
|
302
|
+
return self
|
303
|
+
end
|
304
|
+
|
305
|
+
|
306
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
307
|
+
# Your code should check "surface.respond_to?(:draw_arc_s)" to see
|
308
|
+
# if you can use this method, or be prepared to rescue from
|
309
|
+
# NameError.
|
310
|
+
#
|
311
|
+
# Like #draw_arc, but the shape is solid, instead of an outline.
|
312
|
+
#
|
313
|
+
def draw_arc_s( center, radius, angles, color )
|
314
|
+
_draw_arc( center, radius, angles, color, true )
|
315
|
+
return self
|
316
|
+
end
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
def _draw_polygon(points, color, smooth, solid) # :nodoc:
|
321
|
+
|
322
|
+
len = points.length
|
323
|
+
xpts = FFI::Buffer.new(:int16, len)
|
324
|
+
ypts = FFI::Buffer.new(:int16, len)
|
325
|
+
|
326
|
+
points.each_with_index { |point, i|
|
327
|
+
xpts[i].put_int16( 0, point[0].round )
|
328
|
+
ypts[i].put_int16( 0, point[1].round )
|
329
|
+
}
|
330
|
+
|
331
|
+
r,g,b,a = Rubygame::Color.make_sdl_rgba( color )
|
332
|
+
|
333
|
+
if solid
|
334
|
+
SDL::Gfx.filledPolygonRGBA(@struct, xpts, ypts, len, r,g,b,a)
|
335
|
+
elsif smooth
|
336
|
+
SDL::Gfx.aapolygonRGBA(@struct, xpts, ypts, len, r,g,b,a)
|
337
|
+
else
|
338
|
+
SDL::Gfx.polygonRGBA(@struct, xpts, ypts, len, r,g,b,a)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
private :_draw_polygon
|
343
|
+
|
344
|
+
|
345
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
346
|
+
# Your code should check "surface.respond_to?(:draw_polygon)" to see
|
347
|
+
# if you can use this method, or be prepared to rescue from
|
348
|
+
# NameError.
|
349
|
+
#
|
350
|
+
# Draw a non-solid polygon, given the coordinates of its vertices, in the
|
351
|
+
# order that they are connected. This is essentially a series of connected
|
352
|
+
# dots. See also #draw_polygon_a and #draw_polygon_s.
|
353
|
+
#
|
354
|
+
# This method takes these arguments:
|
355
|
+
# points:: an Array containing the coordinate pairs for each vertex of the
|
356
|
+
# polygon, in the order that they are connected, e.g.
|
357
|
+
# [ [x1,y1], [x2,y2], ..., [xn,yn] ].
|
358
|
+
# color:: the color of the shape. [r,g,b] or [r,g,b,a] (0-255),
|
359
|
+
# color name, or Rubygame::Color.
|
360
|
+
#
|
361
|
+
def draw_polygon( points, color )
|
362
|
+
_draw_polygon( points, color, false, false )
|
363
|
+
return self
|
364
|
+
end
|
365
|
+
|
366
|
+
|
367
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
368
|
+
# Your code should check "surface.respond_to?(:draw_polygon_a)" to
|
369
|
+
# see if you can use this method, or be prepared to rescue from
|
370
|
+
# NameError.
|
371
|
+
#
|
372
|
+
# Like #draw_polygon, but the lines are anti-aliased.
|
373
|
+
#
|
374
|
+
def draw_polygon_a( points, color )
|
375
|
+
_draw_polygon( points, color, true, false )
|
376
|
+
return self
|
377
|
+
end
|
378
|
+
|
379
|
+
|
380
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
381
|
+
# Your code should check "surface.respond_to?(:draw_polygon_s)" to
|
382
|
+
# see if you can use this method, or be prepared to rescue from
|
383
|
+
# NameError.
|
384
|
+
#
|
385
|
+
# Like #draw_polygon, but the shape is solid, instead of an outline.
|
386
|
+
#
|
387
|
+
def draw_polygon_s( points, color )
|
388
|
+
_draw_polygon( points, color, false, true )
|
389
|
+
return self
|
390
|
+
end
|
391
|
+
|
392
|
+
|
393
|
+
|
394
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
395
|
+
# Your code should check "surface.respond_to?(:rotozoom)" to see if
|
396
|
+
# you can use this method, or be prepared to rescue from NameError.
|
397
|
+
#
|
398
|
+
# Return a rotated and/or zoomed version of the given surface. Note
|
399
|
+
# that rotating a Surface anything other than a multiple of 90
|
400
|
+
# degrees will cause the new surface to be larger than the original
|
401
|
+
# to accomodate the corners (which would otherwise extend beyond the
|
402
|
+
# surface).
|
403
|
+
#
|
404
|
+
# May raise Rubygame::SDLError if the rotozoom fails.
|
405
|
+
#
|
406
|
+
# angle:: degrees to rotate counter-clockwise (negative for
|
407
|
+
# clockwise).
|
408
|
+
# zoom:: scaling factor(s). A number (to scale X and Y by the same
|
409
|
+
# factor) or an array of 2 numbers (to scale X and Y by
|
410
|
+
# different factors). Negative numbers flip the image.
|
411
|
+
# NOTE: Due to a quirk in SDL_gfx, if angle is not 0, the
|
412
|
+
# image is zoomed by the X factor on both X and Y, and the
|
413
|
+
# Y factor is only used for flipping (if it's negative).
|
414
|
+
# smooth:: whether to anti-alias the new surface.
|
415
|
+
# By the way, if true, the new surface will be 32bit RGBA.
|
416
|
+
#
|
417
|
+
def rotozoom( angle, zoom, smooth=false )
|
418
|
+
smooth = smooth ? 1 : 0
|
419
|
+
|
420
|
+
surf = case zoom
|
421
|
+
when Array
|
422
|
+
zx, zy = zoom.collect { |n| n.to_f }
|
423
|
+
SDL::Gfx.rotozoomSurfaceXY(@struct, angle, zx, zy, smooth)
|
424
|
+
when Numeric
|
425
|
+
zoom = zoom.to_f
|
426
|
+
SDL::Gfx.rotozoomSurface(@struct, angle, zoom, smooth)
|
427
|
+
else
|
428
|
+
raise ArgumentError, "Invalid zoom factor: #{zoom.inspect}"
|
429
|
+
end
|
430
|
+
|
431
|
+
if( surf.pointer.null? )
|
432
|
+
raise( Rubygame::SDLError,
|
433
|
+
"Rotozoom failed: " + SDL.GetError() )
|
434
|
+
end
|
435
|
+
|
436
|
+
return self.class.new(surf)
|
437
|
+
end
|
438
|
+
|
439
|
+
|
440
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
441
|
+
# Your code should check "surface.respond_to?(:rotozoom_size)" to
|
442
|
+
# see if you can use this method, or be prepared to rescue from
|
443
|
+
# NameError.
|
444
|
+
#
|
445
|
+
# Return the dimensions of the surface that would be returned if
|
446
|
+
# #rotozoom were called on a Surface of the given size, with
|
447
|
+
# the same angle and zoom factors.
|
448
|
+
#
|
449
|
+
# This method takes these arguments:
|
450
|
+
# size:: an Array with the hypothetical Surface width and height (pixels)
|
451
|
+
# angle:: degrees to rotate counter-clockwise (negative for clockwise).
|
452
|
+
# zoom:: scaling factor(s). A number (to scale X and Y by the same
|
453
|
+
# factor) or an array of 2 numbers (to scale X and Y by
|
454
|
+
# different factors). NOTE: Due to a quirk in SDL_gfx, if
|
455
|
+
# angle is not 0, the image is zoomed by the X factor on
|
456
|
+
# both X and Y, and the Y factor is only used for flipping
|
457
|
+
# (if it's negative).
|
458
|
+
#
|
459
|
+
def self.rotozoom_size( size, angle, zoom )
|
460
|
+
w, h = size
|
461
|
+
|
462
|
+
case zoom
|
463
|
+
when Array
|
464
|
+
zx, zy = zoom.collect { |n| n.to_f }
|
465
|
+
SDL::Gfx.rotozoomSurfaceSizeXY(w, h, angle, zx, zy)
|
466
|
+
when Numeric
|
467
|
+
zoom = zoom.to_f
|
468
|
+
SDL::Gfx.rotozoomSurfaceSize(w, h, angle, zoom)
|
469
|
+
else
|
470
|
+
raise ArgumentError, "Invalid zoom factor: #{zoom.inspect}"
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
|
475
|
+
|
476
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
477
|
+
# Your code should check "surface.respond_to?(:zoom)" to see if you
|
478
|
+
# can use this method, or be prepared to rescue from NameError.
|
479
|
+
#
|
480
|
+
# Return a zoomed version of the Surface.
|
481
|
+
#
|
482
|
+
# This method takes these arguments:
|
483
|
+
# zoom:: a Numeric factor to scale by in both x and y directions,
|
484
|
+
# or an Array with separate x and y scale factors.
|
485
|
+
# smooth:: whether to anti-alias the new surface.
|
486
|
+
# By the way, if true, the new surface will be 32bit RGBA.
|
487
|
+
#
|
488
|
+
def zoom( zoom, smooth=false )
|
489
|
+
smooth = smooth ? 1 : 0
|
490
|
+
|
491
|
+
surf = case zoom
|
492
|
+
when Array
|
493
|
+
zx, zy = zoom.collect { |n| n.to_f }
|
494
|
+
SDL::Gfx.zoomSurface(@struct, zx, zy, smooth)
|
495
|
+
when Numeric
|
496
|
+
zoom = zoom.to_f
|
497
|
+
SDL::Gfx.zoomSurface(@struct, zoom, zoom, smooth)
|
498
|
+
else
|
499
|
+
raise ArgumentError, "Invalid zoom factor: #{zoom.inspect}"
|
500
|
+
end
|
501
|
+
|
502
|
+
if( surf.pointer.null? )
|
503
|
+
raise( Rubygame::SDLError, "Zoom failed: " + SDL.GetError() )
|
504
|
+
end
|
505
|
+
|
506
|
+
return self.class.new(surf)
|
507
|
+
end
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
512
|
+
# Your code should check "surface.respond_to?(:zoom_size)" to see if
|
513
|
+
# you can use this method, or be prepared to rescue from NameError.
|
514
|
+
#
|
515
|
+
# Return the dimensions of the surface that would be returned if
|
516
|
+
# #zoom were called on a Surface of the given size, with the same
|
517
|
+
# zoom factors.
|
518
|
+
#
|
519
|
+
# This method takes these arguments:
|
520
|
+
# size:: an Array with the hypothetical Surface width and height (pixels)
|
521
|
+
# zoom:: scaling factor(s). A number (to scale X and Y by the same
|
522
|
+
# factor) or an array of 2 numbers (to scale X and Y by
|
523
|
+
# different factors).
|
524
|
+
#
|
525
|
+
def self.zoom_size( size, zoom )
|
526
|
+
w, h = size
|
527
|
+
|
528
|
+
case zoom
|
529
|
+
when Array
|
530
|
+
zx, zy = zoom.collect { |n| n.to_f }
|
531
|
+
SDL::Gfx.zoomSurfaceSize(w, h, zx, zy)
|
532
|
+
when Numeric
|
533
|
+
zoom = zoom.to_f
|
534
|
+
SDL::Gfx.zoomSurfaceSize(w, h, zoom, zoom)
|
535
|
+
else
|
536
|
+
raise ArgumentError, "Invalid zoom factor: #{zoom.inspect}"
|
537
|
+
end
|
538
|
+
end
|
539
|
+
|
540
|
+
|
541
|
+
|
542
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
543
|
+
# Your code should check "surface.respond_to?(:zoom_to)" to see if
|
544
|
+
# you can use this method, or be prepared to rescue from NameError.
|
545
|
+
#
|
546
|
+
# Return a version of the Surface zoomed to a new size.
|
547
|
+
#
|
548
|
+
# This method takes these arguments:
|
549
|
+
# width:: the desired width. If nil, the width will stay the same.
|
550
|
+
# height:: the desired height. If nil, the height will stay the same.
|
551
|
+
# smooth:: whether to anti-alias the new surface. This option can be
|
552
|
+
# omitted, in which case the surface will not be anti-aliased.
|
553
|
+
# If true, the new surface will be 32bit RGBA.
|
554
|
+
#
|
555
|
+
def zoom_to( width, height, smooth=false )
|
556
|
+
zoomx = case width
|
557
|
+
when nil; 1.0
|
558
|
+
when Numeric; width.to_f / @struct.w
|
559
|
+
end
|
560
|
+
|
561
|
+
zoomy = case height
|
562
|
+
when nil; 1.0
|
563
|
+
when Numeric; height.to_f / @struct.h
|
564
|
+
end
|
565
|
+
|
566
|
+
return self.zoom( [zoomx, zoomy], smooth )
|
567
|
+
end
|
568
|
+
|
569
|
+
|
570
|
+
|
571
|
+
# *IMPORTANT*: this method only exists if SDL_gfx is available!
|
572
|
+
# Your code should check "surface.respond_to?(:flip)" to see if you
|
573
|
+
# can use this method, or be prepared to rescue from NameError.
|
574
|
+
#
|
575
|
+
# Flips the source surface horizontally (if +horz+ is true), vertically
|
576
|
+
# (if +vert+ is true), or both (if both are true).
|
577
|
+
#
|
578
|
+
def flip( horz, vert )
|
579
|
+
self.zoom( [ (horz ? -1.0 : 1.0), (vert ? -1.0 : 1.0)], false )
|
580
|
+
end
|
581
|
+
|
582
|
+
|
583
|
+
end
|