cyross-ruby-miyako 2.0.0 → 2.0.5.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.
Files changed (102) hide show
  1. data/README +106 -154
  2. data/defines.h +144 -0
  3. data/{miyako_no_katana/extconf.rb → extconf.rb} +10 -0
  4. data/extern.h +29 -0
  5. data/install_miyako.rb +26 -14
  6. data/lib/Miyako/API/audio.rb +2 -2
  7. data/lib/Miyako/API/basic_data.rb +183 -41
  8. data/lib/Miyako/API/bitmap.rb +474 -2
  9. data/lib/Miyako/API/choices.rb +215 -48
  10. data/lib/Miyako/API/collision.rb +267 -251
  11. data/lib/Miyako/API/diagram.rb +58 -70
  12. data/lib/Miyako/API/drawing.rb +93 -52
  13. data/lib/Miyako/API/fixedmap.rb +233 -120
  14. data/lib/Miyako/API/font.rb +59 -40
  15. data/lib/Miyako/API/input.rb +34 -27
  16. data/lib/Miyako/API/layout.rb +154 -172
  17. data/lib/Miyako/API/map.rb +285 -159
  18. data/lib/Miyako/API/map_event.rb +4 -4
  19. data/lib/Miyako/API/modules.rb +1 -1
  20. data/lib/Miyako/API/movie.rb +8 -5
  21. data/lib/Miyako/API/parts.rb +44 -9
  22. data/lib/Miyako/API/plane.rb +37 -2
  23. data/lib/Miyako/API/screen.rb +90 -22
  24. data/lib/Miyako/API/shape.rb +118 -37
  25. data/lib/Miyako/API/sprite.rb +475 -61
  26. data/lib/Miyako/API/sprite_animation.rb +83 -63
  27. data/lib/Miyako/API/spriteunit.rb +47 -13
  28. data/lib/Miyako/API/story.rb +123 -47
  29. data/lib/Miyako/API/textbox.rb +361 -132
  30. data/lib/Miyako/API/utility.rb +388 -0
  31. data/lib/Miyako/API/viewport.rb +54 -349
  32. data/lib/Miyako/API/yuki.rb +570 -353
  33. data/lib/Miyako/EXT/miyako_cairo.rb +5 -3
  34. data/lib/Miyako/EXT/slides.rb +22 -1
  35. data/lib/Miyako/miyako.rb +12 -13
  36. data/logo/EGSR_logo.png +0 -0
  37. data/logo/EGSR_logo_bg.png +0 -0
  38. data/logo/EGSR_logo_fg.png +0 -0
  39. data/logo/EGSR_title_banner.png +0 -0
  40. data/logo/EGSR_title_logo.png +0 -0
  41. data/logo/miyako.png +0 -0
  42. data/logo/miyako_banner.png +0 -0
  43. data/logo/space.png +0 -0
  44. data/miyako_basicdata.c +590 -0
  45. data/miyako_bitmap.c +1225 -0
  46. data/miyako_collision.c +403 -0
  47. data/miyako_drawing.c +187 -0
  48. data/miyako_font.c +334 -0
  49. data/miyako_hsv.c +830 -0
  50. data/miyako_layout.c +191 -0
  51. data/miyako_no_katana.c +1074 -0
  52. data/miyako_transform.c +438 -0
  53. data/miyako_utility.c +288 -0
  54. data/sample/Animation1/m1ku.rb +10 -31
  55. data/sample/Animation1/readme.txt +6 -6
  56. data/sample/Animation2/lex.rb +1 -0
  57. data/sample/Animation2/readme.txt +6 -6
  58. data/sample/Diagram_sample/diagram_sample_yuki2.rb +152 -48
  59. data/sample/Diagram_sample/readme.txt +9 -6
  60. data/sample/Room3/blue.rb +234 -187
  61. data/sample/Room3/ending.rb +68 -63
  62. data/sample/Room3/green.rb +159 -124
  63. data/sample/Room3/main.rb +50 -32
  64. data/sample/Room3/main_component.rb +3 -2
  65. data/sample/Room3/readme.txt +6 -6
  66. data/sample/Room3/red.rb +161 -134
  67. data/sample/Room3/room3.rb +1 -0
  68. data/sample/Room3/title.rb +75 -62
  69. data/sample/ball_action_sample.rb +204 -0
  70. data/sample/blit_rop.rb +70 -0
  71. data/sample/cairo_sample.rb +25 -0
  72. data/sample/circle_collision_test.rb +66 -0
  73. data/sample/collision_test.rb +33 -0
  74. data/sample/collision_test2.rb +108 -0
  75. data/sample/fixed_map_test/fixed_map_sample.rb +23 -32
  76. data/sample/fixed_map_test/readme.txt +38 -38
  77. data/sample/map_test/chara.rb +17 -9
  78. data/sample/map_test/main_parts.rb +30 -9
  79. data/sample/map_test/main_scene.rb +57 -41
  80. data/sample/map_test/map_manager.rb +13 -30
  81. data/sample/map_test/map_test.rb +2 -2
  82. data/sample/map_test/oasis.rb +17 -11
  83. data/sample/map_test/readme.txt +50 -48
  84. data/sample/map_test/route.rb +46 -33
  85. data/sample/map_test/town.rb +19 -13
  86. data/sample/polygon_test.rb +35 -0
  87. data/sample/rasterscroll.rb +25 -0
  88. data/sample/takahashi.rb +42 -0
  89. data/sample/text.png +0 -0
  90. data/sample/textbox_sample.rb +190 -0
  91. data/sample/transform.rb +54 -0
  92. data/sample/utility_test.rb +73 -0
  93. data/sample/utility_test2.rb +61 -0
  94. data/sample/utility_test3.rb +64 -0
  95. data/sample/utility_test4.rb +73 -0
  96. data/uninstall_miyako.rb +19 -0
  97. data/win/miyako_no_katana.so +0 -0
  98. metadata +165 -148
  99. data/miyako.png +0 -0
  100. data/miyako_banner.png +0 -0
  101. data/miyako_no_katana/miyako_no_katana.c +0 -3301
  102. data/sample/fixed_map_test/map_sample.rb +0 -121
@@ -0,0 +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
+ }
data/miyako_utility.c ADDED
@@ -0,0 +1,288 @@
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
+
31
+ static VALUE mSDL = Qnil;
32
+ static VALUE mMiyako = Qnil;
33
+ static VALUE eMiyakoError = Qnil;
34
+ static VALUE cSurface = Qnil;
35
+ static VALUE sSpriteUnit = Qnil;
36
+
37
+ // from rubysdl_video.c
38
+ static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
39
+
40
+ void _miyako_yield_unit_1(MiyakoBitmap *src)
41
+ {
42
+ if(rb_block_given_p() == Qtrue){ src->unit = rb_obj_dup(src->unit); rb_yield(src->unit); }
43
+ }
44
+
45
+ void _miyako_yield_unit_2(MiyakoBitmap *src, MiyakoBitmap *dst)
46
+ {
47
+ if(rb_block_given_p() == Qtrue)
48
+ {
49
+ src->unit = rb_obj_dup(src->unit);
50
+ dst->unit = rb_obj_dup(dst->unit);
51
+ rb_yield_values(2, src->unit, dst->unit);
52
+ }
53
+ }
54
+
55
+ void _miyako_setup_unit(VALUE unit, SDL_Surface *screen, MiyakoBitmap *mb, VALUE x, VALUE y, int use_yield)
56
+ {
57
+ mb->unit = unit;
58
+ if(rb_obj_is_kind_of(mb->unit, sSpriteUnit) == Qfalse){
59
+ mb->unit = rb_funcall(mb->unit, rb_intern("to_unit"), 0);
60
+ if(mb->unit == Qnil){ rb_raise(eMiyakoError, "Source instance has not SpriteUnit!"); }
61
+ }
62
+
63
+ if(use_yield) _miyako_yield_unit_1(mb);
64
+
65
+ mb->rect.x = NUM2INT(*(RSTRUCT_PTR(mb->unit) + 1));
66
+ mb->rect.y = NUM2INT(*(RSTRUCT_PTR(mb->unit) + 2));
67
+ mb->rect.w = NUM2INT(*(RSTRUCT_PTR(mb->unit) + 3));
68
+ mb->rect.h = NUM2INT(*(RSTRUCT_PTR(mb->unit) + 4));
69
+
70
+ mb->surface = GetSurface(*(RSTRUCT_PTR(mb->unit)))->surface;
71
+ mb->ptr = (Uint32 *)(mb->surface->pixels);
72
+ mb->fmt = mb->surface->format;
73
+
74
+ // adjust clip_rect
75
+ if(mb->surface == screen)
76
+ {
77
+ SDL_Rect *crect = &(mb->surface->clip_rect);
78
+ mb->rect.x += crect->x;
79
+ if(mb->rect.x < 0){
80
+ mb->rect.w += mb->rect.x;
81
+ mb->rect.x = 0;
82
+ }
83
+ mb->rect.y += crect->y;
84
+ if(mb->rect.y < 0){
85
+ mb->rect.h += mb->rect.y;
86
+ mb->rect.y = 0;
87
+ }
88
+ if(mb->rect.w > crect->w) mb->rect.w = crect->w;
89
+ if(mb->rect.h > crect->h) mb->rect.h = crect->h;
90
+ if(mb->rect.x + mb->rect.w > mb->surface->w)
91
+ mb->rect.w = mb->surface->w - mb->rect.x;
92
+ if(mb->rect.y + mb->rect.h > mb->surface->h)
93
+ mb->rect.h = mb->surface->h - mb->rect.y;
94
+ }
95
+
96
+ mb->a255 = (mb->surface == screen) ? 0xff : 0;
97
+
98
+ mb->x = (x == Qnil ? NUM2INT(*(RSTRUCT_PTR(mb->unit) + 5)) : NUM2INT(x));
99
+ mb->y = (y == Qnil ? NUM2INT(*(RSTRUCT_PTR(mb->unit) + 6)) : NUM2INT(y));
100
+ }
101
+
102
+ void _miyako_setup_unit_2(VALUE unit_s, VALUE unit_d,
103
+ SDL_Surface *screen,
104
+ MiyakoBitmap *mb_s, MiyakoBitmap *mb_d,
105
+ VALUE x, VALUE y, int use_yield)
106
+ {
107
+ mb_s->unit = unit_s;
108
+ if(rb_obj_is_kind_of(mb_s->unit, sSpriteUnit) == Qfalse){
109
+ mb_s->unit = rb_funcall(mb_s->unit, rb_intern("to_unit"), 0);
110
+ if(mb_s->unit == Qnil){ rb_raise(eMiyakoError, "Source instance has not SpriteUnit!"); }
111
+ }
112
+
113
+ mb_d->unit = unit_d;
114
+ if(rb_obj_is_kind_of(mb_d->unit, sSpriteUnit) == Qfalse){
115
+ mb_d->unit = rb_funcall(mb_d->unit, rb_intern("to_unit"), 0);
116
+ if(mb_d->unit == Qnil){ rb_raise(eMiyakoError, "Source instance has not SpriteUnit!"); }
117
+ }
118
+
119
+ if(use_yield) _miyako_yield_unit_2(mb_s, mb_d);
120
+
121
+ mb_s->surface = GetSurface(*(RSTRUCT_PTR(mb_s->unit)))->surface;
122
+ mb_s->ptr = (Uint32 *)(mb_s->surface->pixels);
123
+ mb_s->fmt = mb_s->surface->format;
124
+
125
+ mb_s->rect.x = NUM2INT(*(RSTRUCT_PTR(mb_s->unit) + 1));
126
+ mb_s->rect.y = NUM2INT(*(RSTRUCT_PTR(mb_s->unit) + 2));
127
+ mb_s->rect.w = NUM2INT(*(RSTRUCT_PTR(mb_s->unit) + 3));
128
+ mb_s->rect.h = NUM2INT(*(RSTRUCT_PTR(mb_s->unit) + 4));
129
+
130
+ // adjust clip_rect
131
+ if(mb_s->surface == screen)
132
+ {
133
+ SDL_Rect *crect = &(mb_s->surface->clip_rect);
134
+ mb_s->rect.x += crect->x;
135
+ if(mb_s->rect.x < 0){
136
+ mb_s->rect.w += mb_s->rect.x;
137
+ mb_s->rect.x = 0;
138
+ }
139
+ mb_s->rect.y += crect->y;
140
+ if(mb_s->rect.y < 0){
141
+ mb_s->rect.h += mb_s->rect.y;
142
+ mb_s->rect.y = 0;
143
+ }
144
+ if(mb_s->rect.w > crect->w) mb_s->rect.w = crect->w;
145
+ if(mb_s->rect.h > crect->h) mb_s->rect.h = crect->h;
146
+ if(mb_s->rect.x + mb_s->rect.w > mb_s->surface->w)
147
+ mb_s->rect.w = mb_s->surface->w - mb_s->rect.x;
148
+ if(mb_s->rect.y + mb_s->rect.h > mb_s->surface->h)
149
+ mb_s->rect.h = mb_s->surface->h - mb_s->rect.y;
150
+ }
151
+
152
+ mb_s->a255 = (mb_s->surface == screen) ? 0xff : 0;
153
+
154
+ mb_s->x = (x == Qnil ? NUM2INT(*(RSTRUCT_PTR(mb_s->unit) + 5)) : NUM2INT(x));
155
+ mb_s->y = (y == Qnil ? NUM2INT(*(RSTRUCT_PTR(mb_s->unit) + 6)) : NUM2INT(y));
156
+
157
+ mb_d->surface = GetSurface(*(RSTRUCT_PTR(mb_d->unit)))->surface;
158
+ mb_d->ptr = (Uint32 *)(mb_d->surface->pixels);
159
+ mb_d->fmt = mb_d->surface->format;
160
+
161
+ mb_d->rect.x = NUM2INT(*(RSTRUCT_PTR(mb_d->unit) + 1));
162
+ mb_d->rect.y = NUM2INT(*(RSTRUCT_PTR(mb_d->unit) + 2));
163
+ mb_d->rect.w = NUM2INT(*(RSTRUCT_PTR(mb_d->unit) + 3));
164
+ mb_d->rect.h = NUM2INT(*(RSTRUCT_PTR(mb_d->unit) + 4));
165
+
166
+ // adjust clip_rect
167
+ if(mb_d->surface == screen)
168
+ {
169
+ SDL_Rect *crect = &(mb_d->surface->clip_rect);
170
+ mb_d->rect.x += crect->x;
171
+ if(mb_d->rect.x < 0){
172
+ mb_d->rect.w += mb_d->rect.x;
173
+ mb_d->rect.x = 0;
174
+ }
175
+ mb_d->rect.y += crect->y;
176
+ if(mb_d->rect.y < 0){
177
+ mb_d->rect.h += mb_d->rect.y;
178
+ mb_d->rect.y = 0;
179
+ }
180
+ if(mb_d->rect.w > crect->w) mb_d->rect.w = crect->w;
181
+ if(mb_d->rect.h > crect->h) mb_d->rect.h = crect->h;
182
+ if(mb_d->rect.x + mb_d->rect.w > mb_d->surface->w)
183
+ mb_d->rect.w = mb_d->surface->w - mb_d->rect.x;
184
+ if(mb_d->rect.y + mb_d->rect.h > mb_d->surface->h)
185
+ mb_d->rect.h = mb_d->surface->h - mb_d->rect.y;
186
+ }
187
+
188
+ mb_d->a255 = (mb_d->surface == screen) ? 0xff : 0;
189
+
190
+ mb_d->x = NUM2INT(*(RSTRUCT_PTR(mb_d->unit) + 5));
191
+ mb_d->y = NUM2INT(*(RSTRUCT_PTR(mb_d->unit) + 6));
192
+ }
193
+
194
+ int _miyako_init_rect(MiyakoBitmap *src, MiyakoBitmap *dst, MiyakoSize *size)
195
+ {
196
+ int sw = src->rect.w;
197
+ int sh = src->rect.h;
198
+ int dw = dst->rect.w;
199
+ int dh = dst->rect.h;
200
+
201
+ // ox(oy)が画像のw(h)以上の時は転送不可
202
+
203
+ if(src->rect.x >= src->surface->w || src->rect.y >= src->surface->h) return 0;
204
+ if(dst->rect.x >= dst->surface->w || dst->rect.y >= dst->surface->h) return 0;
205
+
206
+ // ox(oy)がマイナスの時は、ow(oh)を減らしておいて、ox, oyをゼロにしておく
207
+ // 0以下になったら転送不可
208
+
209
+ if(src->rect.x < 0){
210
+ sw += src->rect.x;
211
+ src->rect.x = 0;
212
+ if(sw <= 0) return 0;
213
+ }
214
+ if(src->rect.y < 0){
215
+ sh += src->rect.y;
216
+ src->rect.y = 0;
217
+ if(sh <= 0) return 0;
218
+ }
219
+ if(dst->rect.x < 0){
220
+ dw += dst->rect.x;
221
+ dst->rect.x = 0;
222
+ if(dw <= 0) return 0;
223
+ }
224
+ if(dst->rect.y < 0){
225
+ dh += dst->rect.y;
226
+ dst->rect.y = 0;
227
+ if(dh <= 0) return 0;
228
+ }
229
+
230
+ // ox(oy)+ow(oh)が、w(h)を越える場合は、ow(oh)を減らしておく
231
+ // 0以下になったら転送不可
232
+
233
+ if(src->rect.x + sw > src->surface->w)
234
+ {
235
+ sw += (src->surface->w - src->rect.x - sw);
236
+ if(sw <= 0) return 0;
237
+ }
238
+ if(src->rect.y + sh > src->surface->h)
239
+ {
240
+ sh += (src->surface->h - src->rect.y - sh);
241
+ if(sh <= 0) return 0;
242
+ }
243
+ if(dst->rect.x + dw > dst->surface->w)
244
+ {
245
+ dw += (dst->surface->w - dst->rect.x - dw);
246
+ if(dw <= 0) return 0;
247
+ }
248
+ if(dst->rect.y + dh > dst->surface->h)
249
+ {
250
+ dh += (dst->surface->h - dst->rect.y - dh);
251
+ if(dh <= 0) return 0;
252
+ }
253
+
254
+ // ox(oy)が画像のw(h)以上、-w(-h)以下の時は転送不可
255
+
256
+ if(src->x >= dw || src->x <= -dw) return 0;
257
+ if(src->y >= dh || src->y <= -dh) return 0;
258
+
259
+ // x(y)がマイナスの時は、ow(oh)を減らしておいて、x, yをゼロにしておく
260
+ // 0以下になったら転送不可
261
+
262
+ if(src->x < 0){
263
+ dw += src->x;
264
+ src->x = 0;
265
+ }
266
+ else{ dw -= src->x; }
267
+ if(dw <= 0) return 0;
268
+ if(src->y < 0){
269
+ dh += src->y;
270
+ src->y = 0;
271
+ }
272
+ else{ dh -= src->y; }
273
+ if(dh <= 0) return 0;
274
+
275
+ size->w = (dw > sw ? sw : dw);
276
+ size->h = (dh > sh ? sh : dh);
277
+
278
+ return 1;
279
+ }
280
+
281
+ void Init_miyako_utility()
282
+ {
283
+ mSDL = rb_define_module("SDL");
284
+ mMiyako = rb_define_module("Miyako");
285
+ eMiyakoError = rb_define_class_under(mMiyako, "MiyakoError", rb_eException);
286
+ cSurface = rb_define_class_under(mSDL, "Surface", rb_cObject);
287
+ sSpriteUnit = rb_define_class_under(mMiyako, "SpriteUnitBase", rb_cStruct);
288
+ }