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.
Files changed (88) hide show
  1. data/CREDITS +6 -4
  2. data/NEWS +79 -0
  3. data/README +55 -72
  4. data/ROADMAP +20 -13
  5. data/doc/custom_sdl_load_paths.rdoc +79 -0
  6. data/doc/getting_started.rdoc +65 -36
  7. data/doc/keyboard_symbols.rdoc +243 -0
  8. data/doc/macosx_install.rdoc +49 -35
  9. data/doc/windows_install.rdoc +36 -108
  10. data/lib/rubygame.rb +62 -24
  11. data/lib/rubygame/audio.rb +147 -0
  12. data/lib/rubygame/clock.rb +164 -1
  13. data/lib/rubygame/color.rb +40 -7
  14. data/lib/rubygame/color/models/hsl.rb +1 -1
  15. data/lib/rubygame/color/models/hsv.rb +1 -1
  16. data/lib/rubygame/color/models/rgb.rb +1 -1
  17. data/lib/rubygame/color/palettes/css.rb +1 -3
  18. data/lib/rubygame/color/palettes/x11.rb +1 -2
  19. data/lib/rubygame/constants.rb +297 -0
  20. data/lib/rubygame/deprecated_mixer.rb +555 -0
  21. data/lib/rubygame/event.rb +122 -6
  22. data/lib/rubygame/event_handler.rb +3 -1
  23. data/lib/rubygame/event_hook.rb +6 -2
  24. data/lib/rubygame/event_triggers.rb +1 -1
  25. data/lib/rubygame/events.rb +416 -1
  26. data/lib/rubygame/ftor.rb +1 -7
  27. data/lib/rubygame/gfx.rb +583 -0
  28. data/lib/rubygame/gl.rb +107 -0
  29. data/lib/rubygame/image.rb +140 -0
  30. data/lib/rubygame/joystick.rb +184 -0
  31. data/lib/rubygame/main.rb +82 -0
  32. data/lib/rubygame/mediabag.rb +1 -1
  33. data/lib/rubygame/mixer.rb +30 -0
  34. data/lib/rubygame/music.rb +493 -0
  35. data/lib/rubygame/queue.rb +3 -1
  36. data/lib/rubygame/rect.rb +9 -9
  37. data/lib/rubygame/screen.rb +357 -0
  38. data/lib/rubygame/shared.rb +40 -4
  39. data/lib/rubygame/sound.rb +428 -0
  40. data/lib/rubygame/surface.rb +626 -0
  41. data/lib/rubygame/ttf.rb +311 -0
  42. data/samples/FreeSans.ttf +0 -0
  43. data/samples/README +6 -5
  44. data/samples/demo_draw.rb +1 -1
  45. data/samples/demo_gl.rb +3 -1
  46. data/samples/demo_gl_tex.rb +4 -2
  47. data/samples/demo_rubygame.rb +114 -105
  48. data/samples/demo_sfont.rb +1 -1
  49. data/samples/demo_ttf.rb +3 -1
  50. data/samples/demo_utf8.rb +1 -1
  51. data/samples/image_viewer.rb +118 -0
  52. data/samples/load_and_blit.rb +1 -1
  53. data/samples/rubygame.png +0 -0
  54. metadata +34 -40
  55. data/Rakefile +0 -537
  56. data/doc/extended_readme.rdoc +0 -49
  57. data/ext/body/rubygame_body.so +0 -0
  58. data/ext/rubygame/rubygame_clock.c +0 -301
  59. data/ext/rubygame/rubygame_clock.h +0 -32
  60. data/ext/rubygame/rubygame_event.c +0 -760
  61. data/ext/rubygame/rubygame_event.h +0 -48
  62. data/ext/rubygame/rubygame_event2.c +0 -661
  63. data/ext/rubygame/rubygame_event2.h +0 -29
  64. data/ext/rubygame/rubygame_gfx.c +0 -942
  65. data/ext/rubygame/rubygame_gfx.h +0 -101
  66. data/ext/rubygame/rubygame_gl.c +0 -154
  67. data/ext/rubygame/rubygame_gl.h +0 -32
  68. data/ext/rubygame/rubygame_image.c +0 -252
  69. data/ext/rubygame/rubygame_image.h +0 -41
  70. data/ext/rubygame/rubygame_joystick.c +0 -336
  71. data/ext/rubygame/rubygame_joystick.h +0 -41
  72. data/ext/rubygame/rubygame_main.c +0 -158
  73. data/ext/rubygame/rubygame_main.h +0 -36
  74. data/ext/rubygame/rubygame_mixer.c +0 -1024
  75. data/ext/rubygame/rubygame_mixer.h +0 -36
  76. data/ext/rubygame/rubygame_music.c +0 -1017
  77. data/ext/rubygame/rubygame_music.h +0 -29
  78. data/ext/rubygame/rubygame_screen.c +0 -572
  79. data/ext/rubygame/rubygame_screen.h +0 -45
  80. data/ext/rubygame/rubygame_shared.c +0 -269
  81. data/ext/rubygame/rubygame_shared.h +0 -69
  82. data/ext/rubygame/rubygame_sound.c +0 -863
  83. data/ext/rubygame/rubygame_sound.h +0 -29
  84. data/ext/rubygame/rubygame_surface.c +0 -1153
  85. data/ext/rubygame/rubygame_surface.h +0 -62
  86. data/ext/rubygame/rubygame_ttf.c +0 -599
  87. data/ext/rubygame/rubygame_ttf.h +0 -69
  88. data/samples/keys.rb +0 -52
@@ -21,7 +21,7 @@
21
21
  #
22
22
  #++
23
23
 
24
- require "rubygame/event"
24
+
25
25
 
26
26
  module Rubygame
27
27
 
@@ -128,6 +128,8 @@ module Rubygame
128
128
  if @new_style_events
129
129
  self.push( Rubygame::Events.fetch_sdl_events() )
130
130
  else
131
+ Rubygame.deprecated("Rubygame::EventQueue with old event classes",
132
+ "3.0")
131
133
  self.push( Rubygame.fetch_sdl_events() )
132
134
  end
133
135
  end
@@ -141,6 +141,15 @@ class Rect < Array
141
141
  # Print the Rect in the form "+#<Rect:id [x,y,w,h]>+"
142
142
  def inspect; "#<Rect:#{self.object_id} [%s,%s,%s,%s]>"%self; end
143
143
 
144
+
145
+ # Returns an SDL::Rect version of this Rect. Float values are
146
+ # rounded to the nearest integer.
147
+ #
148
+ def to_sdl # :nodoc:
149
+ SDL::Rect.new( self.collect{|n| n.round } )
150
+ end
151
+
152
+
144
153
  #--
145
154
  # ATTRIBUTES
146
155
  #++
@@ -600,13 +609,4 @@ class Rect < Array
600
609
 
601
610
  end # class Rect
602
611
 
603
-
604
- class Surface
605
- # Return a Rect with the same width and height as the Surface, positioned
606
- # at (0,0).
607
- def make_rect()
608
- return Rect.new(0,0,self.width,self.height)
609
- end
610
- end
611
-
612
612
  end # module Rubygame
@@ -0,0 +1,357 @@
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
+ # Screen represents the display window for the game. The Screen is a
23
+ # special Surface that is displayed to the user. By changing and then
24
+ # updating the Screen many times per second, you can create the
25
+ # illusion of continous motion.
26
+ #
27
+ # Screen inherits most of the Surface methods, and can be passed to
28
+ # methods which expect a Surface, including Surface#blit. However, the
29
+ # Screen cannot have an alpha channel or a colorkey, so
30
+ # Surface#alpha=, Surface#set_alpha, Surface#colorkey=, and
31
+ # Surface#set_colorkey are not inherited.
32
+ #
33
+ # Please note that only one Screen can exist at a time, per
34
+ # application; this is a limitation of SDL. Use Screen.new (or its
35
+ # alias, Screen.open) to create or modify the Screen.
36
+ #
37
+ # Also note that no changes to the Screen will be seen until it is
38
+ # refreshed. See #update, #update_rects, and #flip for ways to refresh
39
+ # all or part of the Screen.
40
+ #
41
+ class Rubygame::Screen < Rubygame::Surface
42
+
43
+ class << self
44
+ # Inherited from Surface, but not applicable to Screen
45
+ [ :[], :[]=, :autoload, :autoload_dirs=, :autoload_dirs,
46
+ :basename, :exist?, :find_file, :load, :load_image
47
+ ].each { |m|
48
+ eval "undef #{m.inspect} if respond_to? #{m.inspect}"
49
+ }
50
+ end
51
+
52
+
53
+ # Inherited from Surface, but not applicable to Screen
54
+ [ :alpha=, :set_alpha, :colorkey=, :set_colorkey ].each { |m|
55
+ eval "undef #{m.inspect} if respond_to? #{m.inspect}"
56
+ }
57
+
58
+
59
+ class << self
60
+
61
+ alias :open :new
62
+
63
+
64
+ # Close the Screen, making the Rubygame window disappear.
65
+ # This method also exits from fullscreen mode, if needed.
66
+ #
67
+ # After calling this method, you should discard any references
68
+ # to the old Screen surface, as it is no longer valid, even
69
+ # if you call Screen.new again.
70
+ #
71
+ # (Note: You do not need to close the Screen to change its size
72
+ # or flags, you can simply call Screen.new while already open.)
73
+ #
74
+ def close
75
+ SDL.QuitSubSystem( SDL::INIT_VIDEO )
76
+ nil
77
+ end
78
+
79
+
80
+ # True if there is an open Rubygame window.
81
+ # See Screen.new and Screen.close.
82
+ #
83
+ def open?
84
+ (not SDL.GetVideoSurface().pointer.null?)
85
+ end
86
+
87
+
88
+ # Returns the currently open Screen, or raises SDLError if it
89
+ # fails to get it (for example, if it doesn't exist yet).
90
+ #
91
+ def get_surface
92
+ s = SDL.GetVideoSurface()
93
+
94
+ if s.pointer.null?
95
+ raise( Rubygame::SDLError,
96
+ "Couldn't get video surface: #{SDL.GetError()}" )
97
+ end
98
+
99
+ return self.new( s )
100
+ end
101
+
102
+
103
+ # Returns the pixel dimensions of the user's display (i.e. monitor).
104
+ # (That is not the same as Screen#size, which only measures the
105
+ # Rubygame window.) You can use this information to detect
106
+ # how large of a Screen can fit on the user's display.
107
+ #
108
+ # This method can _only_ be used when there is no open Screen instance.
109
+ # This method raises SDLError if there is a Screen instance (i.e.
110
+ # you have done Screen.new before). This is a limitation of the SDL
111
+ # function SDL_GetVideoInfo, which behaves differently when a Screen
112
+ # is open than when it is closed.
113
+ #
114
+ # This method will also raise SDLError if it cannot get the display
115
+ # size for some other reason.
116
+ #
117
+ def get_resolution
118
+ if( Rubygame.init_video_system() != 0 )
119
+ raise(Rubygame::SDLError, "Could not initialize SDL video subsystem.")
120
+ end
121
+
122
+ unless SDL.GetVideoSurface().pointer.null?
123
+ raise( Rubygame::SDLError, "You cannot get resolution when there " +
124
+ "is an open Screen. See the docs for the reason." )
125
+ end
126
+
127
+ info = SDL::GetVideoInfo()
128
+ if( info.pointer.null? )
129
+ raise Rubygame::SDLError, "Couldn't get video info: #{SDL.GetError()}"
130
+ end
131
+
132
+ return [info.current_w, info.current_h]
133
+ end
134
+
135
+ end
136
+
137
+
138
+
139
+ # Create a new Rubygame window if there is none, or modify the
140
+ # existing one. You cannot create more than one Screen; the existing
141
+ # one will be replaced. (This is a limitation of SDL.)
142
+ #
143
+ # Returns the resulting Screen.
144
+ #
145
+ # size:: requested window size (in pixels), in the form [width,height]
146
+ # depth:: requested color depth (in bits per pixel). If 0 (default), the
147
+ # current system color depth.
148
+ # flags:: an Array of zero or more of the following flags (located under the
149
+ # Rubygame module).
150
+ #
151
+ # SWSURFACE:: Create the video surface in system memory.
152
+ # HWSURFACE:: Create the video surface in video memory.
153
+ # ASYNCBLIT:: Enables the use of asynchronous updates of the
154
+ # display surface. This will usually slow down
155
+ # blitting on single CPU machines, but may provide a
156
+ # speed increase on SMP systems.
157
+ # ANYFORMAT:: Normally, if a video surface of the requested
158
+ # bits-per-pixel (bpp) is not available, Rubygame
159
+ # will emulate one with a shadow surface. Passing
160
+ # +ANYFORMAT+ prevents this and causes Rubygame to
161
+ # use the video surface regardless of its depth.
162
+ # DOUBLEBUF:: Enable hardware double buffering; only valid with
163
+ # +HWSURFACE+. Calling #flip will flip the
164
+ # buffers and update the screen. All drawing will
165
+ # take place on the surface that is not displayed at
166
+ # the moment. If double buffering could not be
167
+ # enabled then #flip will just update the
168
+ # entire screen.
169
+ # FULLSCREEN:: Rubygame will attempt to use a fullscreen mode. If
170
+ # a hardware resolution change is not possible (for
171
+ # whatever reason), the next higher resolution will
172
+ # be used and the display window centered on a black
173
+ # background.
174
+ # OPENGL:: Create an OpenGL rendering context. You must set
175
+ # proper OpenGL video attributes with GL#set_attrib
176
+ # before calling this method with this flag. You can
177
+ # then use separate opengl libraries (for example rbogl)
178
+ # to do all OpenGL-related functions.
179
+ # Please note that you can't blit or draw regular SDL
180
+ # Surfaces onto an OpenGL-mode screen; you must use
181
+ # OpenGL functions.
182
+ # RESIZABLE:: Create a resizable window. When the window is
183
+ # resized by the user, a ResizeEvent is
184
+ # generated and this method can be called again
185
+ # with the new size.
186
+ # NOFRAME:: If possible, create a window with no title bar or
187
+ # frame decoration.
188
+ # Fullscreen modes automatically have this flag set.
189
+ #
190
+ def initialize( size, depth=0, flags=[Rubygame::SWSURFACE] )
191
+
192
+ # Cheating a bit. First arg can be a SDL::Surface to wrap it.
193
+ #
194
+ if( size.kind_of? SDL::Surface )
195
+ surf = size
196
+ if( surf.pointer.null? )
197
+ raise Rubygame::SDLError, "Screen cannot wrap NULL Surface!"
198
+ elsif( surf.pointer != SDL.GetVideoSurface().pointer )
199
+ raise Rubygame::SDLError, "Screen can only wrap the video Surface!"
200
+ else
201
+ @struct = surf
202
+ end
203
+ return
204
+ end
205
+
206
+
207
+ w,h = size
208
+ flags = Rubygame.collapse_flags(flags)
209
+
210
+ @struct = SDL.SetVideoMode( w, h, depth, flags )
211
+
212
+ if( @struct.pointer.null? )
213
+ @struct = nil
214
+ raise( Rubygame::SDLError,
215
+ "Couldn't set [%d x %d] %d bpp video mode: %s"%\
216
+ [w, h, depth, SDL.GetError()] )
217
+ end
218
+
219
+ end
220
+
221
+
222
+
223
+ # If the Rubygame display is double-buffered (see Screen.new), flips
224
+ # the buffers and updates the whole screen. Otherwise, just updates
225
+ # the whole screen.
226
+ #
227
+ def flip
228
+ SDL.Flip( @struct )
229
+ self
230
+ end
231
+
232
+
233
+ # call-seq:
234
+ # update
235
+ # update( rect )
236
+ # update( x,y,w,h )
237
+ #
238
+ # Updates (refreshes) all or part of the Rubygame window, revealing
239
+ # to the user any changes that have been made since the last update.
240
+ # If you're using a double-buffered display (see Screen.new), you
241
+ # should use Screen#flip instead.
242
+ #
243
+ # rect:: a Rubygame::Rect representing the area of the screen to update.
244
+ # Can also be an length-4 Array, or given as 4 separate arguments.
245
+ # If omitted or nil, the entire screen is updated.
246
+ #
247
+ def update( *args )
248
+ r = case args[0]
249
+ when nil
250
+ # Update the whole screen. Skip the stuff below.
251
+ SDL.UpdateRect( @struct, 0, 0, 0, 0 );
252
+ return self
253
+ when SDL::Rect
254
+ Rubygame::Rect.new( args[0].to_ary )
255
+ when Array
256
+ Rubygame::Rect.new( args[0] )
257
+ when Numeric
258
+ Rubygame::Rect.new( args[0,4] )
259
+ else
260
+ raise( ArgumentError,
261
+ "Invalid args for #{self.class}#update: #{args.inspect}" )
262
+ end
263
+
264
+ SDL.UpdateRect( @struct, *(r.clip!( self.make_rect ).to_sdl) );
265
+
266
+ return self
267
+ end
268
+
269
+
270
+
271
+ # Updates (as Screen#update does) several areas of the screen.
272
+ #
273
+ # rects:: an Array containing any number of Rect objects, each
274
+ # rect representing a portion of the screen to update.
275
+ #
276
+ def update_rects( rects )
277
+ my_rect = self.make_rect
278
+
279
+ rects.collect! do |r|
280
+ r = case r
281
+ when SDL::Rect
282
+ Rubygame::Rect.new( r.to_ary )
283
+ when Array
284
+ Rubygame::Rect.new( r )
285
+ else
286
+ raise( ArgumentError,
287
+ "Invalid rect for #{self.class}#update_rects: #{r.inspect}" )
288
+ end
289
+
290
+ r.clip!(my_rect).to_sdl
291
+ end
292
+
293
+ SDL.UpdateRects( @struct, rects )
294
+
295
+ return self
296
+ end
297
+
298
+
299
+
300
+ # Sets the window icon for the Screen.
301
+ #
302
+ # icon:: a Rubygame::Surface to be displayed at the top of the Rubygame
303
+ # window (when not in fullscreen mode), and in other OS-specific
304
+ # areas (like the taskbar entry). If omitted or +nil+, no icon
305
+ # will be shown at all.
306
+ #
307
+ # NOTE: The SDL docs state that icons on Win32 systems must be 32x32
308
+ # pixels. That may or may not be true anymore, but you might want to
309
+ # consider it when creating games to run on Windows.
310
+ #
311
+ def icon=( surface )
312
+ SDL.WM_SetIcon( surface.struct, nil )
313
+ return self
314
+ end
315
+
316
+
317
+
318
+ # Returns true if the mouse cursor is shown, or false if hidden.
319
+ # See also #show_cursor=
320
+ #
321
+ def show_cursor?
322
+ return ( SDL.ShowCursor(SDL::QUERY) == 1 )
323
+ end
324
+
325
+
326
+ # Set whether the mouse cursor is displayed or not. If +value+ is
327
+ # true, the cursor will be shown; if false, it will be hidden.
328
+ # See also #show_cursor?
329
+ #
330
+ def show_cursor=( value )
331
+ value = value ? SDL::ENABLE : SDL::DISABLE
332
+ return ( SDL.ShowCursor(value) == SDL::ENABLE )
333
+ end
334
+
335
+
336
+
337
+ # Returns the current window title for the Screen.
338
+ # The default is an empty string.
339
+ #
340
+ def title
341
+ return SDL.WM_GetCaption()[0]
342
+ end
343
+
344
+
345
+ # Sets the window title for the Screen.
346
+ #
347
+ # newtitle:: a string, (usually) displayed at the top of the Rubygame
348
+ # window (when not in fullscreen mode). If omitted or +nil+,
349
+ # +title+ will be an empty string.
350
+ # How this string is displayed (if at all) is system-dependent.
351
+ #
352
+ def title=( newtitle )
353
+ SDL.WM_SetCaption( newtitle, newtitle )
354
+ end
355
+
356
+
357
+ end
@@ -26,10 +26,46 @@
26
26
  module Rubygame
27
27
 
28
28
  # Warn of a deprecated Rubygame feature.
29
- def self.deprecated( feature, version ) # :nodoc:
30
- if $VERBOSE
31
- warn( "warning: #{feature} is DEPRECATED and will be removed in " + \
32
- "Rubygame #{version}! Please see the docs for more information." )
29
+ def self.deprecated( feature, version=nil ) # :nodoc:
30
+ @deprec_warned ||= {}
31
+
32
+ if $VERBOSE and not @deprec_warned[feature]
33
+ if version
34
+ warn( "warning: #{feature} is DEPRECATED and will be removed " +
35
+ "in Rubygame #{version}! Please see the docs for more " +
36
+ "information." )
37
+ else
38
+ warn( "warning: #{feature} is DEPRECATED and will be removed " +
39
+ "in a future version of Rubygame! Please see the docs " +
40
+ "for more information." )
41
+ end
42
+ @deprec_warned[feature] = true
43
+ end
44
+ end
45
+
46
+
47
+ # Initialize the SDL video system if necessary.
48
+ def self.init_video_system # :nodoc:
49
+ if( SDL::WasInit(SDL::INIT_VIDEO) == 0 )
50
+ return SDL::Init(SDL::INIT_VIDEO)
51
+ else
52
+ return 0
53
+ end
54
+ end
55
+
56
+
57
+ # Take nil, an integer, or an Array of integers. Returns an integer.
58
+ def self.collapse_flags( flags ) # :nodoc:
59
+ case flags
60
+ when Array
61
+ flags.inject(0){ |mem, flag| mem|flag }
62
+ when Numeric
63
+ flags
64
+ when nil
65
+ 0
66
+ else
67
+ raise( ArgumentError, "Wrong type for flags " +
68
+ "(wanted integer, Array, or nil; got #{flags.class})." )
33
69
  end
34
70
  end
35
71