rubysdl 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +505 -0
- data/MANIFEST +81 -0
- data/NEWS.en +144 -0
- data/NEWS.ja +151 -0
- data/README.en +117 -0
- data/README.ja +166 -0
- data/SDL_kanji.c +403 -0
- data/SDL_kanji.h +48 -0
- data/depend +18 -0
- data/doc/Makefile +18 -0
- data/doc/cdrom.rsd +431 -0
- data/doc/collision.rsd +162 -0
- data/doc/event.rsd +1487 -0
- data/doc/font.rsd +839 -0
- data/doc/general.rsd +49 -0
- data/doc/init.rsd +175 -0
- data/doc/joystick.rsd +387 -0
- data/doc/mixer.rsd +837 -0
- data/doc/mpeg.rsd +595 -0
- data/doc/rsd.rb +125 -0
- data/doc/sdlskk.rsd +496 -0
- data/doc/time.rsd +45 -0
- data/doc/video.rsd +2499 -0
- data/doc/wm.rsd +113 -0
- data/extconf.rb +92 -0
- data/lib/rubysdl_aliases.rb +431 -0
- data/lib/sdl.rb +271 -0
- data/rubysdl.h +109 -0
- data/rubysdl_cdrom.c +176 -0
- data/rubysdl_const_list.txt +280 -0
- data/rubysdl_doc.en.rd +2180 -0
- data/rubysdl_doc_old.rd +2402 -0
- data/rubysdl_event.c +346 -0
- data/rubysdl_event2.c +417 -0
- data/rubysdl_event_key.c +356 -0
- data/rubysdl_image.c +53 -0
- data/rubysdl_joystick.c +156 -0
- data/rubysdl_kanji.c +135 -0
- data/rubysdl_main.c +202 -0
- data/rubysdl_mixer.c +422 -0
- data/rubysdl_mouse.c +96 -0
- data/rubysdl_opengl.c +63 -0
- data/rubysdl_pixel.c +133 -0
- data/rubysdl_ref.html +5550 -0
- data/rubysdl_ref.rd +6163 -0
- data/rubysdl_rwops.c +90 -0
- data/rubysdl_sdlskk.c +312 -0
- data/rubysdl_sge_video.c +622 -0
- data/rubysdl_smpeg.c +341 -0
- data/rubysdl_time.c +36 -0
- data/rubysdl_ttf.c +324 -0
- data/rubysdl_video.c +749 -0
- data/rubysdl_wm.c +71 -0
- data/sample/aadraw.rb +24 -0
- data/sample/alpha.rb +27 -0
- data/sample/alphadraw.rb +25 -0
- data/sample/bfont.rb +24 -0
- data/sample/cdrom.rb +17 -0
- data/sample/collision.rb +97 -0
- data/sample/cursor.bmp +0 -0
- data/sample/cursor.rb +22 -0
- data/sample/ellipses.rb +35 -0
- data/sample/event2.rb +32 -0
- data/sample/font.bmp +0 -0
- data/sample/font.rb +25 -0
- data/sample/fpstimer.rb +175 -0
- data/sample/icon.bmp +0 -0
- data/sample/joy2.rb +81 -0
- data/sample/kanji.rb +36 -0
- data/sample/movesp.rb +93 -0
- data/sample/playmod.rb +14 -0
- data/sample/plaympeg.rb +48 -0
- data/sample/playwave.rb +16 -0
- data/sample/randrect.rb +40 -0
- data/sample/sample.ttf +0 -0
- data/sample/sdlskk.rb +70 -0
- data/sample/sgetest.rb +31 -0
- data/sample/stetris.rb +275 -0
- data/sample/testgl.rb +166 -0
- data/sample/testsprite.rb +68 -0
- data/sample/transformblit.rb +41 -0
- metadata +121 -0
data/rubysdl_rwops.c
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
/*
|
2
|
+
Ruby/SDL Ruby extension library for SDL
|
3
|
+
|
4
|
+
Copyright (C) 2001-2007 Ohbayashi Ippei
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License as published by the Free Software Foundation; either
|
9
|
+
version 2.1 of the License, or (at your option) any later version.
|
10
|
+
|
11
|
+
This library is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public
|
17
|
+
License along with this library; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
#include "rubysdl.h"
|
21
|
+
|
22
|
+
static int rubyio_read(SDL_RWops* context, void* ptr, int size, int maxnum)
|
23
|
+
{
|
24
|
+
volatile VALUE io = (VALUE)context->hidden.unknown.data1;
|
25
|
+
volatile VALUE str;
|
26
|
+
str = rb_funcall(io, rb_intern("read"), 1, INT2NUM(size*maxnum));
|
27
|
+
StringValue(str);
|
28
|
+
|
29
|
+
memcpy(ptr, RSTRING(str)->ptr, RSTRING(str)->len);
|
30
|
+
return RSTRING(str)->len/size;
|
31
|
+
}
|
32
|
+
|
33
|
+
static int rubyio_write(SDL_RWops* context, const void* ptr, int size, int num)
|
34
|
+
{
|
35
|
+
rb_raise(rb_eTypeError, "not implemented yet RWops write");
|
36
|
+
}
|
37
|
+
|
38
|
+
static int rubyio_pseudo_seek(SDL_RWops* context, int offset, int whence)
|
39
|
+
{
|
40
|
+
volatile VALUE io = (VALUE)context->hidden.unknown.data1;
|
41
|
+
volatile VALUE str;
|
42
|
+
if(offset < 0)
|
43
|
+
rb_raise(eSDLError, "cannot seek backward");
|
44
|
+
|
45
|
+
|
46
|
+
switch(whence){
|
47
|
+
case SEEK_SET:
|
48
|
+
rb_funcall(io, rb_intern("rewind"), 0);
|
49
|
+
rb_funcall(io, rb_intern("read"), 1, INT2NUM(offset));
|
50
|
+
break;
|
51
|
+
case SEEK_CUR:
|
52
|
+
str = rb_funcall(io, rb_intern("read"), 1, INT2NUM(offset));
|
53
|
+
break;
|
54
|
+
case SEEK_END:
|
55
|
+
rb_raise(eSDLError, "cannot seek SEEK_END");
|
56
|
+
default:
|
57
|
+
SDL_SetError("Unknown value for 'whence'");
|
58
|
+
return(-1);
|
59
|
+
}
|
60
|
+
return NUM2INT(rb_funcall(io, rb_intern("tell"), 0));
|
61
|
+
}
|
62
|
+
|
63
|
+
static int rubyio_close(SDL_RWops* context)
|
64
|
+
{
|
65
|
+
if(context)
|
66
|
+
SDL_FreeRW(context);
|
67
|
+
return 0;
|
68
|
+
}
|
69
|
+
|
70
|
+
/* WARNING: +obj+ is not marked when GC starts,
|
71
|
+
so you should use `volatile' when this function is used
|
72
|
+
and you should not take out this RWops pointer to ruby's world.
|
73
|
+
*/
|
74
|
+
SDL_RWops* rubysdl_RWops_from_ruby_obj(VALUE obj)
|
75
|
+
{
|
76
|
+
SDL_RWops* rwops;
|
77
|
+
|
78
|
+
rwops = SDL_AllocRW();
|
79
|
+
if( rwops == NULL )
|
80
|
+
rb_raise(eSDLError, "Out of memory:%s", SDL_GetError());
|
81
|
+
|
82
|
+
rwops->seek = rubyio_pseudo_seek;
|
83
|
+
rwops->read = rubyio_read;
|
84
|
+
rwops->write = rubyio_write;
|
85
|
+
rwops->close = rubyio_close;
|
86
|
+
rwops->hidden.unknown.data1 = (void*)obj;
|
87
|
+
|
88
|
+
return rwops;
|
89
|
+
}
|
90
|
+
|
data/rubysdl_sdlskk.c
ADDED
@@ -0,0 +1,312 @@
|
|
1
|
+
/*
|
2
|
+
Ruby/SDL Ruby extension library for SDL
|
3
|
+
|
4
|
+
Copyright (C) 2001-2007 Ohbayashi Ippei
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License as published by the Free Software Foundation; either
|
9
|
+
version 2.1 of the License, or (at your option) any later version.
|
10
|
+
|
11
|
+
This library is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public
|
17
|
+
License along with this library; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
#ifdef HAVE_SDLSKK
|
21
|
+
#include "rubysdl.h"
|
22
|
+
#include <sdlskk.h>
|
23
|
+
#include <SDL_ttf.h>
|
24
|
+
|
25
|
+
typedef SDL_Surface* (*Renderer)(SDLSKK_Context*,TTF_Font*,SDL_Color);
|
26
|
+
|
27
|
+
static void skk_error_handler(SDLSKK_Error err)
|
28
|
+
{
|
29
|
+
switch( err ){
|
30
|
+
case SDLSKK_NOERROR:
|
31
|
+
return;
|
32
|
+
case SDLSKK_MEMERROR:
|
33
|
+
rb_fatal("SDLSKK: memory allocation error");
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
static VALUE skk_set_encoding(VALUE mod,VALUE encoding)
|
38
|
+
{
|
39
|
+
SDLSKK_set_encoding( NUM2INT(encoding) );
|
40
|
+
return Qnil;
|
41
|
+
}
|
42
|
+
|
43
|
+
static VALUE skk_get_encoding(VALUE mod)
|
44
|
+
{
|
45
|
+
return INT2FIX(SDLSKK_get_encoding());
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
static VALUE skk_Context_new(VALUE class,VALUE dict,VALUE rule_table,
|
50
|
+
VALUE keybind, VALUE use_minibuffer )
|
51
|
+
{
|
52
|
+
SDLSKK_Context* c_context;
|
53
|
+
SDLSKK_RomKanaRuleTable* c_table;
|
54
|
+
SDLSKK_Dictionary* c_dict;
|
55
|
+
SDLSKK_Keybind* c_bind;
|
56
|
+
VALUE context;
|
57
|
+
|
58
|
+
if( !rb_obj_is_kind_of(dict,cDictionary) )
|
59
|
+
rb_raise(rb_eArgError,"type mismatch(expect SDL::SKK::Dictionary)");
|
60
|
+
if( !rb_obj_is_kind_of(rule_table,cRomKanaRuleTable) )
|
61
|
+
rb_raise(rb_eArgError,"type mismatch(expect SDL::SKK::RomKanaRuleTable)");
|
62
|
+
if( !rb_obj_is_kind_of(keybind,cKeybind) )
|
63
|
+
rb_raise(rb_eArgError,"type mismatch(expect SDL::SKK::Keybind)");
|
64
|
+
|
65
|
+
Data_Get_Struct(dict,SDLSKK_Dictionary,c_dict);
|
66
|
+
Data_Get_Struct(rule_table,SDLSKK_RomKanaRuleTable,c_table);
|
67
|
+
Data_Get_Struct(keybind,SDLSKK_Keybind,c_bind);
|
68
|
+
|
69
|
+
c_context = SDLSKK_Context_new( c_dict, c_table, c_bind, RTEST(use_minibuffer) );
|
70
|
+
if( c_context == NULL )
|
71
|
+
rb_raise(eSDLError,"Couldn't create Context");
|
72
|
+
|
73
|
+
context = Data_Wrap_Struct(class,0,SDLSKK_Context_delete,c_context);
|
74
|
+
rb_iv_set(context,"dict",dict);
|
75
|
+
rb_iv_set(context,"rule_table",rule_table);
|
76
|
+
|
77
|
+
return context;
|
78
|
+
}
|
79
|
+
|
80
|
+
static VALUE skk_Context_input_event(VALUE obj,VALUE event)
|
81
|
+
{
|
82
|
+
SDLSKK_Context* context;
|
83
|
+
SDL_Event *ev;
|
84
|
+
|
85
|
+
Data_Get_Struct(obj,SDLSKK_Context,context);
|
86
|
+
if( rb_obj_is_kind_of( event,cEvent ) ){
|
87
|
+
Data_Get_Struct(event,SDL_Event,ev);
|
88
|
+
SDLSKK_Context_input_event( context, ev );
|
89
|
+
return Qnil;
|
90
|
+
}
|
91
|
+
|
92
|
+
#ifdef DEF_EVENT2
|
93
|
+
if( rb_obj_is_kind_of( event,cEvent2 ) ){
|
94
|
+
if( rb_obj_is_kind_of( event,cKeyDownEvent ) ){
|
95
|
+
SDL_Event ev2;
|
96
|
+
ev2.type = SDL_KEYDOWN;
|
97
|
+
ev2.key.keysym.sym = NUM2INT( rb_iv_get(event,"@sym") );
|
98
|
+
ev2.key.keysym.unicode = NUM2UINT( rb_iv_get(event,"@unicode") );
|
99
|
+
ev2.key.keysym.mod = NUM2INT( rb_iv_get(event,"@mod"));
|
100
|
+
SDLSKK_Context_input_event( context, &ev2 );
|
101
|
+
return Qnil;
|
102
|
+
}else{
|
103
|
+
return Qnil;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
#endif
|
108
|
+
rb_raise( rb_eArgError,"type mismatch(expect SDL::Event or SDL::Event2)");
|
109
|
+
|
110
|
+
/* NOT REACHED */
|
111
|
+
}
|
112
|
+
|
113
|
+
static VALUE skk_Context_get_str(VALUE obj)
|
114
|
+
{
|
115
|
+
SDLSKK_Context* context;
|
116
|
+
char cstr[10000];
|
117
|
+
|
118
|
+
Data_Get_Struct(obj,SDLSKK_Context,context);
|
119
|
+
|
120
|
+
SDLSKK_Context_get_str(context,cstr,sizeof(cstr));
|
121
|
+
|
122
|
+
return rb_str_new2(cstr);
|
123
|
+
}
|
124
|
+
|
125
|
+
static VALUE render_str(VALUE obj,VALUE font,VALUE r,VALUE g,VALUE b,
|
126
|
+
Renderer func)
|
127
|
+
{
|
128
|
+
SDLSKK_Context* context;
|
129
|
+
SDL_Surface* surface;
|
130
|
+
TTF_Font* ttf_font;
|
131
|
+
SDL_Color color;
|
132
|
+
|
133
|
+
if( !rb_obj_is_kind_of(font,cTTF) )
|
134
|
+
rb_raise( rb_eArgError,"type mismatch(expect SDL::TTF)");
|
135
|
+
|
136
|
+
color.r = NUM2UINT(r);
|
137
|
+
color.g = NUM2UINT(g);
|
138
|
+
color.b = NUM2UINT(b);
|
139
|
+
|
140
|
+
Data_Get_Struct(obj,SDLSKK_Context,context);
|
141
|
+
Data_Get_Struct(font,TTF_Font,ttf_font);
|
142
|
+
|
143
|
+
surface = func(context,ttf_font,color);
|
144
|
+
|
145
|
+
if( surface == NULL )
|
146
|
+
return Qnil;
|
147
|
+
|
148
|
+
return Data_Wrap_Struct(cSurface,0,sdl_freeSurface,surface);
|
149
|
+
}
|
150
|
+
|
151
|
+
static VALUE skk_Context_render_str(VALUE obj,VALUE font,VALUE r,VALUE g,
|
152
|
+
VALUE b)
|
153
|
+
{
|
154
|
+
return render_str(obj,font,r,g,b,SDLSKK_Context_render_display_str);
|
155
|
+
}
|
156
|
+
|
157
|
+
static VALUE skk_Context_render_minibuffer_str(VALUE obj,VALUE font,VALUE r,
|
158
|
+
VALUE g,VALUE b)
|
159
|
+
{
|
160
|
+
return render_str(obj,font,r,g,b,SDLSKK_Context_render_minibuffer_str);
|
161
|
+
}
|
162
|
+
|
163
|
+
static VALUE skk_Context_get_basic_mode(VALUE obj)
|
164
|
+
{
|
165
|
+
SDLSKK_Context* context;
|
166
|
+
|
167
|
+
Data_Get_Struct(obj,SDLSKK_Context,context);
|
168
|
+
return BOOL(SDLSKK_Context_get_basic_mode(context));
|
169
|
+
}
|
170
|
+
|
171
|
+
static VALUE skk_Context_clear(VALUE obj)
|
172
|
+
{
|
173
|
+
SDLSKK_Context* context;
|
174
|
+
|
175
|
+
Data_Get_Struct(obj,SDLSKK_Context,context);
|
176
|
+
SDLSKK_Context_clear(context);
|
177
|
+
return Qnil;
|
178
|
+
}
|
179
|
+
|
180
|
+
static VALUE skk_Context_clear_text(VALUE obj)
|
181
|
+
{
|
182
|
+
SDLSKK_Context* context;
|
183
|
+
|
184
|
+
Data_Get_Struct(obj,SDLSKK_Context,context);
|
185
|
+
SDLSKK_Context_clear_text(context);
|
186
|
+
return Qnil;
|
187
|
+
}
|
188
|
+
|
189
|
+
static VALUE skk_Dictionary_new(VALUE class)
|
190
|
+
{
|
191
|
+
SDLSKK_Dictionary* dict;
|
192
|
+
|
193
|
+
dict = SDLSKK_Dict_new();
|
194
|
+
if( dict == NULL )
|
195
|
+
rb_raise(eSDLError,"Couldn't create SDL::SKK::Dictionary" );
|
196
|
+
|
197
|
+
return Data_Wrap_Struct(class,0,SDLSKK_Dict_delete,dict);
|
198
|
+
}
|
199
|
+
|
200
|
+
static VALUE skk_Dict_load(VALUE obj,VALUE filename,VALUE users)
|
201
|
+
{
|
202
|
+
SDLSKK_Dictionary* dict;
|
203
|
+
|
204
|
+
Data_Get_Struct(obj,SDLSKK_Dictionary,dict);
|
205
|
+
|
206
|
+
if( !SDLSKK_Dict_load(dict,GETCSTR(filename),RTEST(users)) )
|
207
|
+
rb_raise(eSDLError,"Couldn't load %s",GETCSTR(filename));
|
208
|
+
|
209
|
+
return Qnil;
|
210
|
+
}
|
211
|
+
|
212
|
+
static VALUE skk_Dict_save(VALUE obj, VALUE filename)
|
213
|
+
{
|
214
|
+
SDLSKK_Dictionary* dict;
|
215
|
+
|
216
|
+
Data_Get_Struct(obj,SDLSKK_Dictionary,dict);
|
217
|
+
|
218
|
+
if( !SDLSKK_Dict_save_user_dict(dict,GETCSTR(filename)) )
|
219
|
+
rb_raise(eSDLError,"Couldn't save %s",GETCSTR(filename));
|
220
|
+
|
221
|
+
return Qnil;
|
222
|
+
}
|
223
|
+
|
224
|
+
static VALUE skk_RomKanaRuleTable_new(VALUE class,VALUE table_file)
|
225
|
+
{
|
226
|
+
SDLSKK_RomKanaRuleTable* rule_table;
|
227
|
+
|
228
|
+
rule_table = SDLSKK_RomKanaRuleTable_new( GETCSTR(table_file) );
|
229
|
+
|
230
|
+
if( rule_table == NULL )
|
231
|
+
rb_raise(eSDLError,"Couldn't load %s",GETCSTR(table_file));
|
232
|
+
|
233
|
+
return Data_Wrap_Struct(class,0,SDLSKK_RomKanaRuleTable_delete,rule_table);
|
234
|
+
}
|
235
|
+
|
236
|
+
static VALUE skk_Keybind_new(VALUE class)
|
237
|
+
{
|
238
|
+
return Data_Wrap_Struct(class,0,SDLSKK_Keybind_delete,SDLSKK_Keybind_new());
|
239
|
+
}
|
240
|
+
|
241
|
+
static VALUE skk_Keybind_set_key(VALUE obj,VALUE key_str,VALUE cmd_str)
|
242
|
+
{
|
243
|
+
SDLSKK_Keybind* keybind;
|
244
|
+
|
245
|
+
Data_Get_Struct(obj,SDLSKK_Keybind,keybind);
|
246
|
+
SDLSKK_Keybind_set_key(keybind,GETCSTR(key_str),GETCSTR(cmd_str));
|
247
|
+
return Qnil;
|
248
|
+
}
|
249
|
+
|
250
|
+
static VALUE skk_Keybind_set_default_key(VALUE obj)
|
251
|
+
{
|
252
|
+
SDLSKK_Keybind* keybind;
|
253
|
+
|
254
|
+
Data_Get_Struct(obj,SDLSKK_Keybind,keybind);
|
255
|
+
SDLSKK_Keybind_set_default_key(keybind);
|
256
|
+
return Qnil;
|
257
|
+
}
|
258
|
+
|
259
|
+
static VALUE skk_Keybind_unset_key(VALUE obj,VALUE key_str)
|
260
|
+
{
|
261
|
+
SDLSKK_Keybind* keybind;
|
262
|
+
|
263
|
+
Data_Get_Struct(obj,SDLSKK_Keybind,keybind);
|
264
|
+
SDLSKK_Keybind_unset_key(keybind,GETCSTR(key_str));
|
265
|
+
return Qnil;
|
266
|
+
}
|
267
|
+
|
268
|
+
static void defineConstForSDLSKK(void)
|
269
|
+
{
|
270
|
+
rb_define_const(mSDLSKK,"EUCJP",INT2NUM(SDLSKK_EUCJP));
|
271
|
+
rb_define_const(mSDLSKK,"UTF8",INT2NUM(SDLSKK_UTF8));
|
272
|
+
rb_define_const(mSDLSKK,"SJIS",INT2NUM(SDLSKK_SJIS));
|
273
|
+
}
|
274
|
+
|
275
|
+
void init_sdlskk(void)
|
276
|
+
{
|
277
|
+
mSDLSKK = rb_define_module_under(mSDL,"SKK");
|
278
|
+
cContext = rb_define_class_under(mSDLSKK,"Context",rb_cObject);
|
279
|
+
cDictionary = rb_define_class_under(mSDLSKK,"Dictionary",rb_cObject);
|
280
|
+
cRomKanaRuleTable = rb_define_class_under(mSDLSKK,"RomKanaRuleTable",
|
281
|
+
rb_cObject);
|
282
|
+
cKeybind = rb_define_class_under(mSDLSKK,"Keybind",rb_cObject);
|
283
|
+
|
284
|
+
rb_define_module_function(mSDLSKK,"encoding=",skk_set_encoding,1);
|
285
|
+
rb_define_module_function(mSDLSKK,"encoding",skk_get_encoding,0);
|
286
|
+
|
287
|
+
rb_define_singleton_method(cContext,"new",skk_Context_new,4);
|
288
|
+
rb_define_method(cContext,"input",skk_Context_input_event,1);
|
289
|
+
rb_define_method(cContext,"str",skk_Context_get_str,0);
|
290
|
+
rb_define_method(cContext,"render_str",skk_Context_render_str,4);
|
291
|
+
rb_define_method(cContext,"render_minibuffer_str",skk_Context_render_minibuffer_str,4);
|
292
|
+
rb_define_method(cContext,"get_basic_mode",skk_Context_get_basic_mode,0);
|
293
|
+
rb_define_method(cContext,"clear",skk_Context_clear,0);
|
294
|
+
rb_define_method(cContext,"clear_text",skk_Context_clear_text,0);
|
295
|
+
|
296
|
+
rb_define_singleton_method(cDictionary,"new",skk_Dictionary_new,0);
|
297
|
+
rb_define_method(cDictionary,"load",skk_Dict_load,2);
|
298
|
+
rb_define_method(cDictionary,"save",skk_Dict_save,1);
|
299
|
+
|
300
|
+
rb_define_singleton_method(cRomKanaRuleTable,"new",
|
301
|
+
skk_RomKanaRuleTable_new,1);
|
302
|
+
|
303
|
+
rb_define_singleton_method(cKeybind,"new",skk_Keybind_new,0);
|
304
|
+
rb_define_method(cKeybind,"set_key",skk_Keybind_set_key,2);
|
305
|
+
rb_define_method(cKeybind,"set_default_key",skk_Keybind_set_default_key,0);
|
306
|
+
rb_define_method(cKeybind,"unset_key",skk_Keybind_unset_key,1);
|
307
|
+
|
308
|
+
SDLSKK_set_error_func(skk_error_handler);
|
309
|
+
|
310
|
+
defineConstForSDLSKK();
|
311
|
+
}
|
312
|
+
#endif /* HAVE_SDLSKK */
|
data/rubysdl_sge_video.c
ADDED
@@ -0,0 +1,622 @@
|
|
1
|
+
/*
|
2
|
+
Ruby/SDL Ruby extension library for SDL
|
3
|
+
|
4
|
+
Copyright (C) 2001-2007 Ohbayashi Ippei
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License as published by the Free Software Foundation; either
|
9
|
+
version 2.1 of the License, or (at your option) any later version.
|
10
|
+
|
11
|
+
This library is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public
|
17
|
+
License along with this library; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
#ifdef HAVE_SGE
|
21
|
+
|
22
|
+
#include "rubysdl.h"
|
23
|
+
#include <sge.h>
|
24
|
+
|
25
|
+
static VALUE sdl_get_autoLocking(VALUE mod)
|
26
|
+
{
|
27
|
+
return BOOL(sge_getLock());
|
28
|
+
}
|
29
|
+
|
30
|
+
static VALUE sdl_set_autoLocking(VALUE mod,VALUE bool)
|
31
|
+
{
|
32
|
+
if(RTEST(bool))
|
33
|
+
sge_Lock_ON();
|
34
|
+
else
|
35
|
+
sge_Lock_OFF();
|
36
|
+
return Qnil;
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
static VALUE sdl_getPixel(VALUE obj,VALUE x,VALUE y)
|
41
|
+
{
|
42
|
+
SDL_Surface *surface;
|
43
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
44
|
+
return UINT2NUM( sge_GetPixel(surface,NUM2INT(x),NUM2INT(y)) );
|
45
|
+
}
|
46
|
+
static VALUE sdl_putPixel(VALUE obj,VALUE x,VALUE y,VALUE color)
|
47
|
+
{
|
48
|
+
SDL_Surface *surface;
|
49
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
50
|
+
sge_PutPixel(surface,NUM2INT(x),NUM2INT(y),VALUE2COLOR(color,surface->format));
|
51
|
+
return Qnil;
|
52
|
+
}
|
53
|
+
static VALUE sdl_drawLine(VALUE obj,VALUE x1,VALUE y1,VALUE x2,VALUE y2,VALUE color)
|
54
|
+
{
|
55
|
+
SDL_Surface *surface;
|
56
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
57
|
+
sge_Line( surface,NUM2INT(x1),NUM2INT(y1),NUM2INT(x2),NUM2INT(y2),
|
58
|
+
VALUE2COLOR(color,surface->format) );
|
59
|
+
return Qnil;
|
60
|
+
}
|
61
|
+
static VALUE sdl_drawAALine(VALUE obj,VALUE x1,VALUE y1,VALUE x2,VALUE y2,VALUE color)
|
62
|
+
{
|
63
|
+
SDL_Surface *surface;
|
64
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
65
|
+
sge_AALine( surface,NUM2INT(x1),NUM2INT(y1),NUM2INT(x2),NUM2INT(y2),
|
66
|
+
VALUE2COLOR(color,surface->format) );
|
67
|
+
return Qnil;
|
68
|
+
}
|
69
|
+
static VALUE sdl_drawLineAlpha(VALUE obj,VALUE x1,VALUE y1,VALUE x2,VALUE y2,VALUE color,VALUE alpha)
|
70
|
+
{
|
71
|
+
SDL_Surface *surface;
|
72
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
73
|
+
sge_LineAlpha( surface,NUM2INT(x1),NUM2INT(y1),NUM2INT(x2),NUM2INT(y2),
|
74
|
+
VALUE2COLOR(color,surface->format), NUM2UINT(alpha) );
|
75
|
+
return Qnil;
|
76
|
+
}
|
77
|
+
static VALUE sdl_drawAALineAlpha(VALUE obj,VALUE x1,VALUE y1,VALUE x2,VALUE y2,VALUE color,VALUE alpha)
|
78
|
+
{
|
79
|
+
SDL_Surface *surface;
|
80
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
81
|
+
sge_AALineAlpha( surface,NUM2INT(x1),NUM2INT(y1),NUM2INT(x2),NUM2INT(y2),
|
82
|
+
VALUE2COLOR(color,surface->format),NUM2UINT(alpha) );
|
83
|
+
return Qnil;
|
84
|
+
}
|
85
|
+
|
86
|
+
static VALUE sdl_drawRect(VALUE obj,VALUE x,VALUE y,VALUE w,VALUE h,VALUE color)
|
87
|
+
{
|
88
|
+
SDL_Surface *surface;
|
89
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
90
|
+
sge_Rect( surface,NUM2INT(x),NUM2INT(y),NUM2INT(x)+NUM2INT(w),
|
91
|
+
NUM2INT(y)+NUM2INT(h),VALUE2COLOR(color,surface->format) );
|
92
|
+
return Qnil;
|
93
|
+
}
|
94
|
+
static VALUE sdl_drawRectAlpha(VALUE obj,VALUE x,VALUE y,VALUE w,VALUE h,VALUE color,VALUE alpha)
|
95
|
+
{
|
96
|
+
SDL_Surface *surface;
|
97
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
98
|
+
sge_RectAlpha( surface,NUM2INT(x),NUM2INT(y),NUM2INT(x)+NUM2INT(w),
|
99
|
+
NUM2INT(y)+NUM2INT(h),VALUE2COLOR(color,surface->format),
|
100
|
+
NUM2UINT(alpha) );
|
101
|
+
return Qnil;
|
102
|
+
}
|
103
|
+
static VALUE sdl_drawFilledRectAlpha(VALUE obj,VALUE x,VALUE y,VALUE w,VALUE h,VALUE color,VALUE alpha)
|
104
|
+
{
|
105
|
+
SDL_Surface *surface;
|
106
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
107
|
+
sge_FilledRectAlpha( surface,NUM2INT(x),NUM2INT(y),NUM2INT(x)+NUM2INT(w),
|
108
|
+
NUM2INT(y)+NUM2INT(h),VALUE2COLOR(color,surface->format),
|
109
|
+
NUM2UINT(alpha) );
|
110
|
+
return Qnil;
|
111
|
+
}
|
112
|
+
static VALUE sdl_drawCircle(VALUE obj,VALUE x,VALUE y,VALUE r,VALUE color)
|
113
|
+
{
|
114
|
+
SDL_Surface *surface;
|
115
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
116
|
+
sge_Circle( surface,NUM2INT(x),NUM2INT(y),NUM2INT(r),
|
117
|
+
VALUE2COLOR(color,surface->format) );
|
118
|
+
return Qnil;
|
119
|
+
}
|
120
|
+
static VALUE sdl_drawAACircle(VALUE obj,VALUE x,VALUE y,VALUE r,VALUE color)
|
121
|
+
{
|
122
|
+
SDL_Surface *surface;
|
123
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
124
|
+
sge_AACircle( surface,NUM2INT(x),NUM2INT(y),NUM2INT(r),
|
125
|
+
VALUE2COLOR(color,surface->format) );
|
126
|
+
return Qnil;
|
127
|
+
}
|
128
|
+
static VALUE sdl_drawCircleAlpha(VALUE obj,VALUE x,VALUE y,VALUE r,VALUE color,VALUE alpha)
|
129
|
+
{
|
130
|
+
SDL_Surface *surface;
|
131
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
132
|
+
sge_CircleAlpha( surface,NUM2INT(x),NUM2INT(y),NUM2INT(r),
|
133
|
+
VALUE2COLOR(color,surface->format),NUM2UINT(alpha) );
|
134
|
+
return Qnil;
|
135
|
+
}
|
136
|
+
static VALUE sdl_drawAACircleAlpha(VALUE obj,VALUE x,VALUE y,VALUE r,VALUE color,
|
137
|
+
VALUE alpha)
|
138
|
+
{
|
139
|
+
SDL_Surface *surface;
|
140
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
141
|
+
sge_AACircleAlpha( surface,NUM2INT(x),NUM2INT(y),NUM2INT(r),
|
142
|
+
VALUE2COLOR(color,surface->format),NUM2UINT(alpha) );
|
143
|
+
return Qnil;
|
144
|
+
}
|
145
|
+
static VALUE sdl_drawFilledCircle(VALUE obj,VALUE x,VALUE y,VALUE r,VALUE color)
|
146
|
+
{
|
147
|
+
SDL_Surface *surface;
|
148
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
149
|
+
sge_FilledCircle( surface,NUM2INT(x),NUM2INT(y),NUM2INT(r),
|
150
|
+
VALUE2COLOR(color,surface->format) );
|
151
|
+
return Qnil;
|
152
|
+
}
|
153
|
+
static VALUE sdl_drawAAFilledCircle(VALUE obj,VALUE x,VALUE y,VALUE r,VALUE color)
|
154
|
+
{
|
155
|
+
SDL_Surface *surface;
|
156
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
157
|
+
sge_AAFilledCircle( surface,NUM2INT(x),NUM2INT(y),NUM2INT(r),
|
158
|
+
VALUE2COLOR(color,surface->format) );
|
159
|
+
return Qnil;
|
160
|
+
}
|
161
|
+
static VALUE sdl_drawFilledCircleAlpha(VALUE obj,VALUE x,VALUE y,VALUE r,VALUE color,VALUE alpha)
|
162
|
+
{
|
163
|
+
SDL_Surface *surface;
|
164
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
165
|
+
sge_FilledCircleAlpha( surface,NUM2INT(x),NUM2INT(y),NUM2INT(r),
|
166
|
+
VALUE2COLOR(color,surface->format),NUM2UINT(alpha) );
|
167
|
+
return Qnil;
|
168
|
+
}
|
169
|
+
static VALUE sdl_drawEllipse(VALUE obj,VALUE x,VALUE y,VALUE rx,VALUE ry,
|
170
|
+
VALUE color)
|
171
|
+
{
|
172
|
+
SDL_Surface *surface;
|
173
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
174
|
+
sge_Ellipse( surface,NUM2INT(x),NUM2INT(y),NUM2INT(rx),NUM2INT(ry),
|
175
|
+
VALUE2COLOR(color,surface->format) );
|
176
|
+
return Qnil;
|
177
|
+
}
|
178
|
+
static VALUE sdl_drawAAEllipse(VALUE obj,VALUE x,VALUE y,VALUE rx,VALUE ry,
|
179
|
+
VALUE color)
|
180
|
+
{
|
181
|
+
SDL_Surface *surface;
|
182
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
183
|
+
sge_AAEllipse( surface,NUM2INT(x),NUM2INT(y),NUM2INT(rx),NUM2INT(ry),
|
184
|
+
VALUE2COLOR(color,surface->format) );
|
185
|
+
return Qnil;
|
186
|
+
}
|
187
|
+
static VALUE sdl_drawEllipseAlpha(VALUE obj,VALUE x,VALUE y,VALUE rx,VALUE ry,
|
188
|
+
VALUE color,VALUE alpha)
|
189
|
+
{
|
190
|
+
SDL_Surface *surface;
|
191
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
192
|
+
sge_EllipseAlpha( surface,NUM2INT(x),NUM2INT(y),NUM2INT(rx),NUM2INT(ry),
|
193
|
+
VALUE2COLOR(color,surface->format),NUM2UINT(alpha) );
|
194
|
+
return Qnil;
|
195
|
+
}
|
196
|
+
static VALUE sdl_drawAAEllipseAlpha(VALUE obj,VALUE x,VALUE y,VALUE rx,VALUE ry,
|
197
|
+
VALUE color,VALUE alpha)
|
198
|
+
{
|
199
|
+
SDL_Surface *surface;
|
200
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
201
|
+
sge_AAEllipseAlpha( surface,NUM2INT(x),NUM2INT(y),NUM2INT(rx),NUM2INT(ry),
|
202
|
+
VALUE2COLOR(color,surface->format),NUM2UINT(alpha) );
|
203
|
+
return Qnil;
|
204
|
+
}
|
205
|
+
static VALUE sdl_drawFilledEllipse(VALUE obj,VALUE x,VALUE y,VALUE rx,VALUE ry,
|
206
|
+
VALUE color)
|
207
|
+
{
|
208
|
+
SDL_Surface *surface;
|
209
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
210
|
+
sge_FilledEllipse( surface,NUM2INT(x),NUM2INT(y),NUM2INT(rx),NUM2INT(ry),
|
211
|
+
VALUE2COLOR(color,surface->format) );
|
212
|
+
return Qnil;
|
213
|
+
}
|
214
|
+
static VALUE sdl_drawAAFilledEllipse(VALUE obj,VALUE x,VALUE y,VALUE rx,VALUE ry,
|
215
|
+
VALUE color)
|
216
|
+
{
|
217
|
+
SDL_Surface *surface;
|
218
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
219
|
+
sge_AAFilledEllipse( surface,NUM2INT(x),NUM2INT(y),NUM2INT(rx),NUM2INT(ry),
|
220
|
+
VALUE2COLOR(color,surface->format) );
|
221
|
+
return Qnil;
|
222
|
+
}
|
223
|
+
static VALUE sdl_drawFilledEllipseAlpha(VALUE obj,VALUE x,VALUE y,VALUE rx,VALUE ry,
|
224
|
+
VALUE color,VALUE alpha)
|
225
|
+
{
|
226
|
+
SDL_Surface *surface;
|
227
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
228
|
+
sge_FilledEllipseAlpha( surface,NUM2INT(x),NUM2INT(y),NUM2INT(rx),NUM2INT(ry),
|
229
|
+
VALUE2COLOR(color,surface->format),NUM2UINT(alpha) );
|
230
|
+
return Qnil;
|
231
|
+
}
|
232
|
+
|
233
|
+
static VALUE sdl_drawBezier(VALUE obj,VALUE x1,VALUE y1,VALUE x2,VALUE y2,
|
234
|
+
VALUE x3,VALUE y3,VALUE x4,VALUE y4,
|
235
|
+
VALUE level,VALUE color)
|
236
|
+
{
|
237
|
+
SDL_Surface *surface;
|
238
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
239
|
+
sge_Bezier(surface,NUM2INT(x1),NUM2INT(y1),NUM2INT(x2),NUM2INT(y2),
|
240
|
+
NUM2INT(x3),NUM2INT(y3),NUM2INT(x4),NUM2INT(y4),
|
241
|
+
NUM2INT(level),VALUE2COLOR(color,surface->format));
|
242
|
+
return Qnil;
|
243
|
+
}
|
244
|
+
|
245
|
+
static VALUE sdl_drawBezierAlpha(VALUE obj,VALUE x1,VALUE y1,VALUE x2,VALUE y2,
|
246
|
+
VALUE x3,VALUE y3,VALUE x4,VALUE y4,
|
247
|
+
VALUE level,VALUE color,VALUE alpha)
|
248
|
+
{
|
249
|
+
SDL_Surface *surface;
|
250
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
251
|
+
sge_BezierAlpha(surface,NUM2INT(x1),NUM2INT(y1),NUM2INT(x2),NUM2INT(y2),
|
252
|
+
NUM2INT(x3),NUM2INT(y3),NUM2INT(x4),NUM2INT(y4),
|
253
|
+
NUM2INT(level),VALUE2COLOR(color,surface->format),
|
254
|
+
NUM2UINT(alpha));
|
255
|
+
return Qnil;
|
256
|
+
}
|
257
|
+
|
258
|
+
static VALUE sdl_drawAABezier(VALUE obj,VALUE x1,VALUE y1,VALUE x2,VALUE y2,
|
259
|
+
VALUE x3,VALUE y3,VALUE x4,VALUE y4,
|
260
|
+
VALUE level,VALUE color)
|
261
|
+
{
|
262
|
+
SDL_Surface *surface;
|
263
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
264
|
+
sge_AABezier(surface,NUM2INT(x1),NUM2INT(y1),NUM2INT(x2),NUM2INT(y2),
|
265
|
+
NUM2INT(x3),NUM2INT(y3),NUM2INT(x4),NUM2INT(y4),
|
266
|
+
NUM2INT(level),VALUE2COLOR(color,surface->format));
|
267
|
+
return Qnil;
|
268
|
+
}
|
269
|
+
|
270
|
+
static VALUE sdl_drawAABezierAlpha(VALUE obj,VALUE x1,VALUE y1,VALUE x2,VALUE y2,
|
271
|
+
VALUE x3,VALUE y3,VALUE x4,VALUE y4,
|
272
|
+
VALUE level,VALUE color,VALUE alpha)
|
273
|
+
{
|
274
|
+
SDL_Surface *surface;
|
275
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
276
|
+
sge_AABezierAlpha(surface,NUM2INT(x1),NUM2INT(y1),NUM2INT(x2),NUM2INT(y2),
|
277
|
+
NUM2INT(x3),NUM2INT(y3),NUM2INT(x4),NUM2INT(y4),
|
278
|
+
NUM2INT(level),VALUE2COLOR(color,surface->format),
|
279
|
+
NUM2UINT(alpha));
|
280
|
+
return Qnil;
|
281
|
+
}
|
282
|
+
|
283
|
+
static VALUE sdl_rotateScaledSurface(VALUE obj,VALUE angle,VALUE scale,VALUE bgcolor)
|
284
|
+
{
|
285
|
+
SDL_Surface *surface,*result;
|
286
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
287
|
+
result=sge_rotate_scaled_surface(surface,NUM2INT(angle),NUM2DBL(scale),
|
288
|
+
VALUE2COLOR(bgcolor,surface->format) );
|
289
|
+
if( result==NULL )
|
290
|
+
rb_raise( eSDLError,"Couldn't Create Surface: %s",SDL_GetError() );
|
291
|
+
return Data_Wrap_Struct(cSurface,0,sdl_freeSurface,result);
|
292
|
+
}
|
293
|
+
/* doesn't respect ColorKey */
|
294
|
+
static VALUE sdl_rotateXYScaled(VALUE mod,VALUE src,VALUE dst,VALUE x,
|
295
|
+
VALUE y,VALUE angle,VALUE xscale,
|
296
|
+
VALUE yscale)
|
297
|
+
{
|
298
|
+
SDL_Surface *srcSurface,*dstSurface;
|
299
|
+
if( !rb_obj_is_kind_of(src,cSurface) || !rb_obj_is_kind_of(dst,cSurface) )
|
300
|
+
rb_raise(rb_eArgError,"type mismatch(expect Surface)");
|
301
|
+
Data_Get_Struct(src,SDL_Surface,srcSurface);
|
302
|
+
Data_Get_Struct(dst,SDL_Surface,dstSurface);
|
303
|
+
sge_rotate_xyscaled(dstSurface,srcSurface,NUM2INT(x),NUM2INT(y),
|
304
|
+
NUM2INT(angle),NUM2DBL(xscale),NUM2DBL(yscale));
|
305
|
+
return Qnil;
|
306
|
+
}
|
307
|
+
static VALUE sdl_rotateScaledBlit(VALUE mod,VALUE src,VALUE dst,VALUE x,
|
308
|
+
VALUE y,VALUE angle,VALUE scale)
|
309
|
+
{
|
310
|
+
SDL_Surface *srcSurface,*dstSurface,*tmpSurface;
|
311
|
+
SDL_Rect destRect;
|
312
|
+
Uint32 colorkey;
|
313
|
+
Uint32 flags;
|
314
|
+
int result;
|
315
|
+
|
316
|
+
if( !rb_obj_is_kind_of(src,cSurface) || !rb_obj_is_kind_of(dst,cSurface) )
|
317
|
+
rb_raise(rb_eArgError,"type mismatch(expect Surface)");
|
318
|
+
Data_Get_Struct(src,SDL_Surface,srcSurface);
|
319
|
+
Data_Get_Struct(dst,SDL_Surface,dstSurface);
|
320
|
+
colorkey=srcSurface->format->colorkey;
|
321
|
+
flags = srcSurface->flags & ( SDL_RLEACCEL|SDL_SRCCOLORKEY );
|
322
|
+
tmpSurface = sge_rotate_scaled_surface(srcSurface,NUM2INT(angle),
|
323
|
+
NUM2DBL(scale),colorkey);
|
324
|
+
if( tmpSurface==NULL )
|
325
|
+
rb_raise(eSDLError,"SDL memory allocate failed :%s",SDL_GetError());
|
326
|
+
SDL_SetColorKey(tmpSurface,flags,colorkey);
|
327
|
+
destRect.x=NUM2INT(x)-tmpSurface->h/2;
|
328
|
+
destRect.y=NUM2INT(y)-tmpSurface->w/2;
|
329
|
+
result = SDL_BlitSurface(tmpSurface,NULL,dstSurface,&destRect);
|
330
|
+
SDL_FreeSurface(tmpSurface);
|
331
|
+
if( result == -1 ){
|
332
|
+
rb_raise(eSDLError,"SDL_BlitSurface fail: %s",SDL_GetError());
|
333
|
+
}
|
334
|
+
return INT2NUM(result);
|
335
|
+
}
|
336
|
+
|
337
|
+
static VALUE sdl_transform(VALUE mod,VALUE src,VALUE dst,VALUE angle,
|
338
|
+
VALUE xscale,VALUE yscale,VALUE px,VALUE py,
|
339
|
+
VALUE qx,VALUE qy,VALUE flags)
|
340
|
+
{
|
341
|
+
SDL_Surface *srcSurface,*dstSurface;
|
342
|
+
if( !rb_obj_is_kind_of(src,cSurface) || !rb_obj_is_kind_of(dst,cSurface) )
|
343
|
+
rb_raise(rb_eArgError,"type mismatch(expect Surface)");
|
344
|
+
Data_Get_Struct(src,SDL_Surface,srcSurface);
|
345
|
+
Data_Get_Struct(dst,SDL_Surface,dstSurface);
|
346
|
+
sge_transform(srcSurface,dstSurface,NUM2DBL(angle),NUM2DBL(xscale),
|
347
|
+
NUM2DBL(yscale),NUM2INT(px),NUM2INT(py),NUM2INT(qx),
|
348
|
+
NUM2INT(qy),NUM2UINT(flags));
|
349
|
+
return Qnil;
|
350
|
+
}
|
351
|
+
|
352
|
+
static VALUE sdl_transformSurface(VALUE obj,VALUE bgcolor,VALUE angle,
|
353
|
+
VALUE xscale,VALUE yscale,VALUE flags)
|
354
|
+
{
|
355
|
+
SDL_Surface *surface,*result;
|
356
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
357
|
+
result = sge_transform_surface(surface,VALUE2COLOR(bgcolor,surface->format),
|
358
|
+
NUM2DBL(angle),NUM2DBL(xscale),
|
359
|
+
NUM2DBL(yscale),NUM2UINT(flags));
|
360
|
+
if( result==NULL )
|
361
|
+
rb_raise( eSDLError,"Couldn't Create Surface: %s",SDL_GetError() );
|
362
|
+
return Data_Wrap_Struct(cSurface,0,sdl_freeSurface,result);
|
363
|
+
}
|
364
|
+
|
365
|
+
static VALUE sdl_makeCollisionMap(VALUE obj)
|
366
|
+
{
|
367
|
+
sge_cdata * cdata;
|
368
|
+
SDL_Surface *surface;
|
369
|
+
Data_Get_Struct(obj,SDL_Surface,surface);
|
370
|
+
cdata = sge_make_cmap(surface);
|
371
|
+
if( cdata==NULL )
|
372
|
+
rb_raise( eSDLError,"Couldn't Create CollisionMap: %s",SDL_GetError() );
|
373
|
+
return Data_Wrap_Struct(cCollisionMap,0,sge_destroy_cmap,cdata);
|
374
|
+
}
|
375
|
+
|
376
|
+
static sge_cdata * value_to_collision_map(VALUE value)
|
377
|
+
{
|
378
|
+
sge_cdata * cdata;
|
379
|
+
if( !rb_obj_is_kind_of(value, cCollisionMap) )
|
380
|
+
rb_raise(rb_eArgError,"type mismatch(expect CollisionMap)");
|
381
|
+
Data_Get_Struct(value, sge_cdata, cdata);
|
382
|
+
return cdata;
|
383
|
+
}
|
384
|
+
|
385
|
+
static VALUE sdl_classBoundingBoxCheck(VALUE class,
|
386
|
+
VALUE x1, VALUE y1, VALUE w1, VALUE h1,
|
387
|
+
VALUE x2, VALUE y2, VALUE w2, VALUE h2)
|
388
|
+
{
|
389
|
+
return BOOL(_sge_bbcheck
|
390
|
+
((Sint16) NUM2INT(x1), (Sint16) NUM2INT(y1),
|
391
|
+
(Sint16) NUM2INT(w1), (Sint16) NUM2INT(h1),
|
392
|
+
(Sint16) NUM2INT(x2), (Sint16) NUM2INT(y2),
|
393
|
+
(Sint16) NUM2INT(w2), (Sint16) NUM2INT(h2)));
|
394
|
+
}
|
395
|
+
|
396
|
+
static VALUE sdl_collisionCheck(VALUE collisionMap1, VALUE x1, VALUE y1,
|
397
|
+
VALUE collisionMap2, VALUE x2, VALUE y2)
|
398
|
+
{
|
399
|
+
sge_cdata * cdata1 = value_to_collision_map(collisionMap1);
|
400
|
+
sge_cdata * cdata2 = value_to_collision_map(collisionMap2);
|
401
|
+
int collided;
|
402
|
+
collided = sge_cmcheck
|
403
|
+
(cdata1, (Sint16) NUM2INT(x1), (Sint16) NUM2INT(y1),
|
404
|
+
cdata2, (Sint16) NUM2INT(x2), (Sint16) NUM2INT(y2));
|
405
|
+
if(!collided)
|
406
|
+
return Qnil;
|
407
|
+
return rb_ary_new3(2, INT2NUM(sge_get_cx()), INT2NUM(sge_get_cy()));
|
408
|
+
}
|
409
|
+
|
410
|
+
static VALUE sdl_boundingBoxCheck(VALUE collisionMap1, VALUE x1, VALUE y1,
|
411
|
+
VALUE collisionMap2, VALUE x2, VALUE y2)
|
412
|
+
{
|
413
|
+
sge_cdata * cdata1 = value_to_collision_map(collisionMap1);
|
414
|
+
sge_cdata * cdata2 = value_to_collision_map(collisionMap2);
|
415
|
+
return BOOL(sge_bbcheck
|
416
|
+
(cdata1, (Sint16) NUM2INT(x1), (Sint16) NUM2INT(y1),
|
417
|
+
cdata2, (Sint16) NUM2INT(x2), (Sint16) NUM2INT(y2)));
|
418
|
+
}
|
419
|
+
|
420
|
+
static VALUE sdl_set_cdata(VALUE obj, VALUE vx, VALUE vy, VALUE vw, VALUE vh)
|
421
|
+
{
|
422
|
+
sge_cdata * cdata = value_to_collision_map(obj);
|
423
|
+
Sint16 x, y, w, h;
|
424
|
+
|
425
|
+
x = NUM2INT(vx);
|
426
|
+
y = NUM2INT(vy);
|
427
|
+
w = NUM2INT(vw);
|
428
|
+
h = NUM2INT(vh);
|
429
|
+
if( x < 0 || y < 0 || x+w > cdata->w || y+h > cdata->h ){
|
430
|
+
rb_raise(eSDLError,"Couldn't clear that area");
|
431
|
+
}
|
432
|
+
sge_set_cdata(cdata, x, y, w, h );
|
433
|
+
return Qnil;
|
434
|
+
}
|
435
|
+
|
436
|
+
static VALUE sdl_unset_cdata(VALUE obj, VALUE vx, VALUE vy, VALUE vw, VALUE vh)
|
437
|
+
{
|
438
|
+
sge_cdata * cdata = value_to_collision_map(obj);
|
439
|
+
Sint16 x, y, w, h;
|
440
|
+
|
441
|
+
x = NUM2INT(vx);
|
442
|
+
y = NUM2INT(vy);
|
443
|
+
w = NUM2INT(vw);
|
444
|
+
h = NUM2INT(vh);
|
445
|
+
if( x < 0 || y < 0 || x+w > cdata->w || y+h > cdata->h ){
|
446
|
+
rb_raise(eSDLError,"Couldn't clear that area");
|
447
|
+
}
|
448
|
+
sge_unset_cdata(cdata, x, y, w, h);
|
449
|
+
return Qnil;
|
450
|
+
}
|
451
|
+
|
452
|
+
static VALUE sdl_w_cdata(VALUE obj)
|
453
|
+
{
|
454
|
+
sge_cdata * cdata = value_to_collision_map(obj);
|
455
|
+
return INT2FIX(cdata->w);
|
456
|
+
}
|
457
|
+
|
458
|
+
static VALUE sdl_h_cdata(VALUE obj)
|
459
|
+
{
|
460
|
+
sge_cdata * cdata = value_to_collision_map(obj);
|
461
|
+
return INT2FIX(cdata->h);
|
462
|
+
}
|
463
|
+
|
464
|
+
/* bitmap font */
|
465
|
+
static void sdl_bf_close(sge_bmpFont* font)
|
466
|
+
{
|
467
|
+
if(!rubysdl_is_quit()){
|
468
|
+
sge_BF_CloseFont(font);
|
469
|
+
}
|
470
|
+
}
|
471
|
+
|
472
|
+
static VALUE sdl_bf_open(VALUE obj, VALUE file, VALUE flags)
|
473
|
+
{
|
474
|
+
sge_bmpFont* font;
|
475
|
+
|
476
|
+
font = sge_BF_OpenFont(GETCSTR(file),NUM2UINT(flags));
|
477
|
+
if( font == NULL )
|
478
|
+
rb_raise(eSDLError,"Couldn't open font: %s", GETCSTR(file));
|
479
|
+
|
480
|
+
return Data_Wrap_Struct(cBMFont,0,sdl_bf_close,font);
|
481
|
+
}
|
482
|
+
|
483
|
+
static VALUE sdl_bf_setColor(VALUE obj,VALUE r,VALUE g,VALUE b)
|
484
|
+
{
|
485
|
+
sge_bmpFont* font;
|
486
|
+
Data_Get_Struct(obj,sge_bmpFont,font);
|
487
|
+
|
488
|
+
sge_BF_SetColor(font,NUM2UINT(r),NUM2UINT(g),NUM2UINT(b));
|
489
|
+
return Qnil;
|
490
|
+
}
|
491
|
+
|
492
|
+
static VALUE sdl_bf_getHeight(VALUE obj)
|
493
|
+
{
|
494
|
+
sge_bmpFont* font;
|
495
|
+
Data_Get_Struct(obj,sge_bmpFont,font);
|
496
|
+
return INT2FIX(sge_BF_GetHeight(font));
|
497
|
+
}
|
498
|
+
|
499
|
+
static VALUE sdl_bf_getWidth(VALUE obj)
|
500
|
+
{
|
501
|
+
sge_bmpFont* font;
|
502
|
+
Data_Get_Struct(obj,sge_bmpFont,font);
|
503
|
+
return INT2FIX(sge_BF_GetWidth(font));
|
504
|
+
}
|
505
|
+
|
506
|
+
static VALUE sdl_bf_textSize(VALUE obj, VALUE text)
|
507
|
+
{
|
508
|
+
sge_bmpFont* font;
|
509
|
+
SDL_Rect rect;
|
510
|
+
Data_Get_Struct(obj,sge_bmpFont,font);
|
511
|
+
rect = sge_BF_TextSize(font, GETCSTR(text));
|
512
|
+
return rb_ary_new3(2, INT2FIX(rect.w), INT2FIX(rect.h));
|
513
|
+
}
|
514
|
+
|
515
|
+
static VALUE sdl_bf_textout(VALUE obj,VALUE surface,VALUE string,
|
516
|
+
VALUE x, VALUE y)
|
517
|
+
{
|
518
|
+
sge_bmpFont* font;
|
519
|
+
SDL_Surface* target;
|
520
|
+
|
521
|
+
if(!rb_obj_is_kind_of(surface,cSurface))
|
522
|
+
rb_raise( rb_eArgError,"type mismatch(expect Surface)" );
|
523
|
+
Data_Get_Struct(obj,sge_bmpFont,font);
|
524
|
+
Data_Get_Struct(surface,SDL_Surface,target);
|
525
|
+
sge_BF_textout(target,font,GETCSTR(string),NUM2INT(x),NUM2INT(y));
|
526
|
+
return Qnil;
|
527
|
+
}
|
528
|
+
|
529
|
+
static void defineConstForSGE()
|
530
|
+
{
|
531
|
+
rb_define_const(mSDL,"TRANSFORM_AA",UINT2NUM(SGE_TAA));
|
532
|
+
rb_define_const(mSDL,"TRANSFORM_SAFE",UINT2NUM(SGE_TSAFE));
|
533
|
+
rb_define_const(mSDL,"TRANSFORM_TMAP",UINT2NUM(SGE_TTMAP));
|
534
|
+
|
535
|
+
rb_define_const(cBMFont,"TRANSPARENT",UINT2NUM(SGE_BFTRANSP));
|
536
|
+
rb_define_const(cBMFont,"NOCONVERT",UINT2NUM(SGE_BFNOCONVERT));
|
537
|
+
rb_define_const(cBMFont,"SFONT",UINT2NUM(SGE_BFSFONT));
|
538
|
+
rb_define_const(cBMFont,"PALETTE",UINT2NUM(SGE_BFPALETTE));
|
539
|
+
}
|
540
|
+
|
541
|
+
void init_sge_video()
|
542
|
+
{
|
543
|
+
sge_Update_OFF();
|
544
|
+
sge_Lock_ON();
|
545
|
+
|
546
|
+
rb_define_module_function(mSDL,"autoLock",sdl_get_autoLocking,0);
|
547
|
+
rb_define_module_function(mSDL,"autoLock=",sdl_set_autoLocking,1);
|
548
|
+
|
549
|
+
rb_define_method(cSurface,"getPixel",sdl_getPixel,2);
|
550
|
+
rb_define_method(cSurface,"putPixel",sdl_putPixel,3);
|
551
|
+
rb_define_method(cSurface,"[]",sdl_getPixel,2);
|
552
|
+
rb_define_method(cSurface,"[]=",sdl_putPixel,3);
|
553
|
+
|
554
|
+
/* primitive drawing */
|
555
|
+
rb_define_method(cSurface,"drawLine",sdl_drawLine,5);
|
556
|
+
rb_define_method(cSurface,"drawRect",sdl_drawRect,5);
|
557
|
+
rb_define_method(cSurface,"drawCircle",sdl_drawCircle,4);
|
558
|
+
rb_define_method(cSurface,"drawFilledCircle",sdl_drawFilledCircle,4);
|
559
|
+
rb_define_method(cSurface,"drawEllispe",sdl_drawEllipse,5);
|
560
|
+
rb_define_method(cSurface,"drawFilledEllispe",sdl_drawFilledEllipse,5);
|
561
|
+
rb_define_method(cSurface,"drawEllipse",sdl_drawEllipse,5);
|
562
|
+
rb_define_method(cSurface,"drawFilledEllipse",sdl_drawFilledEllipse,5);
|
563
|
+
rb_define_method(cSurface,"drawBezier",sdl_drawBezier,10);
|
564
|
+
|
565
|
+
/* antialiased primitive drawing */
|
566
|
+
rb_define_method(cSurface,"drawAALine",sdl_drawAALine,5);
|
567
|
+
rb_define_method(cSurface,"drawAACircle",sdl_drawAACircle,4);
|
568
|
+
rb_define_method(cSurface,"drawAAFilledCircle",sdl_drawAAFilledCircle,4);
|
569
|
+
rb_define_method(cSurface,"drawAAEllipse",sdl_drawAAEllipse,5);
|
570
|
+
rb_define_method(cSurface,"drawAAFilledEllipse",sdl_drawAAFilledEllipse,5);
|
571
|
+
rb_define_method(cSurface,"drawAABezier",sdl_drawAABezier,10);
|
572
|
+
|
573
|
+
/* primitive drawing with alpha */
|
574
|
+
rb_define_method(cSurface,"drawLineAlpha",sdl_drawLineAlpha,6);
|
575
|
+
rb_define_method(cSurface,"drawRectAlpha",sdl_drawRectAlpha,6);
|
576
|
+
rb_define_method(cSurface,"drawFilledRectAlpha",sdl_drawFilledRectAlpha,6);
|
577
|
+
rb_define_method(cSurface,"drawCircleAlpha",sdl_drawCircleAlpha,5);
|
578
|
+
rb_define_method(cSurface,"drawFilledCircleAlpha",sdl_drawFilledCircleAlpha,5);
|
579
|
+
rb_define_method(cSurface,"drawEllipseAlpha",sdl_drawEllipseAlpha,6);
|
580
|
+
rb_define_method(cSurface,"drawFilledEllipseAlpha",sdl_drawFilledEllipseAlpha,6);
|
581
|
+
rb_define_method(cSurface,"drawBezierAlpha",sdl_drawBezierAlpha,11);
|
582
|
+
|
583
|
+
/* antialiased primitive drawing with alpha */
|
584
|
+
rb_define_method(cSurface,"drawAALineAlpha",sdl_drawAALineAlpha,6);
|
585
|
+
rb_define_method(cSurface,"drawAACircleAlpha",sdl_drawAACircleAlpha,5);
|
586
|
+
rb_define_method(cSurface,"drawAAEllipseAlpha",sdl_drawAAEllipseAlpha,6);
|
587
|
+
rb_define_method(cSurface,"drawAABezierAlpha",sdl_drawAABezierAlpha,11);
|
588
|
+
|
589
|
+
/* rotation and scaling */
|
590
|
+
rb_define_method(cSurface,"rotateScaledSurface",sdl_rotateScaledSurface,3);
|
591
|
+
rb_define_module_function(mSDL,"rotateScaledBlit",sdl_rotateScaledBlit,6);
|
592
|
+
rb_define_module_function(mSDL,"rotateXYScaled",sdl_rotateXYScaled,7);
|
593
|
+
|
594
|
+
rb_define_module_function(mSDL,"transform",sdl_transform,10);
|
595
|
+
rb_define_method(cSurface,"transformSurface",sdl_transformSurface,5);
|
596
|
+
|
597
|
+
/* collision detection */
|
598
|
+
rb_define_method(cSurface,"makeCollisionMap", sdl_makeCollisionMap, 0);
|
599
|
+
|
600
|
+
cCollisionMap = rb_define_class_under(mSDL,"CollisionMap",rb_cObject);
|
601
|
+
rb_define_singleton_method(cCollisionMap,"boundingBoxCheck",
|
602
|
+
sdl_classBoundingBoxCheck, 8);
|
603
|
+
rb_define_method(cCollisionMap,"collisionCheck", sdl_collisionCheck, 5);
|
604
|
+
rb_define_method(cCollisionMap,"boundingBoxCheck", sdl_boundingBoxCheck, 5);
|
605
|
+
rb_define_method(cCollisionMap,"clear", sdl_unset_cdata, 4);
|
606
|
+
rb_define_method(cCollisionMap,"set", sdl_set_cdata, 4);
|
607
|
+
rb_define_method(cCollisionMap,"w", sdl_w_cdata, 0);
|
608
|
+
rb_define_method(cCollisionMap,"h", sdl_h_cdata, 0);
|
609
|
+
|
610
|
+
/* bitmap font */
|
611
|
+
cBMFont = rb_define_class_under(mSDL,"BMFont",rb_cObject);
|
612
|
+
rb_define_singleton_method(cBMFont,"open",sdl_bf_open,2);
|
613
|
+
|
614
|
+
rb_define_method(cBMFont,"setColor",sdl_bf_setColor,3);
|
615
|
+
rb_define_method(cBMFont,"height",sdl_bf_getHeight,0);
|
616
|
+
rb_define_method(cBMFont,"width",sdl_bf_getWidth,0);
|
617
|
+
rb_define_method(cBMFont,"textSize",sdl_bf_textSize, 1);
|
618
|
+
rb_define_method(cBMFont,"textout",sdl_bf_textout,4);
|
619
|
+
|
620
|
+
defineConstForSGE();
|
621
|
+
}
|
622
|
+
#endif /* HAVE_SGE */
|