rubysdl 1.3.1 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/MANIFEST +22 -2
  2. data/NEWS.en +80 -0
  3. data/NEWS.ja +83 -0
  4. data/README.en +2 -1
  5. data/README.ja +2 -2
  6. data/doc-en/Makefile +18 -0
  7. data/doc-en/cdrom.rsd +417 -0
  8. data/doc-en/collision.rsd +174 -0
  9. data/doc-en/event.rsd +1476 -0
  10. data/doc-en/font.rsd +811 -0
  11. data/doc-en/general.rsd +43 -0
  12. data/doc-en/init.rsd +168 -0
  13. data/doc-en/joystick.rsd +401 -0
  14. data/doc-en/mixer.rsd +869 -0
  15. data/doc-en/mpeg.rsd +585 -0
  16. data/doc-en/opengl.rsd +155 -0
  17. data/doc-en/sdlskk.rsd +472 -0
  18. data/doc-en/time.rsd +46 -0
  19. data/doc-en/video.rsd +2806 -0
  20. data/doc-en/wm.rsd +112 -0
  21. data/doc/Makefile +1 -1
  22. data/doc/cdrom.rsd +3 -3
  23. data/doc/event.rsd +178 -179
  24. data/doc/general.rsd +10 -0
  25. data/doc/init.rsd +2 -2
  26. data/doc/joystick.rsd +29 -5
  27. data/doc/mixer.rsd +20 -0
  28. data/doc/rsd.rb +42 -9
  29. data/doc/sdlskk.rsd +7 -7
  30. data/doc/video.rsd +461 -168
  31. data/doc/wm.rsd +2 -2
  32. data/extconf.rb +1 -8
  33. data/lib/rubysdl_aliases.rb +52 -190
  34. data/lib/rubysdl_compatible_ver1.rb +243 -0
  35. data/lib/sdl.rb +58 -92
  36. data/rubysdl.h +59 -68
  37. data/rubysdl_cdrom.c +125 -102
  38. data/{rubysdl_doc.en.rd → rubysdl_doc_old.en.rd} +3 -2
  39. data/rubysdl_event.c +318 -255
  40. data/rubysdl_event_key.c +299 -287
  41. data/rubysdl_image.c +37 -13
  42. data/rubysdl_joystick.c +180 -67
  43. data/rubysdl_kanji.c +61 -75
  44. data/rubysdl_main.c +65 -138
  45. data/rubysdl_mixer.c +339 -214
  46. data/rubysdl_mouse.c +50 -43
  47. data/rubysdl_opengl.c +31 -28
  48. data/rubysdl_pixel.c +17 -28
  49. data/rubysdl_ref.en.html +5658 -0
  50. data/rubysdl_ref.en.rd +6337 -0
  51. data/rubysdl_ref.html +2253 -1964
  52. data/rubysdl_ref.rd +823 -469
  53. data/rubysdl_rwops.c +9 -6
  54. data/rubysdl_sdlskk.c +137 -165
  55. data/rubysdl_sge_video.c +355 -469
  56. data/rubysdl_smpeg.c +189 -190
  57. data/rubysdl_time.c +1 -1
  58. data/rubysdl_ttf.c +147 -215
  59. data/rubysdl_video.c +486 -405
  60. data/rubysdl_wm.c +30 -30
  61. data/sample/aadraw.rb +9 -9
  62. data/sample/alpha.rb +12 -13
  63. data/sample/alphadraw.rb +10 -10
  64. data/sample/bfont.rb +4 -4
  65. data/sample/cdrom.rb +11 -4
  66. data/sample/collision.rb +20 -20
  67. data/sample/cursor.rb +5 -5
  68. data/sample/ellipses.rb +20 -16
  69. data/sample/event2.rb +11 -9
  70. data/sample/font.rb +4 -4
  71. data/sample/fpstimer.rb +3 -3
  72. data/sample/icon.bmp.gz +0 -0
  73. data/sample/icon.png +0 -0
  74. data/sample/joy2.rb +14 -14
  75. data/sample/kanji.rb +7 -7
  76. data/sample/load_from_io.rb +44 -0
  77. data/sample/movesp.rb +13 -12
  78. data/sample/playmod.rb +2 -3
  79. data/sample/plaympeg.rb +8 -8
  80. data/sample/playwave.rb +5 -6
  81. data/sample/sdlskk.rb +11 -11
  82. data/sample/sgetest.rb +14 -12
  83. data/sample/stetris.rb +12 -13
  84. data/sample/testgl.rb +13 -14
  85. data/sample/testsprite.rb +12 -11
  86. data/sample/transformblit.rb +23 -22
  87. metadata +62 -35
  88. 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 sdl_load(VALUE class,VALUE filename)
24
+ static VALUE Surface_s_load(VALUE klass, VALUE filename)
25
25
  {
26
26
  SDL_Surface *surface;
27
- surface = IMG_Load(GETCSTR(filename));
28
- if(surface==NULL){
29
- rb_raise(eSDLError,"Couldn't load %s: %s",GETCSTR(filename),
30
- SDL_GetError());
31
- }
32
- return Data_Wrap_Struct(class,0,sdl_freeSurface,surface);
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 sdl_loadFromIO(VALUE class,VALUE io)
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 Data_Wrap_Struct(class,0,sdl_freeSurface,surface);
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 init_sdl_image()
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 sdl_getJoyPolling(VALUE class)
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
- return BOOL(SDL_JoystickEventState(SDL_QUERY)==SDL_ENABLE);
65
+ Joystick* joy = ALLOC(Joystick);
66
+ joy->joystick = NULL;
67
+ return Data_Wrap_Struct(cJoystick, 0, Joystick_free, joy);
26
68
  }
27
- static VALUE sdl_setJoyPolling(VALUE class,VALUE poll)
69
+
70
+ static VALUE Joystick_initialize(VALUE self, VALUE index)
28
71
  {
29
- if(poll)
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 sdl_joystick_num(VALUE class)
101
+ static VALUE Joystick_s_num(VALUE klass)
37
102
  {
103
+ rb_secure(4);
38
104
  return INT2FIX(SDL_NumJoysticks());
39
105
  }
40
- static VALUE sdl_joystick_name(VALUE class,VALUE index)
106
+
107
+ static VALUE Joystick_s_indexName(VALUE klass, VALUE index)
41
108
  {
42
- return rb_str_new2( SDL_JoystickName(NUM2INT(index)) );
109
+ rb_secure(4);
110
+ return rb_str_new2(SDL_JoystickName(NUM2INT(index)));
43
111
  }
44
- static VALUE sdl_joystick_open(VALUE class,VALUE index)
112
+
113
+ static VALUE Joystick_s_open_p(VALUE klass, VALUE index)
45
114
  {
46
- SDL_Joystick *joystick;
47
- joystick=SDL_JoystickOpen(NUM2INT(index));
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
- static VALUE sdl_joystick_opened(VALUE class,VALUE index)
118
+
119
+ static VALUE Joystick_s_open(VALUE klass, VALUE index)
54
120
  {
55
- return (SDL_JoystickOpened(NUM2INT(index)))?Qtrue:Qfalse;
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
- static VALUE sdl_joystick_update(VALUE class)
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
- static VALUE sdl_joystick_index(VALUE obj)
135
+
136
+ /* methods */
137
+ static VALUE Joystick_close(VALUE self)
63
138
  {
64
- SDL_Joystick *joystick;
65
- Data_Get_Struct(obj,SDL_Joystick,joystick);
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
- static VALUE sdl_joystick_numAxes(VALUE obj)
156
+
157
+ static VALUE Joystick_numAxes(VALUE self)
69
158
  {
70
- SDL_Joystick *joystick;
71
- Data_Get_Struct(obj,SDL_Joystick,joystick);
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
- static VALUE sdl_joystick_numBalls(VALUE obj)
165
+
166
+ static VALUE Joystick_numBalls(VALUE self)
75
167
  {
76
168
  SDL_Joystick *joystick;
77
- Data_Get_Struct(obj,SDL_Joystick,joystick);
169
+ rb_secure(4);
170
+
171
+ joystick = Get_SDL_Joystick(self);
78
172
  return INT2FIX(SDL_JoystickNumBalls(joystick));
79
173
  }
80
- static VALUE sdl_joystick_numHats(VALUE obj)
174
+
175
+ static VALUE Joystick_numHats(VALUE self)
81
176
  {
82
177
  SDL_Joystick *joystick;
83
- Data_Get_Struct(obj,SDL_Joystick,joystick);
178
+ rb_secure(4);
179
+ joystick = Get_SDL_Joystick(self);
84
180
  return INT2FIX(SDL_JoystickNumHats(joystick));
85
181
  }
86
- static VALUE sdl_joystick_numButtons(VALUE obj)
182
+
183
+ static VALUE Joystick_numButtons(VALUE self)
87
184
  {
88
185
  SDL_Joystick *joystick;
89
- Data_Get_Struct(obj,SDL_Joystick,joystick);
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 sdl_joystick_getAxis(VALUE obj,VALUE axis)
192
+ static VALUE Joystick_getAxis(VALUE self, VALUE axis)
94
193
  {
95
194
  SDL_Joystick *joystick;
96
- Data_Get_Struct(obj,SDL_Joystick,joystick);
97
- return INT2NUM(SDL_JoystickGetAxis(joystick,NUM2INT(axis)));
195
+ rb_secure(4);
196
+
197
+ joystick = Get_SDL_Joystick(self);
198
+ return INT2NUM(SDL_JoystickGetAxis(joystick, NUM2INT(axis)));
98
199
  }
99
- static VALUE sdl_joystick_getHat(VALUE obj,VALUE hat)
200
+
201
+ static VALUE Joystick_getHat(VALUE self, VALUE hat)
100
202
  {
101
203
  SDL_Joystick *joystick;
102
- Data_Get_Struct(obj,SDL_Joystick,joystick);
103
- return UINT2NUM(SDL_JoystickGetHat(joystick,NUM2INT(hat)));
204
+ rb_secure(4);
205
+
206
+ joystick = Get_SDL_Joystick(self);
207
+ return UINT2NUM(SDL_JoystickGetHat(joystick, NUM2INT(hat)));
104
208
  }
105
- static VALUE sdl_joystick_getButton(VALUE obj,VALUE button)
209
+
210
+ static VALUE Joystick_getButton(VALUE self, VALUE button)
106
211
  {
107
212
  SDL_Joystick *joystick;
108
- Data_Get_Struct(obj,SDL_Joystick,joystick);
109
- return (SDL_JoystickGetButton(joystick,NUM2INT(button)))?Qtrue:Qfalse;
213
+ rb_secure(4);
214
+
215
+ joystick = Get_SDL_Joystick(self);
216
+ return INT2BOOL(SDL_JoystickGetButton(joystick, NUM2INT(button)));
110
217
  }
111
- static VALUE sdl_joystick_getBall(VALUE obj,VALUE ball)
218
+
219
+ static VALUE Joystick_getBall(VALUE self, VALUE ball)
112
220
  {
113
221
  SDL_Joystick *joystick;
114
222
  int dx,dy;
115
- Data_Get_Struct(obj,SDL_Joystick,joystick);
116
- if( SDL_JoystickGetBall(joystick,NUM2INT(ball),&dx,&dy)== -1 )
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
- static void defineConstForJoystick()
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 cKanji;
24
+ static VALUE cKanjiFont;
25
+ typedef int (*Drawer)(Kanji_Font*, int, int, SDL_Surface*, const char*, SDL_Color);
25
26
 
26
- static VALUE kanji_open(VALUE obj,VALUE filename,VALUE size)
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
- font = Kanji_OpenFont(GETCSTR(filename),NUM2INT(size));
31
- if( font == NULL )
32
- rb_raise(eSDLError,"Couldn't open bdf font: %s",GETCSTR(filename));
33
- return Data_Wrap_Struct(cKanji,0,Kanji_CloseFont,font);
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 kanji_setCodingSystem(VALUE obj,VALUE sys)
42
+ static VALUE Font_setCodingSystem(VALUE self, VALUE sys)
37
43
  {
38
- Kanji_Font* font;
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 kanji_addFont(VALUE obj, VALUE filename)
48
+ static VALUE Font_add(VALUE self, VALUE filename)
47
49
  {
48
- Kanji_Font* font;
49
-
50
- Data_Get_Struct(obj,Kanji_Font,font);
51
- if( Kanji_AddFont(font,GETCSTR(filename)) == -1)
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 kanji_textwidth(VALUE obj,VALUE text)
57
+ static VALUE Font_textwidth(VALUE self, VALUE text)
57
58
  {
58
- Kanji_Font* font;
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 kanji_width(VALUE obj)
63
+ static VALUE Font_width(VALUE self)
65
64
  {
66
- Kanji_Font* font;
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 kanji_height(VALUE obj)
68
+ static VALUE Font_height(VALUE self)
73
69
  {
74
- Kanji_Font* font;
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 VALUE kanji_putText(VALUE obj,VALUE surface,VALUE text,VALUE x,VALUE y,
81
- VALUE r, VALUE g, VALUE b)
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
- Kanji_PutText(font,NUM2INT(x),NUM2INT(y),target,GETCSTR(text),
95
- color);
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 kanji_putTextTate(VALUE obj,VALUE surface,VALUE text,VALUE x,VALUE y,
100
- VALUE r, VALUE g, VALUE b)
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
- Kanji_Font* font;
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 init_kanji(void)
104
+ void rubysdl_init_Kanji(VALUE mSDL)
120
105
  {
121
- cKanji = rb_define_class_under(mSDL,"Kanji",rb_cObject);
122
-
123
- rb_define_singleton_method(cKanji,"open",kanji_open,2);
124
- rb_define_method(cKanji,"add",kanji_addFont,1);
125
- rb_define_method(cKanji,"setCodingSystem",kanji_setCodingSystem,1);
126
- rb_define_method(cKanji,"textwidth",kanji_textwidth,1);
127
- rb_define_method(cKanji,"width",kanji_width,0);
128
- rb_define_method(cKanji,"height",kanji_height,0);
129
- rb_define_method(cKanji,"put",kanji_putText,7);
130
- rb_define_method(cKanji,"putTate",kanji_putTextTate,7);
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(cKanji,"SJIS",INT2NUM(KANJI_SJIS));
133
- rb_define_const(cKanji,"EUC",INT2NUM(KANJI_EUC));
134
- rb_define_const(cKanji,"JIS",INT2NUM(KANJI_JIS));
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
  }