ruby-miyako 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/README +1115 -0
  2. data/Rakefile +7 -0
  3. data/defines.h +144 -0
  4. data/extconf.rb +44 -0
  5. data/extern.h +29 -0
  6. data/img/cursor.png +0 -0
  7. data/img/cursors.png +0 -0
  8. data/img/dice.png +0 -0
  9. data/img/wait_cursor.png +0 -0
  10. data/img/win_base.png +0 -0
  11. data/img/window.png +0 -0
  12. data/install_miyako.rb +87 -0
  13. data/lib/Miyako/API/audio.rb +584 -0
  14. data/lib/Miyako/API/basic_data.rb +1026 -0
  15. data/lib/Miyako/API/bitmap.rb +534 -0
  16. data/lib/Miyako/API/choices.rb +481 -0
  17. data/lib/Miyako/API/collision.rb +638 -0
  18. data/lib/Miyako/API/diagram.rb +586 -0
  19. data/lib/Miyako/API/drawing.rb +151 -0
  20. data/lib/Miyako/API/exceptions.rb +105 -0
  21. data/lib/Miyako/API/fixedmap.rb +462 -0
  22. data/lib/Miyako/API/font.rb +430 -0
  23. data/lib/Miyako/API/input.rb +456 -0
  24. data/lib/Miyako/API/layout.rb +644 -0
  25. data/lib/Miyako/API/map.rb +583 -0
  26. data/lib/Miyako/API/map_event.rb +222 -0
  27. data/lib/Miyako/API/modules.rb +357 -0
  28. data/lib/Miyako/API/movie.rb +166 -0
  29. data/lib/Miyako/API/parts.rb +188 -0
  30. data/lib/Miyako/API/plane.rb +205 -0
  31. data/lib/Miyako/API/screen.rb +341 -0
  32. data/lib/Miyako/API/shape.rb +443 -0
  33. data/lib/Miyako/API/sprite.rb +773 -0
  34. data/lib/Miyako/API/sprite_animation.rb +494 -0
  35. data/lib/Miyako/API/sprite_list.rb +1135 -0
  36. data/lib/Miyako/API/spriteunit.rb +168 -0
  37. data/lib/Miyako/API/story.rb +350 -0
  38. data/lib/Miyako/API/textbox.rb +773 -0
  39. data/lib/Miyako/API/utility.rb +419 -0
  40. data/lib/Miyako/API/viewport.rb +190 -0
  41. data/lib/Miyako/API/yuki.rb +1180 -0
  42. data/lib/Miyako/EXT/miyako_cairo.rb +62 -0
  43. data/lib/Miyako/EXT/raster_scroll.rb +138 -0
  44. data/lib/Miyako/EXT/slides.rb +157 -0
  45. data/lib/Miyako/miyako.rb +201 -0
  46. data/lib/Miyako/miyako_require_only.rb +35 -0
  47. data/logo/EGSR_logo.png +0 -0
  48. data/logo/EGSR_logo_bg.png +0 -0
  49. data/logo/EGSR_logo_fg.png +0 -0
  50. data/logo/EGSR_title_banner.png +0 -0
  51. data/logo/EGSR_title_logo.png +0 -0
  52. data/logo/miyako.png +0 -0
  53. data/logo/miyako_banner.png +0 -0
  54. data/logo/space.png +0 -0
  55. data/miyako_basicdata.c +484 -0
  56. data/miyako_bitmap.c +1225 -0
  57. data/miyako_collision.c +403 -0
  58. data/miyako_drawing.c +187 -0
  59. data/miyako_font.c +334 -0
  60. data/miyako_hsv.c +830 -0
  61. data/miyako_input_audio.c +254 -0
  62. data/miyako_layout.c +191 -0
  63. data/miyako_no_katana.c +1086 -0
  64. data/miyako_sprite2.c +431 -0
  65. data/miyako_transform.c +438 -0
  66. data/miyako_utility.c +288 -0
  67. data/sample/Animation1/m1ku.rb +68 -0
  68. data/sample/Animation1/m1ku_arm_0.png +0 -0
  69. data/sample/Animation1/m1ku_arm_1.png +0 -0
  70. data/sample/Animation1/m1ku_arm_2.png +0 -0
  71. data/sample/Animation1/m1ku_arm_3.png +0 -0
  72. data/sample/Animation1/m1ku_back.jpg +0 -0
  73. data/sample/Animation1/m1ku_body.png +0 -0
  74. data/sample/Animation1/m1ku_eye_0.png +0 -0
  75. data/sample/Animation1/m1ku_eye_1.png +0 -0
  76. data/sample/Animation1/m1ku_eye_2.png +0 -0
  77. data/sample/Animation1/m1ku_eye_3.png +0 -0
  78. data/sample/Animation1/m1ku_hair_front.png +0 -0
  79. data/sample/Animation1/m1ku_hair_rear.png +0 -0
  80. data/sample/Animation1/readme.txt +72 -0
  81. data/sample/Animation2/lex.rb +96 -0
  82. data/sample/Animation2/lex_back.png +0 -0
  83. data/sample/Animation2/lex_body.png +0 -0
  84. data/sample/Animation2/lex_roadroller.png +0 -0
  85. data/sample/Animation2/lex_wheel_0.png +0 -0
  86. data/sample/Animation2/lex_wheel_1.png +0 -0
  87. data/sample/Animation2/lex_wheel_2.png +0 -0
  88. data/sample/Animation2/readme.txt +72 -0
  89. data/sample/Animation2/song_title.png +0 -0
  90. data/sample/Diagram_sample/back.png +0 -0
  91. data/sample/Diagram_sample/chr01.png +0 -0
  92. data/sample/Diagram_sample/chr02.png +0 -0
  93. data/sample/Diagram_sample/cursor.png +0 -0
  94. data/sample/Diagram_sample/diagram_sample_yuki2.rb +329 -0
  95. data/sample/Diagram_sample/readme.txt +90 -0
  96. data/sample/Diagram_sample/wait_cursor.png +0 -0
  97. data/sample/Room3/blue.rb +297 -0
  98. data/sample/Room3/ending.rb +180 -0
  99. data/sample/Room3/green.rb +220 -0
  100. data/sample/Room3/image/akamatsu.png +0 -0
  101. data/sample/Room3/image/aoyama.png +0 -0
  102. data/sample/Room3/image/congra.png +0 -0
  103. data/sample/Room3/image/congratulation.png +0 -0
  104. data/sample/Room3/image/congratulation_bg.png +0 -0
  105. data/sample/Room3/image/cursor.png +0 -0
  106. data/sample/Room3/image/midori.png +0 -0
  107. data/sample/Room3/image/mittsu_no_oheya.png +0 -0
  108. data/sample/Room3/image/mittsu_no_oheya_logo.png +0 -0
  109. data/sample/Room3/image/room_blue.png +0 -0
  110. data/sample/Room3/image/room_green.png +0 -0
  111. data/sample/Room3/image/room_red.png +0 -0
  112. data/sample/Room3/image/start.png +0 -0
  113. data/sample/Room3/image/three_doors.png +0 -0
  114. data/sample/Room3/image/wait_cursor.png +0 -0
  115. data/sample/Room3/main.rb +120 -0
  116. data/sample/Room3/main_component.rb +59 -0
  117. data/sample/Room3/readme.txt +76 -0
  118. data/sample/Room3/red.rb +227 -0
  119. data/sample/Room3/room3.rb +25 -0
  120. data/sample/Room3/title.rb +184 -0
  121. data/sample/ball_action_sample.rb +204 -0
  122. data/sample/blit_rop.rb +70 -0
  123. data/sample/cairo_sample.rb +25 -0
  124. data/sample/circle_collision_test.rb +66 -0
  125. data/sample/collision_test.rb +33 -0
  126. data/sample/collision_test2.rb +108 -0
  127. data/sample/fixed_map_test/cursor.png +0 -0
  128. data/sample/fixed_map_test/fixed_map_sample.rb +140 -0
  129. data/sample/fixed_map_test/map.csv +19 -0
  130. data/sample/fixed_map_test/map_01.png +0 -0
  131. data/sample/fixed_map_test/mapchip.csv +23 -0
  132. data/sample/fixed_map_test/monster.png +0 -0
  133. data/sample/fixed_map_test/readme.txt +72 -0
  134. data/sample/map_test/chara.rb +58 -0
  135. data/sample/map_test/chr1.png +0 -0
  136. data/sample/map_test/cursor.png +0 -0
  137. data/sample/map_test/main_parts.rb +69 -0
  138. data/sample/map_test/main_scene.rb +153 -0
  139. data/sample/map_test/map.png +0 -0
  140. data/sample/map_test/map2.png +0 -0
  141. data/sample/map_test/map_layer.csv +127 -0
  142. data/sample/map_test/map_manager.rb +75 -0
  143. data/sample/map_test/map_test.rb +23 -0
  144. data/sample/map_test/mapchip.csv +21 -0
  145. data/sample/map_test/oasis.rb +71 -0
  146. data/sample/map_test/readme.txt +89 -0
  147. data/sample/map_test/route.rb +157 -0
  148. data/sample/map_test/sea.png +0 -0
  149. data/sample/map_test/town.rb +74 -0
  150. data/sample/map_test/wait_cursor.png +0 -0
  151. data/sample/map_test/window.png +0 -0
  152. data/sample/polygon_test.rb +35 -0
  153. data/sample/rasterscroll.rb +25 -0
  154. data/sample/takahashi.rb +42 -0
  155. data/sample/text.png +0 -0
  156. data/sample/textbox_sample.rb +192 -0
  157. data/sample/transform.rb +54 -0
  158. data/sample/utility_test.rb +73 -0
  159. data/sample/utility_test2.rb +61 -0
  160. data/sample/utility_test3.rb +64 -0
  161. data/sample/utility_test4.rb +73 -0
  162. data/uninstall_miyako.rb +19 -0
  163. data/win/miyako_no_katana.so +0 -0
  164. metadata +216 -0
@@ -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
+ }