rubysdl 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.en +36 -0
- data/NEWS.ja +36 -0
- data/README.en +1 -1
- data/README.ja +1 -1
- data/doc-en/Makefile +1 -1
- data/doc-en/cdrom.rsd +31 -0
- data/doc-en/event.rsd +6 -2
- data/doc-en/font.rsd +141 -4
- data/doc-en/general.rsd +14 -0
- data/doc-en/init.rsd +3 -3
- data/doc-en/mixer.rsd +68 -0
- data/doc-en/mpeg.rsd +24 -0
- data/doc-en/sdlskk.rsd +5 -0
- data/doc-en/video.rsd +35 -0
- data/doc-en/wm.rsd +6 -0
- data/doc/cdrom.rsd +29 -0
- data/doc/event.rsd +5 -2
- data/doc/font.rsd +250 -4
- data/doc/general.rsd +12 -0
- data/doc/mixer.rsd +68 -0
- data/doc/mpeg.rsd +24 -0
- data/doc/sdlskk.rsd +5 -1
- data/doc/video.rsd +35 -0
- data/doc/wm.rsd +10 -0
- data/extconf.rb +9 -0
- data/lib/rubysdl_aliases.rb +9 -0
- data/lib/sdl.rb +19 -32
- data/rubysdl.h +37 -4
- data/rubysdl_cdrom.c +14 -1
- data/rubysdl_event.c +14 -0
- data/rubysdl_image.c +1 -1
- data/rubysdl_joystick.c +0 -1
- data/rubysdl_kanji.c +86 -11
- data/rubysdl_main.c +8 -1
- data/rubysdl_mixer.c +17 -4
- data/rubysdl_sdlskk.c +19 -0
- data/rubysdl_sge_video.c +44 -12
- data/rubysdl_smpeg.c +7 -2
- data/rubysdl_time.c +13 -1
- data/rubysdl_ttf.c +92 -13
- data/rubysdl_video.c +10 -4
- data/rubysdl_wm.c +9 -3
- data/sample/font.rb +1 -0
- data/sample/load_from_io.rb +2 -2
- data/sample/plaympeg.rb +1 -5
- metadata +3 -3
data/rubysdl_joystick.c
CHANGED
data/rubysdl_kanji.c
CHANGED
@@ -24,19 +24,84 @@
|
|
24
24
|
static VALUE cKanjiFont;
|
25
25
|
typedef int (*Drawer)(Kanji_Font*, int, int, SDL_Surface*, const char*, SDL_Color);
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
typedef struct {
|
28
|
+
Kanji_Font* font;
|
29
|
+
} KFont;
|
30
|
+
|
31
|
+
DEFINE_GET_STRUCT(KFont, Get_KFont, cKanjiFont, "SDL::Kanji::Font");
|
32
|
+
static Kanji_Font* Get_Kanji_Font(VALUE obj)
|
33
|
+
{
|
34
|
+
KFont* kfont = Get_KFont(obj);
|
35
|
+
if (kfont->font == NULL)
|
36
|
+
rb_raise(eSDLError, "Kanji Font data is already disposed");
|
37
|
+
return kfont->font;
|
38
|
+
}
|
39
|
+
static void Font_free(KFont* kfont)
|
40
|
+
{
|
41
|
+
if (kfont->font)
|
42
|
+
Kanji_CloseFont(kfont->font);
|
43
|
+
free(kfont);
|
44
|
+
}
|
45
|
+
static VALUE Font_s_alloc(VALUE klass)
|
46
|
+
{
|
47
|
+
KFont* kfont = ALLOC(KFont);
|
48
|
+
kfont->font = NULL;
|
49
|
+
return Data_Wrap_Struct(klass, 0, Font_free, kfont);
|
50
|
+
}
|
51
|
+
static VALUE Font_create(Kanji_Font* font)
|
52
|
+
{
|
53
|
+
VALUE newobj = Font_s_alloc(cKanjiFont);
|
54
|
+
Get_KFont(newobj)->font = font;
|
55
|
+
return newobj;
|
56
|
+
}
|
57
|
+
|
58
|
+
#ifdef ENABLE_M17N
|
59
|
+
static rb_encoding* get_enc(Kanji_Font* font)
|
60
|
+
{
|
61
|
+
switch (font->sys) {
|
62
|
+
case KANJI_JIS:
|
63
|
+
return iso2022jp_enc;
|
64
|
+
break;
|
65
|
+
case KANJI_EUC:
|
66
|
+
return eucjp_enc;
|
67
|
+
break;
|
68
|
+
case KANJI_SJIS:
|
69
|
+
return sjis_enc;
|
70
|
+
break;
|
71
|
+
default:
|
72
|
+
rb_raise(eSDLError, "Unsupported Kanji encoding");
|
73
|
+
return NULL;
|
74
|
+
break;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
#endif
|
78
|
+
|
29
79
|
static VALUE Font_s_open(VALUE klass, VALUE filename, VALUE size)
|
30
80
|
{
|
31
81
|
Kanji_Font* font;
|
32
82
|
|
33
83
|
rb_secure(4);
|
34
|
-
|
84
|
+
ExportFilenameStringValue(filename);
|
35
85
|
|
36
86
|
font = Kanji_OpenFont(RSTRING_PTR(filename), NUM2INT(size));
|
37
87
|
if(font == NULL)
|
38
88
|
rb_raise(eSDLError,"Couldn't open bdf font: %s", RSTRING_PTR(filename));
|
39
|
-
return
|
89
|
+
return Font_create(font);
|
90
|
+
}
|
91
|
+
static VALUE Font_close(VALUE self)
|
92
|
+
{
|
93
|
+
KFont* kfont;
|
94
|
+
|
95
|
+
rb_secure(4);
|
96
|
+
kfont = Get_KFont(self);
|
97
|
+
if (kfont->font)
|
98
|
+
Kanji_CloseFont(kfont->font);
|
99
|
+
kfont->font = NULL;
|
100
|
+
return Qnil;
|
101
|
+
}
|
102
|
+
static VALUE Font_closed(VALUE self)
|
103
|
+
{
|
104
|
+
return INT2BOOL(Get_KFont(self)->font == NULL);
|
40
105
|
}
|
41
106
|
|
42
107
|
static VALUE Font_setCodingSystem(VALUE self, VALUE sys)
|
@@ -44,11 +109,15 @@ static VALUE Font_setCodingSystem(VALUE self, VALUE sys)
|
|
44
109
|
Kanji_SetCodingSystem(Get_Kanji_Font(self), NUM2INT(sys));
|
45
110
|
return Qnil;
|
46
111
|
}
|
47
|
-
|
112
|
+
static VALUE Font_getCodingSystem(VALUE self)
|
113
|
+
{
|
114
|
+
return INT2NUM(Get_Kanji_Font(self)->sys);
|
115
|
+
}
|
116
|
+
|
48
117
|
static VALUE Font_add(VALUE self, VALUE filename)
|
49
118
|
{
|
50
119
|
rb_secure(4);
|
51
|
-
|
120
|
+
ExportFilenameStringValue(filename);
|
52
121
|
if(Kanji_AddFont(Get_Kanji_Font(self), RSTRING_PTR(filename)) == -1)
|
53
122
|
rb_raise(eSDLError, "Couldn't use font: %s", RSTRING_PTR(filename));
|
54
123
|
return Qnil;
|
@@ -56,8 +125,11 @@ static VALUE Font_add(VALUE self, VALUE filename)
|
|
56
125
|
|
57
126
|
static VALUE Font_textwidth(VALUE self, VALUE text)
|
58
127
|
{
|
59
|
-
|
60
|
-
|
128
|
+
Kanji_Font* font;
|
129
|
+
rb_secure(4);
|
130
|
+
font = Get_Kanji_Font(self);
|
131
|
+
ExportStringValueToEnc(text, get_enc(font));
|
132
|
+
return INT2FIX(Kanji_FontWidth(font, RSTRING_PTR(text)));
|
61
133
|
}
|
62
134
|
|
63
135
|
static VALUE Font_width(VALUE self)
|
@@ -75,10 +147,10 @@ static void Font_put(VALUE self, VALUE surface, VALUE text,
|
|
75
147
|
VALUE r, VALUE g, VALUE b, Drawer draw)
|
76
148
|
{
|
77
149
|
SDL_Color color;
|
78
|
-
|
150
|
+
Kanji_Font* font;
|
79
151
|
rb_secure(4);
|
80
|
-
|
81
|
-
|
152
|
+
font = Get_Kanji_Font(self);
|
153
|
+
ExportStringValueToEnc(text, get_enc(font));
|
82
154
|
color.r = NUM2INT(r);color.g = NUM2INT(g); color.b = NUM2INT(b);
|
83
155
|
|
84
156
|
draw(Get_Kanji_Font(self), NUM2INT(x), NUM2INT(y),
|
@@ -107,8 +179,11 @@ void rubysdl_init_Kanji(VALUE mSDL)
|
|
107
179
|
rb_undef_alloc_func(cKanjiFont);
|
108
180
|
|
109
181
|
rb_define_singleton_method(cKanjiFont, "open", Font_s_open, 2);
|
182
|
+
rb_define_method(cKanjiFont, "close", Font_close, 0);
|
183
|
+
rb_define_method(cKanjiFont, "closed?", Font_closed, 0);
|
110
184
|
rb_define_method(cKanjiFont, "add", Font_add, 1);
|
111
185
|
rb_define_method(cKanjiFont, "setCodingSystem", Font_setCodingSystem, 1);
|
186
|
+
rb_define_method(cKanjiFont, "getCodingSystem", Font_getCodingSystem, 0);
|
112
187
|
rb_define_method(cKanjiFont, "textwidth", Font_textwidth, 1);
|
113
188
|
rb_define_method(cKanjiFont, "width", Font_width, 0);
|
114
189
|
rb_define_method(cKanjiFont, "height", Font_height, 0);
|
data/rubysdl_main.c
CHANGED
@@ -88,7 +88,14 @@ void Init_sdl()
|
|
88
88
|
{
|
89
89
|
VALUE mSDL = rb_define_module("SDL");
|
90
90
|
VALUE cSurface;
|
91
|
-
|
91
|
+
|
92
|
+
#ifdef ENABLE_M17N
|
93
|
+
utf8_enc = rb_utf8_encoding();
|
94
|
+
eucjp_enc = rb_enc_find("EUC-JP");
|
95
|
+
iso2022jp_enc = rb_enc_find("ISO-2022-JP");
|
96
|
+
sjis_enc = rb_enc_find("SJIS");
|
97
|
+
#endif
|
98
|
+
|
92
99
|
eSDLError = rb_define_class_under(mSDL, "Error", rb_eStandardError);
|
93
100
|
rb_define_module_function(mSDL, "init", sdl_s_init, 1);
|
94
101
|
rb_define_module_function(mSDL, "initedSystem", sdl_s_inited_system, 1);
|
data/rubysdl_mixer.c
CHANGED
@@ -56,6 +56,7 @@ static void Wave_free(Wave* wave)
|
|
56
56
|
Mix_FreeChunk(wave->chunk);
|
57
57
|
free(wave);
|
58
58
|
}
|
59
|
+
|
59
60
|
static VALUE Wave_s_alloc(VALUE klass)
|
60
61
|
{
|
61
62
|
Wave* wave = ALLOC(Wave);
|
@@ -243,7 +244,7 @@ static VALUE Wave_s_load(VALUE class, VALUE filename)
|
|
243
244
|
Mix_Chunk *chunk;
|
244
245
|
|
245
246
|
rb_secure(4);
|
246
|
-
|
247
|
+
ExportFilenameStringValue(filename);
|
247
248
|
|
248
249
|
chunk = Mix_LoadWAV(RSTRING_PTR(filename));
|
249
250
|
if( chunk == NULL ){
|
@@ -400,7 +401,7 @@ static VALUE Music_s_load(VALUE class, VALUE filename)
|
|
400
401
|
Mix_Music* music;
|
401
402
|
|
402
403
|
rb_secure(4);
|
403
|
-
|
404
|
+
ExportFilenameStringValue(filename);
|
404
405
|
|
405
406
|
music = Mix_LoadMUS(RSTRING_PTR(filename));
|
406
407
|
if( music == NULL )
|
@@ -442,6 +443,11 @@ static VALUE Wave_destroy(VALUE self)
|
|
442
443
|
}
|
443
444
|
return Qnil;
|
444
445
|
}
|
446
|
+
static VALUE Wave_destroyed(VALUE self)
|
447
|
+
{
|
448
|
+
Wave* wave = GetWave(self);
|
449
|
+
return INT2BOOL(wave->chunk == NULL);
|
450
|
+
}
|
445
451
|
|
446
452
|
static VALUE Music_destroy(VALUE self)
|
447
453
|
{
|
@@ -452,6 +458,11 @@ static VALUE Music_destroy(VALUE self)
|
|
452
458
|
}
|
453
459
|
return Qnil;
|
454
460
|
}
|
461
|
+
static VALUE Music_destroyed(VALUE self)
|
462
|
+
{
|
463
|
+
Music* mus = GetMusic(self);
|
464
|
+
return INT2BOOL(mus->music == NULL);
|
465
|
+
}
|
455
466
|
|
456
467
|
void rubysdl_init_Mixer(VALUE mSDL)
|
457
468
|
{
|
@@ -462,7 +473,7 @@ void rubysdl_init_Mixer(VALUE mSDL)
|
|
462
473
|
rb_define_module_function(mMixer, "driverName", Mixer_s_driverName, 0);
|
463
474
|
rb_define_module_function(mMixer, "playChannel", Mixer_s_playChannel, 3);
|
464
475
|
rb_define_module_function(mMixer, "playChannelTimed", Mixer_s_playChannelTimed, 4);
|
465
|
-
rb_define_module_function(mMixer, "fadeInChannel",
|
476
|
+
rb_define_module_function(mMixer, "fadeInChannel", Mixer_s_fadeInChannel, 4);
|
466
477
|
rb_define_module_function(mMixer, "fadeInChannelTimed", Mixer_s_fadeInChannelTimed, 5);
|
467
478
|
|
468
479
|
rb_define_module_function(mMixer, "play?", Mixer_s_play_p, 1);
|
@@ -503,8 +514,10 @@ void rubysdl_init_Mixer(VALUE mSDL)
|
|
503
514
|
Mixer_s_loadMusFromString,1);
|
504
515
|
#endif
|
505
516
|
rb_define_method(cWave, "destroy", Wave_destroy, 0);
|
517
|
+
rb_define_method(cWave, "destroyed_", Wave_destroyed, 0);
|
506
518
|
rb_define_method(cMusic, "destroy", Music_destroy, 0);
|
507
|
-
|
519
|
+
rb_define_method(cMusic, "destroyed?", Music_destroyed, 0);
|
520
|
+
|
508
521
|
/* to avoid to do garbage collect when playing */
|
509
522
|
rb_global_variable( &playing_wave );
|
510
523
|
rb_global_variable( &playing_music );
|
data/rubysdl_sdlskk.c
CHANGED
@@ -100,8 +100,27 @@ static VALUE Context_input(VALUE self, VALUE event)
|
|
100
100
|
static VALUE Context_str(VALUE self)
|
101
101
|
{
|
102
102
|
char cstr[10000];
|
103
|
+
#ifdef ENABLE_M17N
|
104
|
+
rb_encoding* enc;
|
105
|
+
switch (SDLSKK_get_encoding()) {
|
106
|
+
case SDLSKK_UTF8:
|
107
|
+
enc = utf8_enc;
|
108
|
+
case SDLSKK_EUCJP:
|
109
|
+
enc = eucjp_enc;
|
110
|
+
break;
|
111
|
+
case SDLSKK_SJIS:
|
112
|
+
enc = sjis_enc;
|
113
|
+
break;
|
114
|
+
default:
|
115
|
+
rb_raise(eSDLError, "SDLSKK encoding error");
|
116
|
+
}
|
117
|
+
#endif
|
103
118
|
SDLSKK_Context_get_str(Get_SDLSKK_Context(self), cstr, sizeof(cstr));
|
119
|
+
#ifdef ENABLE_M17N
|
120
|
+
return ENC_STR_NEW2(cstr, enc);
|
121
|
+
#else
|
104
122
|
return rb_str_new2(cstr);
|
123
|
+
#endif
|
105
124
|
}
|
106
125
|
|
107
126
|
static VALUE render_str(VALUE self, VALUE font, VALUE r, VALUE g, VALUE b,
|
data/rubysdl_sge_video.c
CHANGED
@@ -25,9 +25,34 @@
|
|
25
25
|
static VALUE cCollisionMap = Qnil;
|
26
26
|
static VALUE cBMFont = Qnil;
|
27
27
|
|
28
|
-
|
28
|
+
typedef struct {
|
29
|
+
sge_bmpFont* font;
|
30
|
+
} BmpFont;
|
31
|
+
|
32
|
+
DEFINE_GET_STRUCT(BmpFont, Get_BmpFont, cBMFont, "SDL::BMFont");
|
29
33
|
DEFINE_GET_STRUCT(sge_cdata, Get_sge_cdata, cCollisionMap, "SDL::CollisionMap");
|
30
34
|
|
35
|
+
static sge_bmpFont* Get_sge_bmpFont(VALUE obj)
|
36
|
+
{
|
37
|
+
BmpFont* bfont = Get_BmpFont(obj);
|
38
|
+
if (bfont->font == NULL)
|
39
|
+
rb_raise(eSDLError, "Bitmap font is already closed");
|
40
|
+
return bfont->font;
|
41
|
+
}
|
42
|
+
static void BMFont_free(BmpFont* bfont)
|
43
|
+
{
|
44
|
+
if (!rubysdl_is_quit() && bfont->font)
|
45
|
+
sge_BF_CloseFont(bfont->font);
|
46
|
+
free(bfont);
|
47
|
+
}
|
48
|
+
|
49
|
+
static VALUE BMFont_create(sge_bmpFont* font)
|
50
|
+
{
|
51
|
+
BmpFont* bfont = ALLOC(BmpFont);
|
52
|
+
bfont->font = font;
|
53
|
+
return Data_Wrap_Struct(cBMFont, 0, BMFont_free, bfont);
|
54
|
+
}
|
55
|
+
|
31
56
|
static VALUE Surface_s_autoLock_p(VALUE klass)
|
32
57
|
{
|
33
58
|
rb_secure(4);
|
@@ -380,25 +405,31 @@ static VALUE CollisionMap_h(VALUE self)
|
|
380
405
|
}
|
381
406
|
|
382
407
|
/* bitmap font */
|
383
|
-
static void bf_close(sge_bmpFont* font)
|
384
|
-
{
|
385
|
-
if(!rubysdl_is_quit()){
|
386
|
-
sge_BF_CloseFont(font);
|
387
|
-
}
|
388
|
-
}
|
389
408
|
|
390
409
|
static VALUE BMFont_open(VALUE klass, VALUE file, VALUE flags)
|
391
410
|
|
392
411
|
{
|
393
412
|
sge_bmpFont* font;
|
394
413
|
rb_secure(4);
|
395
|
-
|
414
|
+
ExportFilenameStringValue(file);
|
396
415
|
|
397
416
|
font = sge_BF_OpenFont(RSTRING_PTR(file), NUM2UINT(flags));
|
398
417
|
if(font == NULL)
|
399
418
|
rb_raise(eSDLError, "Couldn't open font: %s", RSTRING_PTR(file));
|
400
419
|
|
401
|
-
return
|
420
|
+
return BMFont_create(font);
|
421
|
+
}
|
422
|
+
static VALUE BMFont_close(VALUE self)
|
423
|
+
{
|
424
|
+
BmpFont* bfont = Get_BmpFont(self);
|
425
|
+
if (!rubysdl_is_quit() && bfont->font)
|
426
|
+
sge_BF_CloseFont(bfont->font);
|
427
|
+
bfont->font = NULL;
|
428
|
+
return Qnil;
|
429
|
+
}
|
430
|
+
static VALUE BMFont_closed(VALUE self)
|
431
|
+
{
|
432
|
+
return INT2BOOL(Get_BmpFont(self)->font == NULL);
|
402
433
|
}
|
403
434
|
|
404
435
|
static VALUE BMFont_setColor(VALUE self, VALUE r, VALUE g, VALUE b)
|
@@ -421,7 +452,7 @@ static VALUE BMFont_getWidth(VALUE self)
|
|
421
452
|
static VALUE BMFont_textSize(VALUE self, VALUE text)
|
422
453
|
{
|
423
454
|
SDL_Rect rect;
|
424
|
-
|
455
|
+
SafeStringValue(text);
|
425
456
|
rect = sge_BF_TextSize(Get_sge_bmpFont(self),
|
426
457
|
RSTRING_PTR(text));
|
427
458
|
return rb_ary_new3(2, INT2FIX(rect.w), INT2FIX(rect.h));
|
@@ -433,7 +464,7 @@ static VALUE BMFont_textout(VALUE self,
|
|
433
464
|
|
434
465
|
{
|
435
466
|
rb_secure(4);
|
436
|
-
|
467
|
+
SafeStringValue(string);
|
437
468
|
|
438
469
|
sge_BF_textout(Get_SDL_Surface(surface), Get_sge_bmpFont(self),
|
439
470
|
RSTRING_PTR(string), NUM2INT(x), NUM2INT(y));
|
@@ -483,7 +514,8 @@ void rubysdl_init_sge(VALUE mSDL, VALUE cSurface)
|
|
483
514
|
rb_undef_alloc_func(cBMFont);
|
484
515
|
|
485
516
|
rb_define_singleton_method(cBMFont, "open", BMFont_open, 2);
|
486
|
-
|
517
|
+
rb_define_method(cBMFont, "close", BMFont_close, 0);
|
518
|
+
rb_define_method(cBMFont, "closed?", BMFont_closed, 0);
|
487
519
|
rb_define_method(cBMFont, "setColor", BMFont_setColor, 3);
|
488
520
|
rb_define_method(cBMFont, "height", BMFont_getHeight, 0);
|
489
521
|
rb_define_method(cBMFont, "width", BMFont_getWidth, 0);
|
data/rubysdl_smpeg.c
CHANGED
@@ -81,10 +81,14 @@ static VALUE MPEG_delete(VALUE self)
|
|
81
81
|
return Qnil;
|
82
82
|
}
|
83
83
|
|
84
|
+
static VALUE MPEG_deleted(VALUE self)
|
85
|
+
{
|
86
|
+
return INT2BOOL(Get_MPEG(self)->smpeg == NULL);
|
87
|
+
}
|
88
|
+
|
84
89
|
static VALUE MPEG_s_load(VALUE klass, VALUE filename)
|
85
90
|
{
|
86
91
|
SMPEG *smpeg;
|
87
|
-
VALUE mpeg;
|
88
92
|
char error_msg[2048];
|
89
93
|
|
90
94
|
rb_secure(4);
|
@@ -307,6 +311,7 @@ void rubysdl_init_MPEG(VALUE mSDL)
|
|
307
311
|
|
308
312
|
rb_define_method(cMPEG, "info", MPEG_info, 0);
|
309
313
|
rb_define_method(cMPEG, "delete", MPEG_delete, 0);
|
314
|
+
rb_define_method(cMPEG, "deleted?", MPEG_deleted, 0);
|
310
315
|
rb_define_method(cMPEG, "enableAudio", MPEG_enableAudio, 1);
|
311
316
|
rb_define_method(cMPEG, "enableVideo", MPEG_enableVideo, 1);
|
312
317
|
rb_define_method(cMPEG, "status", MPEG_status, 0);
|
@@ -315,7 +320,7 @@ void rubysdl_init_MPEG(VALUE mSDL)
|
|
315
320
|
rb_define_method(cMPEG, "setLoop", MPEG_setLoop, 1);
|
316
321
|
rb_define_method(cMPEG, "scaleXY", MPEG_scaleXY, 2);
|
317
322
|
rb_define_method(cMPEG, "scale", MPEG_scale, 1);
|
318
|
-
rb_define_method(cMPEG, "move", MPEG_move,
|
323
|
+
rb_define_method(cMPEG, "move", MPEG_move, 2);
|
319
324
|
rb_define_method(cMPEG, "setDisplayRegion", MPEG_setDisplayRegion, 4);
|
320
325
|
rb_define_method(cMPEG, "play", MPEG_play, 0);
|
321
326
|
rb_define_method(cMPEG, "pause", MPEG_pause, 0);
|
data/rubysdl_time.c
CHANGED
@@ -23,9 +23,21 @@ static VALUE sdl_getTicks(VALUE mod)
|
|
23
23
|
{
|
24
24
|
return UINT2NUM(SDL_GetTicks());
|
25
25
|
}
|
26
|
+
|
27
|
+
static VALUE delay(void* t)
|
28
|
+
{
|
29
|
+
SDL_Delay(*((Uint32*)t));
|
30
|
+
return Qnil;
|
31
|
+
}
|
32
|
+
|
26
33
|
static VALUE sdl_delay(VALUE mod,VALUE ms)
|
27
34
|
{
|
28
|
-
|
35
|
+
Uint32 t = NUM2UINT(ms);
|
36
|
+
#ifdef HAVE_RB_THREAD_BLOCKING_REGION
|
37
|
+
rb_thread_blocking_region(delay, &t, RUBY_UBF_IO, NULL);
|
38
|
+
#else
|
39
|
+
SDL_Delay(t);
|
40
|
+
#endif
|
29
41
|
return Qnil;
|
30
42
|
}
|
31
43
|
|
data/rubysdl_ttf.c
CHANGED
@@ -21,18 +21,44 @@
|
|
21
21
|
#include "rubysdl.h"
|
22
22
|
#include <SDL_ttf.h>
|
23
23
|
|
24
|
+
typedef struct {
|
25
|
+
TTF_Font* font;
|
26
|
+
} TTFont;
|
27
|
+
|
24
28
|
typedef SDL_Surface* (*RenderFunc)(TTF_Font *,const char *,SDL_Color,SDL_Color);
|
25
29
|
|
26
30
|
static int ttf_init = 0;
|
27
31
|
static VALUE cTTFFont = Qnil;
|
28
32
|
|
29
|
-
static void Font_free(
|
33
|
+
static void Font_free(TTFont *f)
|
34
|
+
{
|
35
|
+
if(!rubysdl_is_quit() && f->font)
|
36
|
+
TTF_CloseFont(f->font);
|
37
|
+
free(f);
|
38
|
+
}
|
39
|
+
|
40
|
+
DEFINE_GET_STRUCT(TTFont, Get_TTFont, cTTFFont, "SDL::TT::Font");
|
41
|
+
|
42
|
+
TTF_Font* Get_TTF_Font(VALUE obj)
|
30
43
|
{
|
31
|
-
|
32
|
-
|
44
|
+
TTFont* f = Get_TTFont(obj);
|
45
|
+
if (f->font == NULL)
|
46
|
+
rb_raise(eSDLError, "TTF is alreadly closed");
|
47
|
+
return f->font;
|
33
48
|
}
|
34
49
|
|
35
|
-
|
50
|
+
static VALUE TTF_s_alloc(VALUE klass)
|
51
|
+
{
|
52
|
+
TTFont* f = ALLOC(TTFont);
|
53
|
+
f->font = NULL;
|
54
|
+
return Data_Wrap_Struct(klass, 0, Font_free, f);
|
55
|
+
}
|
56
|
+
static VALUE TTF_create(TTF_Font* font)
|
57
|
+
{
|
58
|
+
VALUE newobj = TTF_s_alloc(cTTFFont);
|
59
|
+
Get_TTFont(newobj)->font = font;
|
60
|
+
return newobj;
|
61
|
+
}
|
36
62
|
|
37
63
|
static VALUE TTF_s_init(VALUE klass)
|
38
64
|
{
|
@@ -67,7 +93,7 @@ static VALUE Font_s_open(int argc, VALUE *argv, VALUE class)
|
|
67
93
|
if(font == NULL)
|
68
94
|
rb_raise(eSDLError,"Couldn't open font %s: %s",
|
69
95
|
RSTRING_PTR(filename), TTF_GetError());
|
70
|
-
return
|
96
|
+
return TTF_create(font);
|
71
97
|
}
|
72
98
|
|
73
99
|
static VALUE Font_style(VALUE self)
|
@@ -112,8 +138,11 @@ static VALUE Font_styleName(VALUE self)
|
|
112
138
|
static VALUE Font_textSize(VALUE self, VALUE text)
|
113
139
|
{
|
114
140
|
int w,h;
|
115
|
-
|
141
|
+
|
116
142
|
StringValue(text);
|
143
|
+
#ifdef ENABLE_M17N
|
144
|
+
text = rb_str_export_to_enc(text, utf8_enc);
|
145
|
+
#endif
|
117
146
|
TTF_SizeUTF8(Get_TTF_Font(self), RSTRING_PTR(text), &w, &h);
|
118
147
|
return rb_ary_new3(2, INT2FIX(w), INT2FIX(h));
|
119
148
|
}
|
@@ -151,13 +180,17 @@ static SDL_Color rgb_to_SDL_Color(VALUE r, VALUE g, VALUE b)
|
|
151
180
|
static VALUE render(VALUE self, VALUE text,
|
152
181
|
VALUE fgr,VALUE fgg,VALUE fgb,
|
153
182
|
VALUE bgr,VALUE bgg,VALUE bgb,
|
183
|
+
int convert_enc,
|
154
184
|
RenderFunc renderer)
|
155
185
|
{
|
156
186
|
SDL_Surface *surface;
|
157
187
|
|
158
188
|
rb_secure(4);
|
159
189
|
StringValue(text);
|
160
|
-
|
190
|
+
#ifdef ENABLE_M17N
|
191
|
+
if (convert_enc)
|
192
|
+
text = rb_str_export_to_enc(text, utf8_enc);
|
193
|
+
#endif
|
161
194
|
surface = renderer(Get_TTF_Font(self),
|
162
195
|
RSTRING_PTR(text),
|
163
196
|
rgb_to_SDL_Color(fgr, fgg, fgb),
|
@@ -191,23 +224,64 @@ static VALUE Font_renderSolidUTF8(VALUE self, VALUE text,
|
|
191
224
|
VALUE r, VALUE g, VALUE b)
|
192
225
|
|
193
226
|
{
|
194
|
-
return render(self, text, r, g, b, 1, 1, 1,
|
227
|
+
return render(self, text, r, g, b, 1, 1, 1, 0,
|
228
|
+
wrap_RenderUTF8_Solid);
|
195
229
|
}
|
196
230
|
|
197
231
|
static VALUE Font_renderBlendedUTF8(VALUE self, VALUE text,
|
198
232
|
VALUE r, VALUE g, VALUE b)
|
199
233
|
|
200
234
|
{
|
201
|
-
return render(self, text, r, g, b, 1, 1, 1,
|
235
|
+
return render(self, text, r, g, b, 1, 1, 1, 0,
|
236
|
+
wrap_RenderUTF8_Blended);
|
202
237
|
}
|
203
238
|
|
204
239
|
static VALUE Font_renderShadedUTF8(VALUE self, VALUE text,
|
205
|
-
|
206
|
-
|
240
|
+
VALUE fgr,VALUE fgg,VALUE fgb,
|
241
|
+
VALUE bgr,VALUE bgg,VALUE bgb)
|
242
|
+
{
|
243
|
+
return render(self, text, fgr, fgg, fgb, bgr, bgg, bgb, 0,
|
244
|
+
TTF_RenderUTF8_Shaded);
|
245
|
+
}
|
246
|
+
|
247
|
+
static VALUE Font_renderSolid(VALUE self, VALUE text,
|
248
|
+
VALUE r, VALUE g, VALUE b)
|
249
|
+
|
207
250
|
{
|
208
|
-
return render(self, text,
|
251
|
+
return render(self, text, r, g, b, 1, 1, 1, 1,
|
252
|
+
wrap_RenderUTF8_Solid);
|
209
253
|
}
|
210
254
|
|
255
|
+
static VALUE Font_renderBlended(VALUE self, VALUE text,
|
256
|
+
VALUE r, VALUE g, VALUE b)
|
257
|
+
|
258
|
+
{
|
259
|
+
return render(self, text, r, g, b, 1, 1, 1, 1,
|
260
|
+
wrap_RenderUTF8_Blended);
|
261
|
+
}
|
262
|
+
|
263
|
+
static VALUE Font_renderShaded(VALUE self, VALUE text,
|
264
|
+
VALUE fgr,VALUE fgg,VALUE fgb,
|
265
|
+
VALUE bgr,VALUE bgg,VALUE bgb)
|
266
|
+
{
|
267
|
+
return render(self, text, fgr, fgg, fgb, bgr, bgg, bgb, 1,
|
268
|
+
TTF_RenderUTF8_Shaded);
|
269
|
+
}
|
270
|
+
|
271
|
+
static VALUE Font_close(VALUE self)
|
272
|
+
{
|
273
|
+
TTFont* f = Get_TTFont(self);
|
274
|
+
if(!rubysdl_is_quit() && f->font)
|
275
|
+
TTF_CloseFont(f->font);
|
276
|
+
f->font = NULL;
|
277
|
+
|
278
|
+
return Qnil;
|
279
|
+
}
|
280
|
+
static VALUE Font_closed(VALUE self)
|
281
|
+
{
|
282
|
+
return INT2BOOL(Get_TTFont(self)->font == NULL);
|
283
|
+
}
|
284
|
+
|
211
285
|
void rubysdl_init_TTF(VALUE mSDL)
|
212
286
|
{
|
213
287
|
cTTFFont = rb_define_class_under(mSDL, "TTF", rb_cObject);
|
@@ -234,7 +308,12 @@ void rubysdl_init_TTF(VALUE mSDL)
|
|
234
308
|
rb_define_method(cTTFFont,"renderSolidUTF8",Font_renderSolidUTF8,4);
|
235
309
|
rb_define_method(cTTFFont,"renderBlendedUTF8",Font_renderBlendedUTF8,4);
|
236
310
|
rb_define_method(cTTFFont,"renderShadedUTF8",Font_renderShadedUTF8,7);
|
237
|
-
|
311
|
+
rb_define_method(cTTFFont,"renderSolid",Font_renderSolid,4);
|
312
|
+
rb_define_method(cTTFFont,"renderBlended",Font_renderBlended,4);
|
313
|
+
rb_define_method(cTTFFont,"renderShaded",Font_renderShaded,7);
|
314
|
+
rb_define_method(cTTFFont,"close", Font_close, 0);
|
315
|
+
rb_define_method(cTTFFont,"closed?", Font_closed, 0);
|
316
|
+
|
238
317
|
rb_define_const(cTTFFont,"STYLE_NORMAL",UINT2NUM(TTF_STYLE_NORMAL));
|
239
318
|
rb_define_const(cTTFFont,"STYLE_BOLD",UINT2NUM(TTF_STYLE_BOLD));
|
240
319
|
rb_define_const(cTTFFont,"STYLE_ITALIC",UINT2NUM(TTF_STYLE_ITALIC));
|