rubysdl 1.3.1 → 2.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/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/rubysdl_video.c
CHANGED
@@ -19,17 +19,76 @@
|
|
19
19
|
*/
|
20
20
|
#include "rubysdl.h"
|
21
21
|
|
22
|
-
|
22
|
+
static VALUE cScreen = Qnil;
|
23
|
+
static VALUE cPixelFormat = Qnil;
|
24
|
+
static VALUE cVideoInfo = Qnil;
|
25
|
+
static VALUE cSurface = Qnil;
|
26
|
+
|
27
|
+
typedef struct {
|
28
|
+
SDL_Surface* surface;
|
29
|
+
} Surface;
|
30
|
+
|
31
|
+
DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
|
32
|
+
DEFINE_GET_STRUCT(SDL_PixelFormat, Get_PixelFormat, cPixelFormat, "SDL::PixelFormat");
|
33
|
+
|
34
|
+
SDL_Surface* Get_SDL_Surface(VALUE obj)
|
23
35
|
{
|
24
|
-
|
25
|
-
|
36
|
+
Surface* sur = GetSurface(obj);
|
37
|
+
if(sur->surface == NULL)
|
38
|
+
rb_raise(eSDLError, "Surface is already destroyed");
|
39
|
+
return sur->surface;
|
40
|
+
}
|
41
|
+
|
42
|
+
SDL_PixelFormat* Get_SDL_PixelFormat(VALUE obj)
|
43
|
+
{
|
44
|
+
if(rb_obj_is_kind_of(obj, cSurface)){
|
45
|
+
return Get_SDL_Surface(obj)->format;
|
46
|
+
}else{
|
47
|
+
return Get_PixelFormat(obj);
|
26
48
|
}
|
27
49
|
}
|
50
|
+
|
51
|
+
static void Surface_free(Surface* sur)
|
52
|
+
{
|
53
|
+
if(!rubysdl_is_quit() && sur->surface)
|
54
|
+
SDL_FreeSurface(sur->surface);
|
55
|
+
free(sur);
|
56
|
+
}
|
57
|
+
|
58
|
+
static void PixelFormat_free(SDL_PixelFormat* format)
|
59
|
+
{
|
60
|
+
if(format->palette){
|
61
|
+
free(format->palette->colors);
|
62
|
+
free(format->palette);
|
63
|
+
}
|
64
|
+
free(format);
|
65
|
+
}
|
66
|
+
|
67
|
+
static VALUE Surface_s_alloc(VALUE klass)
|
68
|
+
{
|
69
|
+
Surface* sur = ALLOC(Surface);
|
70
|
+
sur->surface = NULL;
|
71
|
+
return Data_Wrap_Struct(klass, 0, Surface_free, sur);
|
72
|
+
}
|
73
|
+
|
74
|
+
VALUE Surface_create(SDL_Surface* surface)
|
75
|
+
{
|
76
|
+
VALUE newobj = Surface_s_alloc(cSurface);
|
77
|
+
GetSurface(newobj)->surface = surface;
|
78
|
+
return newobj;
|
79
|
+
}
|
80
|
+
|
81
|
+
static VALUE Screen_create(SDL_Surface* surface)
|
82
|
+
{
|
83
|
+
VALUE newobj = Surface_s_alloc(cScreen);
|
84
|
+
GetSurface(newobj)->surface = surface;
|
85
|
+
return newobj;
|
86
|
+
}
|
28
87
|
|
29
88
|
Uint32 VALUE2COLOR(VALUE color,SDL_PixelFormat *format)
|
30
89
|
{
|
31
90
|
if( rb_obj_is_kind_of( color, rb_cArray ) ){
|
32
|
-
switch(
|
91
|
+
switch( RARRAY_LEN(color) ){
|
33
92
|
case 3:
|
34
93
|
return SDL_MapRGB(format,
|
35
94
|
NUM2UINT(rb_ary_entry(color,0)),
|
@@ -49,31 +108,34 @@ Uint32 VALUE2COLOR(VALUE color,SDL_PixelFormat *format)
|
|
49
108
|
}
|
50
109
|
}
|
51
110
|
|
52
|
-
static VALUE
|
111
|
+
static VALUE Screen_s_get(VALUE klass)
|
53
112
|
{
|
54
113
|
SDL_Surface *surface;
|
114
|
+
rb_secure(4);
|
55
115
|
surface = SDL_GetVideoSurface();
|
56
116
|
if(surface==NULL)
|
57
117
|
rb_raise(eSDLError,"Couldn't get video surface: %s",SDL_GetError());
|
58
|
-
return
|
118
|
+
return Screen_create(surface);
|
59
119
|
}
|
60
120
|
|
61
|
-
static VALUE
|
121
|
+
static VALUE Screen_s_driverName(VALUE klass)
|
62
122
|
{
|
63
123
|
char namebuf[256];
|
124
|
+
rb_secure(4);
|
64
125
|
if(SDL_VideoDriverName(namebuf, sizeof(namebuf)) == NULL) {
|
65
126
|
rb_raise(eSDLError, "SDL is not initialized yet: %s", SDL_GetError());
|
66
127
|
}
|
67
128
|
return rb_str_new2( namebuf );
|
68
129
|
}
|
69
130
|
|
70
|
-
static VALUE
|
131
|
+
static VALUE Screen_s_listModes(VALUE klass,VALUE flags)
|
71
132
|
{
|
72
133
|
SDL_Rect **modes;
|
73
134
|
int i;
|
74
|
-
VALUE
|
75
|
-
|
76
|
-
|
135
|
+
VALUE array;
|
136
|
+
|
137
|
+
rb_secure(4);
|
138
|
+
modes = SDL_ListModes(NULL,NUM2UINT(flags));
|
77
139
|
|
78
140
|
if( modes == NULL )
|
79
141
|
return Qnil;/* no modes available */
|
@@ -81,61 +143,62 @@ static VALUE sdl_listModes(VALUE mod,VALUE flags)
|
|
81
143
|
return Qtrue;/* all resolutions available */
|
82
144
|
|
83
145
|
/* available modes into modesArray */
|
84
|
-
|
146
|
+
array = rb_ary_new();
|
85
147
|
|
86
148
|
for(i=0;modes[i]!=NULL;++i){
|
87
|
-
rb_ary_push(
|
88
|
-
|
149
|
+
rb_ary_push(array,
|
150
|
+
rb_ary_new3(2, INT2NUM(modes[i]->w), INT2NUM(modes[i]->h)));
|
89
151
|
}
|
90
|
-
return
|
152
|
+
return array;
|
91
153
|
}
|
92
154
|
|
93
|
-
static VALUE
|
94
|
-
|
155
|
+
static VALUE Screen_s_checkMode(VALUE klass,VALUE w,VALUE h,VALUE bpp,
|
156
|
+
VALUE flags)
|
95
157
|
{
|
96
|
-
|
97
|
-
|
158
|
+
rb_secure(4);
|
159
|
+
return INT2FIX(SDL_VideoModeOK(NUM2INT(w),NUM2INT(h),NUM2INT(bpp),
|
160
|
+
NUM2UINT(flags)));
|
98
161
|
}
|
99
|
-
|
162
|
+
|
163
|
+
static VALUE Screen_s_info(VALUE klass)
|
100
164
|
{
|
101
165
|
const SDL_VideoInfo *info;
|
102
166
|
VALUE obj;
|
167
|
+
rb_secure(4);
|
168
|
+
|
103
169
|
info = SDL_GetVideoInfo();
|
104
170
|
if(info==NULL)
|
105
171
|
rb_raise(eSDLError,"Couldn't get video information");
|
106
172
|
obj=rb_obj_alloc(cVideoInfo);
|
107
|
-
rb_iv_set(obj,"@hw_available",
|
108
|
-
rb_iv_set(obj,"@wm_available",
|
109
|
-
rb_iv_set(obj,"@blit_hw",
|
110
|
-
rb_iv_set(obj,"@blit_hw_CC",
|
111
|
-
rb_iv_set(obj,"@blit_hw_A",
|
112
|
-
rb_iv_set(obj,"@blit_sw",
|
113
|
-
rb_iv_set(obj,"@blit_sw_CC",
|
114
|
-
rb_iv_set(obj,"@blit_sw_A",
|
115
|
-
rb_iv_set(obj,"@blit_fill",
|
173
|
+
rb_iv_set(obj,"@hw_available",INT2BOOL(info->hw_available));
|
174
|
+
rb_iv_set(obj,"@wm_available",INT2BOOL(info->wm_available));
|
175
|
+
rb_iv_set(obj,"@blit_hw",INT2BOOL(info->blit_hw));
|
176
|
+
rb_iv_set(obj,"@blit_hw_CC",INT2BOOL(info->blit_hw_CC));
|
177
|
+
rb_iv_set(obj,"@blit_hw_A",INT2BOOL(info->blit_hw_A));
|
178
|
+
rb_iv_set(obj,"@blit_sw",INT2BOOL(info->blit_sw));
|
179
|
+
rb_iv_set(obj,"@blit_sw_CC",INT2BOOL(info->blit_sw_CC));
|
180
|
+
rb_iv_set(obj,"@blit_sw_A",INT2BOOL(info->blit_sw_A));
|
181
|
+
rb_iv_set(obj,"@blit_fill",INT2BOOL(info->blit_fill));
|
116
182
|
rb_iv_set(obj,"@video_mem",UINT2NUM(info->video_mem));
|
117
183
|
rb_iv_set(obj,"@bpp",UINT2NUM(info->vfmt->BitsPerPixel));
|
118
184
|
return obj;
|
119
185
|
}
|
120
186
|
|
121
187
|
|
122
|
-
static VALUE
|
188
|
+
static VALUE Screen_updateRect(VALUE self,VALUE x,VALUE y,VALUE w,VALUE h)
|
123
189
|
{
|
124
|
-
|
125
|
-
|
126
|
-
|
190
|
+
rb_secure(4);
|
191
|
+
SDL_UpdateRect(Get_SDL_Surface(self),
|
192
|
+
NUM2INT(x),NUM2INT(y),NUM2INT(w),NUM2INT(h));
|
127
193
|
return Qnil;
|
128
194
|
}
|
129
195
|
|
130
|
-
static VALUE
|
196
|
+
static VALUE Screen_updateRects(int argc, VALUE *argv, VALUE self)
|
131
197
|
{
|
132
|
-
SDL_Surface *screen;
|
133
198
|
SDL_Rect* rects;
|
134
199
|
int i;
|
135
|
-
|
136
|
-
Data_Get_Struct(obj,SDL_Surface,screen);
|
137
|
-
rects = ALLOCA_N(SDL_Rect, argc);
|
138
200
|
|
201
|
+
rects = ALLOCA_N(SDL_Rect, argc);
|
139
202
|
for (i=0; i<argc; i++) {
|
140
203
|
rects[i].x = NUM2INT(rb_ary_entry(argv[i], 0));
|
141
204
|
rects[i].y = NUM2INT(rb_ary_entry(argv[i], 1));
|
@@ -143,54 +206,56 @@ static VALUE sdl_updateRects(int argc, VALUE *argv, VALUE obj)
|
|
143
206
|
rects[i].h = NUM2INT(rb_ary_entry(argv[i], 3));
|
144
207
|
}
|
145
208
|
|
146
|
-
SDL_UpdateRects(
|
209
|
+
SDL_UpdateRects(Get_SDL_Surface(self), argc, rects);
|
147
210
|
return Qnil;
|
148
211
|
}
|
149
212
|
|
150
|
-
static VALUE
|
213
|
+
static VALUE Screen_flip(VALUE self)
|
151
214
|
{
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
rb_raise( eSDLError,"flip fail : %s",SDL_GetError() );
|
215
|
+
rb_secure(4);
|
216
|
+
if( SDL_Flip(Get_SDL_Surface(self)) < 0 ){
|
217
|
+
rb_raise(eSDLError,"flip fail : %s",SDL_GetError());
|
156
218
|
}
|
157
219
|
return Qnil;
|
158
220
|
}
|
159
221
|
|
160
|
-
static VALUE
|
222
|
+
static VALUE Screen_toggleFullScreen(VALUE self)
|
161
223
|
{
|
162
|
-
|
163
|
-
|
164
|
-
if( SDL_WM_ToggleFullScreen(screen)==0 ){
|
224
|
+
rb_secure(4);
|
225
|
+
if( SDL_WM_ToggleFullScreen(Get_SDL_Surface(self)) == 0 ){
|
165
226
|
rb_raise( eSDLError,"toggle full screen fail : %s", SDL_GetError() );
|
166
227
|
}
|
167
228
|
return Qnil;
|
168
229
|
}
|
169
230
|
|
170
|
-
static VALUE
|
171
|
-
|
231
|
+
static VALUE Screen_s_open(VALUE klass,VALUE w,VALUE h,VALUE bpp,
|
232
|
+
VALUE flags)
|
172
233
|
{
|
173
234
|
SDL_Surface *screen;
|
235
|
+
rb_secure(4);
|
174
236
|
screen=SDL_SetVideoMode(NUM2INT(w),NUM2INT(h),NUM2INT(bpp),
|
175
237
|
NUM2UINT(flags));
|
176
238
|
if( screen==NULL ){
|
177
239
|
rb_raise(eSDLError,"Cound't set %dx%d %d bpp video mode: %s",
|
178
240
|
NUM2INT(w),NUM2INT(h),NUM2INT(bpp),SDL_GetError());
|
179
241
|
}
|
180
|
-
return
|
242
|
+
return Screen_create(screen);
|
181
243
|
}
|
182
|
-
|
244
|
+
|
245
|
+
static VALUE Screen_s_setGamma(VALUE klass,VALUE rgamma,VALUE ggamma,VALUE bgamma)
|
183
246
|
{
|
247
|
+
rb_secure(4);
|
184
248
|
if(SDL_SetGamma(NUM2DBL(rgamma),NUM2DBL(ggamma),NUM2DBL(bgamma))==-1)
|
185
249
|
rb_raise(eSDLError,"set gamma failed: %s",SDL_GetError());
|
186
250
|
return Qnil;
|
187
251
|
}
|
188
252
|
|
189
|
-
static VALUE
|
253
|
+
static VALUE Screen_s_getGammaRamp(VALUE klass)
|
190
254
|
{
|
191
255
|
Uint16 table[3][256];
|
192
256
|
VALUE ary_table, ary_subtable;
|
193
257
|
int i,j;
|
258
|
+
rb_secure(4);
|
194
259
|
|
195
260
|
if( SDL_GetGammaRamp( table[0], table[1], table[2] ) == -1 ){
|
196
261
|
rb_raise(eSDLError,"cannot get gamma lookup table: %s",SDL_GetError());
|
@@ -207,53 +272,54 @@ static VALUE sdl_getGammaRamp(VALUE mod)
|
|
207
272
|
return ary_table;
|
208
273
|
}
|
209
274
|
|
210
|
-
static VALUE
|
275
|
+
static VALUE Screen_s_setGammaRamp(VALUE klass, VALUE ary_table)
|
211
276
|
{
|
212
277
|
Uint16 table[3][256];
|
213
|
-
VALUE
|
278
|
+
VALUE subtable;
|
214
279
|
int i,j;
|
215
|
-
|
280
|
+
|
281
|
+
rb_secure(4);
|
282
|
+
Check_Type(ary_table, T_ARRAY);
|
283
|
+
|
216
284
|
for( i=0; i<3; ++i ){
|
217
|
-
|
285
|
+
subtable = rb_ary_entry(ary_table, i);
|
286
|
+
Check_Type(subtable, T_ARRAY);
|
218
287
|
for( j=0; j<256; ++j ){
|
219
|
-
table[i][j] = NUM2INT(
|
288
|
+
table[i][j] = NUM2INT(rb_ary_entry(subtable, j));
|
220
289
|
}
|
221
290
|
}
|
222
|
-
if(
|
291
|
+
if(SDL_SetGammaRamp(table[0], table[1], table[2]) == -1){
|
223
292
|
rb_raise(eSDLError,"cannot set gamma lookup table: %s",SDL_GetError());
|
224
293
|
}
|
225
294
|
return Qnil;
|
226
295
|
}
|
227
296
|
|
228
|
-
static VALUE
|
229
|
-
|
297
|
+
static VALUE Surface_s_create(VALUE klass,VALUE flags,VALUE w,VALUE h,
|
298
|
+
VALUE pixel_format)
|
230
299
|
{
|
231
|
-
SDL_Surface
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
if( newSurface==NULL ){
|
245
|
-
rb_raise( eSDLError,"Couldn't Create Surface: %s",SDL_GetError() );
|
246
|
-
}
|
247
|
-
return Data_Wrap_Struct(class,0,sdl_freeSurface,newSurface);
|
300
|
+
SDL_Surface* surface;
|
301
|
+
SDL_PixelFormat* format;
|
302
|
+
|
303
|
+
rb_secure(4);
|
304
|
+
format = Get_SDL_PixelFormat(pixel_format);
|
305
|
+
surface = SDL_CreateRGBSurface(NUM2UINT(flags),NUM2INT(w),NUM2INT(h),
|
306
|
+
format->BitsPerPixel,
|
307
|
+
format->Rmask,format->Gmask,
|
308
|
+
format->Bmask,format->Amask);
|
309
|
+
if(surface == NULL)
|
310
|
+
rb_raise(eSDLError,"Couldn't Create Surface: %s",SDL_GetError());
|
311
|
+
|
312
|
+
return Surface_create(surface);
|
248
313
|
}
|
249
314
|
|
250
|
-
static VALUE
|
251
|
-
|
252
|
-
|
253
|
-
|
315
|
+
static VALUE Surface_s_createWithFormat(VALUE klass,VALUE flags,VALUE w,
|
316
|
+
VALUE h,VALUE depth,VALUE Rmask,
|
317
|
+
VALUE Gmask,VALUE Bmask,
|
318
|
+
VALUE Amask)
|
254
319
|
{
|
255
320
|
SDL_Surface *surface;
|
256
321
|
|
322
|
+
rb_secure(4);
|
257
323
|
surface = SDL_CreateRGBSurface(NUM2UINT(flags),NUM2INT(w),NUM2INT(h),
|
258
324
|
NUM2UINT(depth),NUM2UINT(Rmask),
|
259
325
|
NUM2UINT(Gmask),NUM2UINT(Bmask),
|
@@ -261,21 +327,21 @@ static VALUE sdl_createSurfaceWithFormat(VALUE class,VALUE flags,VALUE w,
|
|
261
327
|
if( surface == NULL ){
|
262
328
|
rb_raise(eSDLError,"Couldn't Create Surface: %s",SDL_GetError());
|
263
329
|
}
|
264
|
-
return
|
330
|
+
return Surface_create(surface);
|
265
331
|
}
|
266
332
|
|
267
333
|
|
268
|
-
static VALUE
|
269
|
-
|
270
|
-
|
271
|
-
|
334
|
+
static VALUE Surface_s_createFrom(VALUE klass,VALUE pixels,VALUE w,
|
335
|
+
VALUE h,VALUE depth,VALUE pitch,
|
336
|
+
VALUE Rmask,VALUE Gmask,VALUE Bmask,
|
337
|
+
VALUE Amask)
|
272
338
|
{
|
273
339
|
SDL_Surface *surface;
|
274
340
|
void* pixel_data;
|
275
341
|
|
276
342
|
StringValue(pixels);
|
277
|
-
pixel_data = ALLOC_N(char,
|
278
|
-
memcpy(pixel_data,
|
343
|
+
pixel_data = ALLOC_N(char, RSTRING_LEN(pixels));
|
344
|
+
memcpy(pixel_data,RSTRING_PTR(pixels),RSTRING_LEN(pixels));
|
279
345
|
|
280
346
|
surface = SDL_CreateRGBSurfaceFrom(pixel_data,NUM2INT(w),NUM2INT(h),
|
281
347
|
NUM2UINT(depth),NUM2INT(pitch),
|
@@ -285,21 +351,24 @@ static VALUE sdl_createSurfaceFrom(VALUE class,VALUE pixels,VALUE w,
|
|
285
351
|
rb_raise(eSDLError,"Couldn't Create Surface: %s",SDL_GetError());
|
286
352
|
}
|
287
353
|
surface->flags &= ~SDL_PREALLOC;
|
288
|
-
return
|
354
|
+
return Surface_create(surface);
|
289
355
|
}
|
290
356
|
|
291
|
-
static VALUE
|
357
|
+
static VALUE Surface_s_loadBMP(VALUE klass,VALUE filename)
|
292
358
|
{
|
293
359
|
SDL_Surface *image;
|
294
|
-
|
295
|
-
|
360
|
+
rb_secure(4);
|
361
|
+
SafeStringValue(filename);
|
362
|
+
|
363
|
+
image = SDL_LoadBMP(RSTRING_PTR(filename));
|
364
|
+
if(image == NULL){
|
296
365
|
rb_raise(eSDLError,"Couldn't Load BMP file %s : %s",
|
297
|
-
|
366
|
+
RSTRING_PTR(filename),SDL_GetError());
|
298
367
|
}
|
299
|
-
return
|
368
|
+
return Surface_create(image);
|
300
369
|
}
|
301
370
|
|
302
|
-
static VALUE
|
371
|
+
static VALUE Surface_s_loadBMPFromIO(VALUE class, VALUE io)
|
303
372
|
{
|
304
373
|
volatile VALUE guard = io;
|
305
374
|
SDL_Surface* image;
|
@@ -307,45 +376,94 @@ static VALUE sdl_loadBMPFromIO(VALUE class, VALUE io)
|
|
307
376
|
if(image == NULL)
|
308
377
|
rb_raise(eSDLError, "Couldn't Load BMP file from IO : %s",
|
309
378
|
SDL_GetError());
|
310
|
-
return
|
379
|
+
return Surface_create(image);
|
311
380
|
}
|
312
381
|
|
313
|
-
static VALUE
|
382
|
+
static VALUE Surface_s_loadBMPFromString(VALUE class, VALUE str)
|
314
383
|
{
|
315
|
-
SDL_Surface
|
316
|
-
|
317
|
-
|
318
|
-
|
384
|
+
SDL_Surface* image;
|
385
|
+
rb_secure(4);
|
386
|
+
SafeStringValue(str);
|
387
|
+
|
388
|
+
image = SDL_LoadBMP_RW(SDL_RWFromConstMem(RSTRING_PTR(str),
|
389
|
+
RSTRING_LEN(str)),
|
390
|
+
1);
|
391
|
+
if(image == NULL)
|
392
|
+
rb_raise(eSDLError, "Couldn't Load BMP file from String : %s",
|
393
|
+
SDL_GetError());
|
394
|
+
return Surface_create(image);
|
395
|
+
}
|
396
|
+
|
397
|
+
static VALUE Surface_saveBMP(VALUE self,VALUE filename)
|
398
|
+
{
|
399
|
+
rb_secure(4);
|
400
|
+
SafeStringValue(filename);
|
401
|
+
if( SDL_SaveBMP(Get_SDL_Surface(self), RSTRING_PTR(filename))==-1 ){
|
402
|
+
rb_raise(eSDLError,"cannot save %s: %s",RSTRING_PTR(filename),SDL_GetError());
|
319
403
|
}
|
320
404
|
return Qnil;
|
321
405
|
}
|
406
|
+
|
407
|
+
static VALUE Surface_destroy(VALUE self)
|
408
|
+
{
|
409
|
+
Surface* sur = GetSurface(self);
|
410
|
+
if(!rubysdl_is_quit() && sur->surface)
|
411
|
+
SDL_FreeSurface(sur->surface);
|
412
|
+
sur->surface = NULL;
|
413
|
+
return Qnil;
|
414
|
+
}
|
415
|
+
|
416
|
+
static VALUE Surface_format(VALUE self)
|
417
|
+
{
|
418
|
+
SDL_Surface* surface = Get_SDL_Surface(self);
|
419
|
+
SDL_PixelFormat* format = ALLOC(SDL_PixelFormat);
|
420
|
+
SDL_Palette* palette;
|
322
421
|
|
323
|
-
|
422
|
+
if(surface->format->palette){
|
423
|
+
palette = ALLOC(SDL_Palette);
|
424
|
+
palette->ncolors = surface->format->palette->ncolors;
|
425
|
+
palette->colors = ALLOC_N(SDL_Color, surface->format->palette->ncolors);
|
426
|
+
memcpy(palette->colors, surface->format->palette->colors,
|
427
|
+
surface->format->palette->ncolors * sizeof(SDL_Color));
|
428
|
+
}else{
|
429
|
+
palette = NULL;
|
430
|
+
}
|
431
|
+
|
432
|
+
*format = *(surface->format);
|
433
|
+
format->palette = palette;
|
434
|
+
|
435
|
+
return Data_Wrap_Struct(cPixelFormat,0,PixelFormat_free,format);
|
436
|
+
}
|
437
|
+
|
438
|
+
static VALUE Surface_displayFormat(VALUE self)
|
324
439
|
{
|
325
|
-
SDL_Surface *
|
326
|
-
|
327
|
-
|
328
|
-
|
440
|
+
SDL_Surface *result;
|
441
|
+
|
442
|
+
rb_secure(4);
|
443
|
+
result = SDL_DisplayFormat(Get_SDL_Surface(self));
|
444
|
+
if(result==NULL){
|
329
445
|
rb_raise(eSDLError,"Couldn't convert surface format: %s",SDL_GetError());
|
330
446
|
}
|
331
|
-
return
|
447
|
+
return Surface_create(result);
|
332
448
|
}
|
333
449
|
|
334
|
-
static VALUE
|
450
|
+
static VALUE Surface_displayFormatAlpha(VALUE self)
|
335
451
|
{
|
336
|
-
SDL_Surface *
|
337
|
-
|
338
|
-
|
339
|
-
|
452
|
+
SDL_Surface *result;
|
453
|
+
|
454
|
+
rb_secure(4);
|
455
|
+
result = SDL_DisplayFormatAlpha(Get_SDL_Surface(self));
|
456
|
+
if(result==NULL){
|
340
457
|
rb_raise(eSDLError,"Couldn't convert surface format: %s",SDL_GetError());
|
341
458
|
}
|
342
|
-
return
|
459
|
+
return Surface_create(result);
|
343
460
|
}
|
344
461
|
|
345
|
-
static VALUE
|
462
|
+
static VALUE Surface_setColorKey(VALUE self,VALUE flag,VALUE key)
|
346
463
|
{
|
347
|
-
SDL_Surface *surface;
|
348
|
-
|
464
|
+
SDL_Surface *surface = Get_SDL_Surface(self);
|
465
|
+
rb_secure(4);
|
466
|
+
|
349
467
|
if( SDL_SetColorKey(surface,NUM2UINT(flag),VALUE2COLOR(key,surface->format))
|
350
468
|
< 0 ){
|
351
469
|
rb_raise(eSDLError,"setColorKey failed: %s",SDL_GetError());
|
@@ -353,117 +471,112 @@ static VALUE sdl_setColorKey(VALUE obj,VALUE flag,VALUE key)
|
|
353
471
|
return Qnil;
|
354
472
|
}
|
355
473
|
|
474
|
+
static VALUE zero_rect_p(SDL_Rect rect)
|
475
|
+
{
|
476
|
+
return rect.x == 0 && rect.y == 0 && rect.w == 0 && rect.h == 0;
|
477
|
+
}
|
478
|
+
|
356
479
|
/* return 0 if succeed, return -2 video memory lost (on Direct X)*/
|
357
|
-
static VALUE
|
358
|
-
|
359
|
-
|
480
|
+
static VALUE Surface_s_blit(VALUE klass,VALUE src,VALUE srcX,VALUE srcY,
|
481
|
+
VALUE srcW,VALUE srcH,VALUE dst,VALUE destX,
|
482
|
+
VALUE destY)
|
360
483
|
{
|
361
|
-
SDL_Surface *
|
362
|
-
SDL_Rect
|
484
|
+
SDL_Surface *src_surface,*dst_surface;
|
485
|
+
SDL_Rect src_rect,dst_rect;
|
486
|
+
SDL_Rect *sr, *dr;
|
363
487
|
int result;
|
364
488
|
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
if (NUM2INT(srcX)==0&&NUM2INT(srcY)==0&&NUM2INT(srcW)==0&&NUM2INT(srcH)==0){
|
373
|
-
if (NUM2INT(destX)==0&&NUM2INT(destY)==0&&NUM2INT(srcW)==0&&NUM2INT(srcH)==0){
|
374
|
-
result = SDL_BlitSurface(srcSurface,NULL,destSurface,NULL);
|
375
|
-
}else{
|
376
|
-
SetRect(destRect,destX,destY,srcW,srcH);
|
377
|
-
result = SDL_BlitSurface(srcSurface,NULL,destSurface,&destRect);
|
378
|
-
}
|
379
|
-
}else{
|
380
|
-
SetRect(srcRect,srcX,srcY,srcW,srcH);
|
381
|
-
if (NUM2INT(destX)==0&&NUM2INT(destY)==0&&NUM2INT(srcW)==0&&NUM2INT(srcH)==0){
|
382
|
-
result = SDL_BlitSurface(srcSurface,&srcRect,destSurface,NULL);
|
383
|
-
}else{
|
384
|
-
SetRect(destRect,destX,destY,srcW,srcH);
|
385
|
-
result = SDL_BlitSurface(srcSurface,&srcRect,destSurface,&destRect);
|
386
|
-
}
|
387
|
-
}
|
489
|
+
rb_secure(4);
|
490
|
+
SetRect(dst_rect,destX,destY,srcW,srcH);
|
491
|
+
SetRect(src_rect,srcX,srcY,srcW,srcH);
|
492
|
+
|
493
|
+
src_surface = Get_SDL_Surface(src);
|
494
|
+
dst_surface = Get_SDL_Surface(dst);
|
388
495
|
|
496
|
+
sr = (zero_rect_p(src_rect))?NULL:&src_rect;
|
497
|
+
dr = (zero_rect_p(dst_rect))?NULL:&dst_rect;
|
498
|
+
|
499
|
+
result = SDL_BlitSurface(src_surface, sr, dst_surface, dr);
|
500
|
+
|
389
501
|
if( result == -1 ){
|
390
|
-
rb_raise(eSDLError,"
|
502
|
+
rb_raise(eSDLError,"SDL::Surface.blit fail: %s",SDL_GetError());
|
391
503
|
}
|
392
504
|
return INT2NUM(result);
|
393
505
|
}
|
394
506
|
|
395
|
-
static VALUE
|
507
|
+
static VALUE Surface_setAlpha(VALUE self,VALUE flag,VALUE alpha)
|
396
508
|
{
|
397
|
-
|
398
|
-
|
399
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
400
|
-
SDL_SetAlpha(surface,NUM2UINT(flag),NUM2INT(alpha));
|
509
|
+
rb_secure(4);
|
510
|
+
SDL_SetAlpha(Get_SDL_Surface(self),NUM2UINT(flag),NUM2INT(alpha));
|
401
511
|
return Qnil;
|
402
512
|
}
|
403
513
|
|
404
|
-
static VALUE
|
514
|
+
static VALUE Surface_setClipRect(VALUE self,VALUE x,VALUE y,VALUE w,VALUE h)
|
405
515
|
{
|
406
|
-
SDL_Surface *surface;
|
407
516
|
SDL_Rect rect;
|
408
517
|
|
409
|
-
|
518
|
+
rb_secure(4);
|
410
519
|
SetRect(rect,x,y,w,h);
|
411
|
-
SDL_SetClipRect(
|
520
|
+
SDL_SetClipRect(Get_SDL_Surface(self),&rect);
|
412
521
|
return Qnil;
|
413
522
|
}
|
414
523
|
|
415
|
-
static VALUE
|
524
|
+
static VALUE Surface_getClipRect(VALUE self)
|
416
525
|
{
|
417
|
-
SDL_Surface *surface;
|
418
526
|
SDL_Rect rect;
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
ary_rect = rb_ary_new();
|
425
|
-
rb_ary_push( ary_rect, INT2FIX(rect.x) );
|
426
|
-
rb_ary_push( ary_rect, INT2FIX(rect.y) );
|
427
|
-
rb_ary_push( ary_rect, INT2FIX(rect.w) );
|
428
|
-
rb_ary_push( ary_rect, INT2FIX(rect.h) );
|
429
|
-
|
430
|
-
return ary_rect;
|
527
|
+
|
528
|
+
rb_secure(4);
|
529
|
+
SDL_GetClipRect( Get_SDL_Surface(self), &rect );
|
530
|
+
return rb_ary_new3(INT2FIX(rect.x),INT2FIX(rect.y),
|
531
|
+
INT2FIX(rect.w),INT2FIX(rect.h));
|
431
532
|
}
|
432
533
|
|
433
|
-
static VALUE
|
434
|
-
|
534
|
+
static VALUE Surface_fillRect(VALUE self,VALUE x,VALUE y,VALUE w,VALUE h,
|
535
|
+
VALUE color)
|
435
536
|
{
|
436
|
-
SDL_Surface *surface;
|
537
|
+
SDL_Surface *surface = Get_SDL_Surface(self);
|
437
538
|
SDL_Rect rect;
|
438
|
-
|
539
|
+
|
540
|
+
rb_secure(4);
|
439
541
|
SetRect(rect,x,y,w,h);
|
440
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
441
542
|
if( SDL_FillRect(surface,&rect,VALUE2COLOR(color,surface->format)) < 0 ){
|
442
543
|
rb_raise(eSDLError,"fillRect fail: %s",SDL_GetError());
|
443
544
|
}
|
444
545
|
return Qnil;
|
445
546
|
}
|
446
547
|
|
447
|
-
static VALUE
|
548
|
+
static VALUE Surface_h(VALUE self)
|
448
549
|
{
|
449
|
-
|
450
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
451
|
-
return INT2NUM( surface->h );
|
550
|
+
return INT2NUM(Get_SDL_Surface(self)->h);
|
452
551
|
}
|
453
|
-
|
552
|
+
|
553
|
+
static VALUE Surface_w(VALUE self)
|
454
554
|
{
|
455
|
-
|
456
|
-
|
457
|
-
|
555
|
+
return INT2NUM(Get_SDL_Surface(self)->w);
|
556
|
+
}
|
557
|
+
|
558
|
+
static VALUE Surface_getPixel(VALUE self, VALUE x, VALUE y)
|
559
|
+
{
|
560
|
+
return UINT2NUM(rubysdl_getPixel(Get_SDL_Surface(self),
|
561
|
+
NUM2INT(x), NUM2INT(y)));
|
562
|
+
}
|
563
|
+
static VALUE Surface_putPixel(VALUE self, VALUE x, VALUE y, VALUE color)
|
564
|
+
{
|
565
|
+
SDL_Surface* surface = Get_SDL_Surface(self);
|
566
|
+
rubysdl_putPixel(surface,
|
567
|
+
NUM2INT(x), NUM2INT(y), VALUE2COLOR(color,surface->format));
|
568
|
+
return Qnil;
|
458
569
|
}
|
459
570
|
|
460
571
|
/* palette and colormap methods */
|
461
|
-
static void
|
572
|
+
static void check_colors(VALUE colors,VALUE firstcolor)
|
462
573
|
{
|
463
574
|
if( NUM2INT(firstcolor)<0 || NUM2INT(firstcolor)>255 )
|
464
575
|
rb_raise(eSDLError,"firstcolor must be more than 0,less than 255");
|
576
|
+
|
465
577
|
Check_Type(colors,T_ARRAY);
|
466
|
-
|
578
|
+
|
579
|
+
if( RARRAY_LEN(colors)+NUM2INT(firstcolor) > 256 )
|
467
580
|
rb_raise(eSDLError,"colors is too large");
|
468
581
|
}
|
469
582
|
static void set_colors_to_array(VALUE colors,SDL_Color palette[])
|
@@ -471,10 +584,10 @@ static void set_colors_to_array(VALUE colors,SDL_Color palette[])
|
|
471
584
|
VALUE color;
|
472
585
|
int i;
|
473
586
|
|
474
|
-
for( i=0; i <
|
587
|
+
for( i=0; i < RARRAY_LEN(colors); ++i){
|
475
588
|
color = rb_ary_entry(colors,i);
|
476
589
|
Check_Type(color,T_ARRAY);
|
477
|
-
if(
|
590
|
+
if( RARRAY_LEN(color) != 3)
|
478
591
|
rb_raise(rb_eArgError,"a color must be array that has 3 length");
|
479
592
|
palette[i].r = NUM2INT(rb_ary_entry(color,0));
|
480
593
|
palette[i].g = NUM2INT(rb_ary_entry(color,1));
|
@@ -483,229 +596,281 @@ static void set_colors_to_array(VALUE colors,SDL_Color palette[])
|
|
483
596
|
|
484
597
|
}
|
485
598
|
|
486
|
-
static VALUE
|
599
|
+
static VALUE Surface_setPalette(VALUE self,VALUE flags,
|
600
|
+
VALUE colors,VALUE firstcolor)
|
487
601
|
{
|
488
|
-
SDL_Surface *surface;
|
489
602
|
SDL_Color palette[256];
|
490
603
|
|
491
|
-
|
492
|
-
|
493
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
494
|
-
|
604
|
+
check_colors(colors,firstcolor);
|
495
605
|
set_colors_to_array(colors,palette);
|
496
|
-
|
497
|
-
|
498
|
-
|
606
|
+
|
607
|
+
rb_secure(4);
|
608
|
+
return INT2BOOL(SDL_SetPalette(Get_SDL_Surface(self), NUM2UINT(flags), palette,
|
609
|
+
NUM2INT(firstcolor), RARRAY_LEN(colors)));
|
499
610
|
}
|
500
611
|
|
501
|
-
static VALUE
|
612
|
+
static VALUE Surface_setColors(VALUE self,VALUE colors,VALUE firstcolor)
|
502
613
|
{
|
503
|
-
SDL_Surface *surface;
|
504
614
|
SDL_Color palette[256];
|
505
615
|
|
506
|
-
|
507
|
-
|
616
|
+
rb_secure(4);
|
617
|
+
check_colors(colors,firstcolor);
|
508
618
|
set_colors_to_array(colors,palette);
|
509
|
-
return
|
510
|
-
|
619
|
+
return INT2BOOL(SDL_SetColors(Get_SDL_Surface(self), palette,
|
620
|
+
NUM2INT(firstcolor), RARRAY_LEN(colors)));
|
511
621
|
}
|
512
622
|
|
513
|
-
static VALUE
|
623
|
+
static VALUE PixelFormat_pallete(VALUE self)
|
514
624
|
{
|
515
|
-
|
625
|
+
SDL_PixelFormat* format = Get_SDL_PixelFormat(self);
|
516
626
|
int i;
|
517
627
|
VALUE palette;
|
518
628
|
SDL_Color *colors;
|
519
629
|
VALUE color;
|
520
|
-
|
521
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
522
630
|
|
523
|
-
if(
|
631
|
+
if(format->palette == NULL)
|
524
632
|
return Qnil;
|
525
633
|
|
526
634
|
palette = rb_ary_new();
|
527
|
-
colors =
|
528
|
-
|
529
|
-
for( i=0; i <
|
530
|
-
color = rb_ary_new3(
|
531
|
-
rb_ary_push(
|
635
|
+
colors = format->palette->colors;
|
636
|
+
|
637
|
+
for( i=0; i < format->palette->ncolors; ++i ){
|
638
|
+
color = rb_ary_new3(3, INT2NUM(colors[i].r), INT2NUM(colors[i].g), INT2NUM(colors[i].b));
|
639
|
+
rb_ary_push(palette, color);
|
532
640
|
}
|
533
641
|
return palette;
|
534
642
|
}
|
535
643
|
|
536
644
|
/* surface lock methods */
|
537
|
-
static VALUE
|
645
|
+
static VALUE Surface_mustlock_p(VALUE self)
|
538
646
|
{
|
539
|
-
|
540
|
-
|
541
|
-
return BOOL( SDL_MUSTLOCK(surface) );
|
647
|
+
rb_secure(4);
|
648
|
+
return INT2BOOL(SDL_MUSTLOCK(Get_SDL_Surface(self)));
|
542
649
|
}
|
543
|
-
static VALUE
|
650
|
+
static VALUE Surface_lock(VALUE self)
|
544
651
|
{
|
545
|
-
|
546
|
-
|
547
|
-
return INT2FIX(SDL_LockSurface(surface));
|
652
|
+
rb_secure(4);
|
653
|
+
return INT2FIX(SDL_LockSurface(Get_SDL_Surface(self)));
|
548
654
|
}
|
549
|
-
static VALUE
|
655
|
+
static VALUE Surface_unlock(VALUE self)
|
550
656
|
{
|
551
|
-
|
552
|
-
|
553
|
-
SDL_UnlockSurface(surface);
|
657
|
+
rb_secure(4);
|
658
|
+
SDL_UnlockSurface(Get_SDL_Surface(self));
|
554
659
|
return Qnil;
|
555
660
|
}
|
556
661
|
|
557
662
|
/* methods to get infomation from SDL_PixelFormat */
|
558
|
-
static VALUE
|
663
|
+
static VALUE PixelFormat_mapRGB(VALUE self,VALUE r,VALUE g,VALUE b)
|
559
664
|
{
|
560
|
-
|
561
|
-
|
562
|
-
return UINT2NUM( SDL_MapRGB( surface->format,NUM2INT(r),NUM2INT(g),
|
563
|
-
NUM2INT(b) ) );
|
665
|
+
return UINT2NUM(SDL_MapRGB(Get_SDL_PixelFormat(self),NUM2INT(r),NUM2INT(g),
|
666
|
+
NUM2INT(b)));
|
564
667
|
}
|
565
|
-
static VALUE
|
668
|
+
static VALUE PixelFormat_mapRGBA(VALUE self,VALUE r,VALUE g,VALUE b,VALUE a)
|
566
669
|
{
|
567
|
-
|
568
|
-
|
569
|
-
return UINT2NUM( SDL_MapRGBA( surface->format,NUM2INT(r),NUM2INT(g),NUM2INT(b),
|
570
|
-
NUM2INT(a) ) );
|
670
|
+
return UINT2NUM(SDL_MapRGBA(Get_SDL_PixelFormat(self),NUM2INT(r),NUM2INT(g),
|
671
|
+
NUM2INT(b),NUM2INT(a)));
|
571
672
|
}
|
572
|
-
static VALUE
|
673
|
+
static VALUE PixelFormat_getRGB(VALUE self,VALUE pixel)
|
573
674
|
{
|
574
|
-
SDL_Surface *surface;
|
575
675
|
Uint8 r,g,b;
|
576
|
-
|
577
|
-
|
578
|
-
return rb_ary_new3( 3,UINT2NUM(r),UINT2NUM(g),UINT2NUM(b) );
|
676
|
+
SDL_GetRGB(NUM2UINT(pixel),Get_SDL_PixelFormat(self),&r,&g,&b);
|
677
|
+
return rb_ary_new3(3,UINT2NUM(r),UINT2NUM(g),UINT2NUM(b));
|
579
678
|
}
|
580
|
-
static VALUE
|
679
|
+
static VALUE PixelFormat_getRGBA(VALUE self,VALUE pixel)
|
581
680
|
{
|
582
|
-
SDL_Surface *surface;
|
583
681
|
Uint8 r,g,b,a;
|
584
|
-
|
585
|
-
|
586
|
-
return rb_ary_new3( 4,UINT2NUM(r),UINT2NUM(g),UINT2NUM(b),UINT2NUM(a) );
|
682
|
+
SDL_GetRGBA(NUM2UINT(pixel),Get_SDL_PixelFormat(self),&r,&g,&b,&a);
|
683
|
+
return rb_ary_new3(4,UINT2NUM(r),UINT2NUM(g),UINT2NUM(b),UINT2NUM(a));
|
587
684
|
}
|
588
|
-
static VALUE
|
685
|
+
static VALUE PixelFormat_bpp(VALUE self)
|
589
686
|
{
|
590
|
-
|
591
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
592
|
-
return INT2FIX(surface->format->BitsPerPixel);
|
687
|
+
return INT2FIX(Get_SDL_PixelFormat(self)->BitsPerPixel);
|
593
688
|
}
|
594
|
-
|
689
|
+
|
690
|
+
static VALUE PixelFormat_colorkey(VALUE self)
|
595
691
|
{
|
596
|
-
|
597
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
598
|
-
return UINT2NUM(surface->format->colorkey);
|
692
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->colorkey);
|
599
693
|
}
|
600
|
-
|
694
|
+
|
695
|
+
static VALUE PixelFormat_alpha(VALUE self)
|
601
696
|
{
|
602
|
-
|
603
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
604
|
-
return UINT2NUM(surface->format->alpha);
|
697
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->alpha);
|
605
698
|
}
|
606
|
-
|
699
|
+
|
700
|
+
static VALUE Surface_flags(VALUE self)
|
607
701
|
{
|
608
|
-
|
609
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
610
|
-
return UINT2NUM(surface->flags);
|
702
|
+
return UINT2NUM(Get_SDL_Surface(self)->flags);
|
611
703
|
}
|
612
|
-
|
704
|
+
|
705
|
+
static VALUE PixelFormat_rmask(VALUE self)
|
613
706
|
{
|
614
|
-
|
615
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
616
|
-
return UINT2NUM(surface->format->Rmask);
|
707
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->Rmask);
|
617
708
|
}
|
618
|
-
|
709
|
+
|
710
|
+
static VALUE PixelFormat_gmask(VALUE self)
|
619
711
|
{
|
620
|
-
|
621
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
622
|
-
return UINT2NUM(surface->format->Gmask);
|
712
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->Gmask);
|
623
713
|
}
|
624
|
-
|
714
|
+
|
715
|
+
static VALUE PixelFormat_bmask(VALUE self)
|
625
716
|
{
|
626
|
-
|
627
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
628
|
-
return UINT2NUM(surface->format->Bmask);
|
717
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->Bmask);
|
629
718
|
}
|
630
|
-
|
719
|
+
|
720
|
+
static VALUE PixelFormat_amask(VALUE self)
|
631
721
|
{
|
632
|
-
|
633
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
634
|
-
return UINT2NUM(surface->format->Amask);
|
722
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->Amask);
|
635
723
|
}
|
636
|
-
|
724
|
+
|
725
|
+
static VALUE PixelFormat_Rloss(VALUE self)
|
637
726
|
{
|
638
|
-
|
639
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
640
|
-
return UINT2NUM(surface->format->Rloss);
|
727
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->Rloss);
|
641
728
|
}
|
642
|
-
static VALUE
|
729
|
+
static VALUE PixelFormat_Gloss(VALUE self)
|
643
730
|
{
|
644
|
-
|
645
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
646
|
-
return UINT2NUM(surface->format->Gloss);
|
731
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->Gloss);
|
647
732
|
}
|
648
|
-
static VALUE
|
733
|
+
static VALUE PixelFormat_Bloss(VALUE self)
|
649
734
|
{
|
650
|
-
|
651
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
652
|
-
return UINT2NUM(surface->format->Bloss);
|
735
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->Rloss);
|
653
736
|
}
|
654
|
-
static VALUE
|
737
|
+
static VALUE PixelFormat_Aloss(VALUE self)
|
655
738
|
{
|
656
|
-
|
657
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
658
|
-
return UINT2NUM(surface->format->Aloss);
|
739
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->Aloss);
|
659
740
|
}
|
660
|
-
|
741
|
+
|
742
|
+
static VALUE PixelFormat_Rshift(VALUE self)
|
661
743
|
{
|
662
|
-
|
663
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
664
|
-
return UINT2NUM(surface->format->Rshift);
|
744
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->Rshift);
|
665
745
|
}
|
666
|
-
static VALUE
|
746
|
+
static VALUE PixelFormat_Gshift(VALUE self)
|
667
747
|
{
|
668
|
-
|
669
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
670
|
-
return UINT2NUM(surface->format->Gshift);
|
748
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->Gshift);
|
671
749
|
}
|
672
|
-
static VALUE
|
750
|
+
static VALUE PixelFormat_Bshift(VALUE self)
|
673
751
|
{
|
674
|
-
|
675
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
676
|
-
return UINT2NUM(surface->format->Bshift);
|
752
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->Bshift);
|
677
753
|
}
|
678
|
-
static VALUE
|
754
|
+
static VALUE PixelFormat_Ashift(VALUE self)
|
679
755
|
{
|
680
|
-
|
681
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
682
|
-
return UINT2NUM(surface->format->Ashift);
|
756
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->Ashift);
|
683
757
|
}
|
684
758
|
|
685
|
-
static VALUE
|
759
|
+
static VALUE Surface_pitch(VALUE self)
|
686
760
|
{
|
687
|
-
|
688
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
689
|
-
return UINT2NUM(surface->pitch);
|
761
|
+
return UINT2NUM(Get_SDL_Surface(self)->pitch);
|
690
762
|
}
|
691
|
-
static VALUE
|
763
|
+
static VALUE PixelFormat_bytesPerPixel(VALUE self)
|
692
764
|
{
|
693
|
-
|
694
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
695
|
-
return UINT2NUM(surface->format->BytesPerPixel);
|
765
|
+
return UINT2NUM(Get_SDL_PixelFormat(self)->BytesPerPixel);
|
696
766
|
}
|
697
767
|
|
698
|
-
static VALUE
|
768
|
+
static VALUE Surface_pixels(VALUE self)
|
699
769
|
{
|
700
|
-
SDL_Surface *surface;
|
701
|
-
Data_Get_Struct(obj,SDL_Surface,surface);
|
770
|
+
SDL_Surface *surface = Get_SDL_Surface(self);
|
702
771
|
return rb_str_new(surface->pixels,
|
703
772
|
surface->h * surface->pitch);
|
704
773
|
}
|
705
774
|
|
706
|
-
|
775
|
+
VALUE rubysdl_init_video(VALUE mSDL)
|
707
776
|
{
|
708
|
-
|
777
|
+
cSurface = rb_define_class_under(mSDL,"Surface",rb_cObject);
|
778
|
+
cScreen = rb_define_class_under(mSDL,"Screen",cSurface);
|
779
|
+
cPixelFormat = rb_define_class_under(mSDL, "PixelFormat", rb_cObject);
|
780
|
+
|
781
|
+
rb_define_alloc_func(cSurface, Surface_s_alloc);
|
782
|
+
rb_undef_alloc_func(cPixelFormat);
|
783
|
+
|
784
|
+
rb_define_singleton_method(cScreen, "get", Screen_s_get, 0);
|
785
|
+
rb_define_singleton_method(cScreen, "driverName", Screen_s_driverName, 0);
|
786
|
+
rb_define_singleton_method(cSurface, "blit", Surface_s_blit, 8);
|
787
|
+
|
788
|
+
rb_define_singleton_method(cScreen, "open", Screen_s_open, 4);
|
789
|
+
rb_define_singleton_method(cScreen, "checkMode", Screen_s_checkMode, 4);
|
790
|
+
rb_define_singleton_method(cScreen, "listModes", Screen_s_listModes, 1);
|
791
|
+
rb_define_singleton_method(cScreen, "setGamma", Screen_s_setGamma, 3);
|
792
|
+
rb_define_singleton_method(cScreen, "getGammaRamp", Screen_s_getGammaRamp, 0);
|
793
|
+
rb_define_singleton_method(cScreen, "setGammaRamp", Screen_s_setGammaRamp, 1);
|
794
|
+
|
795
|
+
cVideoInfo=rb_define_class_under(mSDL,"VideoInfo",rb_cObject);
|
796
|
+
rb_define_attr(cVideoInfo,"hw_available",1,0);
|
797
|
+
rb_define_attr(cVideoInfo,"wm_available",1,0);
|
798
|
+
rb_define_attr(cVideoInfo,"blit_hw",1,0);
|
799
|
+
rb_define_attr(cVideoInfo,"blit_hw_CC",1,0);
|
800
|
+
rb_define_attr(cVideoInfo,"blit_hw_A",1,0);
|
801
|
+
rb_define_attr(cVideoInfo,"blit_sw",1,0);
|
802
|
+
rb_define_attr(cVideoInfo,"blit_sw_CC",1,0);
|
803
|
+
rb_define_attr(cVideoInfo,"blit_sw_A",1,0);
|
804
|
+
rb_define_attr(cVideoInfo,"blit_fill",1,0);
|
805
|
+
rb_define_attr(cVideoInfo,"video_mem",1,0);
|
806
|
+
rb_define_attr(cVideoInfo,"bpp",1,0);
|
807
|
+
|
808
|
+
rb_define_singleton_method(cScreen, "info", Screen_s_info, 0);
|
809
|
+
|
810
|
+
rb_define_singleton_method(cSurface,"create",Surface_s_create,4);
|
811
|
+
rb_define_singleton_method(cSurface,"createWithFormat",Surface_s_createWithFormat,8);
|
812
|
+
rb_define_singleton_method(cSurface,"new_from",Surface_s_createFrom,9);
|
813
|
+
rb_define_singleton_method(cSurface,"loadBMP",Surface_s_loadBMP,1);
|
814
|
+
rb_define_singleton_method(cSurface,"loadBMPFromIO",Surface_s_loadBMPFromIO,1);
|
815
|
+
rb_define_singleton_method(cSurface,"loadBMPFromString",Surface_s_loadBMPFromString,1);
|
816
|
+
|
817
|
+
rb_define_method(cSurface,"saveBMP",Surface_saveBMP,1);
|
818
|
+
rb_define_method(cSurface,"destroy",Surface_destroy,0);
|
819
|
+
rb_define_method(cSurface,"displayFormat",Surface_displayFormat,0);
|
820
|
+
rb_define_method(cSurface,"displayFormatAlpha",Surface_displayFormatAlpha,0);
|
821
|
+
rb_define_method(cSurface,"setColorKey",Surface_setColorKey,2);
|
822
|
+
rb_define_method(cSurface,"fillRect",Surface_fillRect,5);
|
823
|
+
rb_define_method(cSurface,"setClipRect",Surface_setClipRect,4);
|
824
|
+
rb_define_method(cSurface,"getClipRect",Surface_getClipRect,0);
|
825
|
+
rb_define_method(cSurface,"setAlpha",Surface_setAlpha,2);
|
826
|
+
rb_define_method(cSurface,"h",Surface_h,0);
|
827
|
+
rb_define_method(cSurface,"w",Surface_w,0);
|
828
|
+
rb_define_method(cSurface,"flags",Surface_flags,0);
|
829
|
+
|
830
|
+
rb_define_method(cSurface,"getPixel",Surface_getPixel,2);
|
831
|
+
rb_define_method(cSurface,"putPixel",Surface_putPixel,3);
|
832
|
+
rb_define_method(cSurface,"[]",Surface_getPixel,2);
|
833
|
+
rb_define_method(cSurface,"[]=",Surface_putPixel,3);
|
834
|
+
|
835
|
+
rb_define_method(cSurface,"setPalette",Surface_setPalette,3);
|
836
|
+
rb_define_method(cSurface,"setColors",Surface_setColors,2);
|
837
|
+
rb_define_method(cPixelFormat,"palette",PixelFormat_pallete,0);
|
838
|
+
|
839
|
+
rb_define_method(cSurface,"mustLock?",Surface_mustlock_p,0);
|
840
|
+
rb_define_method(cSurface,"lock",Surface_lock,0);
|
841
|
+
rb_define_method(cSurface,"unlock",Surface_unlock,0);
|
842
|
+
|
843
|
+
rb_define_method(cSurface,"format",Surface_format,0);
|
844
|
+
rb_define_method(cPixelFormat,"mapRGB",PixelFormat_mapRGB,3);
|
845
|
+
rb_define_method(cPixelFormat,"mapRGBA",PixelFormat_mapRGBA,4);
|
846
|
+
rb_define_method(cPixelFormat,"getRGB",PixelFormat_getRGB,1);
|
847
|
+
rb_define_method(cPixelFormat,"getRGBA",PixelFormat_getRGBA,1);
|
848
|
+
rb_define_method(cPixelFormat,"bpp",PixelFormat_bpp,0);
|
849
|
+
rb_define_method(cPixelFormat,"bytesPerPixel",PixelFormat_bytesPerPixel,0);
|
850
|
+
rb_define_method(cPixelFormat,"colorkey",PixelFormat_colorkey,0);
|
851
|
+
rb_define_method(cPixelFormat,"alpha",PixelFormat_alpha,0);
|
852
|
+
rb_define_method(cPixelFormat,"Rmask",PixelFormat_rmask,0);
|
853
|
+
rb_define_method(cPixelFormat,"Gmask",PixelFormat_gmask,0);
|
854
|
+
rb_define_method(cPixelFormat,"Bmask",PixelFormat_bmask,0);
|
855
|
+
rb_define_method(cPixelFormat,"Amask",PixelFormat_amask,0);
|
856
|
+
rb_define_method(cPixelFormat,"Rloss",PixelFormat_Rloss,0);
|
857
|
+
rb_define_method(cPixelFormat,"Gloss",PixelFormat_Gloss,0);
|
858
|
+
rb_define_method(cPixelFormat,"Bloss",PixelFormat_Bloss,0);
|
859
|
+
rb_define_method(cPixelFormat,"Aloss",PixelFormat_Aloss,0);
|
860
|
+
rb_define_method(cPixelFormat,"Rshift",PixelFormat_Rshift,0);
|
861
|
+
rb_define_method(cPixelFormat,"Gshift",PixelFormat_Gshift,0);
|
862
|
+
rb_define_method(cPixelFormat,"Bshift",PixelFormat_Bshift,0);
|
863
|
+
rb_define_method(cPixelFormat,"Ashift",PixelFormat_Ashift,0);
|
864
|
+
rb_define_method(cSurface,"pixels",Surface_pixels,0);
|
865
|
+
rb_define_method(cSurface,"pitch",Surface_pitch,0);
|
866
|
+
|
867
|
+
rb_define_method(cScreen,"updateRect",Screen_updateRect,4);
|
868
|
+
rb_define_method(cScreen,"updateRects",Screen_updateRects,-1);
|
869
|
+
rb_define_method(cScreen,"flip",Screen_flip,0);
|
870
|
+
rb_define_method(cScreen,"toggleFullScreen",Screen_toggleFullScreen,0);
|
871
|
+
|
872
|
+
|
873
|
+
/* Available for Screen.open */
|
709
874
|
rb_define_const(mSDL,"SWSURFACE",UINT2NUM(SDL_SWSURFACE));
|
710
875
|
rb_define_const(mSDL,"HWSURFACE",UINT2NUM(SDL_HWSURFACE));
|
711
876
|
rb_define_const(mSDL,"ASYNCBLIT",UINT2NUM(SDL_ASYNCBLIT));
|
@@ -731,90 +896,6 @@ static void defineConstForVideo()
|
|
731
896
|
/* flags for SDL::Surface.setPalette */
|
732
897
|
rb_define_const(mSDL,"LOGPAL",INT2NUM(SDL_LOGPAL));
|
733
898
|
rb_define_const(mSDL,"PHYSPAL",INT2NUM(SDL_PHYSPAL));
|
734
|
-
}
|
735
|
-
|
736
|
-
void init_video()
|
737
|
-
{
|
738
|
-
rb_define_module_function(mSDL,"getVideoSurface",sdl_getVideoSurface,0);
|
739
|
-
rb_define_module_function(mSDL,"videoDriverName",sdl_videoDriverName,0);
|
740
|
-
rb_define_module_function(mSDL,"blitSurface",sdl_blitSurface,8);
|
741
|
-
rb_define_module_function(mSDL,"setVideoMode",sdl_setVideoMode,4);
|
742
|
-
rb_define_module_function(mSDL,"checkVideoMode",sdl_checkVideoMode,4);
|
743
|
-
rb_define_module_function(mSDL,"listModes",sdl_listModes,1);
|
744
|
-
rb_define_module_function(mSDL,"setGamma",sdl_setGamma,3);
|
745
|
-
rb_define_module_function(mSDL,"getGammaRamp",sdl_getGammaRamp,0);
|
746
|
-
rb_define_module_function(mSDL,"setGammaRamp",sdl_setGammaRamp,1);
|
747
|
-
cVideoInfo=rb_define_class_under(mSDL,"VideoInfo",rb_cObject);
|
748
|
-
rb_define_attr(cVideoInfo,"hw_available",1,0);
|
749
|
-
rb_define_attr(cVideoInfo,"wm_available",1,0);
|
750
|
-
rb_define_attr(cVideoInfo,"blit_hw",1,0);
|
751
|
-
rb_define_attr(cVideoInfo,"blit_hw_CC",1,0);
|
752
|
-
rb_define_attr(cVideoInfo,"blit_hw_A",1,0);
|
753
|
-
rb_define_attr(cVideoInfo,"blit_sw",1,0);
|
754
|
-
rb_define_attr(cVideoInfo,"blit_sw_CC",1,0);
|
755
|
-
rb_define_attr(cVideoInfo,"blit_sw_A",1,0);
|
756
|
-
rb_define_attr(cVideoInfo,"blit_fill",1,0);
|
757
|
-
rb_define_attr(cVideoInfo,"video_mem",1,0);
|
758
|
-
rb_define_attr(cVideoInfo,"bpp",1,0);
|
759
|
-
|
760
|
-
|
761
|
-
rb_define_module_function(mSDL,"videoInfo",sdl_getVideoInfo,0);
|
762
|
-
|
763
|
-
cSurface = rb_define_class_under(mSDL,"Surface",rb_cObject);
|
764
899
|
|
765
|
-
|
766
|
-
rb_define_singleton_method(cSurface,"createWithFormat",sdl_createSurfaceWithFormat,8);
|
767
|
-
rb_define_singleton_method(cSurface,"new_from",sdl_createSurfaceFrom,9);
|
768
|
-
rb_define_singleton_method(cSurface,"loadBMP",sdl_loadBMP,1);
|
769
|
-
rb_define_singleton_method(cSurface,"loadBMPFromIO",sdl_loadBMPFromIO,1);
|
770
|
-
rb_define_method(cSurface,"saveBMP",sdl_saveBMP,1);
|
771
|
-
rb_define_method(cSurface,"displayFormat",sdl_displayFormat,0);
|
772
|
-
rb_define_method(cSurface,"displayFormatAlpha",sdl_displayFormatAlpha,0);
|
773
|
-
rb_define_method(cSurface,"setColorKey",sdl_setColorKey,2);
|
774
|
-
rb_define_method(cSurface,"fillRect",sdl_fillRect,5);
|
775
|
-
rb_define_method(cSurface,"setClipRect",sdl_setClipRect,4);
|
776
|
-
rb_define_method(cSurface,"getClipRect",sdl_getClipRect,0);
|
777
|
-
rb_define_method(cSurface,"setAlpha",sdl_setAlpha,2);
|
778
|
-
rb_define_method(cSurface,"h",sdl_surfaceH,0);
|
779
|
-
rb_define_method(cSurface,"w",sdl_surfaceW,0);
|
780
|
-
rb_define_method(cSurface,"flags",sdl_getFlags,0);
|
781
|
-
|
782
|
-
rb_define_method(cSurface,"setPalette",sdl_setPalette,3);
|
783
|
-
rb_define_method(cSurface,"setColors",sdl_setColors,2);
|
784
|
-
rb_define_method(cSurface,"getPalette",sdl_getPalette,0);
|
785
|
-
|
786
|
-
rb_define_method(cSurface,"mustLock?",sdl_mustlock,0);
|
787
|
-
rb_define_method(cSurface,"lock",sdl_lockSurface,0);
|
788
|
-
rb_define_method(cSurface,"unlock",sdl_unlockSurface,0);
|
789
|
-
|
790
|
-
rb_define_method(cSurface,"mapRGB",sdl_mapRGB,3);
|
791
|
-
rb_define_method(cSurface,"mapRGBA",sdl_mapRGBA,4);
|
792
|
-
rb_define_method(cSurface,"getRGB",sdl_getRGB,1);
|
793
|
-
rb_define_method(cSurface,"getRGBA",sdl_getRGBA,1);
|
794
|
-
rb_define_method(cSurface,"bpp",sdl_getBpp,0);
|
795
|
-
rb_define_method(cSurface,"colorkey",sdl_getColorkey,0);
|
796
|
-
rb_define_method(cSurface,"alpha",sdl_getAlpha,0);
|
797
|
-
rb_define_method(cSurface,"Rmask",sdl_surface_rmask,0);
|
798
|
-
rb_define_method(cSurface,"Gmask",sdl_surface_gmask,0);
|
799
|
-
rb_define_method(cSurface,"Bmask",sdl_surface_bmask,0);
|
800
|
-
rb_define_method(cSurface,"Amask",sdl_surface_amask,0);
|
801
|
-
rb_define_method(cSurface,"Rloss",sdl_surface_rloss,0);
|
802
|
-
rb_define_method(cSurface,"Gloss",sdl_surface_gloss,0);
|
803
|
-
rb_define_method(cSurface,"Bloss",sdl_surface_bloss,0);
|
804
|
-
rb_define_method(cSurface,"Aloss",sdl_surface_aloss,0);
|
805
|
-
rb_define_method(cSurface,"Rshift",sdl_surface_rshift,0);
|
806
|
-
rb_define_method(cSurface,"Gshift",sdl_surface_gshift,0);
|
807
|
-
rb_define_method(cSurface,"Bshift",sdl_surface_bshift,0);
|
808
|
-
rb_define_method(cSurface,"Ashift",sdl_surface_ashift,0);
|
809
|
-
rb_define_method(cSurface,"pixels",sdl_surface_pixels,0);
|
810
|
-
rb_define_method(cSurface,"pitch",sdl_surface_pitch,0);
|
811
|
-
rb_define_method(cSurface,"BytesPerPixel",sdl_surface_bytes_per_pixel,0);
|
812
|
-
|
813
|
-
cScreen = rb_define_class_under(mSDL,"Screen",cSurface);
|
814
|
-
rb_define_method(cScreen,"updateRect",sdl_updateRect,4);
|
815
|
-
rb_define_method(cScreen,"updateRects",sdl_updateRects, -1);
|
816
|
-
rb_define_method(cScreen,"flip",sdl_flip,0);
|
817
|
-
rb_define_method(cScreen,"toggleFullScreen",sdl_toggleFullScreen,0);
|
818
|
-
defineConstForVideo();
|
819
|
-
return;
|
900
|
+
return cSurface;
|
820
901
|
}
|