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.
Files changed (91) hide show
  1. data/README +1092 -929
  2. data/Rakefile +7 -7
  3. data/defines.h +144 -144
  4. data/extern.h +29 -29
  5. data/install_miyako.rb +87 -87
  6. data/lib/Miyako/API/audio.rb +572 -198
  7. data/lib/Miyako/API/basic_data.rb +825 -573
  8. data/lib/Miyako/API/bitmap.rb +534 -507
  9. data/lib/Miyako/API/choices.rb +481 -475
  10. data/lib/Miyako/API/collision.rb +486 -460
  11. data/lib/Miyako/API/diagram.rb +586 -561
  12. data/lib/Miyako/API/drawing.rb +151 -151
  13. data/lib/Miyako/API/exceptions.rb +105 -0
  14. data/lib/Miyako/API/fixedmap.rb +462 -428
  15. data/lib/Miyako/API/font.rb +430 -403
  16. data/lib/Miyako/API/input.rb +456 -447
  17. data/lib/Miyako/API/layout.rb +636 -433
  18. data/lib/Miyako/API/map.rb +583 -529
  19. data/lib/Miyako/API/map_event.rb +222 -198
  20. data/lib/Miyako/API/modules.rb +357 -109
  21. data/lib/Miyako/API/movie.rb +166 -154
  22. data/lib/Miyako/API/parts.rb +276 -189
  23. data/lib/Miyako/API/plane.rb +205 -166
  24. data/lib/Miyako/API/screen.rb +341 -325
  25. data/lib/Miyako/API/shape.rb +443 -443
  26. data/lib/Miyako/API/sprite.rb +771 -752
  27. data/lib/Miyako/API/sprite_animation.rb +490 -481
  28. data/lib/Miyako/API/sprite_list.rb +1135 -0
  29. data/lib/Miyako/API/spriteunit.rb +168 -147
  30. data/lib/Miyako/API/story.rb +350 -300
  31. data/lib/Miyako/API/textbox.rb +770 -725
  32. data/lib/Miyako/API/utility.rb +419 -388
  33. data/lib/Miyako/API/viewport.rb +189 -139
  34. data/lib/Miyako/API/yuki.rb +1226 -996
  35. data/lib/Miyako/EXT/miyako_cairo.rb +62 -62
  36. data/lib/Miyako/EXT/raster_scroll.rb +138 -138
  37. data/lib/Miyako/EXT/slides.rb +157 -157
  38. data/lib/Miyako/miyako.rb +201 -171
  39. data/lib/Miyako/miyako_require_only.rb +35 -0
  40. data/miyako_basicdata.c +590 -590
  41. data/miyako_bitmap.c +1225 -1225
  42. data/miyako_collision.c +403 -403
  43. data/miyako_drawing.c +187 -187
  44. data/miyako_font.c +334 -334
  45. data/miyako_hsv.c +830 -830
  46. data/miyako_input_audio.c +254 -0
  47. data/miyako_layout.c +191 -191
  48. data/miyako_no_katana.c +1078 -1074
  49. data/miyako_sprite2.c +431 -0
  50. data/miyako_transform.c +438 -438
  51. data/miyako_utility.c +288 -288
  52. data/sample/Animation1/m1ku.rb +68 -68
  53. data/sample/Animation2/lex.rb +96 -96
  54. data/sample/Diagram_sample/diagram_sample_yuki2.rb +328 -386
  55. data/sample/Room3/blue.rb +297 -297
  56. data/sample/Room3/ending.rb +180 -180
  57. data/sample/Room3/green.rb +220 -220
  58. data/sample/Room3/main.rb +119 -119
  59. data/sample/Room3/main_component.rb +59 -59
  60. data/sample/Room3/red.rb +227 -227
  61. data/sample/Room3/room3.rb +25 -27
  62. data/sample/Room3/title.rb +184 -184
  63. data/sample/ball_action_sample.rb +204 -204
  64. data/sample/blit_rop.rb +70 -70
  65. data/sample/cairo_sample.rb +25 -25
  66. data/sample/circle_collision_test.rb +66 -66
  67. data/sample/collision_test.rb +33 -33
  68. data/sample/collision_test2.rb +108 -108
  69. data/sample/fixed_map_test/fixed_map_sample.rb +140 -140
  70. data/sample/fixed_map_test/readme.txt +72 -72
  71. data/sample/map_test/chara.rb +58 -58
  72. data/sample/map_test/main_parts.rb +69 -69
  73. data/sample/map_test/main_scene.rb +153 -153
  74. data/sample/map_test/map_manager.rb +75 -75
  75. data/sample/map_test/map_test.rb +23 -23
  76. data/sample/map_test/oasis.rb +71 -71
  77. data/sample/map_test/readme.txt +89 -89
  78. data/sample/map_test/route.rb +157 -157
  79. data/sample/map_test/town.rb +74 -74
  80. data/sample/polygon_test.rb +35 -35
  81. data/sample/rasterscroll.rb +24 -24
  82. data/sample/takahashi.rb +42 -42
  83. data/sample/textbox_sample.rb +189 -189
  84. data/sample/transform.rb +54 -54
  85. data/sample/utility_test.rb +73 -73
  86. data/sample/utility_test2.rb +61 -61
  87. data/sample/utility_test3.rb +64 -64
  88. data/sample/utility_test4.rb +73 -73
  89. data/uninstall_miyako.rb +19 -19
  90. data/win/miyako_no_katana.so +0 -0
  91. metadata +7 -2
data/miyako_drawing.c CHANGED
@@ -1,187 +1,187 @@
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
- #include <sge.h>
32
-
33
- static VALUE mSDL = Qnil;
34
- static VALUE mMiyako = Qnil;
35
- static VALUE mScreen = Qnil;
36
- static VALUE mDrawing = Qnil;
37
- static VALUE eMiyakoError = Qnil;
38
- static VALUE cSurface = Qnil;
39
- static VALUE cColor = Qnil;
40
-
41
- // from rubysdl_video.c
42
- static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
43
-
44
- static Uint32 value_2_color(VALUE color, SDL_PixelFormat *fmt, Uint8 *alpha)
45
- {
46
- VALUE *array = RARRAY_PTR(color);
47
- if(alpha != NULL){ *alpha = (Uint8)(NUM2INT(*(array+3))); }
48
- return SDL_MapRGBA(fmt,
49
- (Uint8)(NUM2INT(*(array+0))),
50
- (Uint8)(NUM2INT(*(array+1))),
51
- (Uint8)(NUM2INT(*(array+2))),
52
- (Uint8)(NUM2INT(*(array+3)))
53
- );
54
- }
55
-
56
- /*
57
- :nodoc:
58
- */
59
- static void get_position(VALUE pos, Sint16 *x, Sint16 *y)
60
- {
61
- VALUE *tmp;
62
- switch(TYPE(pos))
63
- {
64
- case T_ARRAY:
65
- if(RARRAY_LEN(pos) < 2)
66
- rb_raise(eMiyakoError, "pairs have illegal array!");
67
- tmp = RARRAY_PTR(pos);
68
- *x = (Sint16)(NUM2INT(*tmp++));
69
- *y = (Sint16)(NUM2INT(*tmp));
70
- break;
71
- case T_STRUCT:
72
- if(RSTRUCT_LEN(pos) < 2)
73
- rb_raise(eMiyakoError, "pairs have illegal struct!");
74
- tmp = RSTRUCT_PTR(pos);
75
- *x = (Sint16)(NUM2INT(*tmp++));
76
- *y = (Sint16)(NUM2INT(*tmp));
77
- break;
78
- default:
79
- *x = (Sint16)(NUM2INT(rb_funcall(pos, rb_intern("x"), 0)));
80
- *y = (Sint16)(NUM2INT(rb_funcall(pos, rb_intern("y"), 0)));
81
- break;
82
- }
83
- }
84
-
85
- /*
86
- ポリゴン描画
87
- */
88
- static VALUE drawing_draw_polygon(int argc, VALUE *argv, VALUE self)
89
- {
90
- VALUE vdst;
91
- VALUE pairs;
92
- VALUE mcolor;
93
- VALUE fill;
94
- VALUE aa;
95
- Uint8 alpha;
96
- Uint32 color;
97
- int i, vertexes;
98
-
99
- rb_scan_args(argc, argv, "32", &vdst, &pairs, &mcolor, &fill, &aa);
100
-
101
- // bitmapメソッドを持っていれば、メソッドの値をvdstとする
102
- VALUE methods = rb_funcall(vdst, rb_intern("methods"), 0);
103
- if(rb_ary_includes(methods, rb_str_intern(rb_str_new2("to_unit"))) == Qfalse &&
104
- rb_ary_includes(methods, rb_str_intern(rb_str_new2("bitmap"))) == Qfalse
105
- )
106
- rb_raise(eMiyakoError, "this method needs sprite have to_method or bitmap method!");
107
- if(rb_ary_includes(methods, rb_str_intern(rb_str_new2("to_unit"))) == Qtrue)
108
- vdst = rb_funcall(vdst, rb_intern("to_unit"), 0);
109
- vdst = rb_funcall(vdst, rb_intern("bitmap"), 0);
110
-
111
- vertexes = RARRAY_LEN(pairs);
112
- // 頂点数チェック
113
- if(vertexes > 65536)
114
- rb_raise(eMiyakoError, "too many pairs. pairs is less than 65536.");
115
-
116
- // 範囲チェック
117
- for(i=0; i<vertexes; i++)
118
- {
119
- VALUE vertex = *(RARRAY_PTR(pairs)+i);
120
- Sint16 x, y;
121
- get_position(vertex, &x, &y);
122
- }
123
-
124
- SDL_Surface *dst = GetSurface(vdst)->surface;
125
-
126
- color = value_2_color(rb_funcall(cColor, rb_intern("to_rgb"), 1, mcolor), dst->format, &alpha);
127
-
128
- if(RTEST(fill) && RTEST(aa) && alpha < 255)
129
- rb_raise(eMiyakoError, "can't draw filled antialiased alpha polygon");
130
-
131
- Sint16 *px = (Sint16 *)malloc(sizeof(Sint16) * vertexes);
132
- Sint16 *py = (Sint16 *)malloc(sizeof(Sint16) * vertexes);
133
- for(i=0; i<vertexes; i++)
134
- {
135
- VALUE vertex = *(RARRAY_PTR(pairs)+i);
136
- get_position(vertex, px+i, py+i);
137
- }
138
-
139
- if(!RTEST(fill) && !RTEST(aa) && alpha == 255)
140
- {
141
- for(i=0; i<vertexes-1; i++)
142
- sge_Line(dst, px[i], py[i], px[i+1], py[i+1], color);
143
- sge_Line(dst, px[vertexes-1], py[vertexes-1], px[0], py[0], color);
144
- }
145
- else if(!RTEST(fill) && !RTEST(aa) && alpha < 255)
146
- {
147
- for(i=0; i<vertexes-1; i++)
148
- sge_LineAlpha(dst, px[i], py[i], px[i+1], py[i+1], color, alpha);
149
- sge_LineAlpha(dst, px[vertexes-1], py[vertexes-1], px[0], py[0], color, alpha);
150
- }
151
- else if(!RTEST(fill) && RTEST(aa) && alpha == 255)
152
- {
153
- for(i=0; i<vertexes-1; i++)
154
- sge_AALine(dst, px[i], py[i], px[i+1], py[i+1], color);
155
- sge_AALine(dst, px[vertexes-1], py[vertexes-1], px[0], py[0], color);
156
- }
157
- else if(!RTEST(fill) && RTEST(aa) && alpha < 255)
158
- {
159
- for(i=0; i<vertexes-1; i++)
160
- sge_AALineAlpha(dst, px[i], py[i], px[i+1], py[i+1], color, alpha);
161
- sge_AALineAlpha(dst, px[vertexes-1], py[vertexes-1], px[0], py[0], color, alpha);
162
- }
163
- else if(RTEST(fill) && !RTEST(aa) && alpha == 255)
164
- sge_FilledPolygon(dst, (Uint16)vertexes, px, py, color);
165
- else if(RTEST(fill) && !RTEST(aa) && alpha < 255)
166
- sge_FilledPolygonAlpha(dst, (Uint16)vertexes, px, py, color, alpha);
167
- else if(RTEST(fill) && RTEST(aa) && alpha == 255)
168
- sge_AAFilledPolygon(dst, (Uint16)vertexes, px, py, color);
169
-
170
- free(py);
171
- free(px);
172
-
173
- return Qnil;
174
- }
175
-
176
- void Init_miyako_drawing()
177
- {
178
- mSDL = rb_define_module("SDL");
179
- mMiyako = rb_define_module("Miyako");
180
- mScreen = rb_define_module_under(mMiyako, "Screen");
181
- mDrawing = rb_define_module_under(mMiyako, "Drawing");
182
- eMiyakoError = rb_define_class_under(mMiyako, "MiyakoError", rb_eException);
183
- cSurface = rb_define_class_under(mSDL, "Surface", rb_cObject);
184
- cColor = rb_define_class_under(mMiyako, "Color", rb_cObject);
185
-
186
- rb_define_singleton_method(mDrawing, "polygon", drawing_draw_polygon, -1);
187
- }
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
+ #include <sge.h>
32
+
33
+ static VALUE mSDL = Qnil;
34
+ static VALUE mMiyako = Qnil;
35
+ static VALUE mScreen = Qnil;
36
+ static VALUE mDrawing = Qnil;
37
+ static VALUE eMiyakoError = Qnil;
38
+ static VALUE cSurface = Qnil;
39
+ static VALUE cColor = Qnil;
40
+
41
+ // from rubysdl_video.c
42
+ static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
43
+
44
+ static Uint32 value_2_color(VALUE color, SDL_PixelFormat *fmt, Uint8 *alpha)
45
+ {
46
+ VALUE *array = RARRAY_PTR(color);
47
+ if(alpha != NULL){ *alpha = (Uint8)(NUM2INT(*(array+3))); }
48
+ return SDL_MapRGBA(fmt,
49
+ (Uint8)(NUM2INT(*(array+0))),
50
+ (Uint8)(NUM2INT(*(array+1))),
51
+ (Uint8)(NUM2INT(*(array+2))),
52
+ (Uint8)(NUM2INT(*(array+3)))
53
+ );
54
+ }
55
+
56
+ /*
57
+ :nodoc:
58
+ */
59
+ static void get_position(VALUE pos, Sint16 *x, Sint16 *y)
60
+ {
61
+ VALUE *tmp;
62
+ switch(TYPE(pos))
63
+ {
64
+ case T_ARRAY:
65
+ if(RARRAY_LEN(pos) < 2)
66
+ rb_raise(eMiyakoError, "pairs have illegal array!");
67
+ tmp = RARRAY_PTR(pos);
68
+ *x = (Sint16)(NUM2INT(*tmp++));
69
+ *y = (Sint16)(NUM2INT(*tmp));
70
+ break;
71
+ case T_STRUCT:
72
+ if(RSTRUCT_LEN(pos) < 2)
73
+ rb_raise(eMiyakoError, "pairs have illegal struct!");
74
+ tmp = RSTRUCT_PTR(pos);
75
+ *x = (Sint16)(NUM2INT(*tmp++));
76
+ *y = (Sint16)(NUM2INT(*tmp));
77
+ break;
78
+ default:
79
+ *x = (Sint16)(NUM2INT(rb_funcall(pos, rb_intern("x"), 0)));
80
+ *y = (Sint16)(NUM2INT(rb_funcall(pos, rb_intern("y"), 0)));
81
+ break;
82
+ }
83
+ }
84
+
85
+ /*
86
+ ポリゴン描画
87
+ */
88
+ static VALUE drawing_draw_polygon(int argc, VALUE *argv, VALUE self)
89
+ {
90
+ VALUE vdst;
91
+ VALUE pairs;
92
+ VALUE mcolor;
93
+ VALUE fill;
94
+ VALUE aa;
95
+ Uint8 alpha;
96
+ Uint32 color;
97
+ int i, vertexes;
98
+
99
+ rb_scan_args(argc, argv, "32", &vdst, &pairs, &mcolor, &fill, &aa);
100
+
101
+ // bitmapメソッドを持っていれば、メソッドの値をvdstとする
102
+ VALUE methods = rb_funcall(vdst, rb_intern("methods"), 0);
103
+ if(rb_ary_includes(methods, rb_str_intern(rb_str_new2("to_unit"))) == Qfalse &&
104
+ rb_ary_includes(methods, rb_str_intern(rb_str_new2("bitmap"))) == Qfalse
105
+ )
106
+ rb_raise(eMiyakoError, "this method needs sprite have to_method or bitmap method!");
107
+ if(rb_ary_includes(methods, rb_str_intern(rb_str_new2("to_unit"))) == Qtrue)
108
+ vdst = rb_funcall(vdst, rb_intern("to_unit"), 0);
109
+ vdst = rb_funcall(vdst, rb_intern("bitmap"), 0);
110
+
111
+ vertexes = RARRAY_LEN(pairs);
112
+ // 頂点数チェック
113
+ if(vertexes > 65536)
114
+ rb_raise(eMiyakoError, "too many pairs. pairs is less than 65536.");
115
+
116
+ // 範囲チェック
117
+ for(i=0; i<vertexes; i++)
118
+ {
119
+ VALUE vertex = *(RARRAY_PTR(pairs)+i);
120
+ Sint16 x, y;
121
+ get_position(vertex, &x, &y);
122
+ }
123
+
124
+ SDL_Surface *dst = GetSurface(vdst)->surface;
125
+
126
+ color = value_2_color(rb_funcall(cColor, rb_intern("to_rgb"), 1, mcolor), dst->format, &alpha);
127
+
128
+ if(RTEST(fill) && RTEST(aa) && alpha < 255)
129
+ rb_raise(eMiyakoError, "can't draw filled antialiased alpha polygon");
130
+
131
+ Sint16 *px = (Sint16 *)malloc(sizeof(Sint16) * vertexes);
132
+ Sint16 *py = (Sint16 *)malloc(sizeof(Sint16) * vertexes);
133
+ for(i=0; i<vertexes; i++)
134
+ {
135
+ VALUE vertex = *(RARRAY_PTR(pairs)+i);
136
+ get_position(vertex, px+i, py+i);
137
+ }
138
+
139
+ if(!RTEST(fill) && !RTEST(aa) && alpha == 255)
140
+ {
141
+ for(i=0; i<vertexes-1; i++)
142
+ sge_Line(dst, px[i], py[i], px[i+1], py[i+1], color);
143
+ sge_Line(dst, px[vertexes-1], py[vertexes-1], px[0], py[0], color);
144
+ }
145
+ else if(!RTEST(fill) && !RTEST(aa) && alpha < 255)
146
+ {
147
+ for(i=0; i<vertexes-1; i++)
148
+ sge_LineAlpha(dst, px[i], py[i], px[i+1], py[i+1], color, alpha);
149
+ sge_LineAlpha(dst, px[vertexes-1], py[vertexes-1], px[0], py[0], color, alpha);
150
+ }
151
+ else if(!RTEST(fill) && RTEST(aa) && alpha == 255)
152
+ {
153
+ for(i=0; i<vertexes-1; i++)
154
+ sge_AALine(dst, px[i], py[i], px[i+1], py[i+1], color);
155
+ sge_AALine(dst, px[vertexes-1], py[vertexes-1], px[0], py[0], color);
156
+ }
157
+ else if(!RTEST(fill) && RTEST(aa) && alpha < 255)
158
+ {
159
+ for(i=0; i<vertexes-1; i++)
160
+ sge_AALineAlpha(dst, px[i], py[i], px[i+1], py[i+1], color, alpha);
161
+ sge_AALineAlpha(dst, px[vertexes-1], py[vertexes-1], px[0], py[0], color, alpha);
162
+ }
163
+ else if(RTEST(fill) && !RTEST(aa) && alpha == 255)
164
+ sge_FilledPolygon(dst, (Uint16)vertexes, px, py, color);
165
+ else if(RTEST(fill) && !RTEST(aa) && alpha < 255)
166
+ sge_FilledPolygonAlpha(dst, (Uint16)vertexes, px, py, color, alpha);
167
+ else if(RTEST(fill) && RTEST(aa) && alpha == 255)
168
+ sge_AAFilledPolygon(dst, (Uint16)vertexes, px, py, color);
169
+
170
+ free(py);
171
+ free(px);
172
+
173
+ return Qnil;
174
+ }
175
+
176
+ void Init_miyako_drawing()
177
+ {
178
+ mSDL = rb_define_module("SDL");
179
+ mMiyako = rb_define_module("Miyako");
180
+ mScreen = rb_define_module_under(mMiyako, "Screen");
181
+ mDrawing = rb_define_module_under(mMiyako, "Drawing");
182
+ eMiyakoError = rb_define_class_under(mMiyako, "MiyakoError", rb_eException);
183
+ cSurface = rb_define_class_under(mSDL, "Surface", rb_cObject);
184
+ cColor = rb_define_class_under(mMiyako, "Color", rb_cObject);
185
+
186
+ rb_define_singleton_method(mDrawing, "polygon", drawing_draw_polygon, -1);
187
+ }