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_font.c
CHANGED
@@ -1,334 +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
|
-
}
|
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
|
+
}
|