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
data/miyako_font.c ADDED
@@ -0,0 +1,334 @@
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 cTTFFont = Qnil;
37
+ static VALUE cFont = Qnil;
38
+ static VALUE cEncoding = Qnil;
39
+ static VALUE nZero = Qnil;
40
+ static VALUE nOne = Qnil;
41
+ static volatile ID id_update = Qnil;
42
+ static volatile ID id_kakko = Qnil;
43
+ static volatile ID id_render = Qnil;
44
+ static volatile ID id_to_a = Qnil;
45
+ static volatile int zero = Qnil;
46
+ static volatile int one = Qnil;
47
+
48
+ static volatile ID id_encode = Qnil;
49
+ static volatile ID id_utf8 = Qnil;
50
+
51
+ typedef struct {
52
+ TTF_Font* font;
53
+ } TTFont;
54
+
55
+ // from rubysdl_video.c
56
+ static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
57
+ // from rubysdl_ttf.c
58
+ static GLOBAL_DEFINE_GET_STRUCT(TTFont, Get_TTFont, cTTFFont, "SDL::TT::Font");
59
+
60
+ static VALUE font_draw_text(VALUE self, VALUE vdst, VALUE str, VALUE vx, VALUE vy)
61
+ {
62
+ rb_secure(4);
63
+ StringValue(str);
64
+
65
+ str = rb_funcall(str, id_encode, 1, rb_const_get(cEncoding, id_utf8));
66
+
67
+ TTF_Font *font = Get_TTFont(rb_iv_get(self, "@font"))->font;
68
+
69
+ VALUE *p_font_color = RARRAY_PTR(rb_iv_get(self, "@color"));
70
+ SDL_Color fore_color;
71
+ fore_color.r = NUM2INT(*(p_font_color+0));
72
+ fore_color.g = NUM2INT(*(p_font_color+1));
73
+ fore_color.b = NUM2INT(*(p_font_color+2));
74
+ fore_color.unused = 0;
75
+
76
+ VALUE *p_shadow_color = RARRAY_PTR(rb_iv_get(self, "@shadow_color"));
77
+ SDL_Color shadow_color;
78
+ shadow_color.r = NUM2INT(*(p_shadow_color+0));
79
+ shadow_color.g = NUM2INT(*(p_shadow_color+1));
80
+ shadow_color.b = NUM2INT(*(p_shadow_color+2));
81
+ shadow_color.unused = 0;
82
+
83
+ int font_size = NUM2INT(rb_iv_get(self, "@size"));
84
+ VALUE use_shadow = rb_iv_get(self, "@use_shadow");
85
+ VALUE shadow_margin = rb_iv_get(self, "@shadow_margin");
86
+ int shadow_margin_x = (use_shadow == Qtrue ? NUM2INT(*(RARRAY_PTR(shadow_margin)+0)) : 0);
87
+ int shadow_margin_y = (use_shadow == Qtrue ? NUM2INT(*(RARRAY_PTR(shadow_margin)+1)) : 0);
88
+ int hspace = NUM2INT(rb_iv_get(self, "@hspace"));
89
+
90
+ SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
91
+
92
+ MiyakoBitmap src, dst;
93
+ _miyako_setup_unit(vdst, scr, &dst, vx, vy, 0);
94
+
95
+ char *sptr = RSTRING_PTR(str);
96
+
97
+ src.x = dst.x;
98
+ src.y = dst.y;
99
+
100
+ int x, y;
101
+
102
+ if(use_shadow == Qtrue)
103
+ {
104
+ SDL_Surface *ssrc2 = TTF_RenderUTF8_Blended(font, sptr, shadow_color);
105
+
106
+ if(ssrc2 == NULL) return INT2NUM(src.x);
107
+ Uint32 *psrc2 = (Uint32 *)(ssrc2->pixels);
108
+
109
+ src.x += shadow_margin_x;
110
+ src.y += shadow_margin_y;
111
+
112
+ MiyakoSize size2;
113
+ size2.w = dst.rect.w - (src.x < 0 ? -(src.x) : src.x);
114
+ size2.h = dst.rect.h - (src.y < 0 ? -(src.y) : src.y);
115
+ if(size2.w > ssrc2->w){ size2.w = ssrc2->w; }
116
+ if(size2.h > ssrc2->h){ size2.h = ssrc2->h; }
117
+
118
+ SDL_LockSurface(ssrc2);
119
+ SDL_LockSurface(dst.surface);
120
+
121
+ for(y = 0; y < size2.h; y++)
122
+ {
123
+ Uint32 *ppsrc2 = psrc2 + y * ssrc2->w;
124
+ Uint32 *ppdst = dst.ptr + (src.y + y) * dst.surface->w + src.x;
125
+ for(x = 0; x < size2.w; x++)
126
+ {
127
+ #if SDL_BYTEORDER == SDL_LIL_ENDIAN
128
+ dst.color.a = (Uint32)(((*ppdst) >> 24) << dst.fmt->Aloss) & 0xff | dst.a255;
129
+ src.color.a = (Uint32)(((*ppsrc2) >> 24) << ssrc2->format->Aloss) & 0xff;
130
+ if(src.color.a == 0){ ppsrc2++; ppdst++; continue; }
131
+ if(dst.color.a == 0 || src.color.a == 255){
132
+ *ppdst = *ppsrc2;
133
+ ppsrc2++;
134
+ ppdst++;
135
+ continue;
136
+ }
137
+ dst.color.r = (Uint32)(((*ppdst) >> 16)) & 0xff;
138
+ dst.color.g = (Uint32)(((*ppdst) >> 8)) & 0xff;
139
+ dst.color.b = (Uint32)(((*ppdst))) & 0xff;
140
+ src.color.r = (Uint32)(((*ppsrc2) >> 16)) & 0xff;
141
+ src.color.g = (Uint32)(((*ppsrc2) >> 8)) & 0xff;
142
+ src.color.b = (Uint32)(((*ppsrc2))) & 0xff;
143
+ int a1 = src.color.a + 1;
144
+ int a2 = 256 - src.color.a;
145
+ *ppdst = (((src.color.r * a1 + dst.color.r * a2) >> 8)) << 16 |
146
+ (((src.color.g * a1 + dst.color.g * a2) >> 8)) << 8 |
147
+ (((src.color.b * a1 + dst.color.b * a2) >> 8)) |
148
+ (255 >> dst.fmt->Aloss) << 24;
149
+ #else
150
+ dst.color.a = (Uint32)(((*ppdst & dst.fmt->Amask)) << dst.fmt->Aloss) | dst.a255;
151
+ src.color.a = (Uint32)(((*ppsrc2 & ssrc2->format->Amask)) << ssrc2->format->Aloss);
152
+ if(src.color.a == 0){ ppsrc2++; ppdst++; continue; }
153
+ if(dst.color.a == 0 || src.color.a == 255){
154
+ *ppdst = *ppsrc2;
155
+ ppsrc2++;
156
+ ppdst++;
157
+ continue;
158
+ }
159
+ dst.color.r = (Uint32)(((*ppdst & dst.fmt->Rmask) >> dst.fmt->Rshift));
160
+ dst.color.g = (Uint32)(((*ppdst & dst.fmt->Gmask) >> dst.fmt->Gshift));
161
+ dst.color.b = (Uint32)(((*ppdst & dst.fmt->Bmask) >> dst.fmt->Bshift));
162
+ src.color.r = (Uint32)(((*ppsrc2 & ssrc2->format->Rmask) >> ssrc2->format->Rshift));
163
+ src.color.g = (Uint32)(((*ppsrc2 & ssrc2->format->Gmask) >> ssrc2->format->Gshift));
164
+ src.color.b = (Uint32)(((*ppsrc2 & ssrc2->format->Bmask) >> ssrc2->format->Bshift));
165
+ int a1 = src.color.a + 1;
166
+ int a2 = 256 - src.color.a;
167
+ *ppdst = (((src.color.r * a1 + dst.color.r * a2) >> 8)) << dst.fmt->Rshift |
168
+ (((src.color.g * a1 + dst.color.g * a2) >> 8)) << dst.fmt->Gshift |
169
+ (((src.color.b * a1 + dst.color.b * a2) >> 8)) << dst.fmt->Bshift |
170
+ (255 >> dst.fmt->Aloss);
171
+ #endif
172
+ ppsrc2++;
173
+ ppdst++;
174
+ }
175
+ }
176
+
177
+ SDL_UnlockSurface(ssrc2);
178
+ SDL_UnlockSurface(dst.surface);
179
+
180
+ SDL_FreeSurface(ssrc2);
181
+
182
+ src.x = dst.x;
183
+ src.y = dst.y;
184
+ }
185
+
186
+ SDL_Surface *ssrc = TTF_RenderUTF8_Blended(font, sptr, fore_color);
187
+
188
+ if(ssrc == NULL) return INT2NUM(src.x);
189
+
190
+ Uint32 *psrc = (Uint32 *)(ssrc->pixels);
191
+
192
+ MiyakoSize size;
193
+ size.w = dst.rect.w - (src.x < 0 ? -(src.x) : src.x);
194
+ size.h = dst.rect.h - (src.y < 0 ? -(src.y) : src.y);
195
+ if(size.w > ssrc->w){ size.w = ssrc->w; }
196
+ if(size.h > ssrc->h){ size.h = ssrc->h; }
197
+
198
+ SDL_LockSurface(ssrc);
199
+ SDL_LockSurface(dst.surface);
200
+
201
+ for(y = 0; y < size.h; y++)
202
+ {
203
+ Uint32 *ppsrc = psrc + y * ssrc->w;
204
+ Uint32 *ppdst = dst.ptr + (src.y + y) * dst.surface->w + src.x;
205
+ for(x = 0; x < size.w; x++)
206
+ {
207
+ #if SDL_BYTEORDER == SDL_LIL_ENDIAN
208
+ dst.color.a = (Uint32)(((*ppdst) >> 24) << dst.fmt->Aloss) & 0xff | dst.a255;
209
+ src.color.a = (Uint32)(((*ppsrc) >> 24) << ssrc->format->Aloss) & 0xff;
210
+ if(src.color.a == 0){ ppsrc++; ppdst++; continue; }
211
+ if(dst.color.a == 0 || src.color.a == 255){
212
+ *ppdst = *ppsrc;
213
+ ppsrc++;
214
+ ppdst++;
215
+ continue;
216
+ }
217
+ dst.color.r = (Uint32)(((*ppdst) >> 16)) & 0xff;
218
+ dst.color.g = (Uint32)(((*ppdst) >> 8)) & 0xff;
219
+ dst.color.b = (Uint32)(((*ppdst))) & 0xff;
220
+ src.color.r = (Uint32)(((*ppsrc) >> 16)) & 0xff;
221
+ src.color.g = (Uint32)(((*ppsrc) >> 8)) & 0xff;
222
+ src.color.b = (Uint32)(((*ppsrc))) & 0xff;
223
+ int a1 = src.color.a + 1;
224
+ int a2 = 256 - src.color.a;
225
+ *ppdst = (((src.color.r * a1 + dst.color.r * a2) >> 8)) << 16 |
226
+ (((src.color.g * a1 + dst.color.g * a2) >> 8)) << 8 |
227
+ (((src.color.b * a1 + dst.color.b * a2) >> 8)) |
228
+ (255 >> dst.fmt->Aloss) << 24;
229
+ #else
230
+ dst.color.a = (Uint32)(((*ppdst & dst.fmt->Amask)) << dst.fmt->Aloss) | dst.a255;
231
+ src.color.a = (Uint32)(((*ppsrc & ssrc->format->Amask)) << ssrc->format->Aloss);
232
+ if(src.color.a == 0){ ppsrc++; ppdst++; continue; }
233
+ if(dst.color.a == 0 || src.color.a == 255){
234
+ *ppdst = *ppsrc;
235
+ ppsrc++;
236
+ ppdst++;
237
+ continue;
238
+ }
239
+ dst.color.r = (Uint32)(((*ppdst & dst.fmt->Rmask) >> dst.fmt->Rshift));
240
+ dst.color.g = (Uint32)(((*ppdst & dst.fmt->Gmask) >> dst.fmt->Gshift));
241
+ dst.color.b = (Uint32)(((*ppdst & dst.fmt->Bmask) >> dst.fmt->Bshift));
242
+ src.color.r = (Uint32)(((*ppsrc & ssrc->format->Rmask) >> ssrc->format->Rshift));
243
+ src.color.g = (Uint32)(((*ppsrc & ssrc->format->Gmask) >> ssrc->format->Gshift));
244
+ src.color.b = (Uint32)(((*ppsrc & ssrc->format->Bmask) >> ssrc->format->Bshift));
245
+ int a1 = src.color.a + 1;
246
+ int a2 = 256 - src.color.a;
247
+ *ppdst = (((src.color.r * a1 + dst.color.r * a2) >> 8)) << dst.fmt->Rshift |
248
+ (((src.color.g * a1 + dst.color.g * a2) >> 8)) << dst.fmt->Gshift |
249
+ (((src.color.b * a1 + dst.color.b * a2) >> 8)) << dst.fmt->Bshift |
250
+ (255 >> dst.fmt->Aloss);
251
+ #endif
252
+ ppsrc++;
253
+ ppdst++;
254
+ }
255
+ }
256
+
257
+ SDL_UnlockSurface(ssrc);
258
+ SDL_UnlockSurface(dst.surface);
259
+ SDL_FreeSurface(ssrc);
260
+
261
+ int i, n;
262
+ const char *ptr = RSTRING_PTR(str);
263
+ int len = RSTRING_LEN(str);
264
+ rb_encoding *enc = rb_enc_get(str);
265
+ for(i=0; i<len; i+=n)
266
+ {
267
+ n = rb_enc_mbclen(ptr+i, ptr+len, enc);
268
+ VALUE chr = rb_str_subseq(str, i, n);
269
+ int clen = RSTRING_LEN(chr);
270
+ dst.x += (clen==1 ? font_size>>1 : font_size) + shadow_margin_x + hspace;
271
+ }
272
+ return INT2NUM(dst.x);
273
+ }
274
+
275
+ static VALUE font_line_height(VALUE self)
276
+ {
277
+ int height = NUM2INT(rb_iv_get(self, "@line_skip"));
278
+ height += NUM2INT(rb_iv_get(self, "@vspace"));
279
+ height += (rb_iv_get(self, "@use_shadow") == Qtrue ? NUM2INT(*(RARRAY_PTR(rb_iv_get(self, "@shadow_margin"))+1)) : 0);
280
+ return INT2NUM(height);
281
+ }
282
+
283
+ static VALUE font_text_size(VALUE self, VALUE str)
284
+ {
285
+ int font_size = NUM2INT(rb_iv_get(self, "@size"));
286
+ VALUE use_shadow = rb_iv_get(self, "@use_shadow");
287
+ VALUE shadow_margin = rb_iv_get(self, "@shadow_margin");
288
+ int shadow_margin_x = (use_shadow == Qtrue ? NUM2INT(*(RARRAY_PTR(shadow_margin)+0)) : 0);
289
+ int hspace = NUM2INT(rb_iv_get(self, "@hspace"));
290
+
291
+ int i, n, l=0;
292
+ const char *ptr = RSTRING_PTR(str);
293
+ int len = RSTRING_LEN(str);
294
+ rb_encoding *enc = rb_enc_get(str);
295
+ for(i=0; i<len; i+=n)
296
+ {
297
+ n = rb_enc_mbclen(ptr+i, ptr+len, enc);
298
+ VALUE chr = rb_str_subseq(str, i, n);
299
+ int clen = RSTRING_LEN(chr);
300
+ l += (clen==1 ? font_size>>1 : font_size) + shadow_margin_x + hspace;
301
+ }
302
+ VALUE array = rb_ary_new();
303
+ rb_ary_push(array, INT2NUM(l));
304
+ rb_ary_push(array, font_line_height(self));
305
+ return array;
306
+ }
307
+
308
+ void Init_miyako_font()
309
+ {
310
+ mSDL = rb_define_module("SDL");
311
+ mMiyako = rb_define_module("Miyako");
312
+ mScreen = rb_define_module_under(mMiyako, "Screen");
313
+ cFont = rb_define_class_under(mMiyako, "Font", rb_cObject);
314
+ cSurface = rb_define_class_under(mSDL, "Surface", rb_cObject);
315
+ cTTFFont = rb_define_class_under(mSDL, "TTF", rb_cObject);
316
+ cEncoding = rb_define_class("Encoding", rb_cObject);
317
+
318
+ id_update = rb_intern("update");
319
+ id_kakko = rb_intern("[]");
320
+ id_render = rb_intern("render");
321
+ id_to_a = rb_intern("to_a");
322
+
323
+ zero = 0;
324
+ nZero = INT2NUM(zero);
325
+ one = 1;
326
+ nOne = INT2NUM(one);
327
+
328
+ id_utf8 = rb_intern("UTF_8");
329
+ id_encode = rb_intern("encode");
330
+
331
+ rb_define_method(cFont, "draw_text", font_draw_text, 4);
332
+ rb_define_method(cFont, "line_height", font_line_height, 0);
333
+ rb_define_method(cFont, "text_size", font_text_size, 1);
334
+ }