ruby-miyako 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1115 -0
- data/Rakefile +7 -0
- data/defines.h +144 -0
- data/extconf.rb +44 -0
- data/extern.h +29 -0
- data/img/cursor.png +0 -0
- data/img/cursors.png +0 -0
- data/img/dice.png +0 -0
- data/img/wait_cursor.png +0 -0
- data/img/win_base.png +0 -0
- data/img/window.png +0 -0
- data/install_miyako.rb +87 -0
- data/lib/Miyako/API/audio.rb +584 -0
- data/lib/Miyako/API/basic_data.rb +1026 -0
- data/lib/Miyako/API/bitmap.rb +534 -0
- data/lib/Miyako/API/choices.rb +481 -0
- data/lib/Miyako/API/collision.rb +638 -0
- data/lib/Miyako/API/diagram.rb +586 -0
- data/lib/Miyako/API/drawing.rb +151 -0
- data/lib/Miyako/API/exceptions.rb +105 -0
- data/lib/Miyako/API/fixedmap.rb +462 -0
- data/lib/Miyako/API/font.rb +430 -0
- data/lib/Miyako/API/input.rb +456 -0
- data/lib/Miyako/API/layout.rb +644 -0
- data/lib/Miyako/API/map.rb +583 -0
- data/lib/Miyako/API/map_event.rb +222 -0
- data/lib/Miyako/API/modules.rb +357 -0
- data/lib/Miyako/API/movie.rb +166 -0
- data/lib/Miyako/API/parts.rb +188 -0
- data/lib/Miyako/API/plane.rb +205 -0
- data/lib/Miyako/API/screen.rb +341 -0
- data/lib/Miyako/API/shape.rb +443 -0
- data/lib/Miyako/API/sprite.rb +773 -0
- data/lib/Miyako/API/sprite_animation.rb +494 -0
- data/lib/Miyako/API/sprite_list.rb +1135 -0
- data/lib/Miyako/API/spriteunit.rb +168 -0
- data/lib/Miyako/API/story.rb +350 -0
- data/lib/Miyako/API/textbox.rb +773 -0
- data/lib/Miyako/API/utility.rb +419 -0
- data/lib/Miyako/API/viewport.rb +190 -0
- data/lib/Miyako/API/yuki.rb +1180 -0
- data/lib/Miyako/EXT/miyako_cairo.rb +62 -0
- data/lib/Miyako/EXT/raster_scroll.rb +138 -0
- data/lib/Miyako/EXT/slides.rb +157 -0
- data/lib/Miyako/miyako.rb +201 -0
- data/lib/Miyako/miyako_require_only.rb +35 -0
- data/logo/EGSR_logo.png +0 -0
- data/logo/EGSR_logo_bg.png +0 -0
- data/logo/EGSR_logo_fg.png +0 -0
- data/logo/EGSR_title_banner.png +0 -0
- data/logo/EGSR_title_logo.png +0 -0
- data/logo/miyako.png +0 -0
- data/logo/miyako_banner.png +0 -0
- data/logo/space.png +0 -0
- data/miyako_basicdata.c +484 -0
- data/miyako_bitmap.c +1225 -0
- data/miyako_collision.c +403 -0
- data/miyako_drawing.c +187 -0
- data/miyako_font.c +334 -0
- data/miyako_hsv.c +830 -0
- data/miyako_input_audio.c +254 -0
- data/miyako_layout.c +191 -0
- data/miyako_no_katana.c +1086 -0
- data/miyako_sprite2.c +431 -0
- data/miyako_transform.c +438 -0
- data/miyako_utility.c +288 -0
- data/sample/Animation1/m1ku.rb +68 -0
- data/sample/Animation1/m1ku_arm_0.png +0 -0
- data/sample/Animation1/m1ku_arm_1.png +0 -0
- data/sample/Animation1/m1ku_arm_2.png +0 -0
- data/sample/Animation1/m1ku_arm_3.png +0 -0
- data/sample/Animation1/m1ku_back.jpg +0 -0
- data/sample/Animation1/m1ku_body.png +0 -0
- data/sample/Animation1/m1ku_eye_0.png +0 -0
- data/sample/Animation1/m1ku_eye_1.png +0 -0
- data/sample/Animation1/m1ku_eye_2.png +0 -0
- data/sample/Animation1/m1ku_eye_3.png +0 -0
- data/sample/Animation1/m1ku_hair_front.png +0 -0
- data/sample/Animation1/m1ku_hair_rear.png +0 -0
- data/sample/Animation1/readme.txt +72 -0
- data/sample/Animation2/lex.rb +96 -0
- data/sample/Animation2/lex_back.png +0 -0
- data/sample/Animation2/lex_body.png +0 -0
- data/sample/Animation2/lex_roadroller.png +0 -0
- data/sample/Animation2/lex_wheel_0.png +0 -0
- data/sample/Animation2/lex_wheel_1.png +0 -0
- data/sample/Animation2/lex_wheel_2.png +0 -0
- data/sample/Animation2/readme.txt +72 -0
- data/sample/Animation2/song_title.png +0 -0
- data/sample/Diagram_sample/back.png +0 -0
- data/sample/Diagram_sample/chr01.png +0 -0
- data/sample/Diagram_sample/chr02.png +0 -0
- data/sample/Diagram_sample/cursor.png +0 -0
- data/sample/Diagram_sample/diagram_sample_yuki2.rb +329 -0
- data/sample/Diagram_sample/readme.txt +90 -0
- data/sample/Diagram_sample/wait_cursor.png +0 -0
- data/sample/Room3/blue.rb +297 -0
- data/sample/Room3/ending.rb +180 -0
- data/sample/Room3/green.rb +220 -0
- data/sample/Room3/image/akamatsu.png +0 -0
- data/sample/Room3/image/aoyama.png +0 -0
- data/sample/Room3/image/congra.png +0 -0
- data/sample/Room3/image/congratulation.png +0 -0
- data/sample/Room3/image/congratulation_bg.png +0 -0
- data/sample/Room3/image/cursor.png +0 -0
- data/sample/Room3/image/midori.png +0 -0
- data/sample/Room3/image/mittsu_no_oheya.png +0 -0
- data/sample/Room3/image/mittsu_no_oheya_logo.png +0 -0
- data/sample/Room3/image/room_blue.png +0 -0
- data/sample/Room3/image/room_green.png +0 -0
- data/sample/Room3/image/room_red.png +0 -0
- data/sample/Room3/image/start.png +0 -0
- data/sample/Room3/image/three_doors.png +0 -0
- data/sample/Room3/image/wait_cursor.png +0 -0
- data/sample/Room3/main.rb +120 -0
- data/sample/Room3/main_component.rb +59 -0
- data/sample/Room3/readme.txt +76 -0
- data/sample/Room3/red.rb +227 -0
- data/sample/Room3/room3.rb +25 -0
- data/sample/Room3/title.rb +184 -0
- data/sample/ball_action_sample.rb +204 -0
- data/sample/blit_rop.rb +70 -0
- data/sample/cairo_sample.rb +25 -0
- data/sample/circle_collision_test.rb +66 -0
- data/sample/collision_test.rb +33 -0
- data/sample/collision_test2.rb +108 -0
- data/sample/fixed_map_test/cursor.png +0 -0
- data/sample/fixed_map_test/fixed_map_sample.rb +140 -0
- data/sample/fixed_map_test/map.csv +19 -0
- data/sample/fixed_map_test/map_01.png +0 -0
- data/sample/fixed_map_test/mapchip.csv +23 -0
- data/sample/fixed_map_test/monster.png +0 -0
- data/sample/fixed_map_test/readme.txt +72 -0
- data/sample/map_test/chara.rb +58 -0
- data/sample/map_test/chr1.png +0 -0
- data/sample/map_test/cursor.png +0 -0
- data/sample/map_test/main_parts.rb +69 -0
- data/sample/map_test/main_scene.rb +153 -0
- data/sample/map_test/map.png +0 -0
- data/sample/map_test/map2.png +0 -0
- data/sample/map_test/map_layer.csv +127 -0
- data/sample/map_test/map_manager.rb +75 -0
- data/sample/map_test/map_test.rb +23 -0
- data/sample/map_test/mapchip.csv +21 -0
- data/sample/map_test/oasis.rb +71 -0
- data/sample/map_test/readme.txt +89 -0
- data/sample/map_test/route.rb +157 -0
- data/sample/map_test/sea.png +0 -0
- data/sample/map_test/town.rb +74 -0
- data/sample/map_test/wait_cursor.png +0 -0
- data/sample/map_test/window.png +0 -0
- data/sample/polygon_test.rb +35 -0
- data/sample/rasterscroll.rb +25 -0
- data/sample/takahashi.rb +42 -0
- data/sample/text.png +0 -0
- data/sample/textbox_sample.rb +192 -0
- data/sample/transform.rb +54 -0
- data/sample/utility_test.rb +73 -0
- data/sample/utility_test2.rb +61 -0
- data/sample/utility_test3.rb +64 -0
- data/sample/utility_test4.rb +73 -0
- data/uninstall_miyako.rb +19 -0
- data/win/miyako_no_katana.so +0 -0
- metadata +216 -0
@@ -0,0 +1,254 @@
|
|
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-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 mAudio = Qnil;
|
34
|
+
static VALUE mInput = Qnil;
|
35
|
+
static VALUE mScreen = Qnil;
|
36
|
+
static VALUE cJoystick = Qnil;
|
37
|
+
static VALUE cEvent = Qnil;
|
38
|
+
static VALUE cBGM = Qnil;
|
39
|
+
static VALUE cSE = Qnil;
|
40
|
+
static VALUE nZero = Qnil;
|
41
|
+
static VALUE nOne = Qnil;
|
42
|
+
static volatile ID id_update_all = Qnil;
|
43
|
+
static volatile ID id_is_playing = Qnil;
|
44
|
+
static volatile ID id_is_fade_out = Qnil;
|
45
|
+
static volatile ID id_in_the_loop = Qnil;
|
46
|
+
static volatile ID id_is_playing_wo_loop = Qnil;
|
47
|
+
static volatile ID id_is_allow_countup = Qnil;
|
48
|
+
static volatile ID id_allow_countup = Qnil;
|
49
|
+
static volatile ID id_countup = Qnil;
|
50
|
+
static volatile ID id_poll = Qnil;
|
51
|
+
static volatile ID id_call = Qnil;
|
52
|
+
static volatile int zero = 0;
|
53
|
+
static volatile int one = 1;
|
54
|
+
static volatile VALUE sy_pushed = Qnil;
|
55
|
+
static volatile VALUE sy_pos = Qnil;
|
56
|
+
static volatile VALUE sy_dx = Qnil;
|
57
|
+
static volatile VALUE sy_dy = Qnil;
|
58
|
+
static volatile VALUE sy_click = Qnil;
|
59
|
+
static volatile VALUE sy_drop = Qnil;
|
60
|
+
static volatile VALUE sy_left = Qnil;
|
61
|
+
static volatile VALUE sy_right = Qnil;
|
62
|
+
static volatile VALUE sy_middle = Qnil;
|
63
|
+
static volatile VALUE sy_trigger = Qnil;
|
64
|
+
static volatile VALUE sy_alt = Qnil;
|
65
|
+
static volatile VALUE sy_ent = Qnil;
|
66
|
+
|
67
|
+
/*
|
68
|
+
:nodoc:
|
69
|
+
*/
|
70
|
+
static VALUE input_update(VALUE self)
|
71
|
+
{
|
72
|
+
int i;
|
73
|
+
VALUE *ptr;
|
74
|
+
|
75
|
+
VALUE btn = rb_iv_get(self, "@@btn");
|
76
|
+
VALUE mouse = rb_iv_get(self, "@@mouse");
|
77
|
+
VALUE process = rb_iv_get(self, "@@process");
|
78
|
+
VALUE toggle = rb_iv_get(self, "@@toggle_screen_mode");
|
79
|
+
|
80
|
+
VALUE trigger = rb_hash_lookup(btn, sy_trigger);
|
81
|
+
VALUE pushed = rb_hash_lookup(btn, sy_pushed);
|
82
|
+
VALUE click = rb_hash_lookup(mouse, sy_click);
|
83
|
+
VALUE drop = rb_hash_lookup(mouse, sy_drop);
|
84
|
+
VALUE pos = rb_hash_lookup(mouse, sy_pos);
|
85
|
+
|
86
|
+
rb_funcall(cJoystick, id_update_all, 0);
|
87
|
+
|
88
|
+
VALUE keys = rb_funcall(pushed, rb_intern("keys"), 0);
|
89
|
+
ptr = RARRAY_PTR(keys);
|
90
|
+
for(i=0; i<RARRAY_LEN(keys); i++)
|
91
|
+
{
|
92
|
+
rb_hash_aset(pushed, *(ptr+i), nZero);
|
93
|
+
}
|
94
|
+
rb_hash_aset(pos, sy_dx, nZero);
|
95
|
+
rb_hash_aset(pos, sy_dy, nZero);
|
96
|
+
|
97
|
+
rb_hash_aset(click, sy_left, Qfalse);
|
98
|
+
rb_hash_aset(click, sy_middle, Qfalse);
|
99
|
+
rb_hash_aset(click, sy_right, Qfalse);
|
100
|
+
rb_hash_aset(drop, sy_left, Qfalse);
|
101
|
+
rb_hash_aset(drop, sy_middle, Qfalse);
|
102
|
+
rb_hash_aset(drop, sy_right, Qfalse);
|
103
|
+
|
104
|
+
VALUE e_list = rb_ary_new();
|
105
|
+
VALUE e = rb_funcall(cEvent, id_poll, 0);
|
106
|
+
while(e != Qnil)
|
107
|
+
{
|
108
|
+
rb_ary_push(e_list, e);
|
109
|
+
e = rb_funcall(cEvent, id_poll, 0);
|
110
|
+
}
|
111
|
+
|
112
|
+
ptr = RARRAY_PTR(e_list);
|
113
|
+
int len = RARRAY_LEN(e_list);
|
114
|
+
for(i=0; i<len; i++)
|
115
|
+
{
|
116
|
+
VALUE e2 = *(ptr + len - i - 1);
|
117
|
+
VALUE proc = rb_hash_lookup(process, CLASS_OF(e2));
|
118
|
+
rb_funcall(proc, id_call, 1, e2);
|
119
|
+
if(rb_hash_lookup(trigger, sy_alt) == nOne &&
|
120
|
+
rb_hash_lookup(pushed, sy_ent) == nOne &&
|
121
|
+
toggle == Qtrue)
|
122
|
+
{
|
123
|
+
rb_funcall(mScreen, rb_intern("toggle_mode"), 0);
|
124
|
+
rb_hash_aset(trigger, sy_alt, nZero);
|
125
|
+
rb_hash_aset(pushed, sy_ent, nZero);
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
return Qnil;
|
130
|
+
}
|
131
|
+
|
132
|
+
/*
|
133
|
+
:nodoc:
|
134
|
+
*/
|
135
|
+
static VALUE bgm_update(VALUE self)
|
136
|
+
{
|
137
|
+
VALUE nua = rb_gv_get("$not_use_audio");
|
138
|
+
if(nua == Qfalse) return Qnil;
|
139
|
+
|
140
|
+
VALUE pb = rb_iv_get(self, "@@playin_bgm");
|
141
|
+
if(pb == Qnil) return Qnil;
|
142
|
+
|
143
|
+
if(rb_funcall(pb, id_is_playing_wo_loop, 0) == Qfalse &&
|
144
|
+
rb_funcall(pb, id_in_the_loop, 0) == Qtrue)
|
145
|
+
{
|
146
|
+
rb_funcall(pb, id_countup, 0);
|
147
|
+
if(rb_funcall(pb, id_in_the_loop, 0) == Qfalse)
|
148
|
+
rb_iv_set(self, "@@playin_bgm", Qnil);
|
149
|
+
}
|
150
|
+
else if(rb_funcall(pb, id_is_playing, 0) == Qfalse &&
|
151
|
+
rb_funcall(pb, id_is_fade_out, 0) == Qfalse)
|
152
|
+
{
|
153
|
+
rb_iv_set(self, "@@playin_bgm", Qnil);
|
154
|
+
}
|
155
|
+
else if(rb_funcall(pb, id_is_allow_countup, 0) == Qfalse)
|
156
|
+
{
|
157
|
+
rb_funcall(pb, id_allow_countup, 0);
|
158
|
+
}
|
159
|
+
|
160
|
+
return Qnil;
|
161
|
+
}
|
162
|
+
|
163
|
+
/*
|
164
|
+
:nodoc:
|
165
|
+
*/
|
166
|
+
static VALUE se_update(VALUE self)
|
167
|
+
{
|
168
|
+
VALUE nua = rb_gv_get("$not_use_audio");
|
169
|
+
if(nua == Qfalse) return Qnil;
|
170
|
+
|
171
|
+
VALUE playings = rb_iv_get(self, "@@playings");
|
172
|
+
VALUE *ptr = RARRAY_PTR(playings);
|
173
|
+
int i;
|
174
|
+
for(i=0; i<RARRAY_LEN(playings); i++)
|
175
|
+
{
|
176
|
+
VALUE pl = *(ptr+i);
|
177
|
+
|
178
|
+
if(rb_funcall(pl, id_is_playing_wo_loop, 0) == Qfalse &&
|
179
|
+
rb_funcall(pl, id_in_the_loop, 0) == Qtrue)
|
180
|
+
{
|
181
|
+
rb_funcall(pl, id_countup, 0);
|
182
|
+
if(rb_funcall(pl, id_in_the_loop, 0) == Qfalse)
|
183
|
+
rb_ary_delete(playings, pl);
|
184
|
+
}
|
185
|
+
else if(rb_funcall(pl, id_is_playing, 0) == Qfalse &&
|
186
|
+
rb_funcall(pl, id_is_fade_out, 0) == Qfalse)
|
187
|
+
{
|
188
|
+
rb_ary_delete(playings, pl);
|
189
|
+
}
|
190
|
+
else if(rb_funcall(pl, id_is_allow_countup, 0) == Qfalse)
|
191
|
+
{
|
192
|
+
rb_funcall(pl, id_allow_countup, 0);
|
193
|
+
}
|
194
|
+
}
|
195
|
+
|
196
|
+
return Qnil;
|
197
|
+
}
|
198
|
+
|
199
|
+
/*
|
200
|
+
:nodoc:
|
201
|
+
*/
|
202
|
+
static VALUE audio_update(VALUE self)
|
203
|
+
{
|
204
|
+
bgm_update(cBGM);
|
205
|
+
se_update(cSE);
|
206
|
+
return self;
|
207
|
+
}
|
208
|
+
|
209
|
+
void Init_miyako_input_audio()
|
210
|
+
{
|
211
|
+
mSDL = rb_define_module("SDL");
|
212
|
+
mMiyako = rb_define_module("Miyako");
|
213
|
+
mAudio = rb_define_module_under(mMiyako, "Audio");
|
214
|
+
mInput = rb_define_module_under(mMiyako, "Input");
|
215
|
+
mScreen = rb_define_module_under(mMiyako, "Screen");
|
216
|
+
cJoystick = rb_define_class_under(mSDL, "Joystick", rb_cObject);
|
217
|
+
cEvent = rb_define_class_under(mSDL, "Event", rb_cObject);
|
218
|
+
cBGM = rb_define_class_under(mAudio, "BGM", rb_cObject);
|
219
|
+
cSE = rb_define_class_under(mAudio, "SE", rb_cObject);
|
220
|
+
|
221
|
+
id_update_all = rb_intern("updateAll");
|
222
|
+
id_poll = rb_intern("poll");
|
223
|
+
id_call = rb_intern("call");
|
224
|
+
id_is_playing = rb_intern("playing?");
|
225
|
+
id_is_fade_out = rb_intern("fade_out?");
|
226
|
+
id_in_the_loop = rb_intern("in_the_loop?");
|
227
|
+
id_is_playing_wo_loop = rb_intern("playing_without_loop?");
|
228
|
+
id_is_allow_countup = rb_intern("allow_loop_count_up?");
|
229
|
+
id_allow_countup = rb_intern("allow_loop_count_up");
|
230
|
+
id_countup = rb_intern("loop_count_up");
|
231
|
+
|
232
|
+
sy_pushed = ID2SYM(rb_intern("pushed"));
|
233
|
+
sy_pos = ID2SYM(rb_intern("pos"));
|
234
|
+
sy_dx = ID2SYM(rb_intern("dx"));
|
235
|
+
sy_dy = ID2SYM(rb_intern("dy"));
|
236
|
+
sy_click = ID2SYM(rb_intern("click"));
|
237
|
+
sy_drop = ID2SYM(rb_intern("drop"));
|
238
|
+
sy_left = ID2SYM(rb_intern("left"));
|
239
|
+
sy_right = ID2SYM(rb_intern("right"));
|
240
|
+
sy_middle = ID2SYM(rb_intern("middle"));
|
241
|
+
sy_trigger = ID2SYM(rb_intern("trigger"));
|
242
|
+
sy_alt = ID2SYM(rb_intern("alt"));
|
243
|
+
sy_ent = ID2SYM(rb_intern("ent"));
|
244
|
+
|
245
|
+
zero = 0;
|
246
|
+
nZero = INT2NUM(zero);
|
247
|
+
one = 1;
|
248
|
+
nOne = INT2NUM(one);
|
249
|
+
|
250
|
+
rb_define_module_function(mInput, "update", input_update, 0);
|
251
|
+
rb_define_module_function(mAudio, "update", audio_update, 0);
|
252
|
+
rb_define_singleton_method(cBGM, "update", bgm_update, 0);
|
253
|
+
rb_define_singleton_method(cSE, "update", se_update, 0);
|
254
|
+
}
|
data/miyako_layout.c
ADDED
@@ -0,0 +1,191 @@
|
|
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 mScreen = Qnil;
|
34
|
+
static VALUE mLayout = Qnil;
|
35
|
+
static VALUE nZero = Qnil;
|
36
|
+
static VALUE nOne = Qnil;
|
37
|
+
static volatile ID id_update = Qnil;
|
38
|
+
static volatile ID id_kakko = Qnil;
|
39
|
+
static volatile ID id_render = Qnil;
|
40
|
+
static volatile ID id_to_a = Qnil;
|
41
|
+
static volatile int zero = Qnil;
|
42
|
+
static volatile int one = Qnil;
|
43
|
+
|
44
|
+
static VALUE layout_snap(int argc, VALUE *argv, VALUE self);
|
45
|
+
static VALUE layout_move(VALUE self, VALUE dx, VALUE dy);
|
46
|
+
|
47
|
+
static VALUE layout_update_layout(VALUE self, VALUE dx, VALUE dy)
|
48
|
+
{
|
49
|
+
rb_funcall(self, rb_intern("update_layout_position"), 0);
|
50
|
+
VALUE layout = rb_iv_get(self, "@layout");
|
51
|
+
VALUE children = *(RSTRUCT_PTR(*(RSTRUCT_PTR(layout)+3))+1);
|
52
|
+
int i;
|
53
|
+
for(i=0; i<RARRAY_LEN(children); i++)
|
54
|
+
{
|
55
|
+
layout_move(*(RARRAY_PTR(children) + i), dx, dy);
|
56
|
+
}
|
57
|
+
return Qnil;
|
58
|
+
}
|
59
|
+
|
60
|
+
static VALUE layout_move(VALUE self, VALUE dx, VALUE dy)
|
61
|
+
{
|
62
|
+
VALUE *pos = RSTRUCT_PTR(*(RSTRUCT_PTR(rb_iv_get(self, "@layout"))));
|
63
|
+
VALUE *pox = pos+0;
|
64
|
+
VALUE *poy = pos+1;
|
65
|
+
VALUE tx = *pox;
|
66
|
+
VALUE ty = *poy;
|
67
|
+
*pox = INT2NUM(NUM2INT(tx)+NUM2INT(dx));
|
68
|
+
*poy = INT2NUM(NUM2INT(ty)+NUM2INT(dy));
|
69
|
+
layout_update_layout(self, dx, dy);
|
70
|
+
VALUE on_move = *(RSTRUCT_PTR(rb_iv_get(self, "@layout")) + 4);
|
71
|
+
int i;
|
72
|
+
for(i=0; i<RARRAY_LEN(on_move); i++)
|
73
|
+
{
|
74
|
+
rb_funcall(*(RARRAY_PTR(on_move) + i), rb_intern("call"), 5, self, *pox, *poy, dx, dy);
|
75
|
+
}
|
76
|
+
if(rb_block_given_p() == Qtrue){
|
77
|
+
VALUE ret = rb_yield(self);
|
78
|
+
if(ret == Qnil || ret == Qfalse)
|
79
|
+
{
|
80
|
+
*pox = tx;
|
81
|
+
*poy = ty;
|
82
|
+
layout_update_layout(self, INT2NUM(-(NUM2INT(dx))), INT2NUM(-(NUM2INT(dy))));
|
83
|
+
}
|
84
|
+
}
|
85
|
+
return self;
|
86
|
+
}
|
87
|
+
|
88
|
+
static VALUE layout_move_to(VALUE self, VALUE x, VALUE y)
|
89
|
+
{
|
90
|
+
VALUE *pos = RSTRUCT_PTR(*(RSTRUCT_PTR(rb_iv_get(self, "@layout"))));
|
91
|
+
VALUE *pox = pos+0;
|
92
|
+
VALUE *poy = pos+1;
|
93
|
+
VALUE tx = *pox;
|
94
|
+
VALUE ty = *poy;
|
95
|
+
*pox = x;
|
96
|
+
*poy = y;
|
97
|
+
VALUE dx = INT2NUM((NUM2INT(x))-(NUM2INT(tx)));
|
98
|
+
VALUE dy = INT2NUM((NUM2INT(y))-(NUM2INT(ty)));
|
99
|
+
layout_update_layout(self, dx, dy);
|
100
|
+
VALUE on_move = *(RSTRUCT_PTR(rb_iv_get(self, "@layout")) + 4);
|
101
|
+
int i;
|
102
|
+
for(i=0; i<RARRAY_LEN(on_move); i++)
|
103
|
+
{
|
104
|
+
rb_funcall(*(RARRAY_PTR(on_move) + i), rb_intern("call"), 5, self, *pox, *poy, dx, dy);
|
105
|
+
}
|
106
|
+
if(rb_block_given_p() == Qtrue){
|
107
|
+
VALUE ret = rb_yield(self);
|
108
|
+
if(ret == Qnil || ret == Qfalse)
|
109
|
+
{
|
110
|
+
*pox = tx;
|
111
|
+
*poy = ty;
|
112
|
+
layout_update_layout(self, INT2NUM(-(NUM2INT(dx))), INT2NUM(-(NUM2INT(dy))));
|
113
|
+
}
|
114
|
+
}
|
115
|
+
return self;
|
116
|
+
}
|
117
|
+
|
118
|
+
static VALUE layout_add_snap_child(VALUE self, VALUE spr)
|
119
|
+
{
|
120
|
+
VALUE layout = rb_iv_get(self, "@layout");
|
121
|
+
VALUE snap = *(RSTRUCT_PTR(layout)+3);
|
122
|
+
VALUE children = *(RSTRUCT_PTR(snap)+1);
|
123
|
+
if(rb_ary_includes(children, spr)==Qfalse){ rb_ary_push(children, spr); }
|
124
|
+
return self;
|
125
|
+
}
|
126
|
+
|
127
|
+
static VALUE layout_delete_snap_child(VALUE self, VALUE spr)
|
128
|
+
{
|
129
|
+
VALUE layout = rb_iv_get(self, "@layout");
|
130
|
+
VALUE snap = *(RSTRUCT_PTR(layout)+3);
|
131
|
+
VALUE children = *(RSTRUCT_PTR(snap)+1);
|
132
|
+
if(TYPE(spr) == T_ARRAY)
|
133
|
+
{
|
134
|
+
int i;
|
135
|
+
for(i=0; i<RARRAY_LEN(spr); i++){ rb_ary_delete(children, *(RARRAY_PTR(spr) + i)); }
|
136
|
+
}
|
137
|
+
else
|
138
|
+
{
|
139
|
+
rb_ary_delete(children, spr);
|
140
|
+
}
|
141
|
+
return self;
|
142
|
+
}
|
143
|
+
|
144
|
+
static VALUE layout_snap(int argc, VALUE *argv, VALUE self)
|
145
|
+
{
|
146
|
+
VALUE spr = Qnil;
|
147
|
+
rb_scan_args(argc, argv, "01", &spr);
|
148
|
+
VALUE layout = rb_iv_get(self, "@layout");
|
149
|
+
VALUE *sprite = RSTRUCT_PTR(*(RSTRUCT_PTR(layout)+3));
|
150
|
+
VALUE *base = RSTRUCT_PTR(layout)+2;
|
151
|
+
if(spr != Qnil)
|
152
|
+
{
|
153
|
+
if(*sprite != Qnil){ layout_delete_snap_child(*sprite, self); }
|
154
|
+
*sprite = spr;
|
155
|
+
layout_add_snap_child(spr, self);
|
156
|
+
}
|
157
|
+
if(*sprite != Qnil)
|
158
|
+
{
|
159
|
+
*base = *sprite;
|
160
|
+
}
|
161
|
+
else
|
162
|
+
{
|
163
|
+
*base = mScreen;
|
164
|
+
}
|
165
|
+
return self;
|
166
|
+
}
|
167
|
+
|
168
|
+
void Init_miyako_layout()
|
169
|
+
{
|
170
|
+
mSDL = rb_define_module("SDL");
|
171
|
+
mMiyako = rb_define_module("Miyako");
|
172
|
+
mScreen = rb_define_module_under(mMiyako, "Screen");
|
173
|
+
mLayout = rb_define_module_under(mMiyako, "Layout");
|
174
|
+
|
175
|
+
id_update = rb_intern("update");
|
176
|
+
id_kakko = rb_intern("[]");
|
177
|
+
id_render = rb_intern("render");
|
178
|
+
id_to_a = rb_intern("to_a");
|
179
|
+
|
180
|
+
zero = 0;
|
181
|
+
nZero = INT2NUM(zero);
|
182
|
+
one = 1;
|
183
|
+
nOne = INT2NUM(one);
|
184
|
+
|
185
|
+
rb_define_method(mLayout, "move!", layout_move, 2);
|
186
|
+
rb_define_method(mLayout, "move_to!", layout_move_to, 2);
|
187
|
+
rb_define_method(mLayout, "update_layout", layout_update_layout, 2);
|
188
|
+
rb_define_method(mLayout, "snap", layout_snap, -1);
|
189
|
+
rb_define_method(mLayout, "add_snap_child", layout_add_snap_child, 1);
|
190
|
+
rb_define_method(mLayout, "delete_snap_child", layout_delete_snap_child, 1);
|
191
|
+
}
|