cyross-ruby-miyako 2.0.5.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1092 -929
- data/Rakefile +7 -7
- data/defines.h +144 -144
- data/extern.h +29 -29
- data/install_miyako.rb +87 -87
- data/lib/Miyako/API/audio.rb +572 -198
- data/lib/Miyako/API/basic_data.rb +825 -573
- data/lib/Miyako/API/bitmap.rb +534 -507
- data/lib/Miyako/API/choices.rb +481 -475
- data/lib/Miyako/API/collision.rb +486 -460
- data/lib/Miyako/API/diagram.rb +586 -561
- data/lib/Miyako/API/drawing.rb +151 -151
- data/lib/Miyako/API/exceptions.rb +105 -0
- data/lib/Miyako/API/fixedmap.rb +462 -428
- data/lib/Miyako/API/font.rb +430 -403
- data/lib/Miyako/API/input.rb +456 -447
- data/lib/Miyako/API/layout.rb +636 -433
- data/lib/Miyako/API/map.rb +583 -529
- data/lib/Miyako/API/map_event.rb +222 -198
- data/lib/Miyako/API/modules.rb +357 -109
- data/lib/Miyako/API/movie.rb +166 -154
- data/lib/Miyako/API/parts.rb +276 -189
- data/lib/Miyako/API/plane.rb +205 -166
- data/lib/Miyako/API/screen.rb +341 -325
- data/lib/Miyako/API/shape.rb +443 -443
- data/lib/Miyako/API/sprite.rb +771 -752
- data/lib/Miyako/API/sprite_animation.rb +490 -481
- data/lib/Miyako/API/sprite_list.rb +1135 -0
- data/lib/Miyako/API/spriteunit.rb +168 -147
- data/lib/Miyako/API/story.rb +350 -300
- data/lib/Miyako/API/textbox.rb +770 -725
- data/lib/Miyako/API/utility.rb +419 -388
- data/lib/Miyako/API/viewport.rb +189 -139
- data/lib/Miyako/API/yuki.rb +1226 -996
- data/lib/Miyako/EXT/miyako_cairo.rb +62 -62
- data/lib/Miyako/EXT/raster_scroll.rb +138 -138
- data/lib/Miyako/EXT/slides.rb +157 -157
- data/lib/Miyako/miyako.rb +201 -171
- data/lib/Miyako/miyako_require_only.rb +35 -0
- data/miyako_basicdata.c +590 -590
- data/miyako_bitmap.c +1225 -1225
- data/miyako_collision.c +403 -403
- data/miyako_drawing.c +187 -187
- data/miyako_font.c +334 -334
- data/miyako_hsv.c +830 -830
- data/miyako_input_audio.c +254 -0
- data/miyako_layout.c +191 -191
- data/miyako_no_katana.c +1078 -1074
- data/miyako_sprite2.c +431 -0
- data/miyako_transform.c +438 -438
- data/miyako_utility.c +288 -288
- data/sample/Animation1/m1ku.rb +68 -68
- data/sample/Animation2/lex.rb +96 -96
- data/sample/Diagram_sample/diagram_sample_yuki2.rb +328 -386
- data/sample/Room3/blue.rb +297 -297
- data/sample/Room3/ending.rb +180 -180
- data/sample/Room3/green.rb +220 -220
- data/sample/Room3/main.rb +119 -119
- data/sample/Room3/main_component.rb +59 -59
- data/sample/Room3/red.rb +227 -227
- data/sample/Room3/room3.rb +25 -27
- data/sample/Room3/title.rb +184 -184
- data/sample/ball_action_sample.rb +204 -204
- data/sample/blit_rop.rb +70 -70
- data/sample/cairo_sample.rb +25 -25
- data/sample/circle_collision_test.rb +66 -66
- data/sample/collision_test.rb +33 -33
- data/sample/collision_test2.rb +108 -108
- data/sample/fixed_map_test/fixed_map_sample.rb +140 -140
- data/sample/fixed_map_test/readme.txt +72 -72
- data/sample/map_test/chara.rb +58 -58
- data/sample/map_test/main_parts.rb +69 -69
- data/sample/map_test/main_scene.rb +153 -153
- data/sample/map_test/map_manager.rb +75 -75
- data/sample/map_test/map_test.rb +23 -23
- data/sample/map_test/oasis.rb +71 -71
- data/sample/map_test/readme.txt +89 -89
- data/sample/map_test/route.rb +157 -157
- data/sample/map_test/town.rb +74 -74
- data/sample/polygon_test.rb +35 -35
- data/sample/rasterscroll.rb +24 -24
- data/sample/takahashi.rb +42 -42
- data/sample/textbox_sample.rb +189 -189
- data/sample/transform.rb +54 -54
- data/sample/utility_test.rb +73 -73
- data/sample/utility_test2.rb +61 -61
- data/sample/utility_test3.rb +64 -64
- data/sample/utility_test4.rb +73 -73
- data/uninstall_miyako.rb +19 -19
- data/win/miyako_no_katana.so +0 -0
- metadata +7 -2
data/miyako_sprite2.c
ADDED
@@ -0,0 +1,431 @@
|
|
1
|
+
/*
|
2
|
+
--
|
3
|
+
Miyako v2.1 Extend Library "Miyako no Katana"
|
4
|
+
Copyright (C) 2009 Cyross Makoto
|
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
|
+
*/
|
21
|
+
|
22
|
+
/*
|
23
|
+
=拡張ライブラリmiyako_no_katana
|
24
|
+
Authors:: サイロス誠
|
25
|
+
Version:: 2.1
|
26
|
+
Copyright:: 2007-2009 Cyross Makoto
|
27
|
+
License:: LGPL2.1
|
28
|
+
*/
|
29
|
+
#include "defines.h"
|
30
|
+
|
31
|
+
static VALUE mSDL = Qnil;
|
32
|
+
static VALUE mMiyako = Qnil;
|
33
|
+
static VALUE mSpriteArray = Qnil;
|
34
|
+
static VALUE mSpriteBase = Qnil;
|
35
|
+
static VALUE cSpriteList = Qnil;
|
36
|
+
static VALUE nZero = Qnil;
|
37
|
+
static VALUE nOne = Qnil;
|
38
|
+
static volatile ID id_kakko = Qnil;
|
39
|
+
static volatile ID id_start = Qnil;
|
40
|
+
static volatile ID id_stop = Qnil;
|
41
|
+
static volatile ID id_reset = Qnil;
|
42
|
+
static volatile ID id_update_animation = Qnil;
|
43
|
+
static volatile ID id_move = Qnil;
|
44
|
+
static volatile ID id_move_to = Qnil;
|
45
|
+
static volatile ID id_render = Qnil;
|
46
|
+
static volatile ID id_render_to = Qnil;
|
47
|
+
static volatile ID id_sprite_only = Qnil;
|
48
|
+
static volatile int zero = 0;
|
49
|
+
static volatile int one = 1;
|
50
|
+
|
51
|
+
/*
|
52
|
+
:nodoc:
|
53
|
+
*/
|
54
|
+
static VALUE sprite_array_sprite_only(VALUE self)
|
55
|
+
{
|
56
|
+
VALUE array = rb_ary_new();
|
57
|
+
|
58
|
+
int i;
|
59
|
+
VALUE *ptr = RARRAY_PTR(self);
|
60
|
+
for(i=0; i<RARRAY_LEN(self); i++)
|
61
|
+
{
|
62
|
+
VALUE e = *(ptr+i);
|
63
|
+
VALUE c = CLASS_OF(e);
|
64
|
+
if(rb_mod_include_p(c, mSpriteBase) == Qtrue ||
|
65
|
+
rb_mod_include_p(c, mSpriteArray) == Qtrue)
|
66
|
+
rb_ary_push(array, e);
|
67
|
+
}
|
68
|
+
return array;
|
69
|
+
}
|
70
|
+
|
71
|
+
/*
|
72
|
+
:nodoc:
|
73
|
+
*/
|
74
|
+
static void sprite_array_move_inner(VALUE array, ID id, VALUE x, VALUE y)
|
75
|
+
{
|
76
|
+
int i;
|
77
|
+
VALUE *ptr = RARRAY_PTR(array);
|
78
|
+
if(rb_block_given_p() == Qtrue)
|
79
|
+
{
|
80
|
+
for(i=0; i<RARRAY_LEN(array); i++)
|
81
|
+
{
|
82
|
+
VALUE e = *(ptr+i);
|
83
|
+
VALUE ret = rb_yield_values(4, e, INT2NUM(i), x, y);
|
84
|
+
VALUE r1 = rb_funcall(ret, id_kakko, 1, nZero);
|
85
|
+
VALUE r2 = rb_funcall(ret, id_kakko, 1, nOne);
|
86
|
+
rb_funcall(e, id, 2, r1, r2);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
else
|
90
|
+
{
|
91
|
+
for(i=0; i<RARRAY_LEN(array); i++)
|
92
|
+
{
|
93
|
+
rb_funcall(*(ptr+i), id, 2, x, y);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
/*
|
99
|
+
:nodoc:
|
100
|
+
*/
|
101
|
+
static VALUE sprite_array_move(VALUE self, VALUE dx, VALUE dy)
|
102
|
+
{
|
103
|
+
sprite_array_move_inner(sprite_array_sprite_only(self),
|
104
|
+
id_move, dx, dy);
|
105
|
+
|
106
|
+
return self;
|
107
|
+
}
|
108
|
+
|
109
|
+
/*
|
110
|
+
:nodoc:
|
111
|
+
*/
|
112
|
+
static VALUE sprite_array_move_to(VALUE self, VALUE x, VALUE y)
|
113
|
+
{
|
114
|
+
sprite_array_move_inner(sprite_array_sprite_only(self),
|
115
|
+
id_move_to, x, y);
|
116
|
+
|
117
|
+
return self;
|
118
|
+
}
|
119
|
+
|
120
|
+
/*
|
121
|
+
:nodoc:
|
122
|
+
*/
|
123
|
+
static void sprite_array_inner(VALUE array, ID id)
|
124
|
+
{
|
125
|
+
int i;
|
126
|
+
for(i=0; i<RARRAY_LEN(array); i++)
|
127
|
+
{
|
128
|
+
rb_funcall(*(RARRAY_PTR(array)+i), id, 0);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
/*
|
133
|
+
:nodoc:
|
134
|
+
*/
|
135
|
+
static VALUE sprite_array_start(VALUE self)
|
136
|
+
{
|
137
|
+
sprite_array_inner(sprite_array_sprite_only(self), id_start);
|
138
|
+
return self;
|
139
|
+
}
|
140
|
+
|
141
|
+
/*
|
142
|
+
:nodoc:
|
143
|
+
*/
|
144
|
+
static VALUE sprite_array_stop(VALUE self)
|
145
|
+
{
|
146
|
+
sprite_array_inner(sprite_array_sprite_only(self), id_stop);
|
147
|
+
return self;
|
148
|
+
}
|
149
|
+
|
150
|
+
/*
|
151
|
+
:nodoc:
|
152
|
+
*/
|
153
|
+
static VALUE sprite_array_reset(VALUE self)
|
154
|
+
{
|
155
|
+
sprite_array_inner(sprite_array_sprite_only(self), id_reset);
|
156
|
+
return self;
|
157
|
+
}
|
158
|
+
|
159
|
+
/*
|
160
|
+
:nodoc:
|
161
|
+
*/
|
162
|
+
static VALUE sprite_array_update_animation(VALUE self)
|
163
|
+
{
|
164
|
+
VALUE array = sprite_array_sprite_only(self);
|
165
|
+
VALUE ret = rb_ary_new();
|
166
|
+
int i;
|
167
|
+
for(i=0; i<RARRAY_LEN(array); i++)
|
168
|
+
{
|
169
|
+
rb_ary_push(ret, rb_funcall(*(RARRAY_PTR(array)+i), id_update_animation, 0));
|
170
|
+
}
|
171
|
+
return ret;
|
172
|
+
}
|
173
|
+
|
174
|
+
/*
|
175
|
+
:nodoc:
|
176
|
+
*/
|
177
|
+
static VALUE sprite_array_render(VALUE self)
|
178
|
+
{
|
179
|
+
sprite_array_inner(sprite_array_sprite_only(self), id_render);
|
180
|
+
return self;
|
181
|
+
}
|
182
|
+
|
183
|
+
/*
|
184
|
+
:nodoc:
|
185
|
+
*/
|
186
|
+
static VALUE sprite_array_render_to(VALUE self, VALUE dst)
|
187
|
+
{
|
188
|
+
VALUE array = sprite_array_sprite_only(self);
|
189
|
+
|
190
|
+
int i;
|
191
|
+
for(i=0; i<RARRAY_LEN(array); i++)
|
192
|
+
{
|
193
|
+
rb_funcall(*(RARRAY_PTR(array)+i), id_render_to, 1, dst);
|
194
|
+
}
|
195
|
+
|
196
|
+
return self;
|
197
|
+
}
|
198
|
+
|
199
|
+
/*
|
200
|
+
:nodoc:
|
201
|
+
*/
|
202
|
+
static VALUE sprite_list_sprite_only(VALUE self)
|
203
|
+
{
|
204
|
+
VALUE hash = rb_hash_new();
|
205
|
+
VALUE names = rb_iv_get(self, "@names");
|
206
|
+
VALUE n2v = rb_iv_get(self, "@n2v");
|
207
|
+
|
208
|
+
int i;
|
209
|
+
VALUE *ptr = RARRAY_PTR(names);
|
210
|
+
for(i=0; i<RARRAY_LEN(names); i++)
|
211
|
+
{
|
212
|
+
VALUE *p2 = RSTRUCT_PTR(rb_hash_lookup(n2v, *(ptr+i)));
|
213
|
+
VALUE n = *(p2+0);
|
214
|
+
VALUE v = *(p2+1);
|
215
|
+
VALUE c = CLASS_OF(v);
|
216
|
+
if(rb_mod_include_p(c, mSpriteBase) == Qtrue ||
|
217
|
+
rb_mod_include_p(c, mSpriteArray) == Qtrue)
|
218
|
+
rb_hash_aset(hash, n, v);
|
219
|
+
}
|
220
|
+
return rb_funcall(cSpriteList, rb_intern("new"), 1, hash);
|
221
|
+
}
|
222
|
+
|
223
|
+
/*
|
224
|
+
:nodoc:
|
225
|
+
*/
|
226
|
+
static void sprite_list_move_inner(VALUE list, ID id, VALUE x, VALUE y)
|
227
|
+
{
|
228
|
+
VALUE names = rb_iv_get(list, "@names");
|
229
|
+
VALUE n2v = rb_iv_get(list, "@n2v");
|
230
|
+
int i;
|
231
|
+
VALUE *ptr = RARRAY_PTR(names);
|
232
|
+
if(rb_block_given_p() == Qtrue)
|
233
|
+
{
|
234
|
+
for(i=0; i<RARRAY_LEN(names); i++)
|
235
|
+
{
|
236
|
+
VALUE e = rb_hash_lookup(n2v, *(ptr+i));
|
237
|
+
VALUE ret = rb_yield_values(4, e, INT2NUM(i), x, y);
|
238
|
+
VALUE r1 = rb_funcall(ret, id_kakko, 1, nZero);
|
239
|
+
VALUE r2 = rb_funcall(ret, id_kakko, 1, nOne);
|
240
|
+
rb_funcall(e, id, 2, r1, r2);
|
241
|
+
}
|
242
|
+
}
|
243
|
+
else
|
244
|
+
{
|
245
|
+
for(i=0; i<RARRAY_LEN(names); i++)
|
246
|
+
{
|
247
|
+
VALUE v = *(RSTRUCT_PTR(rb_hash_lookup(n2v, *(ptr+i)))+1);
|
248
|
+
rb_funcall(v, id, 2, x, y);
|
249
|
+
}
|
250
|
+
}
|
251
|
+
}
|
252
|
+
|
253
|
+
/*
|
254
|
+
:nodoc:
|
255
|
+
*/
|
256
|
+
static VALUE sprite_list_move(VALUE self, VALUE dx, VALUE dy)
|
257
|
+
{
|
258
|
+
sprite_list_move_inner(self, id_move, dx, dy);
|
259
|
+
|
260
|
+
return self;
|
261
|
+
}
|
262
|
+
|
263
|
+
/*
|
264
|
+
:nodoc:
|
265
|
+
*/
|
266
|
+
static VALUE sprite_list_move_to(VALUE self, VALUE x, VALUE y)
|
267
|
+
{
|
268
|
+
sprite_list_move_inner(self, id_move_to, x, y);
|
269
|
+
|
270
|
+
return self;
|
271
|
+
}
|
272
|
+
|
273
|
+
/*
|
274
|
+
:nodoc:
|
275
|
+
*/
|
276
|
+
static VALUE sprite_list_to_ary(VALUE self)
|
277
|
+
{
|
278
|
+
VALUE ret = rb_ary_new();
|
279
|
+
VALUE names = rb_iv_get(self, "@names");
|
280
|
+
VALUE n2v = rb_iv_get(self, "@n2v");
|
281
|
+
|
282
|
+
int i;
|
283
|
+
VALUE *ptr = RARRAY_PTR(names);
|
284
|
+
for(i=0; i<RARRAY_LEN(names); i++)
|
285
|
+
rb_ary_push(ret, rb_hash_lookup(n2v, *(ptr+i)));
|
286
|
+
|
287
|
+
return ret;
|
288
|
+
}
|
289
|
+
|
290
|
+
/*
|
291
|
+
:nodoc:
|
292
|
+
*/
|
293
|
+
static VALUE sprite_list_each(VALUE self)
|
294
|
+
{
|
295
|
+
VALUE array = sprite_list_to_ary(self);
|
296
|
+
|
297
|
+
int i;
|
298
|
+
VALUE *ptr = RARRAY_PTR(array);
|
299
|
+
for(i=0; i<RARRAY_LEN(array); i++)
|
300
|
+
rb_yield_values(1, *(ptr+i));
|
301
|
+
|
302
|
+
return self;
|
303
|
+
}
|
304
|
+
|
305
|
+
/*
|
306
|
+
:nodoc:
|
307
|
+
*/
|
308
|
+
static void sprite_list_inner(VALUE list, ID id)
|
309
|
+
{
|
310
|
+
VALUE array = sprite_list_to_ary(list);
|
311
|
+
int i;
|
312
|
+
for(i=0; i<RARRAY_LEN(array); i++)
|
313
|
+
{
|
314
|
+
VALUE pair = *(RARRAY_PTR(array)+i);
|
315
|
+
rb_funcall(*(RSTRUCT_PTR(pair)+1), id ,0);
|
316
|
+
}
|
317
|
+
}
|
318
|
+
|
319
|
+
/*
|
320
|
+
:nodoc:
|
321
|
+
*/
|
322
|
+
static VALUE sprite_list_start(VALUE self)
|
323
|
+
{
|
324
|
+
sprite_list_inner(self, id_start);
|
325
|
+
return self;
|
326
|
+
}
|
327
|
+
|
328
|
+
/*
|
329
|
+
:nodoc:
|
330
|
+
*/
|
331
|
+
static VALUE sprite_list_stop(VALUE self)
|
332
|
+
{
|
333
|
+
sprite_list_inner(self, id_stop);
|
334
|
+
return self;
|
335
|
+
}
|
336
|
+
|
337
|
+
/*
|
338
|
+
:nodoc:
|
339
|
+
*/
|
340
|
+
static VALUE sprite_list_reset(VALUE self)
|
341
|
+
{
|
342
|
+
sprite_list_inner(self, id_reset);
|
343
|
+
return self;
|
344
|
+
}
|
345
|
+
|
346
|
+
/*
|
347
|
+
:nodoc:
|
348
|
+
*/
|
349
|
+
static VALUE sprite_list_update_animation(VALUE self)
|
350
|
+
{
|
351
|
+
VALUE array = sprite_list_to_ary(self);
|
352
|
+
VALUE ret = rb_ary_new();
|
353
|
+
int i;
|
354
|
+
for(i=0; i<RARRAY_LEN(array); i++)
|
355
|
+
{
|
356
|
+
VALUE pair = *(RARRAY_PTR(array)+i);
|
357
|
+
rb_ary_push(ret, rb_funcall(*(RSTRUCT_PTR(pair)+1), id_update_animation, 0));
|
358
|
+
}
|
359
|
+
return ret;
|
360
|
+
}
|
361
|
+
|
362
|
+
/*
|
363
|
+
:nodoc:
|
364
|
+
*/
|
365
|
+
static VALUE sprite_list_render(VALUE self)
|
366
|
+
{
|
367
|
+
sprite_list_inner(self, id_render);
|
368
|
+
return self;
|
369
|
+
}
|
370
|
+
|
371
|
+
/*
|
372
|
+
:nodoc:
|
373
|
+
*/
|
374
|
+
static VALUE sprite_list_render_to(VALUE self, VALUE dst)
|
375
|
+
{
|
376
|
+
VALUE array = sprite_list_to_ary(self);
|
377
|
+
int i;
|
378
|
+
for(i=0; i<RARRAY_LEN(array); i++)
|
379
|
+
{
|
380
|
+
VALUE pair = *(RARRAY_PTR(array)+i);
|
381
|
+
rb_funcall(*(RSTRUCT_PTR(pair)+1), id_render_to, 1, dst);
|
382
|
+
}
|
383
|
+
|
384
|
+
return self;
|
385
|
+
}
|
386
|
+
|
387
|
+
void Init_miyako_sprite2()
|
388
|
+
{
|
389
|
+
mSDL = rb_define_module("SDL");
|
390
|
+
mMiyako = rb_define_module("Miyako");
|
391
|
+
mSpriteArray = rb_define_module_under(mMiyako, "SpriteArray");
|
392
|
+
mSpriteBase = rb_define_module_under(mMiyako, "SpriteBase");
|
393
|
+
cSpriteList = rb_define_class_under(mMiyako, "SpriteList", rb_cObject);
|
394
|
+
|
395
|
+
id_kakko = rb_intern("[]");
|
396
|
+
id_start = rb_intern("start");
|
397
|
+
id_stop = rb_intern("stop");
|
398
|
+
id_reset = rb_intern("reset");
|
399
|
+
id_update_animation = rb_intern("update_animation");
|
400
|
+
id_move = rb_intern("move!");
|
401
|
+
id_move_to = rb_intern("move_to!");
|
402
|
+
id_render = rb_intern("render");
|
403
|
+
id_render_to = rb_intern("render_to");
|
404
|
+
id_sprite_only = rb_intern("sprite_only");
|
405
|
+
|
406
|
+
zero = 0;
|
407
|
+
nZero = INT2NUM(zero);
|
408
|
+
one = 1;
|
409
|
+
nOne = INT2NUM(one);
|
410
|
+
|
411
|
+
rb_define_method(mSpriteArray, "sprite_only", sprite_array_sprite_only, 0);
|
412
|
+
rb_define_method(mSpriteArray, "start", sprite_array_start, 0);
|
413
|
+
rb_define_method(mSpriteArray, "stop", sprite_array_stop, 0);
|
414
|
+
rb_define_method(mSpriteArray, "reset", sprite_array_reset, 0);
|
415
|
+
rb_define_method(mSpriteArray, "update_animation", sprite_array_update_animation, 0);
|
416
|
+
rb_define_method(mSpriteArray, "move!", sprite_array_move, 2);
|
417
|
+
rb_define_method(mSpriteArray, "move_to!", sprite_array_move_to, 2);
|
418
|
+
rb_define_method(mSpriteArray, "render", sprite_array_render, 0);
|
419
|
+
rb_define_method(mSpriteArray, "render_to", sprite_array_render_to, 1);
|
420
|
+
rb_define_method(cSpriteList, "sprite_only", sprite_list_sprite_only, 0);
|
421
|
+
rb_define_method(cSpriteList, "start", sprite_list_start, 0);
|
422
|
+
rb_define_method(cSpriteList, "stop", sprite_list_stop, 0);
|
423
|
+
rb_define_method(cSpriteList, "reset", sprite_list_reset, 0);
|
424
|
+
rb_define_method(cSpriteList, "update_animation", sprite_list_update_animation, 0);
|
425
|
+
rb_define_method(cSpriteList, "move!", sprite_list_move, 2);
|
426
|
+
rb_define_method(cSpriteList, "move_to!", sprite_list_move_to, 2);
|
427
|
+
rb_define_method(cSpriteList, "to_ary", sprite_list_to_ary, 0);
|
428
|
+
rb_define_method(cSpriteList, "each", sprite_list_each, 0);
|
429
|
+
rb_define_method(cSpriteList, "render", sprite_list_render, 0);
|
430
|
+
rb_define_method(cSpriteList, "render_to", sprite_list_render_to, 1);
|
431
|
+
}
|
data/miyako_transform.c
CHANGED
@@ -1,438 +1,438 @@
|
|
1
|
-
/*
|
2
|
-
--
|
3
|
-
Miyako v2.0 Extend Library "Miyako no Katana"
|
4
|
-
Copyright (C) 2008 Cyross Makoto
|
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
|
-
*/
|
21
|
-
|
22
|
-
/*
|
23
|
-
=拡張ライブラリmiyako_no_katana
|
24
|
-
Authors:: サイロス誠
|
25
|
-
Version:: 2.0
|
26
|
-
Copyright:: 2007-2008 Cyross Makoto
|
27
|
-
License:: LGPL2.1
|
28
|
-
*/
|
29
|
-
#include "defines.h"
|
30
|
-
#include "extern.h"
|
31
|
-
|
32
|
-
static VALUE mSDL = Qnil;
|
33
|
-
static VALUE mMiyako = Qnil;
|
34
|
-
static VALUE mScreen = Qnil;
|
35
|
-
static VALUE cSurface = Qnil;
|
36
|
-
static VALUE cBitmap = Qnil;
|
37
|
-
static VALUE cSprite = Qnil;
|
38
|
-
static VALUE nZero = Qnil;
|
39
|
-
static VALUE nOne = Qnil;
|
40
|
-
static volatile ID id_update = Qnil;
|
41
|
-
static volatile ID id_kakko = Qnil;
|
42
|
-
static volatile ID id_render = Qnil;
|
43
|
-
static volatile ID id_to_a = Qnil;
|
44
|
-
static volatile int zero = Qnil;
|
45
|
-
static volatile int one = Qnil;
|
46
|
-
|
47
|
-
// from rubysdl_video.c
|
48
|
-
static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
|
49
|
-
|
50
|
-
/*
|
51
|
-
画像を回転させて貼り付ける
|
52
|
-
*/
|
53
|
-
static VALUE bitmap_miyako_rotate(VALUE self, VALUE vsrc, VALUE vdst, VALUE radian)
|
54
|
-
{
|
55
|
-
MiyakoBitmap src, dst;
|
56
|
-
MiyakoSize size;
|
57
|
-
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
58
|
-
|
59
|
-
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
60
|
-
|
61
|
-
size.w = dst.rect.w;
|
62
|
-
size.h = dst.rect.h;
|
63
|
-
|
64
|
-
if(src.surface == dst.surface){ return Qnil; }
|
65
|
-
|
66
|
-
if(dst.rect.w >= 32768 || dst.rect.h >= 32768){ return Qnil; }
|
67
|
-
|
68
|
-
double rad = NUM2DBL(radian) * -1.0;
|
69
|
-
long isin = (long)(sin(rad)*4096.0);
|
70
|
-
long icos = (long)(cos(rad)*4096.0);
|
71
|
-
|
72
|
-
int px = -(NUM2INT(*(RSTRUCT_PTR(src.unit)+7)));
|
73
|
-
int py = -(NUM2INT(*(RSTRUCT_PTR(src.unit)+8)));
|
74
|
-
int pr = src.rect.w + px;
|
75
|
-
int pb = src.rect.h + py;
|
76
|
-
int qx = -(NUM2INT(*(RSTRUCT_PTR(dst.unit)+7)));
|
77
|
-
int qy = -(NUM2INT(*(RSTRUCT_PTR(dst.unit)+8)));
|
78
|
-
int qr = dst.rect.w + qx;
|
79
|
-
int qb = dst.rect.h + qy;
|
80
|
-
|
81
|
-
SDL_LockSurface(src.surface);
|
82
|
-
SDL_LockSurface(dst.surface);
|
83
|
-
|
84
|
-
int x, y;
|
85
|
-
for(y = qy; y < qb; y++)
|
86
|
-
{
|
87
|
-
Uint32 *tp = dst.ptr + (dst.rect.y + y - qy) * dst.surface->w + dst.rect.x;
|
88
|
-
for(x = qx; x < qr; x++)
|
89
|
-
{
|
90
|
-
int nx = (x*icos-y*isin) >> 12;
|
91
|
-
if(nx < px || nx >= pr){ tp++; continue; }
|
92
|
-
int ny = (x*isin+y*icos) >> 12;
|
93
|
-
if(ny < py || ny >= pb){ tp++; continue; }
|
94
|
-
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
95
|
-
dst.color.r = (*tp >> 16) & 0xff;
|
96
|
-
dst.color.g = (*tp >> 8) & 0xff;
|
97
|
-
dst.color.b = (*tp ) & 0xff;
|
98
|
-
dst.color.a = (*tp >> 24) & 0xff | dst.a255;
|
99
|
-
Uint32 *psrc = src.ptr + (src.rect.x + ny - py) * src.surface->w + src.rect.x + nx - px;
|
100
|
-
src.color.a = (*psrc >> 24) & 0xff | src.a255;
|
101
|
-
if(src.color.a == 0){ tp++; continue; }
|
102
|
-
if(dst.color.a == 0 || src.color.a == 255)
|
103
|
-
{
|
104
|
-
*tp = *psrc;
|
105
|
-
tp++;
|
106
|
-
continue;
|
107
|
-
}
|
108
|
-
int a1 = src.color.a + 1;
|
109
|
-
int a2 = 256 - src.color.a;
|
110
|
-
src.color.r = (*psrc >> 16) & 0xff;
|
111
|
-
src.color.g = (*psrc >> 8) & 0xff;
|
112
|
-
src.color.b = (*psrc ) & 0xff;
|
113
|
-
*tp = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
|
114
|
-
((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
|
115
|
-
((src.color.b * a1 + dst.color.b * a2) >> 8) |
|
116
|
-
0xff << 24;
|
117
|
-
#else
|
118
|
-
dst.color.r = (*tp & dst.fmt->Rmask) >> dst.fmt->Rshift;
|
119
|
-
dst.color.g = (*tp & dst.fmt->Gmask) >> dst.fmt->Gshift;
|
120
|
-
dst.color.b = (*tp & dst.fmt->Bmask) >> dst.fmt->Bshift;
|
121
|
-
dst.color.a = (*tp & dst.fmt->Amask) | dst.a255;
|
122
|
-
Uint32 *psrc = src.ptr + (src.rect.x + ny - py) * src.surface->w + src.rect.x + nx - px;
|
123
|
-
src.color.a = (*psrc & src.fmt->Amask) | src.a255;
|
124
|
-
if(src.color.a == 0){ tp++; continue; }
|
125
|
-
if(dst.color.a == 0 || src.color.a == 255)
|
126
|
-
{
|
127
|
-
*tp = *psrc;
|
128
|
-
tp++;
|
129
|
-
continue;
|
130
|
-
}
|
131
|
-
int a1 = src.color.a + 1;
|
132
|
-
int a2 = 256 - src.color.a;
|
133
|
-
src.color.r = (*psrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
134
|
-
src.color.g = (*psrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
135
|
-
src.color.b = (*psrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
136
|
-
*tp = (((src.color.r * a1 + dst.color.r * a2) >> 8)) << dst.fmt->Rshift |
|
137
|
-
(((src.color.g * a1 + dst.color.g * a2) >> 8)) << dst.fmt->Gshift |
|
138
|
-
(((src.color.b * a1 + dst.color.b * a2) >> 8)) << dst.fmt->Bshift |
|
139
|
-
0xff;
|
140
|
-
#endif
|
141
|
-
tp++;
|
142
|
-
}
|
143
|
-
}
|
144
|
-
|
145
|
-
SDL_UnlockSurface(src.surface);
|
146
|
-
SDL_UnlockSurface(dst.surface);
|
147
|
-
|
148
|
-
return vdst;
|
149
|
-
}
|
150
|
-
|
151
|
-
/*
|
152
|
-
画像を拡大・縮小・鏡像(ミラー反転)させて貼り付ける
|
153
|
-
*/
|
154
|
-
static VALUE bitmap_miyako_scale(VALUE self, VALUE vsrc, VALUE vdst, VALUE xscale, VALUE yscale)
|
155
|
-
{
|
156
|
-
MiyakoBitmap src, dst;
|
157
|
-
MiyakoSize size;
|
158
|
-
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
159
|
-
|
160
|
-
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
161
|
-
|
162
|
-
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
163
|
-
|
164
|
-
if(src.surface == dst.surface){ return Qnil; }
|
165
|
-
|
166
|
-
if(dst.rect.w >= 32768 || dst.rect.h >= 32768){ return Qnil; }
|
167
|
-
|
168
|
-
double tscx = NUM2DBL(xscale);
|
169
|
-
double tscy = NUM2DBL(yscale);
|
170
|
-
|
171
|
-
if(tscx == 0.0 || tscy == 0.0){ return Qnil; }
|
172
|
-
|
173
|
-
int scx = (int)(4096.0 / tscx);
|
174
|
-
int scy = (int)(4096.0 / tscy);
|
175
|
-
|
176
|
-
int off_x = scx < 0 ? 1 : 0;
|
177
|
-
int off_y = scy < 0 ? 1 : 0;
|
178
|
-
|
179
|
-
int px = -(NUM2INT(*(RSTRUCT_PTR(src.unit)+7)));
|
180
|
-
int py = -(NUM2INT(*(RSTRUCT_PTR(src.unit)+8)));
|
181
|
-
int pr = src.rect.w + px;
|
182
|
-
int pb = src.rect.h + py;
|
183
|
-
int qx = -(NUM2INT(*(RSTRUCT_PTR(dst.unit)+7)));
|
184
|
-
int qy = -(NUM2INT(*(RSTRUCT_PTR(dst.unit)+8)));
|
185
|
-
int qr = dst.rect.w + qx;
|
186
|
-
int qb = dst.rect.h + qy;
|
187
|
-
|
188
|
-
SDL_LockSurface(src.surface);
|
189
|
-
SDL_LockSurface(dst.surface);
|
190
|
-
|
191
|
-
int x, y;
|
192
|
-
for(y = qy; y < qb; y++)
|
193
|
-
{
|
194
|
-
Uint32 *tp = dst.ptr + (dst.rect.y + y - qy) * dst.surface->w + dst.rect.x;
|
195
|
-
for(x = qx; x < qr; x++)
|
196
|
-
{
|
197
|
-
int nx = (x*scx) >> 12 - off_x;
|
198
|
-
if(nx < px || nx >= pr){ tp++; continue; }
|
199
|
-
int ny = (y*scy) >> 12 - off_y;
|
200
|
-
if(ny < py || ny >= pb){ tp++; continue; }
|
201
|
-
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
202
|
-
dst.color.r = (*tp >> 16) & 0xff;
|
203
|
-
dst.color.g = (*tp >> 8) & 0xff;
|
204
|
-
dst.color.b = (*tp ) & 0xff;
|
205
|
-
dst.color.a = (*tp >> 24) & 0xff | dst.a255;
|
206
|
-
Uint32 *psrc = src.ptr + (src.rect.x + ny - py) * src.surface->w + src.rect.x + nx - px;
|
207
|
-
src.color.a = (*psrc >> 24) & 0xff | src.a255;
|
208
|
-
if(src.color.a == 0){ tp++; continue; }
|
209
|
-
if(dst.color.a == 0 || src.color.a == 255)
|
210
|
-
{
|
211
|
-
*tp = *psrc;
|
212
|
-
tp++;
|
213
|
-
continue;
|
214
|
-
}
|
215
|
-
int a1 = src.color.a + 1;
|
216
|
-
int a2 = 256 - src.color.a;
|
217
|
-
src.color.r = (*psrc >> 16) & 0xff;
|
218
|
-
src.color.g = (*psrc >> 8) & 0xff;
|
219
|
-
src.color.b = (*psrc ) & 0xff;
|
220
|
-
*tp = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
|
221
|
-
((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
|
222
|
-
((src.color.b * a1 + dst.color.b * a2) >> 8) |
|
223
|
-
0xff << 24;
|
224
|
-
#else
|
225
|
-
dst.color.r = (*tp & dst.fmt->Rmask) >> dst.fmt->Rshift;
|
226
|
-
dst.color.g = (*tp & dst.fmt->Gmask) >> dst.fmt->Gshift;
|
227
|
-
dst.color.b = (*tp & dst.fmt->Bmask) >> dst.fmt->Bshift;
|
228
|
-
dst.color.a = (*tp & dst.fmt->Amask) | dst.a255;
|
229
|
-
Uint32 *psrc = src.ptr + (src.rect.x + ny - py) * src.surface->w + src.rect.x + nx - px;
|
230
|
-
src.color.a = (*psrc & src.fmt->Amask) | src.a255;
|
231
|
-
if(src.color.a == 0){ tp++; continue; }
|
232
|
-
if(dst.color.a == 0 || src.color.a == 255)
|
233
|
-
{
|
234
|
-
*tp = *psrc;
|
235
|
-
tp++;
|
236
|
-
continue;
|
237
|
-
}
|
238
|
-
int a1 = src.color.a + 1;
|
239
|
-
int a2 = 256 - src.color.a;
|
240
|
-
src.color.r = (*psrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
241
|
-
src.color.g = (*psrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
242
|
-
src.color.b = (*psrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
243
|
-
*tp = ((src.color.r * a1 + dst.color.r * a2) >> 8) << dst.fmt->Rshift |
|
244
|
-
((src.color.g * a1 + dst.color.g * a2) >> 8) << dst.fmt->Gshift |
|
245
|
-
((src.color.b * a1 + dst.color.b * a2) >> 8) << dst.fmt->Bshift |
|
246
|
-
0xff;
|
247
|
-
#endif
|
248
|
-
tp++;
|
249
|
-
}
|
250
|
-
}
|
251
|
-
|
252
|
-
SDL_UnlockSurface(src.surface);
|
253
|
-
SDL_UnlockSurface(dst.surface);
|
254
|
-
|
255
|
-
return vdst;
|
256
|
-
}
|
257
|
-
|
258
|
-
/*
|
259
|
-
===回転・拡大・縮小・鏡像用インナーメソッド
|
260
|
-
*/
|
261
|
-
static void transform_inner(MiyakoBitmap *src, MiyakoBitmap *dst, VALUE radian, VALUE xscale, VALUE yscale)
|
262
|
-
{
|
263
|
-
if(dst->rect.w >= 32768 || dst->rect.h >= 32768) return;
|
264
|
-
|
265
|
-
MiyakoSize size;
|
266
|
-
|
267
|
-
if(_miyako_init_rect(src, dst, &size) == 0) return;
|
268
|
-
|
269
|
-
double rad = NUM2DBL(radian) * -1.0;
|
270
|
-
long isin = (long)(sin(rad)*4096.0);
|
271
|
-
long icos = (long)(cos(rad)*4096.0);
|
272
|
-
|
273
|
-
double tscx = NUM2DBL(xscale);
|
274
|
-
double tscy = NUM2DBL(yscale);
|
275
|
-
|
276
|
-
if(tscx == 0.0 || tscy == 0.0) return;
|
277
|
-
|
278
|
-
int scx = (int)(4096.0 / tscx);
|
279
|
-
int scy = (int)(4096.0 / tscy);
|
280
|
-
|
281
|
-
int off_x = scx < 0 ? 1 : 0;
|
282
|
-
int off_y = scy < 0 ? 1 : 0;
|
283
|
-
|
284
|
-
int px = -(NUM2INT(*(RSTRUCT_PTR(src->unit)+7)));
|
285
|
-
int py = -(NUM2INT(*(RSTRUCT_PTR(src->unit)+8)));
|
286
|
-
int pr = src->rect.w + px;
|
287
|
-
int pb = src->rect.h + py;
|
288
|
-
int qx = -(NUM2INT(*(RSTRUCT_PTR(dst->unit)+7)));
|
289
|
-
int qy = -(NUM2INT(*(RSTRUCT_PTR(dst->unit)+8)));
|
290
|
-
int qr = dst->rect.w + qx;
|
291
|
-
int qb = dst->rect.h + qy;
|
292
|
-
|
293
|
-
SDL_LockSurface(src->surface);
|
294
|
-
SDL_LockSurface(dst->surface);
|
295
|
-
|
296
|
-
int x, y;
|
297
|
-
for(y = qy; y < qb; y++)
|
298
|
-
{
|
299
|
-
Uint32 *tp = dst->ptr + (dst->rect.y + y - qy) * dst->surface->w + dst->rect.x;
|
300
|
-
for(x = qx; x < qr; x++)
|
301
|
-
{
|
302
|
-
int nx = (((x*icos-y*isin) >> 12) * scx) >> 12 - off_x;
|
303
|
-
if(nx < px || nx >= pr){ tp++; continue; }
|
304
|
-
int ny = (((x*isin+y*icos) >> 12) * scy) >> 12 - off_y;
|
305
|
-
if(ny < py || ny >= pb){ tp++; continue; }
|
306
|
-
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
307
|
-
dst->color.r = (*tp >> 16) & 0xff;
|
308
|
-
dst->color.g = (*tp >> 8) & 0xff;
|
309
|
-
dst->color.b = (*tp ) & 0xff;
|
310
|
-
dst->color.a = (*tp >> 24) & 0xff | dst->a255;
|
311
|
-
Uint32 *psrc = src->ptr + (src->rect.x + ny - py) * src->surface->w + src->rect.x + nx - px;
|
312
|
-
src->color.a = (*psrc >> 24) & 0xff | src->a255;
|
313
|
-
if(src->color.a == 0){ tp++; continue; }
|
314
|
-
if(dst->color.a == 0 || src->color.a == 255)
|
315
|
-
{
|
316
|
-
*tp = *psrc;
|
317
|
-
tp++;
|
318
|
-
continue;
|
319
|
-
}
|
320
|
-
int a1 = src->color.a + 1;
|
321
|
-
int a2 = 256 - src->color.a;
|
322
|
-
src->color.r = (*psrc >> 16) & 0xff;
|
323
|
-
src->color.g = (*psrc >> 8) & 0xff;
|
324
|
-
src->color.b = (*psrc ) & 0xff;
|
325
|
-
*tp = ((src->color.r * a1 + dst->color.r * a2) >> 8) << 16 |
|
326
|
-
((src->color.g * a1 + dst->color.g * a2) >> 8) << 8 |
|
327
|
-
((src->color.b * a1 + dst->color.b * a2) >> 8) |
|
328
|
-
0xff << 24;
|
329
|
-
#else
|
330
|
-
dst->color.r = (*tp & dst->fmt->Rmask) >> dst->fmt->Rshift;
|
331
|
-
dst->color.g = (*tp & dst->fmt->Gmask) >> dst->fmt->Gshift;
|
332
|
-
dst->color.b = (*tp & dst->fmt->Bmask) >> dst->fmt->Bshift;
|
333
|
-
dst->color.a = (*tp & dst->fmt->Amask) | dst->a255;
|
334
|
-
Uint32 *psrc = src->ptr + (src->rect.x + ny - py) * src->surface->w + src->rect.x + nx - px;
|
335
|
-
src->color.a = (*psrc & src->fmt->Amask) | src->a255;
|
336
|
-
if(src->color.a == 0){ tp++; continue; }
|
337
|
-
if(dst->color.a == 0 || src->color.a == 255)
|
338
|
-
{
|
339
|
-
*tp = *psrc;
|
340
|
-
tp++;
|
341
|
-
continue;
|
342
|
-
}
|
343
|
-
int a1 = src->color.a + 1;
|
344
|
-
int a2 = 256 - src->color.a;
|
345
|
-
src->color.r = (*psrc & src->fmt->Rmask) >> src->fmt->Rshift;
|
346
|
-
src->color.g = (*psrc & src->fmt->Gmask) >> src->fmt->Gshift;
|
347
|
-
src->color.b = (*psrc & src->fmt->Bmask) >> src->fmt->Bshift;
|
348
|
-
*tp = ((src->color.r * a1 + dst->color.r * a2) >> 8) << dst->fmt->Rshift |
|
349
|
-
((src->color.g * a1 + dst->color.g * a2) >> 8) << dst->fmt->Gshift |
|
350
|
-
((src->color.b * a1 + dst->color.b * a2) >> 8) << dst->fmt->Bshift |
|
351
|
-
0xff;
|
352
|
-
#endif
|
353
|
-
tp++;
|
354
|
-
}
|
355
|
-
}
|
356
|
-
|
357
|
-
SDL_UnlockSurface(src->surface);
|
358
|
-
SDL_UnlockSurface(dst->surface);
|
359
|
-
}
|
360
|
-
|
361
|
-
/*
|
362
|
-
画像を変形(回転・拡大・縮小・鏡像)させて貼り付ける
|
363
|
-
*/
|
364
|
-
static VALUE bitmap_miyako_transform(VALUE self, VALUE vsrc, VALUE vdst, VALUE radian, VALUE xscale, VALUE yscale)
|
365
|
-
{
|
366
|
-
MiyakoBitmap src, dst;
|
367
|
-
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
368
|
-
|
369
|
-
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
370
|
-
|
371
|
-
if(src.surface == dst.surface){ return Qnil; }
|
372
|
-
|
373
|
-
transform_inner(&src, &dst, radian, xscale, yscale);
|
374
|
-
return vdst;
|
375
|
-
}
|
376
|
-
|
377
|
-
/*
|
378
|
-
インスタンスの内容を画面に描画する(回転/拡大/縮小/鏡像付き)
|
379
|
-
*/
|
380
|
-
static VALUE sprite_render_transform(VALUE self, VALUE radian, VALUE xscale, VALUE yscale)
|
381
|
-
{
|
382
|
-
VALUE visible = rb_iv_get(self, "@visible");
|
383
|
-
if(visible == Qfalse) return self;
|
384
|
-
MiyakoBitmap src, dst;
|
385
|
-
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
386
|
-
|
387
|
-
_miyako_setup_unit_2(self, mScreen, scr, &src, &dst, Qnil, Qnil, 1);
|
388
|
-
|
389
|
-
if(src.surface == dst.surface){ return Qnil; }
|
390
|
-
|
391
|
-
transform_inner(&src, &dst, radian, xscale, yscale);
|
392
|
-
return self;
|
393
|
-
}
|
394
|
-
|
395
|
-
/*
|
396
|
-
インスタンスの内容を画面に描画する(回転/拡大/縮小/鏡像付き)
|
397
|
-
*/
|
398
|
-
static VALUE sprite_render_to_sprite_transform(VALUE self, VALUE vdst, VALUE radian, VALUE xscale, VALUE yscale)
|
399
|
-
{
|
400
|
-
VALUE visible = rb_iv_get(self, "@visible");
|
401
|
-
if(visible == Qfalse) return self;
|
402
|
-
MiyakoBitmap src, dst;
|
403
|
-
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
404
|
-
|
405
|
-
_miyako_setup_unit_2(self, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
406
|
-
|
407
|
-
if(src.surface == dst.surface){ return Qnil; }
|
408
|
-
|
409
|
-
transform_inner(&src, &dst, radian, xscale, yscale);
|
410
|
-
return self;
|
411
|
-
}
|
412
|
-
|
413
|
-
void Init_miyako_transform()
|
414
|
-
{
|
415
|
-
mSDL = rb_define_module("SDL");
|
416
|
-
mMiyako = rb_define_module("Miyako");
|
417
|
-
mScreen = rb_define_module_under(mMiyako, "Screen");
|
418
|
-
cSurface = rb_define_class_under(mSDL, "Surface", rb_cObject);
|
419
|
-
cBitmap = rb_define_class_under(mMiyako, "Bitmap", rb_cObject);
|
420
|
-
cSprite = rb_define_class_under(mMiyako, "Sprite", rb_cObject);
|
421
|
-
|
422
|
-
rb_define_method(cSprite, "render_transform", sprite_render_transform, 3);
|
423
|
-
rb_define_method(cSprite, "render_to_transform", sprite_render_to_sprite_transform, 4);
|
424
|
-
|
425
|
-
id_update = rb_intern("update");
|
426
|
-
id_kakko = rb_intern("[]");
|
427
|
-
id_render = rb_intern("render");
|
428
|
-
id_to_a = rb_intern("to_a");
|
429
|
-
|
430
|
-
zero = 0;
|
431
|
-
nZero = INT2NUM(zero);
|
432
|
-
one = 1;
|
433
|
-
nOne = INT2NUM(one);
|
434
|
-
|
435
|
-
rb_define_singleton_method(cBitmap, "rotate", bitmap_miyako_rotate, 3);
|
436
|
-
rb_define_singleton_method(cBitmap, "scale", bitmap_miyako_scale, 4);
|
437
|
-
rb_define_singleton_method(cBitmap, "transform", bitmap_miyako_transform, 5);
|
438
|
-
}
|
1
|
+
/*
|
2
|
+
--
|
3
|
+
Miyako v2.0 Extend Library "Miyako no Katana"
|
4
|
+
Copyright (C) 2008 Cyross Makoto
|
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
|
+
*/
|
21
|
+
|
22
|
+
/*
|
23
|
+
=拡張ライブラリmiyako_no_katana
|
24
|
+
Authors:: サイロス誠
|
25
|
+
Version:: 2.0
|
26
|
+
Copyright:: 2007-2008 Cyross Makoto
|
27
|
+
License:: LGPL2.1
|
28
|
+
*/
|
29
|
+
#include "defines.h"
|
30
|
+
#include "extern.h"
|
31
|
+
|
32
|
+
static VALUE mSDL = Qnil;
|
33
|
+
static VALUE mMiyako = Qnil;
|
34
|
+
static VALUE mScreen = Qnil;
|
35
|
+
static VALUE cSurface = Qnil;
|
36
|
+
static VALUE cBitmap = Qnil;
|
37
|
+
static VALUE cSprite = Qnil;
|
38
|
+
static VALUE nZero = Qnil;
|
39
|
+
static VALUE nOne = Qnil;
|
40
|
+
static volatile ID id_update = Qnil;
|
41
|
+
static volatile ID id_kakko = Qnil;
|
42
|
+
static volatile ID id_render = Qnil;
|
43
|
+
static volatile ID id_to_a = Qnil;
|
44
|
+
static volatile int zero = Qnil;
|
45
|
+
static volatile int one = Qnil;
|
46
|
+
|
47
|
+
// from rubysdl_video.c
|
48
|
+
static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
|
49
|
+
|
50
|
+
/*
|
51
|
+
画像を回転させて貼り付ける
|
52
|
+
*/
|
53
|
+
static VALUE bitmap_miyako_rotate(VALUE self, VALUE vsrc, VALUE vdst, VALUE radian)
|
54
|
+
{
|
55
|
+
MiyakoBitmap src, dst;
|
56
|
+
MiyakoSize size;
|
57
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
58
|
+
|
59
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
60
|
+
|
61
|
+
size.w = dst.rect.w;
|
62
|
+
size.h = dst.rect.h;
|
63
|
+
|
64
|
+
if(src.surface == dst.surface){ return Qnil; }
|
65
|
+
|
66
|
+
if(dst.rect.w >= 32768 || dst.rect.h >= 32768){ return Qnil; }
|
67
|
+
|
68
|
+
double rad = NUM2DBL(radian) * -1.0;
|
69
|
+
long isin = (long)(sin(rad)*4096.0);
|
70
|
+
long icos = (long)(cos(rad)*4096.0);
|
71
|
+
|
72
|
+
int px = -(NUM2INT(*(RSTRUCT_PTR(src.unit)+7)));
|
73
|
+
int py = -(NUM2INT(*(RSTRUCT_PTR(src.unit)+8)));
|
74
|
+
int pr = src.rect.w + px;
|
75
|
+
int pb = src.rect.h + py;
|
76
|
+
int qx = -(NUM2INT(*(RSTRUCT_PTR(dst.unit)+7)));
|
77
|
+
int qy = -(NUM2INT(*(RSTRUCT_PTR(dst.unit)+8)));
|
78
|
+
int qr = dst.rect.w + qx;
|
79
|
+
int qb = dst.rect.h + qy;
|
80
|
+
|
81
|
+
SDL_LockSurface(src.surface);
|
82
|
+
SDL_LockSurface(dst.surface);
|
83
|
+
|
84
|
+
int x, y;
|
85
|
+
for(y = qy; y < qb; y++)
|
86
|
+
{
|
87
|
+
Uint32 *tp = dst.ptr + (dst.rect.y + y - qy) * dst.surface->w + dst.rect.x;
|
88
|
+
for(x = qx; x < qr; x++)
|
89
|
+
{
|
90
|
+
int nx = (x*icos-y*isin) >> 12;
|
91
|
+
if(nx < px || nx >= pr){ tp++; continue; }
|
92
|
+
int ny = (x*isin+y*icos) >> 12;
|
93
|
+
if(ny < py || ny >= pb){ tp++; continue; }
|
94
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
95
|
+
dst.color.r = (*tp >> 16) & 0xff;
|
96
|
+
dst.color.g = (*tp >> 8) & 0xff;
|
97
|
+
dst.color.b = (*tp ) & 0xff;
|
98
|
+
dst.color.a = (*tp >> 24) & 0xff | dst.a255;
|
99
|
+
Uint32 *psrc = src.ptr + (src.rect.x + ny - py) * src.surface->w + src.rect.x + nx - px;
|
100
|
+
src.color.a = (*psrc >> 24) & 0xff | src.a255;
|
101
|
+
if(src.color.a == 0){ tp++; continue; }
|
102
|
+
if(dst.color.a == 0 || src.color.a == 255)
|
103
|
+
{
|
104
|
+
*tp = *psrc;
|
105
|
+
tp++;
|
106
|
+
continue;
|
107
|
+
}
|
108
|
+
int a1 = src.color.a + 1;
|
109
|
+
int a2 = 256 - src.color.a;
|
110
|
+
src.color.r = (*psrc >> 16) & 0xff;
|
111
|
+
src.color.g = (*psrc >> 8) & 0xff;
|
112
|
+
src.color.b = (*psrc ) & 0xff;
|
113
|
+
*tp = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
|
114
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
|
115
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) |
|
116
|
+
0xff << 24;
|
117
|
+
#else
|
118
|
+
dst.color.r = (*tp & dst.fmt->Rmask) >> dst.fmt->Rshift;
|
119
|
+
dst.color.g = (*tp & dst.fmt->Gmask) >> dst.fmt->Gshift;
|
120
|
+
dst.color.b = (*tp & dst.fmt->Bmask) >> dst.fmt->Bshift;
|
121
|
+
dst.color.a = (*tp & dst.fmt->Amask) | dst.a255;
|
122
|
+
Uint32 *psrc = src.ptr + (src.rect.x + ny - py) * src.surface->w + src.rect.x + nx - px;
|
123
|
+
src.color.a = (*psrc & src.fmt->Amask) | src.a255;
|
124
|
+
if(src.color.a == 0){ tp++; continue; }
|
125
|
+
if(dst.color.a == 0 || src.color.a == 255)
|
126
|
+
{
|
127
|
+
*tp = *psrc;
|
128
|
+
tp++;
|
129
|
+
continue;
|
130
|
+
}
|
131
|
+
int a1 = src.color.a + 1;
|
132
|
+
int a2 = 256 - src.color.a;
|
133
|
+
src.color.r = (*psrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
134
|
+
src.color.g = (*psrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
135
|
+
src.color.b = (*psrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
136
|
+
*tp = (((src.color.r * a1 + dst.color.r * a2) >> 8)) << dst.fmt->Rshift |
|
137
|
+
(((src.color.g * a1 + dst.color.g * a2) >> 8)) << dst.fmt->Gshift |
|
138
|
+
(((src.color.b * a1 + dst.color.b * a2) >> 8)) << dst.fmt->Bshift |
|
139
|
+
0xff;
|
140
|
+
#endif
|
141
|
+
tp++;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
SDL_UnlockSurface(src.surface);
|
146
|
+
SDL_UnlockSurface(dst.surface);
|
147
|
+
|
148
|
+
return vdst;
|
149
|
+
}
|
150
|
+
|
151
|
+
/*
|
152
|
+
画像を拡大・縮小・鏡像(ミラー反転)させて貼り付ける
|
153
|
+
*/
|
154
|
+
static VALUE bitmap_miyako_scale(VALUE self, VALUE vsrc, VALUE vdst, VALUE xscale, VALUE yscale)
|
155
|
+
{
|
156
|
+
MiyakoBitmap src, dst;
|
157
|
+
MiyakoSize size;
|
158
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
159
|
+
|
160
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
161
|
+
|
162
|
+
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
163
|
+
|
164
|
+
if(src.surface == dst.surface){ return Qnil; }
|
165
|
+
|
166
|
+
if(dst.rect.w >= 32768 || dst.rect.h >= 32768){ return Qnil; }
|
167
|
+
|
168
|
+
double tscx = NUM2DBL(xscale);
|
169
|
+
double tscy = NUM2DBL(yscale);
|
170
|
+
|
171
|
+
if(tscx == 0.0 || tscy == 0.0){ return Qnil; }
|
172
|
+
|
173
|
+
int scx = (int)(4096.0 / tscx);
|
174
|
+
int scy = (int)(4096.0 / tscy);
|
175
|
+
|
176
|
+
int off_x = scx < 0 ? 1 : 0;
|
177
|
+
int off_y = scy < 0 ? 1 : 0;
|
178
|
+
|
179
|
+
int px = -(NUM2INT(*(RSTRUCT_PTR(src.unit)+7)));
|
180
|
+
int py = -(NUM2INT(*(RSTRUCT_PTR(src.unit)+8)));
|
181
|
+
int pr = src.rect.w + px;
|
182
|
+
int pb = src.rect.h + py;
|
183
|
+
int qx = -(NUM2INT(*(RSTRUCT_PTR(dst.unit)+7)));
|
184
|
+
int qy = -(NUM2INT(*(RSTRUCT_PTR(dst.unit)+8)));
|
185
|
+
int qr = dst.rect.w + qx;
|
186
|
+
int qb = dst.rect.h + qy;
|
187
|
+
|
188
|
+
SDL_LockSurface(src.surface);
|
189
|
+
SDL_LockSurface(dst.surface);
|
190
|
+
|
191
|
+
int x, y;
|
192
|
+
for(y = qy; y < qb; y++)
|
193
|
+
{
|
194
|
+
Uint32 *tp = dst.ptr + (dst.rect.y + y - qy) * dst.surface->w + dst.rect.x;
|
195
|
+
for(x = qx; x < qr; x++)
|
196
|
+
{
|
197
|
+
int nx = (x*scx) >> 12 - off_x;
|
198
|
+
if(nx < px || nx >= pr){ tp++; continue; }
|
199
|
+
int ny = (y*scy) >> 12 - off_y;
|
200
|
+
if(ny < py || ny >= pb){ tp++; continue; }
|
201
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
202
|
+
dst.color.r = (*tp >> 16) & 0xff;
|
203
|
+
dst.color.g = (*tp >> 8) & 0xff;
|
204
|
+
dst.color.b = (*tp ) & 0xff;
|
205
|
+
dst.color.a = (*tp >> 24) & 0xff | dst.a255;
|
206
|
+
Uint32 *psrc = src.ptr + (src.rect.x + ny - py) * src.surface->w + src.rect.x + nx - px;
|
207
|
+
src.color.a = (*psrc >> 24) & 0xff | src.a255;
|
208
|
+
if(src.color.a == 0){ tp++; continue; }
|
209
|
+
if(dst.color.a == 0 || src.color.a == 255)
|
210
|
+
{
|
211
|
+
*tp = *psrc;
|
212
|
+
tp++;
|
213
|
+
continue;
|
214
|
+
}
|
215
|
+
int a1 = src.color.a + 1;
|
216
|
+
int a2 = 256 - src.color.a;
|
217
|
+
src.color.r = (*psrc >> 16) & 0xff;
|
218
|
+
src.color.g = (*psrc >> 8) & 0xff;
|
219
|
+
src.color.b = (*psrc ) & 0xff;
|
220
|
+
*tp = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
|
221
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
|
222
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) |
|
223
|
+
0xff << 24;
|
224
|
+
#else
|
225
|
+
dst.color.r = (*tp & dst.fmt->Rmask) >> dst.fmt->Rshift;
|
226
|
+
dst.color.g = (*tp & dst.fmt->Gmask) >> dst.fmt->Gshift;
|
227
|
+
dst.color.b = (*tp & dst.fmt->Bmask) >> dst.fmt->Bshift;
|
228
|
+
dst.color.a = (*tp & dst.fmt->Amask) | dst.a255;
|
229
|
+
Uint32 *psrc = src.ptr + (src.rect.x + ny - py) * src.surface->w + src.rect.x + nx - px;
|
230
|
+
src.color.a = (*psrc & src.fmt->Amask) | src.a255;
|
231
|
+
if(src.color.a == 0){ tp++; continue; }
|
232
|
+
if(dst.color.a == 0 || src.color.a == 255)
|
233
|
+
{
|
234
|
+
*tp = *psrc;
|
235
|
+
tp++;
|
236
|
+
continue;
|
237
|
+
}
|
238
|
+
int a1 = src.color.a + 1;
|
239
|
+
int a2 = 256 - src.color.a;
|
240
|
+
src.color.r = (*psrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
241
|
+
src.color.g = (*psrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
242
|
+
src.color.b = (*psrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
243
|
+
*tp = ((src.color.r * a1 + dst.color.r * a2) >> 8) << dst.fmt->Rshift |
|
244
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << dst.fmt->Gshift |
|
245
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) << dst.fmt->Bshift |
|
246
|
+
0xff;
|
247
|
+
#endif
|
248
|
+
tp++;
|
249
|
+
}
|
250
|
+
}
|
251
|
+
|
252
|
+
SDL_UnlockSurface(src.surface);
|
253
|
+
SDL_UnlockSurface(dst.surface);
|
254
|
+
|
255
|
+
return vdst;
|
256
|
+
}
|
257
|
+
|
258
|
+
/*
|
259
|
+
===回転・拡大・縮小・鏡像用インナーメソッド
|
260
|
+
*/
|
261
|
+
static void transform_inner(MiyakoBitmap *src, MiyakoBitmap *dst, VALUE radian, VALUE xscale, VALUE yscale)
|
262
|
+
{
|
263
|
+
if(dst->rect.w >= 32768 || dst->rect.h >= 32768) return;
|
264
|
+
|
265
|
+
MiyakoSize size;
|
266
|
+
|
267
|
+
if(_miyako_init_rect(src, dst, &size) == 0) return;
|
268
|
+
|
269
|
+
double rad = NUM2DBL(radian) * -1.0;
|
270
|
+
long isin = (long)(sin(rad)*4096.0);
|
271
|
+
long icos = (long)(cos(rad)*4096.0);
|
272
|
+
|
273
|
+
double tscx = NUM2DBL(xscale);
|
274
|
+
double tscy = NUM2DBL(yscale);
|
275
|
+
|
276
|
+
if(tscx == 0.0 || tscy == 0.0) return;
|
277
|
+
|
278
|
+
int scx = (int)(4096.0 / tscx);
|
279
|
+
int scy = (int)(4096.0 / tscy);
|
280
|
+
|
281
|
+
int off_x = scx < 0 ? 1 : 0;
|
282
|
+
int off_y = scy < 0 ? 1 : 0;
|
283
|
+
|
284
|
+
int px = -(NUM2INT(*(RSTRUCT_PTR(src->unit)+7)));
|
285
|
+
int py = -(NUM2INT(*(RSTRUCT_PTR(src->unit)+8)));
|
286
|
+
int pr = src->rect.w + px;
|
287
|
+
int pb = src->rect.h + py;
|
288
|
+
int qx = -(NUM2INT(*(RSTRUCT_PTR(dst->unit)+7)));
|
289
|
+
int qy = -(NUM2INT(*(RSTRUCT_PTR(dst->unit)+8)));
|
290
|
+
int qr = dst->rect.w + qx;
|
291
|
+
int qb = dst->rect.h + qy;
|
292
|
+
|
293
|
+
SDL_LockSurface(src->surface);
|
294
|
+
SDL_LockSurface(dst->surface);
|
295
|
+
|
296
|
+
int x, y;
|
297
|
+
for(y = qy; y < qb; y++)
|
298
|
+
{
|
299
|
+
Uint32 *tp = dst->ptr + (dst->rect.y + y - qy) * dst->surface->w + dst->rect.x;
|
300
|
+
for(x = qx; x < qr; x++)
|
301
|
+
{
|
302
|
+
int nx = (((x*icos-y*isin) >> 12) * scx) >> 12 - off_x;
|
303
|
+
if(nx < px || nx >= pr){ tp++; continue; }
|
304
|
+
int ny = (((x*isin+y*icos) >> 12) * scy) >> 12 - off_y;
|
305
|
+
if(ny < py || ny >= pb){ tp++; continue; }
|
306
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
307
|
+
dst->color.r = (*tp >> 16) & 0xff;
|
308
|
+
dst->color.g = (*tp >> 8) & 0xff;
|
309
|
+
dst->color.b = (*tp ) & 0xff;
|
310
|
+
dst->color.a = (*tp >> 24) & 0xff | dst->a255;
|
311
|
+
Uint32 *psrc = src->ptr + (src->rect.x + ny - py) * src->surface->w + src->rect.x + nx - px;
|
312
|
+
src->color.a = (*psrc >> 24) & 0xff | src->a255;
|
313
|
+
if(src->color.a == 0){ tp++; continue; }
|
314
|
+
if(dst->color.a == 0 || src->color.a == 255)
|
315
|
+
{
|
316
|
+
*tp = *psrc;
|
317
|
+
tp++;
|
318
|
+
continue;
|
319
|
+
}
|
320
|
+
int a1 = src->color.a + 1;
|
321
|
+
int a2 = 256 - src->color.a;
|
322
|
+
src->color.r = (*psrc >> 16) & 0xff;
|
323
|
+
src->color.g = (*psrc >> 8) & 0xff;
|
324
|
+
src->color.b = (*psrc ) & 0xff;
|
325
|
+
*tp = ((src->color.r * a1 + dst->color.r * a2) >> 8) << 16 |
|
326
|
+
((src->color.g * a1 + dst->color.g * a2) >> 8) << 8 |
|
327
|
+
((src->color.b * a1 + dst->color.b * a2) >> 8) |
|
328
|
+
0xff << 24;
|
329
|
+
#else
|
330
|
+
dst->color.r = (*tp & dst->fmt->Rmask) >> dst->fmt->Rshift;
|
331
|
+
dst->color.g = (*tp & dst->fmt->Gmask) >> dst->fmt->Gshift;
|
332
|
+
dst->color.b = (*tp & dst->fmt->Bmask) >> dst->fmt->Bshift;
|
333
|
+
dst->color.a = (*tp & dst->fmt->Amask) | dst->a255;
|
334
|
+
Uint32 *psrc = src->ptr + (src->rect.x + ny - py) * src->surface->w + src->rect.x + nx - px;
|
335
|
+
src->color.a = (*psrc & src->fmt->Amask) | src->a255;
|
336
|
+
if(src->color.a == 0){ tp++; continue; }
|
337
|
+
if(dst->color.a == 0 || src->color.a == 255)
|
338
|
+
{
|
339
|
+
*tp = *psrc;
|
340
|
+
tp++;
|
341
|
+
continue;
|
342
|
+
}
|
343
|
+
int a1 = src->color.a + 1;
|
344
|
+
int a2 = 256 - src->color.a;
|
345
|
+
src->color.r = (*psrc & src->fmt->Rmask) >> src->fmt->Rshift;
|
346
|
+
src->color.g = (*psrc & src->fmt->Gmask) >> src->fmt->Gshift;
|
347
|
+
src->color.b = (*psrc & src->fmt->Bmask) >> src->fmt->Bshift;
|
348
|
+
*tp = ((src->color.r * a1 + dst->color.r * a2) >> 8) << dst->fmt->Rshift |
|
349
|
+
((src->color.g * a1 + dst->color.g * a2) >> 8) << dst->fmt->Gshift |
|
350
|
+
((src->color.b * a1 + dst->color.b * a2) >> 8) << dst->fmt->Bshift |
|
351
|
+
0xff;
|
352
|
+
#endif
|
353
|
+
tp++;
|
354
|
+
}
|
355
|
+
}
|
356
|
+
|
357
|
+
SDL_UnlockSurface(src->surface);
|
358
|
+
SDL_UnlockSurface(dst->surface);
|
359
|
+
}
|
360
|
+
|
361
|
+
/*
|
362
|
+
画像を変形(回転・拡大・縮小・鏡像)させて貼り付ける
|
363
|
+
*/
|
364
|
+
static VALUE bitmap_miyako_transform(VALUE self, VALUE vsrc, VALUE vdst, VALUE radian, VALUE xscale, VALUE yscale)
|
365
|
+
{
|
366
|
+
MiyakoBitmap src, dst;
|
367
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
368
|
+
|
369
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
370
|
+
|
371
|
+
if(src.surface == dst.surface){ return Qnil; }
|
372
|
+
|
373
|
+
transform_inner(&src, &dst, radian, xscale, yscale);
|
374
|
+
return vdst;
|
375
|
+
}
|
376
|
+
|
377
|
+
/*
|
378
|
+
インスタンスの内容を画面に描画する(回転/拡大/縮小/鏡像付き)
|
379
|
+
*/
|
380
|
+
static VALUE sprite_render_transform(VALUE self, VALUE radian, VALUE xscale, VALUE yscale)
|
381
|
+
{
|
382
|
+
VALUE visible = rb_iv_get(self, "@visible");
|
383
|
+
if(visible == Qfalse) return self;
|
384
|
+
MiyakoBitmap src, dst;
|
385
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
386
|
+
|
387
|
+
_miyako_setup_unit_2(self, mScreen, scr, &src, &dst, Qnil, Qnil, 1);
|
388
|
+
|
389
|
+
if(src.surface == dst.surface){ return Qnil; }
|
390
|
+
|
391
|
+
transform_inner(&src, &dst, radian, xscale, yscale);
|
392
|
+
return self;
|
393
|
+
}
|
394
|
+
|
395
|
+
/*
|
396
|
+
インスタンスの内容を画面に描画する(回転/拡大/縮小/鏡像付き)
|
397
|
+
*/
|
398
|
+
static VALUE sprite_render_to_sprite_transform(VALUE self, VALUE vdst, VALUE radian, VALUE xscale, VALUE yscale)
|
399
|
+
{
|
400
|
+
VALUE visible = rb_iv_get(self, "@visible");
|
401
|
+
if(visible == Qfalse) return self;
|
402
|
+
MiyakoBitmap src, dst;
|
403
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
404
|
+
|
405
|
+
_miyako_setup_unit_2(self, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
406
|
+
|
407
|
+
if(src.surface == dst.surface){ return Qnil; }
|
408
|
+
|
409
|
+
transform_inner(&src, &dst, radian, xscale, yscale);
|
410
|
+
return self;
|
411
|
+
}
|
412
|
+
|
413
|
+
void Init_miyako_transform()
|
414
|
+
{
|
415
|
+
mSDL = rb_define_module("SDL");
|
416
|
+
mMiyako = rb_define_module("Miyako");
|
417
|
+
mScreen = rb_define_module_under(mMiyako, "Screen");
|
418
|
+
cSurface = rb_define_class_under(mSDL, "Surface", rb_cObject);
|
419
|
+
cBitmap = rb_define_class_under(mMiyako, "Bitmap", rb_cObject);
|
420
|
+
cSprite = rb_define_class_under(mMiyako, "Sprite", rb_cObject);
|
421
|
+
|
422
|
+
rb_define_method(cSprite, "render_transform", sprite_render_transform, 3);
|
423
|
+
rb_define_method(cSprite, "render_to_transform", sprite_render_to_sprite_transform, 4);
|
424
|
+
|
425
|
+
id_update = rb_intern("update");
|
426
|
+
id_kakko = rb_intern("[]");
|
427
|
+
id_render = rb_intern("render");
|
428
|
+
id_to_a = rb_intern("to_a");
|
429
|
+
|
430
|
+
zero = 0;
|
431
|
+
nZero = INT2NUM(zero);
|
432
|
+
one = 1;
|
433
|
+
nOne = INT2NUM(one);
|
434
|
+
|
435
|
+
rb_define_singleton_method(cBitmap, "rotate", bitmap_miyako_rotate, 3);
|
436
|
+
rb_define_singleton_method(cBitmap, "scale", bitmap_miyako_scale, 4);
|
437
|
+
rb_define_singleton_method(cBitmap, "transform", bitmap_miyako_transform, 5);
|
438
|
+
}
|