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/rubysdl_image.c
CHANGED
@@ -17,21 +17,24 @@
|
|
17
17
|
License along with this library; if not, write to the Free Software
|
18
18
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
19
|
*/
|
20
|
-
#ifdef HAVE_SDL_IMAGE
|
21
20
|
#include "rubysdl.h"
|
21
|
+
#ifdef HAVE_SDL_IMAGE
|
22
22
|
#include <SDL_image.h>
|
23
23
|
|
24
|
-
static VALUE
|
24
|
+
static VALUE Surface_s_load(VALUE klass, VALUE filename)
|
25
25
|
{
|
26
26
|
SDL_Surface *surface;
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
|
28
|
+
rb_secure(4);
|
29
|
+
SafeStringValue(filename);
|
30
|
+
|
31
|
+
surface = IMG_Load(RSTRING_PTR(filename));
|
32
|
+
if(surface == NULL)
|
33
|
+
rb_raise(eSDLError,"Couldn't load %s: %s",
|
34
|
+
RSTRING_PTR(filename), SDL_GetError());
|
35
|
+
return Surface_create(surface);
|
33
36
|
}
|
34
|
-
static VALUE
|
37
|
+
static VALUE Surface_s_loadFromIO(VALUE class,VALUE io)
|
35
38
|
{
|
36
39
|
volatile VALUE guard = io;
|
37
40
|
SDL_Surface *surface;
|
@@ -42,12 +45,33 @@ static VALUE sdl_loadFromIO(VALUE class,VALUE io)
|
|
42
45
|
rb_raise(eSDLError,"Couldn't load image from IO: %s",
|
43
46
|
SDL_GetError());
|
44
47
|
}
|
45
|
-
return
|
48
|
+
return Surface_create(surface);
|
49
|
+
}
|
50
|
+
static VALUE Surface_s_loadFromString(VALUE class,VALUE str)
|
51
|
+
{
|
52
|
+
SDL_Surface *surface;
|
53
|
+
rb_secure(4);
|
54
|
+
SafeStringValue(str);
|
55
|
+
|
56
|
+
surface = IMG_Load_RW(SDL_RWFromConstMem(RSTRING_PTR(str),
|
57
|
+
RSTRING_LEN(str)),
|
58
|
+
1);
|
59
|
+
|
60
|
+
if(surface==NULL){
|
61
|
+
rb_raise(eSDLError,"Couldn't load image from String: %s",
|
62
|
+
SDL_GetError());
|
63
|
+
}
|
64
|
+
return Surface_create(surface);
|
46
65
|
}
|
47
66
|
|
48
|
-
void
|
67
|
+
void rubysdl_init_image(VALUE mSDL, VALUE cSurface)
|
68
|
+
{
|
69
|
+
rb_define_singleton_method(cSurface, "load", Surface_s_load, 1);
|
70
|
+
rb_define_singleton_method(cSurface, "loadFromIO", Surface_s_loadFromIO, 1);
|
71
|
+
rb_define_singleton_method(cSurface, "loadFromString", Surface_s_loadFromString, 1);
|
72
|
+
}
|
73
|
+
#else /* HAVE_SDL_IMAGE */
|
74
|
+
void rubysdl_init_image(VALUE mSDL, VALUE cSurface)
|
49
75
|
{
|
50
|
-
rb_define_singleton_method(cSurface,"load",sdl_load,1);
|
51
|
-
rb_define_singleton_method(cSurface,"loadFromIO",sdl_loadFromIO,1);
|
52
76
|
}
|
53
77
|
#endif /* HAVE_SDL_IMAGE */
|
data/rubysdl_joystick.c
CHANGED
@@ -19,107 +19,244 @@
|
|
19
19
|
*/
|
20
20
|
#include "rubysdl.h"
|
21
21
|
|
22
|
+
/* basic */
|
23
|
+
typedef struct{
|
24
|
+
SDL_Joystick* joystick;
|
25
|
+
} Joystick;
|
22
26
|
|
23
|
-
static VALUE
|
27
|
+
static VALUE cJoystick=Qnil;
|
28
|
+
|
29
|
+
static Joystick* GetJoystick(VALUE obj)
|
30
|
+
{
|
31
|
+
Joystick* joy;
|
32
|
+
|
33
|
+
if(!rb_obj_is_kind_of(obj, cJoystick)){
|
34
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected SDL::Joystick)",
|
35
|
+
rb_obj_classname(obj));
|
36
|
+
}
|
37
|
+
|
38
|
+
Data_Get_Struct(obj, Joystick, joy);
|
39
|
+
return joy;
|
40
|
+
}
|
41
|
+
|
42
|
+
static SDL_Joystick* Get_SDL_Joystick(VALUE obj)
|
43
|
+
{
|
44
|
+
Joystick* joy = GetJoystick(obj);
|
45
|
+
if(joy->joystick == NULL){
|
46
|
+
rb_raise(rb_eRuntimeError, "joystick is closed");
|
47
|
+
}
|
48
|
+
|
49
|
+
return joy->joystick;
|
50
|
+
}
|
51
|
+
|
52
|
+
static void Joystick_free(Joystick* joy)
|
53
|
+
{
|
54
|
+
if(rubysdl_is_quit() || joy->joystick == NULL){
|
55
|
+
free(joy);
|
56
|
+
}else{
|
57
|
+
SDL_JoystickClose(joy->joystick);
|
58
|
+
free(joy);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
/* initialize methods */
|
63
|
+
static VALUE Joystick_s_alloc(VALUE klass)
|
24
64
|
{
|
25
|
-
|
65
|
+
Joystick* joy = ALLOC(Joystick);
|
66
|
+
joy->joystick = NULL;
|
67
|
+
return Data_Wrap_Struct(cJoystick, 0, Joystick_free, joy);
|
26
68
|
}
|
27
|
-
|
69
|
+
|
70
|
+
static VALUE Joystick_initialize(VALUE self, VALUE index)
|
28
71
|
{
|
29
|
-
|
72
|
+
Joystick* joy = GetJoystick(self);
|
73
|
+
rb_secure(4);
|
74
|
+
|
75
|
+
joy->joystick = SDL_JoystickOpen(NUM2INT(index));
|
76
|
+
if( joy->joystick == NULL ){
|
77
|
+
rb_raise(eSDLError, "Couldn't open joystick No.%d :%s", NUM2INT(index),
|
78
|
+
SDL_GetError());
|
79
|
+
}
|
80
|
+
return Qnil;
|
81
|
+
}
|
82
|
+
|
83
|
+
/* class methods */
|
84
|
+
static VALUE Joystick_s_poll(VALUE klass)
|
85
|
+
{
|
86
|
+
rb_secure(4);
|
87
|
+
return INT2BOOL(SDL_JoystickEventState(SDL_QUERY) == SDL_ENABLE);
|
88
|
+
}
|
89
|
+
|
90
|
+
static VALUE Joystick_s_set_poll(VALUE klass, VALUE poll)
|
91
|
+
{
|
92
|
+
rb_secure(4);
|
93
|
+
|
94
|
+
if(RTEST(poll))
|
30
95
|
SDL_JoystickEventState(SDL_ENABLE);
|
31
96
|
else
|
32
97
|
SDL_JoystickEventState(SDL_IGNORE);
|
33
98
|
return poll;
|
34
99
|
}
|
35
100
|
|
36
|
-
static VALUE
|
101
|
+
static VALUE Joystick_s_num(VALUE klass)
|
37
102
|
{
|
103
|
+
rb_secure(4);
|
38
104
|
return INT2FIX(SDL_NumJoysticks());
|
39
105
|
}
|
40
|
-
|
106
|
+
|
107
|
+
static VALUE Joystick_s_indexName(VALUE klass, VALUE index)
|
41
108
|
{
|
42
|
-
|
109
|
+
rb_secure(4);
|
110
|
+
return rb_str_new2(SDL_JoystickName(NUM2INT(index)));
|
43
111
|
}
|
44
|
-
|
112
|
+
|
113
|
+
static VALUE Joystick_s_open_p(VALUE klass, VALUE index)
|
45
114
|
{
|
46
|
-
|
47
|
-
|
48
|
-
if(joystick==NULL)
|
49
|
-
rb_raise(eSDLError,"Couldn't open joystick No.%d :%s",NUM2INT(index),
|
50
|
-
SDL_GetError());
|
51
|
-
return Data_Wrap_Struct(class,0,0,joystick);
|
115
|
+
rb_secure(4);
|
116
|
+
return INT2BOOL(SDL_JoystickOpened(NUM2INT(index)));
|
52
117
|
}
|
53
|
-
|
118
|
+
|
119
|
+
static VALUE Joystick_s_open(VALUE klass, VALUE index)
|
54
120
|
{
|
55
|
-
|
121
|
+
VALUE newobj;
|
122
|
+
rb_secure(4);
|
123
|
+
|
124
|
+
newobj = Joystick_s_alloc(klass);
|
125
|
+
Joystick_initialize(newobj, index);
|
126
|
+
return newobj;
|
56
127
|
}
|
57
|
-
|
128
|
+
|
129
|
+
static VALUE Joystick_s_update(VALUE klass)
|
58
130
|
{
|
131
|
+
rb_secure(4);
|
59
132
|
SDL_JoystickUpdate();
|
60
133
|
return Qnil;
|
61
134
|
}
|
62
|
-
|
135
|
+
|
136
|
+
/* methods */
|
137
|
+
static VALUE Joystick_close(VALUE self)
|
63
138
|
{
|
64
|
-
|
65
|
-
|
139
|
+
Joystick* joy;
|
140
|
+
rb_secure(4);
|
141
|
+
|
142
|
+
joy = GetJoystick(self);
|
143
|
+
SDL_JoystickClose(joy->joystick);
|
144
|
+
joy->joystick = NULL;
|
145
|
+
return Qnil;
|
146
|
+
}
|
147
|
+
|
148
|
+
static VALUE Joystick_index(VALUE self)
|
149
|
+
{
|
150
|
+
SDL_Joystick* joystick;
|
151
|
+
rb_secure(4);
|
152
|
+
|
153
|
+
joystick = Get_SDL_Joystick(self);
|
66
154
|
return INT2FIX(SDL_JoystickIndex(joystick));
|
67
155
|
}
|
68
|
-
|
156
|
+
|
157
|
+
static VALUE Joystick_numAxes(VALUE self)
|
69
158
|
{
|
70
|
-
SDL_Joystick
|
71
|
-
|
159
|
+
SDL_Joystick* joystick;
|
160
|
+
rb_secure(4);
|
161
|
+
|
162
|
+
joystick = Get_SDL_Joystick(self);
|
72
163
|
return INT2FIX(SDL_JoystickNumAxes(joystick));
|
73
164
|
}
|
74
|
-
|
165
|
+
|
166
|
+
static VALUE Joystick_numBalls(VALUE self)
|
75
167
|
{
|
76
168
|
SDL_Joystick *joystick;
|
77
|
-
|
169
|
+
rb_secure(4);
|
170
|
+
|
171
|
+
joystick = Get_SDL_Joystick(self);
|
78
172
|
return INT2FIX(SDL_JoystickNumBalls(joystick));
|
79
173
|
}
|
80
|
-
|
174
|
+
|
175
|
+
static VALUE Joystick_numHats(VALUE self)
|
81
176
|
{
|
82
177
|
SDL_Joystick *joystick;
|
83
|
-
|
178
|
+
rb_secure(4);
|
179
|
+
joystick = Get_SDL_Joystick(self);
|
84
180
|
return INT2FIX(SDL_JoystickNumHats(joystick));
|
85
181
|
}
|
86
|
-
|
182
|
+
|
183
|
+
static VALUE Joystick_numButtons(VALUE self)
|
87
184
|
{
|
88
185
|
SDL_Joystick *joystick;
|
89
|
-
|
186
|
+
rb_secure(4);
|
187
|
+
|
188
|
+
joystick = Get_SDL_Joystick(self);
|
90
189
|
return INT2FIX(SDL_JoystickNumButtons(joystick));
|
91
190
|
}
|
92
191
|
|
93
|
-
static VALUE
|
192
|
+
static VALUE Joystick_getAxis(VALUE self, VALUE axis)
|
94
193
|
{
|
95
194
|
SDL_Joystick *joystick;
|
96
|
-
|
97
|
-
|
195
|
+
rb_secure(4);
|
196
|
+
|
197
|
+
joystick = Get_SDL_Joystick(self);
|
198
|
+
return INT2NUM(SDL_JoystickGetAxis(joystick, NUM2INT(axis)));
|
98
199
|
}
|
99
|
-
|
200
|
+
|
201
|
+
static VALUE Joystick_getHat(VALUE self, VALUE hat)
|
100
202
|
{
|
101
203
|
SDL_Joystick *joystick;
|
102
|
-
|
103
|
-
|
204
|
+
rb_secure(4);
|
205
|
+
|
206
|
+
joystick = Get_SDL_Joystick(self);
|
207
|
+
return UINT2NUM(SDL_JoystickGetHat(joystick, NUM2INT(hat)));
|
104
208
|
}
|
105
|
-
|
209
|
+
|
210
|
+
static VALUE Joystick_getButton(VALUE self, VALUE button)
|
106
211
|
{
|
107
212
|
SDL_Joystick *joystick;
|
108
|
-
|
109
|
-
|
213
|
+
rb_secure(4);
|
214
|
+
|
215
|
+
joystick = Get_SDL_Joystick(self);
|
216
|
+
return INT2BOOL(SDL_JoystickGetButton(joystick, NUM2INT(button)));
|
110
217
|
}
|
111
|
-
|
218
|
+
|
219
|
+
static VALUE Joystick_getBall(VALUE self, VALUE ball)
|
112
220
|
{
|
113
221
|
SDL_Joystick *joystick;
|
114
222
|
int dx,dy;
|
115
|
-
|
116
|
-
|
223
|
+
|
224
|
+
rb_secure(4);
|
225
|
+
|
226
|
+
joystick = Get_SDL_Joystick(self);
|
227
|
+
if( SDL_JoystickGetBall(joystick, NUM2INT(ball), &dx, &dy) == -1 )
|
117
228
|
rb_raise(eSDLError,"SDL_JoystickGetBall failed :%s",SDL_GetError());
|
118
|
-
return rb_ary_new3(2,INT2FIX(dx),INT2FIX(dy));
|
229
|
+
return rb_ary_new3(2, INT2FIX(dx), INT2FIX(dy));
|
119
230
|
}
|
120
231
|
|
121
|
-
|
232
|
+
void rubysdl_init_Joystick(VALUE mSDL)
|
122
233
|
{
|
234
|
+
cJoystick = rb_define_class_under(mSDL, "Joystick", rb_cObject);
|
235
|
+
|
236
|
+
rb_define_singleton_method(cJoystick, "poll", Joystick_s_poll, 0);
|
237
|
+
rb_define_singleton_method(cJoystick, "poll=", Joystick_s_set_poll, 1);
|
238
|
+
rb_define_singleton_method(cJoystick, "num", Joystick_s_num, 0);
|
239
|
+
rb_define_singleton_method(cJoystick, "indexName", Joystick_s_indexName, 1);
|
240
|
+
rb_define_singleton_method(cJoystick, "open?", Joystick_s_open_p, 1);
|
241
|
+
rb_define_singleton_method(cJoystick, "update", Joystick_s_update, 0);
|
242
|
+
rb_define_singleton_method(cJoystick, "updateAll", Joystick_s_update, 0);
|
243
|
+
rb_define_singleton_method(cJoystick, "open", Joystick_s_open, 1);
|
244
|
+
|
245
|
+
rb_define_alloc_func(cJoystick, Joystick_s_alloc);
|
246
|
+
rb_define_private_method(cJoystick, "initialize", Joystick_initialize, 1);
|
247
|
+
|
248
|
+
rb_define_method(cJoystick, "close", Joystick_close, 0);
|
249
|
+
rb_define_method(cJoystick, "index", Joystick_index, 0);
|
250
|
+
rb_define_method(cJoystick, "numAxes", Joystick_numAxes, 0);
|
251
|
+
rb_define_method(cJoystick, "numBalls", Joystick_numBalls, 0);
|
252
|
+
rb_define_method(cJoystick, "numHats", Joystick_numHats, 0);
|
253
|
+
rb_define_method(cJoystick, "numButtons", Joystick_numButtons, 0);
|
254
|
+
|
255
|
+
rb_define_method(cJoystick, "axis", Joystick_getAxis, 1);
|
256
|
+
rb_define_method(cJoystick, "hat", Joystick_getHat, 1);
|
257
|
+
rb_define_method(cJoystick, "button", Joystick_getButton, 1);
|
258
|
+
rb_define_method(cJoystick, "ball", Joystick_getBall, 1);
|
259
|
+
|
123
260
|
rb_define_const(cJoystick,"HAT_CENTERED",UINT2NUM(SDL_HAT_CENTERED));
|
124
261
|
rb_define_const(cJoystick,"HAT_UP",UINT2NUM(SDL_HAT_UP));
|
125
262
|
rb_define_const(cJoystick,"HAT_RIGHT",UINT2NUM(SDL_HAT_RIGHT));
|
@@ -130,27 +267,3 @@ static void defineConstForJoystick()
|
|
130
267
|
rb_define_const(cJoystick,"HAT_LEFTUP",UINT2NUM(SDL_HAT_LEFTUP));
|
131
268
|
rb_define_const(cJoystick,"HAT_LEFTDOWN",UINT2NUM(SDL_HAT_LEFTDOWN));
|
132
269
|
}
|
133
|
-
void init_joystick()
|
134
|
-
{
|
135
|
-
cJoystick = rb_define_class_under(mSDL,"Joystick",rb_cObject);
|
136
|
-
rb_define_singleton_method(cJoystick,"poll",sdl_getJoyPolling,0);
|
137
|
-
rb_define_singleton_method(cJoystick,"poll=",sdl_setJoyPolling,1);
|
138
|
-
rb_define_singleton_method(cJoystick,"num",sdl_joystick_num,0);
|
139
|
-
rb_define_singleton_method(cJoystick,"indexName",sdl_joystick_name,1);
|
140
|
-
rb_define_singleton_method(cJoystick,"open",sdl_joystick_open,1);
|
141
|
-
rb_define_singleton_method(cJoystick,"open?",sdl_joystick_opened,1);
|
142
|
-
rb_define_singleton_method(cJoystick,"updateAll",sdl_joystick_update,0);
|
143
|
-
|
144
|
-
rb_define_method(cJoystick,"index",sdl_joystick_index,0);
|
145
|
-
rb_define_method(cJoystick,"numAxes",sdl_joystick_numAxes,0);
|
146
|
-
rb_define_method(cJoystick,"numBalls",sdl_joystick_numBalls,0);
|
147
|
-
rb_define_method(cJoystick,"numHats",sdl_joystick_numHats,0);
|
148
|
-
rb_define_method(cJoystick,"numButtons",sdl_joystick_numButtons,0);
|
149
|
-
|
150
|
-
rb_define_method(cJoystick,"axis",sdl_joystick_getAxis,1);
|
151
|
-
rb_define_method(cJoystick,"hat",sdl_joystick_getHat,1);
|
152
|
-
rb_define_method(cJoystick,"button",sdl_joystick_getButton,1);
|
153
|
-
rb_define_method(cJoystick,"ball",sdl_joystick_getBall,1);
|
154
|
-
|
155
|
-
defineConstForJoystick();
|
156
|
-
}
|
data/rubysdl_kanji.c
CHANGED
@@ -21,115 +21,101 @@
|
|
21
21
|
#include "SDL_kanji.h"
|
22
22
|
#include "rubysdl.h"
|
23
23
|
|
24
|
-
static VALUE
|
24
|
+
static VALUE cKanjiFont;
|
25
|
+
typedef int (*Drawer)(Kanji_Font*, int, int, SDL_Surface*, const char*, SDL_Color);
|
25
26
|
|
26
|
-
|
27
|
+
DEFINE_GET_STRUCT(Kanji_Font, Get_Kanji_Font, cKanjiFont, "SDL::Kanji::Font");
|
28
|
+
|
29
|
+
static VALUE Font_s_open(VALUE klass, VALUE filename, VALUE size)
|
27
30
|
{
|
28
31
|
Kanji_Font* font;
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
rb_secure(4);
|
34
|
+
SafeStringValue(filename);
|
35
|
+
|
36
|
+
font = Kanji_OpenFont(RSTRING_PTR(filename), NUM2INT(size));
|
37
|
+
if(font == NULL)
|
38
|
+
rb_raise(eSDLError,"Couldn't open bdf font: %s", RSTRING_PTR(filename));
|
39
|
+
return Data_Wrap_Struct(cKanjiFont, 0, Kanji_CloseFont, font);
|
34
40
|
}
|
35
41
|
|
36
|
-
static VALUE
|
42
|
+
static VALUE Font_setCodingSystem(VALUE self, VALUE sys)
|
37
43
|
{
|
38
|
-
|
39
|
-
|
40
|
-
Data_Get_Struct(obj,Kanji_Font,font);
|
41
|
-
|
42
|
-
Kanji_SetCodingSystem(font,NUM2INT(sys));
|
44
|
+
Kanji_SetCodingSystem(Get_Kanji_Font(self), NUM2INT(sys));
|
43
45
|
return Qnil;
|
44
46
|
}
|
45
47
|
|
46
|
-
static VALUE
|
48
|
+
static VALUE Font_add(VALUE self, VALUE filename)
|
47
49
|
{
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
rb_raise(eSDLError,"Couldn't use font: %s",GETCSTR(filename));
|
50
|
+
rb_secure(4);
|
51
|
+
SafeStringValue(filename);
|
52
|
+
if(Kanji_AddFont(Get_Kanji_Font(self), RSTRING_PTR(filename)) == -1)
|
53
|
+
rb_raise(eSDLError, "Couldn't use font: %s", RSTRING_PTR(filename));
|
53
54
|
return Qnil;
|
54
55
|
}
|
55
56
|
|
56
|
-
static VALUE
|
57
|
+
static VALUE Font_textwidth(VALUE self, VALUE text)
|
57
58
|
{
|
58
|
-
|
59
|
-
|
60
|
-
Data_Get_Struct(obj,Kanji_Font,font);
|
61
|
-
return INT2FIX(Kanji_FontWidth(font,GETCSTR(text)));
|
59
|
+
StringValue(text);
|
60
|
+
return INT2FIX(Kanji_FontWidth(Get_Kanji_Font(self), RSTRING_PTR(text)));
|
62
61
|
}
|
63
62
|
|
64
|
-
static VALUE
|
63
|
+
static VALUE Font_width(VALUE self)
|
65
64
|
{
|
66
|
-
|
67
|
-
|
68
|
-
Data_Get_Struct(obj,Kanji_Font,font);
|
69
|
-
return INT2FIX(Kanji_FontWidth(font,NULL));
|
65
|
+
return INT2FIX(Kanji_FontWidth(Get_Kanji_Font(self), NULL));
|
70
66
|
}
|
71
67
|
|
72
|
-
static VALUE
|
68
|
+
static VALUE Font_height(VALUE self)
|
73
69
|
{
|
74
|
-
|
75
|
-
|
76
|
-
Data_Get_Struct(obj,Kanji_Font,font);
|
77
|
-
return INT2FIX(Kanji_FontHeight(font));
|
70
|
+
return INT2FIX(Kanji_FontHeight(Get_Kanji_Font(self)));
|
78
71
|
}
|
79
72
|
|
80
|
-
static
|
81
|
-
|
73
|
+
static void Font_put(VALUE self, VALUE surface, VALUE text,
|
74
|
+
VALUE x, VALUE y,
|
75
|
+
VALUE r, VALUE g, VALUE b, Drawer draw)
|
82
76
|
{
|
83
|
-
Kanji_Font* font;
|
84
|
-
SDL_Surface* target;
|
85
77
|
SDL_Color color;
|
86
|
-
|
87
|
-
if(!rb_obj_is_kind_of(surface,cSurface))
|
88
|
-
rb_raise( rb_eArgError,"type mismatch(expect Surface)" );
|
89
|
-
|
90
|
-
Data_Get_Struct(obj,Kanji_Font,font);
|
91
|
-
Data_Get_Struct(surface,SDL_Surface,target);
|
92
78
|
|
79
|
+
rb_secure(4);
|
80
|
+
SafeStringValue(text);
|
81
|
+
|
93
82
|
color.r = NUM2INT(r);color.g = NUM2INT(g); color.b = NUM2INT(b);
|
94
|
-
|
95
|
-
|
83
|
+
|
84
|
+
draw(Get_Kanji_Font(self), NUM2INT(x), NUM2INT(y),
|
85
|
+
Get_SDL_Surface(surface), RSTRING_PTR(text), color);
|
86
|
+
}
|
87
|
+
|
88
|
+
static VALUE Font_putText(VALUE self, VALUE surface, VALUE text,
|
89
|
+
VALUE x, VALUE y,
|
90
|
+
VALUE r, VALUE g, VALUE b)
|
91
|
+
{
|
92
|
+
Font_put(self, surface, text, x, y, r, g, b, Kanji_PutText);
|
96
93
|
return Qnil;
|
97
94
|
}
|
98
95
|
|
99
|
-
static VALUE
|
100
|
-
|
96
|
+
static VALUE Font_putTextTate(VALUE self, VALUE surface, VALUE text,
|
97
|
+
VALUE x, VALUE y,
|
98
|
+
VALUE r, VALUE g, VALUE b)
|
101
99
|
{
|
102
|
-
|
103
|
-
SDL_Surface* target;
|
104
|
-
SDL_Color color;
|
105
|
-
|
106
|
-
if(!rb_obj_is_kind_of(surface,cSurface))
|
107
|
-
rb_raise( rb_eArgError,"type mismatch(expect Surface)" );
|
108
|
-
|
109
|
-
Data_Get_Struct(obj,Kanji_Font,font);
|
110
|
-
Data_Get_Struct(surface,SDL_Surface,target);
|
111
|
-
|
112
|
-
color.r = NUM2INT(r);color.g = NUM2INT(g); color.b = NUM2INT(b);
|
113
|
-
|
114
|
-
Kanji_PutTextTate(font,NUM2INT(x),NUM2INT(y),target,GETCSTR(text),
|
115
|
-
color);
|
100
|
+
Font_put(self, surface, text, x, y, r, g, b, Kanji_PutTextTate);
|
116
101
|
return Qnil;
|
117
102
|
}
|
118
103
|
|
119
|
-
void
|
104
|
+
void rubysdl_init_Kanji(VALUE mSDL)
|
120
105
|
{
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
rb_define_method(
|
126
|
-
rb_define_method(
|
127
|
-
rb_define_method(
|
128
|
-
rb_define_method(
|
129
|
-
rb_define_method(
|
130
|
-
rb_define_method(
|
106
|
+
cKanjiFont = rb_define_class_under(mSDL, "Kanji", rb_cObject);
|
107
|
+
rb_undef_alloc_func(cKanjiFont);
|
108
|
+
|
109
|
+
rb_define_singleton_method(cKanjiFont, "open", Font_s_open, 2);
|
110
|
+
rb_define_method(cKanjiFont, "add", Font_add, 1);
|
111
|
+
rb_define_method(cKanjiFont, "setCodingSystem", Font_setCodingSystem, 1);
|
112
|
+
rb_define_method(cKanjiFont, "textwidth", Font_textwidth, 1);
|
113
|
+
rb_define_method(cKanjiFont, "width", Font_width, 0);
|
114
|
+
rb_define_method(cKanjiFont, "height", Font_height, 0);
|
115
|
+
rb_define_method(cKanjiFont, "put", Font_putText, 7);
|
116
|
+
rb_define_method(cKanjiFont, "putTate", Font_putTextTate, 7);
|
131
117
|
|
132
|
-
rb_define_const(
|
133
|
-
rb_define_const(
|
134
|
-
rb_define_const(
|
118
|
+
rb_define_const(cKanjiFont, "SJIS", INT2NUM(KANJI_SJIS));
|
119
|
+
rb_define_const(cKanjiFont, "EUC", INT2NUM(KANJI_EUC));
|
120
|
+
rb_define_const(cKanjiFont, "JIS", INT2NUM(KANJI_JIS));
|
135
121
|
}
|