rubysdl 1.3.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 (82) hide show
  1. data/LICENSE +505 -0
  2. data/MANIFEST +81 -0
  3. data/NEWS.en +144 -0
  4. data/NEWS.ja +151 -0
  5. data/README.en +117 -0
  6. data/README.ja +166 -0
  7. data/SDL_kanji.c +403 -0
  8. data/SDL_kanji.h +48 -0
  9. data/depend +18 -0
  10. data/doc/Makefile +18 -0
  11. data/doc/cdrom.rsd +431 -0
  12. data/doc/collision.rsd +162 -0
  13. data/doc/event.rsd +1487 -0
  14. data/doc/font.rsd +839 -0
  15. data/doc/general.rsd +49 -0
  16. data/doc/init.rsd +175 -0
  17. data/doc/joystick.rsd +387 -0
  18. data/doc/mixer.rsd +837 -0
  19. data/doc/mpeg.rsd +595 -0
  20. data/doc/rsd.rb +125 -0
  21. data/doc/sdlskk.rsd +496 -0
  22. data/doc/time.rsd +45 -0
  23. data/doc/video.rsd +2499 -0
  24. data/doc/wm.rsd +113 -0
  25. data/extconf.rb +92 -0
  26. data/lib/rubysdl_aliases.rb +431 -0
  27. data/lib/sdl.rb +271 -0
  28. data/rubysdl.h +109 -0
  29. data/rubysdl_cdrom.c +176 -0
  30. data/rubysdl_const_list.txt +280 -0
  31. data/rubysdl_doc.en.rd +2180 -0
  32. data/rubysdl_doc_old.rd +2402 -0
  33. data/rubysdl_event.c +346 -0
  34. data/rubysdl_event2.c +417 -0
  35. data/rubysdl_event_key.c +356 -0
  36. data/rubysdl_image.c +53 -0
  37. data/rubysdl_joystick.c +156 -0
  38. data/rubysdl_kanji.c +135 -0
  39. data/rubysdl_main.c +202 -0
  40. data/rubysdl_mixer.c +422 -0
  41. data/rubysdl_mouse.c +96 -0
  42. data/rubysdl_opengl.c +63 -0
  43. data/rubysdl_pixel.c +133 -0
  44. data/rubysdl_ref.html +5550 -0
  45. data/rubysdl_ref.rd +6163 -0
  46. data/rubysdl_rwops.c +90 -0
  47. data/rubysdl_sdlskk.c +312 -0
  48. data/rubysdl_sge_video.c +622 -0
  49. data/rubysdl_smpeg.c +341 -0
  50. data/rubysdl_time.c +36 -0
  51. data/rubysdl_ttf.c +324 -0
  52. data/rubysdl_video.c +749 -0
  53. data/rubysdl_wm.c +71 -0
  54. data/sample/aadraw.rb +24 -0
  55. data/sample/alpha.rb +27 -0
  56. data/sample/alphadraw.rb +25 -0
  57. data/sample/bfont.rb +24 -0
  58. data/sample/cdrom.rb +17 -0
  59. data/sample/collision.rb +97 -0
  60. data/sample/cursor.bmp +0 -0
  61. data/sample/cursor.rb +22 -0
  62. data/sample/ellipses.rb +35 -0
  63. data/sample/event2.rb +32 -0
  64. data/sample/font.bmp +0 -0
  65. data/sample/font.rb +25 -0
  66. data/sample/fpstimer.rb +175 -0
  67. data/sample/icon.bmp +0 -0
  68. data/sample/joy2.rb +81 -0
  69. data/sample/kanji.rb +36 -0
  70. data/sample/movesp.rb +93 -0
  71. data/sample/playmod.rb +14 -0
  72. data/sample/plaympeg.rb +48 -0
  73. data/sample/playwave.rb +16 -0
  74. data/sample/randrect.rb +40 -0
  75. data/sample/sample.ttf +0 -0
  76. data/sample/sdlskk.rb +70 -0
  77. data/sample/sgetest.rb +31 -0
  78. data/sample/stetris.rb +275 -0
  79. data/sample/testgl.rb +166 -0
  80. data/sample/testsprite.rb +68 -0
  81. data/sample/transformblit.rb +41 -0
  82. metadata +121 -0
@@ -0,0 +1,271 @@
1
+ #
2
+ # Ruby/SDL Ruby extension library for SDL
3
+ # Copyright (C) 2001-2007 Ohbayashi Ippei
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
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
+ #
17
+ require 'sdl.so'
18
+ require 'forwardable'
19
+
20
+ if !defined?(block_given?) then
21
+ alias block_given? iterator?
22
+ end
23
+
24
+ module SDL
25
+
26
+ VERSION = "1.3.0"
27
+
28
+ class PixelFormat
29
+
30
+ extend Forwardable
31
+
32
+ def initialize(surface)
33
+ @surface = surface
34
+ end
35
+
36
+ def_delegators( :@surface, :mapRGB, :mapRGBA, :getRGB, :getRGBA, :bpp,
37
+ :colorkey, :alpha )
38
+ end
39
+
40
+ class Surface
41
+ def put(surface,x,y)
42
+ SDL::blitSurface(surface,0,0,surface.w,surface.h,self,x,y)
43
+ end
44
+
45
+ def format
46
+ return PixelFormat.new(self)
47
+ end
48
+
49
+ if method_defined?(:rotateScaledSurface) then
50
+ def rotateSurface(angle,bgcolor)
51
+ rotateScaledSurface(angle,1.0,bgcolor)
52
+ end
53
+ end
54
+
55
+ def copyRect(x,y,w,h)
56
+ flagbase=SDL::SWSURFACE|SDL::HWSURFACE|SDL::SRCCOLORKEY|SDL::SRCALPHA
57
+ alpha_flag = self.flags & (SDL::SRCCOLORKEY|SDL::RLEACCEL)
58
+ self.setAlpha(0,self.alpha)
59
+ begin
60
+ new_surface=Surface.new(flagbase&self.flags,w,h,self)
61
+ ensure
62
+ self.setAlpha(alpha_flag,self.alpha)
63
+ end
64
+ SDL.blitSurface(self,x,y,w,h,new_surface,0,0)
65
+ new_surface.setColorKey(self.flags & (SDL::SRCCOLORKEY|SDL::RLEACCEL),
66
+ self.colorkey )
67
+ new_surface.setAlpha(self.flags & (SDL::SRCALPHA|SDL::RLEACCEL),
68
+ self.alpha )
69
+ return new_surface
70
+ end
71
+
72
+ def self.blit(src, srcX, srcY, srcW, srcH, dst, dstX, dstY)
73
+ SDL.blitSurface(src, srcX, srcY, srcW, srcH, dst, dstX, dstY)
74
+ end
75
+
76
+ def self.new(*args)
77
+ case args.size
78
+ when 4
79
+ create(*args)
80
+ when 8
81
+ createWithFormat(*args)
82
+ else
83
+ raise ArgumentError,"must be SDL::Surface.new(flags,w,h,surface) or SDL::Surface.new(flags,w,h,depth,Rmask,Gmask,Bmask,Amask)"
84
+ end
85
+ end
86
+ end
87
+
88
+ class Screen
89
+ def self.open(*args); SDL.setVideoMode(*args) end
90
+ end
91
+
92
+ def color2int(color,format)
93
+ case color
94
+ when Integer
95
+ return color
96
+ when Array
97
+ return format.mapRGB(*color)
98
+ else
99
+ raise Error,'first argument must be Integer or Array'
100
+ end
101
+ end
102
+ module_function :color2int
103
+
104
+ module Mouse
105
+ module_function
106
+
107
+ def setCursor(bitmap,white,black,transparent,inverted,hot_x=0,hot_y=0)
108
+ if bitmap.w % 8 != 0 then
109
+ raise SDL::Error,"width of cursor must be muliple of 8"
110
+ end
111
+
112
+ white=SDL.color2int(white,bitmap.format)
113
+ black=SDL.color2int(black,bitmap.format)
114
+ transparent=SDL.color2int(transparent,bitmap.format)
115
+ inverted=SDL.color2int(inverted,bitmap.format)
116
+
117
+ data=[]
118
+ mask=[]
119
+
120
+ i=-1
121
+ for y in 0..(bitmap.h-1)
122
+ for x in 0..(bitmap.w-1)
123
+ if x%8 != 0 then
124
+ data[i] <<= 1
125
+ mask[i] <<= 1
126
+ else
127
+ i+=1
128
+ data[i]=mask[i]=0
129
+ end
130
+
131
+ case bitmap.getPixel(x,y)
132
+ when white
133
+ mask[i] |= 0x01
134
+ when black
135
+ data[i] |= 0x01
136
+ mask[i] |= 0x01
137
+ when transparent
138
+ # do nothing
139
+ when inverted
140
+ data[i] |= 0x01
141
+ end
142
+
143
+ end
144
+ end
145
+
146
+ setCursor_imp data.pack('C*'),mask.pack('C*'),bitmap.w,bitmap.h,hot_x,hot_y
147
+ end
148
+
149
+ end # of module Mouse
150
+
151
+ class CD
152
+ def in_drive?
153
+ status > 0
154
+ end
155
+ end
156
+
157
+ module_function
158
+
159
+ if defined?(rotateXYScaled) then
160
+ def rotateScaled(src,dst,x,y,angle,scale)
161
+ rotateXYScaled(src,dst,x,y,angle,scale,scale)
162
+ end
163
+ def rotate(src,dst,x,y,angle)
164
+ rotateXYScaled(src,dst,x,y,angle,1,1)
165
+ end
166
+
167
+ def rotateBlit(src,dst,x,y,angle)
168
+ rotateScaledBlit(src,dst,x,y,angle,1)
169
+ end
170
+
171
+ def autoLock?
172
+ autoLock
173
+ end
174
+
175
+ def autoLockON
176
+ self.autoLock = true
177
+ end
178
+ def autoLockOFF
179
+ self.autoLock =false
180
+ end
181
+ end
182
+
183
+ if defined?(transform) then
184
+ def transformBlit(src,dst,angle,xscale,yscale,px,py,qx,qy,flags)
185
+ transformed = src.transformSurface( src.colorkey, angle,
186
+ xscale, yscale, flags )
187
+ transformed.setColorKey( src.flags & (SDL::SRCCOLORKEY|SDL::RLEACCEL),
188
+ src.colorkey )
189
+ transformed.setAlpha( src.flags & (SDL::SRCALPHA|SDL::RLEACCEL),
190
+ src.alpha )
191
+ rad = Math::PI*angle/180.0
192
+ x = px - src.w/2.0 ; y = py - src.h/2.0
193
+ x *= xscale ; y *= yscale
194
+ dst_x = x*Math.cos(rad)-y*Math.sin(rad)
195
+ dst_y = x*Math.sin(rad)+y*Math.cos(rad)
196
+ dst_x += transformed.w/2
197
+ dst_y += transformed.h/2
198
+ blitSurface( transformed, 0, 0, 0, 0, dst, qx-dst_x, qy-dst_y )
199
+ end
200
+ end
201
+
202
+ Rect = Struct.new( :x, :y, :w, :h )
203
+
204
+ def convertRect(rect)
205
+ case rect
206
+ when NilClass
207
+ return Rect.new( 0, 0, 0, 0 )
208
+ when Array
209
+ return Rect.new( rect[0], rect[1], rect[2], rect[3] )
210
+ else
211
+ return rect
212
+ end
213
+ end
214
+
215
+ def blitSurface2(src,srcRect,dst,dstRect)
216
+ srcR = convertRect(srcRect)
217
+ dstR = convertRect(dstRect)
218
+ blitSurface( src, srcR.x, srcR.y, srcR.w, srcR.h , dst, dstR.x, dstR.y )
219
+ end
220
+
221
+ if defined?(Mixer)
222
+ class << Mixer
223
+ alias open_imp open
224
+ private :open_imp
225
+ def open(frequency=Mixer::DEFAULT_FREQUENCY,format=Mixer::DEFAULT_FORMAT,
226
+ cannels=Mixer::DEFAULT_CHANNELS,chunksize=4096)
227
+ open_imp(frequency,format,cannels,chunksize)
228
+ end
229
+ end
230
+ end
231
+
232
+ if defined?(MPEG)
233
+ class MPEG
234
+ alias info_imp info
235
+ private :info_imp
236
+ def info(*arg)
237
+ case arg.size
238
+ when 0
239
+ result = SDL::MPEG::Info.new
240
+ info_imp(result)
241
+ result
242
+ when 1
243
+ info_imp(arg[0])
244
+ arg[0]
245
+ end
246
+ end
247
+ end
248
+ end
249
+
250
+ end
251
+
252
+ if defined?(GL) then
253
+ class << GL
254
+ alias Begin_imp Begin
255
+ private :Begin_imp
256
+ def Begin(mode)
257
+ if block_given? then
258
+ begin
259
+ Begin_imp(mode)
260
+ yield
261
+ ensure
262
+ End()
263
+ end
264
+ else
265
+ Begin_imp(mode)
266
+ end
267
+ end
268
+ end
269
+ end
270
+
271
+ require 'rubysdl_aliases.rb'
@@ -0,0 +1,109 @@
1
+ /*
2
+ Ruby/SDL Ruby extension library for SDL
3
+
4
+ Copyright (C) 2001-2007 Ohbayashi Ippei
5
+
6
+ This library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License as published by the Free Software Foundation; either
9
+ version 2.1 of the License, or (at your option) any later version.
10
+
11
+ This library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public
17
+ License along with this library; if not, write to the Free Software
18
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ */
20
+
21
+ #include <SDL.h>
22
+ #include <ruby.h>
23
+ #include <stdio.h>
24
+ #ifndef UINT2NUM
25
+ #define UINT2NUM(v) INT2NUM(v)
26
+ #endif
27
+
28
+ #ifdef DEF_GLOBAL
29
+ #define GLOBAL
30
+ #else
31
+ #define GLOBAL extern
32
+ #endif
33
+
34
+ #ifdef StringValuePtr
35
+ #define GETCSTR(v) StringValuePtr(v)
36
+ #else
37
+ #define GETCSTR(v) STR2CSTR(v)
38
+ #endif
39
+
40
+ GLOBAL VALUE mSDL;
41
+ GLOBAL VALUE eSDLError;
42
+ GLOBAL VALUE cVideoInfo;
43
+ GLOBAL VALUE cSurface;
44
+ GLOBAL VALUE cScreen;
45
+ GLOBAL VALUE cEvent;
46
+ GLOBAL VALUE mKey;
47
+ GLOBAL VALUE mMixer;
48
+ GLOBAL VALUE cWave;
49
+ GLOBAL VALUE cMusic;
50
+ GLOBAL VALUE mWM;
51
+ GLOBAL VALUE mMouse;
52
+ GLOBAL VALUE cTTF;
53
+ GLOBAL VALUE cJoystick;
54
+ GLOBAL VALUE cCD;
55
+ GLOBAL VALUE cMPEG;
56
+ GLOBAL VALUE cMPEGInfo;
57
+ GLOBAL VALUE mSDLSKK;
58
+ GLOBAL VALUE cContext;
59
+ GLOBAL VALUE cDictionary;
60
+ GLOBAL VALUE cRomKanaRuleTable;
61
+ GLOBAL VALUE cKeybind;
62
+
63
+ #ifdef HAVE_SGE
64
+ GLOBAL VALUE cCollisionMap;
65
+ GLOBAL VALUE cBMFont;
66
+ #endif /* ifdef HAVE_SGE */
67
+
68
+ #ifdef DEF_EVENT2
69
+ GLOBAL VALUE cEvent2;
70
+ GLOBAL VALUE cActiveEvent;
71
+ GLOBAL VALUE cKeyDownEvent;
72
+ GLOBAL VALUE cKeyUpEvent;
73
+ GLOBAL VALUE cMouseMotionEvent;
74
+ GLOBAL VALUE cMouseButtonDownEvent;
75
+ GLOBAL VALUE cMouseButtonUpEvent;
76
+ GLOBAL VALUE cJoyAxisEvent;
77
+ GLOBAL VALUE cJoyBallEvent;
78
+ GLOBAL VALUE cJoyHatEvent;
79
+ GLOBAL VALUE cJoyButtonUpEvent;
80
+ GLOBAL VALUE cJoyButtonDownEvent;
81
+ GLOBAL VALUE cQuitEvent;
82
+ GLOBAL VALUE cSysWMEvent;
83
+ GLOBAL VALUE cVideoResizeEvent;
84
+ GLOBAL VALUE cVideoExposeEvent;
85
+ #endif
86
+
87
+ #define SetRect(Rect,X,Y,W,H) \
88
+ do{ \
89
+ Rect.x=NUM2INT(X); \
90
+ Rect.y=NUM2INT(Y); \
91
+ Rect.w=NUM2INT(W); \
92
+ Rect.h=NUM2INT(H); \
93
+ }while(0) \
94
+
95
+ #define BOOL(x) (x)?Qtrue:Qfalse
96
+
97
+ #ifndef SDL_VERSION_ATLEAST
98
+ #define SDL_COMPILEDVERSION SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL)
99
+
100
+ #define SDL_VERSION_ATLEAST(X, Y, Z) (SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
101
+
102
+ #endif
103
+
104
+ Uint32 VALUE2COLOR(VALUE color,SDL_PixelFormat *format);
105
+ void rubysdl_putPixel(SDL_Surface *surface, Sint16 x, Sint16 y, Uint32 color);
106
+ Uint32 rubysdl_getPixel(SDL_Surface *surface, Sint16 x, Sint16 y);
107
+ void sdl_freeSurface(SDL_Surface* surface);
108
+ int rubysdl_is_quit(void);
109
+ SDL_RWops* rubysdl_RWops_from_ruby_obj(VALUE obj);
@@ -0,0 +1,176 @@
1
+ /*
2
+ Ruby/SDL Ruby extension library for SDL
3
+
4
+ Copyright (C) 2001-2007 Ohbayashi Ippei
5
+
6
+ This library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License as published by the Free Software Foundation; either
9
+ version 2.1 of the License, or (at your option) any later version.
10
+
11
+ This library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public
17
+ License along with this library; if not, write to the Free Software
18
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ */
20
+ #include "rubysdl.h"
21
+
22
+ static VALUE sdl_cd_numDrive(VALUE class)
23
+ {
24
+ return INT2FIX(SDL_CDNumDrives());
25
+ }
26
+ static VALUE sdl_cd_name(VALUE class,VALUE drive)
27
+ {
28
+ return rb_str_new2(SDL_CDName(NUM2INT(drive)));
29
+ }
30
+ static VALUE sdl_cd_open(VALUE class,VALUE drive)
31
+ {
32
+ SDL_CD *cd;
33
+ cd=SDL_CDOpen(NUM2INT(drive));
34
+ if(cd==NULL)
35
+ rb_raise(eSDLError,"Couldn't open drive %d: %s",
36
+ NUM2INT(drive),SDL_GetError());
37
+ return Data_Wrap_Struct(class,0,SDL_CDClose,cd);
38
+ }
39
+ static VALUE sdl_cd_status(VALUE obj)
40
+ {
41
+ SDL_CD *cd;
42
+ Data_Get_Struct(obj,SDL_CD,cd);
43
+ return INT2FIX(SDL_CDStatus(cd));
44
+ }
45
+ static VALUE sdl_cd_play(VALUE obj,VALUE start,VALUE length)
46
+ {
47
+ SDL_CD *cd;
48
+ Data_Get_Struct(obj,SDL_CD,cd);
49
+ if( SDL_CDPlay(cd,NUM2INT(start),NUM2INT(length))==-1 )
50
+ rb_raise(eSDLError,"Couldn't play cd :%s",SDL_GetError() );
51
+ return Qnil;
52
+ }
53
+ static VALUE sdl_cd_playTracks(VALUE obj,VALUE start_track,VALUE start_frame,
54
+ VALUE ntracks,VALUE nframes)
55
+ {
56
+ SDL_CD *cd;
57
+ Data_Get_Struct(obj,SDL_CD,cd);
58
+ if( SDL_CDPlayTracks(cd,NUM2INT(start_track),NUM2INT(start_frame),
59
+ NUM2INT(ntracks),NUM2INT(nframes))==-1 )
60
+ rb_raise(eSDLError,"Couldn't play cd :%s",SDL_GetError() );
61
+ return Qnil;
62
+ }
63
+ static VALUE sdl_cd_pause(VALUE obj)
64
+ {
65
+ SDL_CD *cd;
66
+ Data_Get_Struct(obj,SDL_CD,cd);
67
+ if( SDL_CDPause(cd)==-1 )
68
+ rb_raise(eSDLError,"cd pause failed :%s",SDL_GetError());
69
+ return Qnil;
70
+ }
71
+ static VALUE sdl_cd_resume(VALUE obj)
72
+ {
73
+ SDL_CD *cd;
74
+ Data_Get_Struct(obj,SDL_CD,cd);
75
+ if( SDL_CDResume(cd)==-1 )
76
+ rb_raise(eSDLError,"cd resume failed :%s",SDL_GetError());
77
+ return Qnil;
78
+ }
79
+ static VALUE sdl_cd_stop(VALUE obj)
80
+ {
81
+ SDL_CD *cd;
82
+ Data_Get_Struct(obj,SDL_CD,cd);
83
+ if( SDL_CDStop(cd)==-1 )
84
+ rb_raise(eSDLError,"cd pause failed :%s",SDL_GetError());
85
+ return Qnil;
86
+ }
87
+ static VALUE sdl_cd_eject(VALUE obj)
88
+ {
89
+ SDL_CD *cd;
90
+ Data_Get_Struct(obj,SDL_CD,cd);
91
+ if( SDL_CDEject(cd)==-1 )
92
+ rb_raise(eSDLError,"cd eject failed :%s",SDL_GetError());
93
+ return Qnil;
94
+ }
95
+
96
+ static VALUE sdl_cd_numTracks(VALUE obj)
97
+ {
98
+ SDL_CD *cd;
99
+ Data_Get_Struct(obj,SDL_CD,cd);
100
+ return INT2NUM(cd->numtracks);
101
+ }
102
+ static VALUE sdl_cd_currentTrack(VALUE obj)
103
+ {
104
+ SDL_CD *cd;
105
+ Data_Get_Struct(obj,SDL_CD,cd);
106
+ return INT2NUM(cd->cur_track);
107
+ }
108
+ static VALUE sdl_cd_currentFrame(VALUE obj)
109
+ {
110
+ SDL_CD *cd;
111
+ Data_Get_Struct(obj,SDL_CD,cd);
112
+ return INT2NUM(cd->cur_frame);
113
+ }
114
+ static VALUE sdl_cd_trackType(VALUE obj,VALUE track)
115
+ {
116
+ SDL_CD *cd;
117
+ int index=NUM2INT(track);
118
+ Data_Get_Struct(obj,SDL_CD,cd);
119
+ return INT2FIX(cd->track[index].type);
120
+ }
121
+ static VALUE sdl_cd_trackLength(VALUE obj,VALUE track)
122
+ {
123
+ SDL_CD *cd;
124
+ int index=NUM2INT(track);
125
+ Data_Get_Struct(obj,SDL_CD,cd);
126
+ return INT2FIX(cd->track[index].length);
127
+ }
128
+
129
+ static VALUE sdl_cd_framesToMSF(VALUE class, VALUE frames)
130
+ {
131
+ int m, s, f;
132
+ FRAMES_TO_MSF(NUM2INT(frames), &m, &s, &f);
133
+ return rb_ary_new3(3, INT2FIX(m), INT2FIX(s), INT2FIX(f));
134
+ }
135
+ static VALUE sdl_cd_MSFToFrames(VALUE class, VALUE m, VALUE s, VALUE f)
136
+ {
137
+ return INT2FIX(MSF_TO_FRAMES(NUM2INT(m),NUM2INT(s),NUM2INT(f)));
138
+ }
139
+
140
+ static void defineConstForCDROM()
141
+ {
142
+ rb_define_const(cCD,"TRAYEMPTY",INT2NUM(CD_TRAYEMPTY));
143
+ rb_define_const(cCD,"STOPPED",INT2NUM(CD_STOPPED));
144
+ rb_define_const(cCD,"PLAYING",INT2NUM(CD_PLAYING));
145
+ rb_define_const(cCD,"PAUSED",INT2NUM(CD_PAUSED));
146
+ rb_define_const(cCD,"ERROR",INT2NUM(CD_ERROR));
147
+
148
+ rb_define_const(cCD,"AUDIO_TRACK",UINT2NUM(SDL_AUDIO_TRACK));
149
+ rb_define_const(cCD,"DATA_TRACK",UINT2NUM(SDL_DATA_TRACK));
150
+
151
+ rb_define_const(cCD,"FPS", UINT2NUM(CD_FPS));
152
+ }
153
+ void init_cdrom()
154
+ {
155
+ cCD=rb_define_class_under(mSDL,"CD",rb_cObject);
156
+ rb_define_singleton_method(cCD,"numDrive",sdl_cd_numDrive,0);
157
+ rb_define_singleton_method(cCD,"indexName",sdl_cd_name,1);
158
+ rb_define_singleton_method(cCD,"open",sdl_cd_open,1);
159
+ rb_define_singleton_method(cCD,"framesToMSF",sdl_cd_framesToMSF,1);
160
+ rb_define_singleton_method(cCD,"MSFToFrames",sdl_cd_MSFToFrames,3);
161
+ rb_define_method(cCD,"status",sdl_cd_status,0);
162
+ rb_define_method(cCD,"play",sdl_cd_play,2);
163
+ rb_define_method(cCD,"playTracks",sdl_cd_playTracks,4);
164
+ rb_define_method(cCD,"pause",sdl_cd_pause,0);
165
+ rb_define_method(cCD,"resume",sdl_cd_resume,0);
166
+ rb_define_method(cCD,"stop",sdl_cd_stop,0);
167
+ rb_define_method(cCD,"eject",sdl_cd_eject,0);
168
+
169
+ rb_define_method(cCD,"numTracks",sdl_cd_numTracks,0);
170
+ rb_define_method(cCD,"currentTrack",sdl_cd_currentTrack,0);
171
+ rb_define_method(cCD,"currentFrame",sdl_cd_currentFrame,0);
172
+ rb_define_method(cCD,"trackType",sdl_cd_trackType,1);
173
+ rb_define_method(cCD,"trackLength",sdl_cd_trackLength,1);
174
+
175
+ defineConstForCDROM();
176
+ }