rubysdl 1.3.1 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MANIFEST +22 -2
- data/NEWS.en +80 -0
- data/NEWS.ja +83 -0
- data/README.en +2 -1
- data/README.ja +2 -2
- data/doc-en/Makefile +18 -0
- data/doc-en/cdrom.rsd +417 -0
- data/doc-en/collision.rsd +174 -0
- data/doc-en/event.rsd +1476 -0
- data/doc-en/font.rsd +811 -0
- data/doc-en/general.rsd +43 -0
- data/doc-en/init.rsd +168 -0
- data/doc-en/joystick.rsd +401 -0
- data/doc-en/mixer.rsd +869 -0
- data/doc-en/mpeg.rsd +585 -0
- data/doc-en/opengl.rsd +155 -0
- data/doc-en/sdlskk.rsd +472 -0
- data/doc-en/time.rsd +46 -0
- data/doc-en/video.rsd +2806 -0
- data/doc-en/wm.rsd +112 -0
- data/doc/Makefile +1 -1
- data/doc/cdrom.rsd +3 -3
- data/doc/event.rsd +178 -179
- data/doc/general.rsd +10 -0
- data/doc/init.rsd +2 -2
- data/doc/joystick.rsd +29 -5
- data/doc/mixer.rsd +20 -0
- data/doc/rsd.rb +42 -9
- data/doc/sdlskk.rsd +7 -7
- data/doc/video.rsd +461 -168
- data/doc/wm.rsd +2 -2
- data/extconf.rb +1 -8
- data/lib/rubysdl_aliases.rb +52 -190
- data/lib/rubysdl_compatible_ver1.rb +243 -0
- data/lib/sdl.rb +58 -92
- data/rubysdl.h +59 -68
- data/rubysdl_cdrom.c +125 -102
- data/{rubysdl_doc.en.rd → rubysdl_doc_old.en.rd} +3 -2
- data/rubysdl_event.c +318 -255
- data/rubysdl_event_key.c +299 -287
- data/rubysdl_image.c +37 -13
- data/rubysdl_joystick.c +180 -67
- data/rubysdl_kanji.c +61 -75
- data/rubysdl_main.c +65 -138
- data/rubysdl_mixer.c +339 -214
- data/rubysdl_mouse.c +50 -43
- data/rubysdl_opengl.c +31 -28
- data/rubysdl_pixel.c +17 -28
- data/rubysdl_ref.en.html +5658 -0
- data/rubysdl_ref.en.rd +6337 -0
- data/rubysdl_ref.html +2253 -1964
- data/rubysdl_ref.rd +823 -469
- data/rubysdl_rwops.c +9 -6
- data/rubysdl_sdlskk.c +137 -165
- data/rubysdl_sge_video.c +355 -469
- data/rubysdl_smpeg.c +189 -190
- data/rubysdl_time.c +1 -1
- data/rubysdl_ttf.c +147 -215
- data/rubysdl_video.c +486 -405
- data/rubysdl_wm.c +30 -30
- data/sample/aadraw.rb +9 -9
- data/sample/alpha.rb +12 -13
- data/sample/alphadraw.rb +10 -10
- data/sample/bfont.rb +4 -4
- data/sample/cdrom.rb +11 -4
- data/sample/collision.rb +20 -20
- data/sample/cursor.rb +5 -5
- data/sample/ellipses.rb +20 -16
- data/sample/event2.rb +11 -9
- data/sample/font.rb +4 -4
- data/sample/fpstimer.rb +3 -3
- data/sample/icon.bmp.gz +0 -0
- data/sample/icon.png +0 -0
- data/sample/joy2.rb +14 -14
- data/sample/kanji.rb +7 -7
- data/sample/load_from_io.rb +44 -0
- data/sample/movesp.rb +13 -12
- data/sample/playmod.rb +2 -3
- data/sample/plaympeg.rb +8 -8
- data/sample/playwave.rb +5 -6
- data/sample/sdlskk.rb +11 -11
- data/sample/sgetest.rb +14 -12
- data/sample/stetris.rb +12 -13
- data/sample/testgl.rb +13 -14
- data/sample/testsprite.rb +12 -11
- data/sample/transformblit.rb +23 -22
- metadata +62 -35
- data/rubysdl_event2.c +0 -417
data/lib/sdl.rb
CHANGED
@@ -17,62 +17,32 @@
|
|
17
17
|
require 'sdl.so'
|
18
18
|
require 'forwardable'
|
19
19
|
|
20
|
-
if !defined?(block_given?) then
|
21
|
-
alias block_given? iterator?
|
22
|
-
end
|
23
|
-
|
24
20
|
module SDL
|
25
|
-
|
26
|
-
VERSION = "1.3.1"
|
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
|
21
|
+
VERSION = "2.0 alpha1"
|
39
22
|
|
40
23
|
class Surface
|
41
24
|
def put(surface,x,y)
|
42
|
-
SDL::
|
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
|
25
|
+
SDL::Surface.blit(surface,0,0,surface.w,surface.h,self,x,y)
|
53
26
|
end
|
54
27
|
|
55
28
|
def copyRect(x,y,w,h)
|
29
|
+
format = self.format
|
56
30
|
flagbase=SDL::SWSURFACE|SDL::HWSURFACE|SDL::SRCCOLORKEY|SDL::SRCALPHA
|
57
31
|
alpha_flag = self.flags & (SDL::SRCCOLORKEY|SDL::RLEACCEL)
|
58
|
-
self.setAlpha(0,
|
32
|
+
self.setAlpha(0,format.alpha)
|
59
33
|
begin
|
60
34
|
new_surface=Surface.new(flagbase&self.flags,w,h,self)
|
61
35
|
ensure
|
62
|
-
self.setAlpha(alpha_flag,
|
36
|
+
self.setAlpha(alpha_flag,format.alpha)
|
63
37
|
end
|
64
38
|
SDL.blitSurface(self,x,y,w,h,new_surface,0,0)
|
65
39
|
new_surface.setColorKey(self.flags & (SDL::SRCCOLORKEY|SDL::RLEACCEL),
|
66
|
-
|
40
|
+
format.colorkey )
|
67
41
|
new_surface.setAlpha(self.flags & (SDL::SRCALPHA|SDL::RLEACCEL),
|
68
|
-
|
42
|
+
format.alpha )
|
69
43
|
return new_surface
|
70
44
|
end
|
71
45
|
|
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
46
|
def self.new(*args)
|
77
47
|
case args.size
|
78
48
|
when 4
|
@@ -83,12 +53,10 @@ module SDL
|
|
83
53
|
raise ArgumentError,"must be SDL::Surface.new(flags,w,h,surface) or SDL::Surface.new(flags,w,h,depth,Rmask,Gmask,Bmask,Amask)"
|
84
54
|
end
|
85
55
|
end
|
86
|
-
end
|
87
56
|
|
88
|
-
|
89
|
-
def self.open(*args); SDL.setVideoMode(*args) end
|
57
|
+
|
90
58
|
end
|
91
|
-
|
59
|
+
|
92
60
|
def color2int(color,format)
|
93
61
|
case color
|
94
62
|
when Integer
|
@@ -120,14 +88,14 @@ module SDL
|
|
120
88
|
i=-1
|
121
89
|
for y in 0..(bitmap.h-1)
|
122
90
|
for x in 0..(bitmap.w-1)
|
123
|
-
if x%8
|
91
|
+
if x%8 == 0 then
|
92
|
+
i+=1
|
93
|
+
data[i]=mask[i]=0
|
94
|
+
else
|
124
95
|
data[i] <<= 1
|
125
96
|
mask[i] <<= 1
|
126
|
-
else
|
127
|
-
i+=1
|
128
|
-
data[i]=mask[i]=0
|
129
97
|
end
|
130
|
-
|
98
|
+
|
131
99
|
case bitmap.getPixel(x,y)
|
132
100
|
when white
|
133
101
|
mask[i] |= 0x01
|
@@ -139,7 +107,6 @@ module SDL
|
|
139
107
|
when inverted
|
140
108
|
data[i] |= 0x01
|
141
109
|
end
|
142
|
-
|
143
110
|
end
|
144
111
|
end
|
145
112
|
|
@@ -148,6 +115,26 @@ module SDL
|
|
148
115
|
|
149
116
|
end # of module Mouse
|
150
117
|
|
118
|
+
if defined?(CollisionMap)
|
119
|
+
def Surface.transformBlit(src, dst, angle, xscale, yscale,
|
120
|
+
px, py, qx, qy, flags)
|
121
|
+
transformed = src.transformSurface(src.colorkey, angle,
|
122
|
+
xscale, yscale, flags)
|
123
|
+
transformed.setColorKey(src.flags & (SDL::SRCCOLORKEY|SDL::RLEACCEL),
|
124
|
+
src.colorkey )
|
125
|
+
transformed.setAlpha(src.flags & (SDL::SRCALPHA|SDL::RLEACCEL),
|
126
|
+
src.alpha )
|
127
|
+
rad = Math::PI*angle / 180.0
|
128
|
+
x = px - src.w/2.0 ; y = py - src.h/2.0
|
129
|
+
x *= xscale ; y *= yscale
|
130
|
+
dst_x = x*Math.cos(rad)-y*Math.sin(rad)
|
131
|
+
dst_y = x*Math.sin(rad)+y*Math.cos(rad)
|
132
|
+
dst_x += transformed.w / 2
|
133
|
+
dst_y += transformed.h / 2
|
134
|
+
Surface.blit(transformed, 0, 0, 0, 0, dst, qx-dst_x, qy-dst_y)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
151
138
|
class CD
|
152
139
|
def in_drive?
|
153
140
|
status > 0
|
@@ -156,49 +143,6 @@ module SDL
|
|
156
143
|
|
157
144
|
module_function
|
158
145
|
|
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
146
|
Rect = Struct.new( :x, :y, :w, :h )
|
203
147
|
|
204
148
|
def convertRect(rect)
|
@@ -211,7 +155,8 @@ module SDL
|
|
211
155
|
return rect
|
212
156
|
end
|
213
157
|
end
|
214
|
-
|
158
|
+
|
159
|
+
# FIX:
|
215
160
|
def blitSurface2(src,srcRect,dst,dstRect)
|
216
161
|
srcR = convertRect(srcRect)
|
217
162
|
dstR = convertRect(dstRect)
|
@@ -246,7 +191,27 @@ module SDL
|
|
246
191
|
end
|
247
192
|
end
|
248
193
|
end
|
249
|
-
|
194
|
+
if defined?(TTF)
|
195
|
+
class TTF
|
196
|
+
def drawSolidUTF8(dst, text, x, y, r, g, b)
|
197
|
+
image = renderSolidUTF8(text, r, g, b)
|
198
|
+
dst.put(image, x, y)
|
199
|
+
image.destroy
|
200
|
+
end
|
201
|
+
|
202
|
+
def drawBlendedUTF8(dst, text, x, y, r, g, b)
|
203
|
+
image = renderBlendedUTF8(text, r, g, b)
|
204
|
+
dst.put(image, x, y)
|
205
|
+
image.destroy
|
206
|
+
end
|
207
|
+
|
208
|
+
def drawShadedUTF8(dst, text, fg_r, fg_g, fg_b, bg_r, bg_g, bg_b)
|
209
|
+
image = renderSolidUTF8(text, fg_r, fg_g, fg_b, bg_r, bg_g, bg_b)
|
210
|
+
dst.put(image, x, y)
|
211
|
+
image.destroy
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
250
215
|
end
|
251
216
|
|
252
217
|
if defined?(GL) then
|
@@ -269,3 +234,4 @@ if defined?(GL) then
|
|
269
234
|
end
|
270
235
|
|
271
236
|
require 'rubysdl_aliases.rb'
|
237
|
+
require 'rubysdl_compatible_ver1.rb'
|
data/rubysdl.h
CHANGED
@@ -21,69 +21,23 @@
|
|
21
21
|
#include <SDL.h>
|
22
22
|
#include <ruby.h>
|
23
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
24
|
|
34
|
-
|
35
|
-
#define
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
25
|
+
/* Macros */
|
26
|
+
#define GLOBAL_DEFINE_GET_STRUCT(struct_name, fun, klass, klassstr) \
|
27
|
+
struct_name* fun(VALUE obj) \
|
28
|
+
{ \
|
29
|
+
struct_name* st; \
|
30
|
+
\
|
31
|
+
if(!rb_obj_is_kind_of(obj, klass)){ \
|
32
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected " klassstr ")", \
|
33
|
+
rb_obj_classname(obj)); \
|
34
|
+
} \
|
35
|
+
Data_Get_Struct(obj, struct_name, st); \
|
36
|
+
return st; \
|
37
|
+
}
|
86
38
|
|
39
|
+
#define DEFINE_GET_STRUCT(struct_name, fun, klass, klassstr) \
|
40
|
+
static GLOBAL_DEFINE_GET_STRUCT(struct_name, fun, klass, klassstr)
|
87
41
|
#define SetRect(Rect,X,Y,W,H) \
|
88
42
|
do{ \
|
89
43
|
Rect.x=NUM2INT(X); \
|
@@ -92,18 +46,55 @@ do{ \
|
|
92
46
|
Rect.h=NUM2INT(H); \
|
93
47
|
}while(0) \
|
94
48
|
|
95
|
-
#define
|
49
|
+
#define INT2BOOL(x) ((x)?Qtrue:Qfalse)
|
96
50
|
|
97
|
-
|
98
|
-
#define
|
99
|
-
|
100
|
-
|
101
|
-
|
51
|
+
/* Global variables */
|
52
|
+
#define eSDLError rubysdl_eSDLError
|
53
|
+
#ifdef DEF_GLOBAL
|
54
|
+
VALUE eSDLError;
|
55
|
+
#else
|
56
|
+
extern VALUE eSDLError;
|
102
57
|
#endif
|
103
58
|
|
59
|
+
/* Global functions */
|
60
|
+
#define VALUE2COLOR rubysdl_VALUE2COLOR
|
104
61
|
Uint32 VALUE2COLOR(VALUE color,SDL_PixelFormat *format);
|
62
|
+
|
105
63
|
void rubysdl_putPixel(SDL_Surface *surface, Sint16 x, Sint16 y, Uint32 color);
|
106
64
|
Uint32 rubysdl_getPixel(SDL_Surface *surface, Sint16 x, Sint16 y);
|
107
|
-
void sdl_freeSurface(SDL_Surface* surface);
|
108
65
|
int rubysdl_is_quit(void);
|
66
|
+
|
109
67
|
SDL_RWops* rubysdl_RWops_from_ruby_obj(VALUE obj);
|
68
|
+
|
69
|
+
#define Surface_create rubysdl_Surface_create
|
70
|
+
VALUE Surface_create(SDL_Surface* surface);
|
71
|
+
|
72
|
+
#define Get_SDL_Surface rubysdl_Get_SDL_Surface
|
73
|
+
SDL_Surface* Get_SDL_Surface(VALUE obj);
|
74
|
+
|
75
|
+
#ifdef HAVE_SDLSKK
|
76
|
+
#include <SDL_ttf.h>
|
77
|
+
#define Get_TTF_Font rubysdl_Get_TTF_Font
|
78
|
+
TTF_Font* Get_TTF_Font(VALUE obj);
|
79
|
+
#endif
|
80
|
+
|
81
|
+
/* declaration of initialize functions */
|
82
|
+
VALUE rubysdl_init_video(VALUE mSDL);
|
83
|
+
void rubysdl_init_sge(VALUE mSDL, VALUE cSurface);
|
84
|
+
void rubysdl_init_GL(VALUE mSDL);
|
85
|
+
void rubysdl_init_image(VALUE mSDL, VALUE cSurface);
|
86
|
+
void rubysdl_init_Event(VALUE mSDL);
|
87
|
+
void rubysdl_init_Key(VALUE mSDL);
|
88
|
+
void rubysdl_init_Mouse(VALUE mSDL);
|
89
|
+
void rubysdl_init_Joystick(VALUE mSDL);
|
90
|
+
void rubysdl_init_CD(VALUE mSDL);
|
91
|
+
void rubysdl_init_time(VALUE mSDL);
|
92
|
+
void rubysdl_init_WM(VALUE mSDL);
|
93
|
+
void rubysdl_init_Kanji(VALUE mSDL);
|
94
|
+
void rubysdl_init_TTF(VALUE mSDL);
|
95
|
+
void rubysdl_quit_TTF(void);
|
96
|
+
void rubysdl_init_Mixer(VALUE mSDL);
|
97
|
+
void rubysdl_quit_Mixer(void);
|
98
|
+
void rubysdl_init_MPEG(VALUE mSDL);
|
99
|
+
void rubysdl_init_SKK(VALUE mSDL);
|
100
|
+
|
data/rubysdl_cdrom.c
CHANGED
@@ -19,158 +19,181 @@
|
|
19
19
|
*/
|
20
20
|
#include "rubysdl.h"
|
21
21
|
|
22
|
-
static VALUE
|
22
|
+
static VALUE cCD;
|
23
|
+
|
24
|
+
typedef struct{
|
25
|
+
SDL_CD* cd;
|
26
|
+
} CD;
|
27
|
+
|
28
|
+
DEFINE_GET_STRUCT(CD, GetCD, cCD, "SDL::CD");
|
29
|
+
|
30
|
+
static SDL_CD* Get_SDL_CD(VALUE obj)
|
31
|
+
{
|
32
|
+
CD* cd = GetCD(obj);
|
33
|
+
if(cd->cd == NULL)
|
34
|
+
rb_raise(rb_eRuntimeError, "CD is closed");
|
35
|
+
return cd->cd;
|
36
|
+
}
|
37
|
+
|
38
|
+
static void CD_free(CD* cd)
|
23
39
|
{
|
40
|
+
if( !rubysdl_is_quit() && cd->cd )
|
41
|
+
SDL_CDClose(cd->cd);
|
42
|
+
free(cd);
|
43
|
+
}
|
44
|
+
|
45
|
+
static VALUE CD_s_alloc(VALUE klass)
|
46
|
+
{
|
47
|
+
CD* cd = ALLOC(CD);
|
48
|
+
cd->cd = NULL;
|
49
|
+
return Data_Wrap_Struct(cCD, 0, CD_free, cd);
|
50
|
+
}
|
51
|
+
|
52
|
+
static VALUE CD_initialize(VALUE self, VALUE drive)
|
53
|
+
{
|
54
|
+
CD* cd = GetCD(self);
|
55
|
+
rb_secure(4);
|
56
|
+
|
57
|
+
cd->cd = SDL_CDOpen(NUM2INT(drive));
|
58
|
+
if(cd->cd == NULL)
|
59
|
+
rb_raise(eSDLError, "Couldn't open drive %d: %s",
|
60
|
+
NUM2INT(drive), SDL_GetError());
|
61
|
+
return Qnil;
|
62
|
+
}
|
63
|
+
|
64
|
+
static VALUE CD_s_numDrive(VALUE klass)
|
65
|
+
{
|
66
|
+
rb_secure(4);
|
24
67
|
return INT2FIX(SDL_CDNumDrives());
|
25
68
|
}
|
26
|
-
static VALUE
|
69
|
+
static VALUE CD_s_name(VALUE klass, VALUE drive)
|
27
70
|
{
|
71
|
+
rb_secure(4);
|
28
72
|
return rb_str_new2(SDL_CDName(NUM2INT(drive)));
|
29
73
|
}
|
30
|
-
static VALUE
|
74
|
+
static VALUE CD_s_open(VALUE klass, VALUE drive)
|
31
75
|
{
|
32
|
-
|
33
|
-
|
34
|
-
|
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);
|
76
|
+
VALUE newobj = CD_s_alloc(klass);
|
77
|
+
CD_initialize(newobj, drive);
|
78
|
+
return newobj;
|
38
79
|
}
|
39
|
-
static VALUE
|
80
|
+
static VALUE CD_status(VALUE self)
|
40
81
|
{
|
41
|
-
|
42
|
-
|
43
|
-
return INT2FIX(SDL_CDStatus(cd));
|
82
|
+
rb_secure(4);
|
83
|
+
return INT2FIX(SDL_CDStatus(Get_SDL_CD(self)));
|
44
84
|
}
|
45
|
-
static VALUE
|
85
|
+
static VALUE CD_play(VALUE self, VALUE start, VALUE length)
|
46
86
|
{
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
rb_raise(eSDLError,"Couldn't play cd :%s",SDL_GetError() );
|
87
|
+
rb_secure(4);
|
88
|
+
if( SDL_CDPlay(Get_SDL_CD(self), NUM2INT(start), NUM2INT(length))==-1 )
|
89
|
+
rb_raise(eSDLError, "Couldn't play cd :%s", SDL_GetError() );
|
51
90
|
return Qnil;
|
52
91
|
}
|
53
|
-
static VALUE
|
54
|
-
VALUE ntracks,VALUE nframes)
|
92
|
+
static VALUE CD_playTracks(VALUE self, VALUE start_track, VALUE start_frame,
|
93
|
+
VALUE ntracks, VALUE nframes)
|
55
94
|
{
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
NUM2INT(
|
60
|
-
rb_raise(eSDLError,"Couldn't play cd :%s",SDL_GetError() );
|
95
|
+
rb_secure(4);
|
96
|
+
if( SDL_CDPlayTracks(Get_SDL_CD(self), NUM2INT(start_track),
|
97
|
+
NUM2INT(start_frame), NUM2INT(ntracks),
|
98
|
+
NUM2INT(nframes))==-1 )
|
99
|
+
rb_raise(eSDLError, "Couldn't play cd :%s", SDL_GetError() );
|
61
100
|
return Qnil;
|
62
101
|
}
|
63
|
-
static VALUE
|
102
|
+
static VALUE CD_pause(VALUE self)
|
64
103
|
{
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
rb_raise(eSDLError,"cd pause failed :%s",SDL_GetError());
|
104
|
+
rb_secure(4);
|
105
|
+
if( SDL_CDPause(Get_SDL_CD(self))==-1 )
|
106
|
+
rb_raise(eSDLError, "cd pause failed :%s", SDL_GetError());
|
69
107
|
return Qnil;
|
70
108
|
}
|
71
|
-
static VALUE
|
109
|
+
static VALUE CD_resume(VALUE self)
|
72
110
|
{
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
rb_raise(eSDLError,"cd resume failed :%s",SDL_GetError());
|
111
|
+
rb_secure(4);
|
112
|
+
if( SDL_CDResume(Get_SDL_CD(self))==-1 )
|
113
|
+
rb_raise(eSDLError, "cd resume failed :%s", SDL_GetError());
|
77
114
|
return Qnil;
|
78
115
|
}
|
79
|
-
static VALUE
|
116
|
+
static VALUE CD_stop(VALUE self)
|
80
117
|
{
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
rb_raise(eSDLError,"cd pause failed :%s",SDL_GetError());
|
118
|
+
rb_secure(4);
|
119
|
+
if( SDL_CDStop(Get_SDL_CD(self))==-1 )
|
120
|
+
rb_raise(eSDLError, "cd pause failed :%s", SDL_GetError());
|
85
121
|
return Qnil;
|
86
122
|
}
|
87
|
-
static VALUE
|
123
|
+
static VALUE CD_eject(VALUE self)
|
88
124
|
{
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
rb_raise(eSDLError,"cd eject failed :%s",SDL_GetError());
|
125
|
+
rb_secure(4);
|
126
|
+
if( SDL_CDEject(Get_SDL_CD(self))==-1 )
|
127
|
+
rb_raise(eSDLError, "cd eject failed :%s", SDL_GetError());
|
93
128
|
return Qnil;
|
94
129
|
}
|
95
130
|
|
96
|
-
static VALUE
|
131
|
+
static VALUE CD_numTracks(VALUE self)
|
97
132
|
{
|
98
|
-
|
99
|
-
Data_Get_Struct(obj,SDL_CD,cd);
|
100
|
-
return INT2NUM(cd->numtracks);
|
133
|
+
return INT2NUM(Get_SDL_CD(self)->numtracks);
|
101
134
|
}
|
102
|
-
static VALUE
|
135
|
+
static VALUE CD_currentTrack(VALUE self)
|
103
136
|
{
|
104
|
-
|
105
|
-
Data_Get_Struct(obj,SDL_CD,cd);
|
106
|
-
return INT2NUM(cd->cur_track);
|
137
|
+
return INT2NUM(Get_SDL_CD(self)->cur_track);
|
107
138
|
}
|
108
|
-
static VALUE
|
139
|
+
static VALUE CD_currentFrame(VALUE self)
|
109
140
|
{
|
110
|
-
|
111
|
-
Data_Get_Struct(obj,SDL_CD,cd);
|
112
|
-
return INT2NUM(cd->cur_frame);
|
141
|
+
return INT2NUM(Get_SDL_CD(self)->cur_frame);
|
113
142
|
}
|
114
|
-
static VALUE
|
143
|
+
static VALUE CD_trackType(VALUE self, VALUE track)
|
115
144
|
{
|
116
|
-
|
117
|
-
int index=NUM2INT(track);
|
118
|
-
Data_Get_Struct(obj,SDL_CD,cd);
|
119
|
-
return INT2FIX(cd->track[index].type);
|
145
|
+
return INT2FIX(Get_SDL_CD(self)->track[NUM2INT(track)].type);
|
120
146
|
}
|
121
|
-
static VALUE
|
147
|
+
static VALUE CD_trackLength(VALUE self, VALUE track)
|
122
148
|
{
|
123
|
-
|
124
|
-
int index=NUM2INT(track);
|
125
|
-
Data_Get_Struct(obj,SDL_CD,cd);
|
126
|
-
return INT2FIX(cd->track[index].length);
|
149
|
+
return INT2FIX(Get_SDL_CD(self)->track[NUM2INT(track)].length);
|
127
150
|
}
|
128
151
|
|
129
|
-
static VALUE
|
152
|
+
static VALUE CD_s_framesToMSF(VALUE klass, VALUE frames)
|
130
153
|
{
|
131
154
|
int m, s, f;
|
132
155
|
FRAMES_TO_MSF(NUM2INT(frames), &m, &s, &f);
|
133
156
|
return rb_ary_new3(3, INT2FIX(m), INT2FIX(s), INT2FIX(f));
|
134
157
|
}
|
135
|
-
static VALUE
|
158
|
+
static VALUE CD_s_MSFToFrames(VALUE klass, VALUE m, VALUE s, VALUE f)
|
136
159
|
{
|
137
160
|
return INT2FIX(MSF_TO_FRAMES(NUM2INT(m),NUM2INT(s),NUM2INT(f)));
|
138
161
|
}
|
139
162
|
|
140
|
-
|
163
|
+
void rubysdl_init_CD(VALUE mSDL)
|
141
164
|
{
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
165
|
+
cCD = rb_define_class_under(mSDL, "CD", rb_cObject);
|
166
|
+
|
167
|
+
rb_define_alloc_func(cCD, CD_s_alloc);
|
168
|
+
rb_define_private_method(cCD, "initialize", CD_initialize, 1);
|
169
|
+
|
170
|
+
rb_define_singleton_method(cCD, "numDrive", CD_s_numDrive, 0);
|
171
|
+
rb_define_singleton_method(cCD, "indexName", CD_s_name, 1);
|
172
|
+
rb_define_singleton_method(cCD, "open", CD_s_open, 1);
|
173
|
+
rb_define_singleton_method(cCD, "framesToMSF", CD_s_framesToMSF,1);
|
174
|
+
rb_define_singleton_method(cCD,"MSFToFrames",CD_s_MSFToFrames,3);
|
175
|
+
rb_define_method(cCD, "status", CD_status, 0);
|
176
|
+
rb_define_method(cCD, "play", CD_play, 2);
|
177
|
+
rb_define_method(cCD, "playTracks", CD_playTracks, 4);
|
178
|
+
rb_define_method(cCD, "pause", CD_pause, 0);
|
179
|
+
rb_define_method(cCD, "resume", CD_resume, 0);
|
180
|
+
rb_define_method(cCD, "stop", CD_stop, 0);
|
181
|
+
rb_define_method(cCD, "eject", CD_eject, 0);
|
182
|
+
|
183
|
+
rb_define_method(cCD, "numTracks", CD_numTracks, 0);
|
184
|
+
rb_define_method(cCD, "currentTrack", CD_currentTrack, 0);
|
185
|
+
rb_define_method(cCD, "currentFrame", CD_currentFrame, 0);
|
186
|
+
rb_define_method(cCD, "trackType", CD_trackType, 1);
|
187
|
+
rb_define_method(cCD, "trackLength", CD_trackLength, 1);
|
188
|
+
|
147
189
|
|
148
|
-
rb_define_const(cCD,"
|
149
|
-
rb_define_const(cCD,"
|
150
|
-
|
151
|
-
rb_define_const(cCD,"
|
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);
|
190
|
+
rb_define_const(cCD, "TRAYEMPTY", INT2NUM(CD_TRAYEMPTY));
|
191
|
+
rb_define_const(cCD, "STOPPED", INT2NUM(CD_STOPPED));
|
192
|
+
rb_define_const(cCD, "PLAYING", INT2NUM(CD_PLAYING));
|
193
|
+
rb_define_const(cCD, "PAUSED", INT2NUM(CD_PAUSED));
|
194
|
+
rb_define_const(cCD, "ERROR", INT2NUM(CD_ERROR));
|
174
195
|
|
175
|
-
|
196
|
+
rb_define_const(cCD, "AUDIO_TRACK", UINT2NUM(SDL_AUDIO_TRACK));
|
197
|
+
rb_define_const(cCD, "DATA_TRACK", UINT2NUM(SDL_DATA_TRACK));
|
198
|
+
rb_define_const(cCD, "FPS", UINT2NUM(CD_FPS));
|
176
199
|
}
|