cyross-ruby-miyako 2.0.5.1.0 → 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_utility.c
CHANGED
@@ -1,288 +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
|
-
}
|
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
|
+
}
|