rubygame 2.2.0-i586-linux
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/CREDITS +60 -0
- data/LICENSE +504 -0
- data/NEWS +201 -0
- data/README +139 -0
- data/ROADMAP +43 -0
- data/Rakefile +409 -0
- data/doc/extended_readme.rdoc +49 -0
- data/doc/getting_started.rdoc +47 -0
- data/doc/macosx_install.rdoc +70 -0
- data/doc/windows_install.rdoc +123 -0
- data/ext/rubygame/MANIFEST +25 -0
- data/ext/rubygame/rubygame_core.so +0 -0
- data/ext/rubygame/rubygame_event.c +644 -0
- data/ext/rubygame/rubygame_event.h +48 -0
- data/ext/rubygame/rubygame_event.o +0 -0
- data/ext/rubygame/rubygame_gfx.c +942 -0
- data/ext/rubygame/rubygame_gfx.h +101 -0
- data/ext/rubygame/rubygame_gfx.o +0 -0
- data/ext/rubygame/rubygame_gfx.so +0 -0
- data/ext/rubygame/rubygame_gl.c +154 -0
- data/ext/rubygame/rubygame_gl.h +32 -0
- data/ext/rubygame/rubygame_gl.o +0 -0
- data/ext/rubygame/rubygame_image.c +108 -0
- data/ext/rubygame/rubygame_image.h +41 -0
- data/ext/rubygame/rubygame_image.o +0 -0
- data/ext/rubygame/rubygame_image.so +0 -0
- data/ext/rubygame/rubygame_joystick.c +247 -0
- data/ext/rubygame/rubygame_joystick.h +41 -0
- data/ext/rubygame/rubygame_joystick.o +0 -0
- data/ext/rubygame/rubygame_main.c +155 -0
- data/ext/rubygame/rubygame_main.h +33 -0
- data/ext/rubygame/rubygame_main.o +0 -0
- data/ext/rubygame/rubygame_mixer.c +764 -0
- data/ext/rubygame/rubygame_mixer.h +62 -0
- data/ext/rubygame/rubygame_mixer.o +0 -0
- data/ext/rubygame/rubygame_mixer.so +0 -0
- data/ext/rubygame/rubygame_screen.c +448 -0
- data/ext/rubygame/rubygame_screen.h +43 -0
- data/ext/rubygame/rubygame_screen.o +0 -0
- data/ext/rubygame/rubygame_shared.c +209 -0
- data/ext/rubygame/rubygame_shared.h +60 -0
- data/ext/rubygame/rubygame_shared.o +0 -0
- data/ext/rubygame/rubygame_surface.c +1147 -0
- data/ext/rubygame/rubygame_surface.h +62 -0
- data/ext/rubygame/rubygame_surface.o +0 -0
- data/ext/rubygame/rubygame_time.c +183 -0
- data/ext/rubygame/rubygame_time.h +32 -0
- data/ext/rubygame/rubygame_time.o +0 -0
- data/ext/rubygame/rubygame_ttf.c +599 -0
- data/ext/rubygame/rubygame_ttf.h +69 -0
- data/ext/rubygame/rubygame_ttf.o +0 -0
- data/ext/rubygame/rubygame_ttf.so +0 -0
- data/lib/rubygame/MANIFEST +12 -0
- data/lib/rubygame/clock.rb +128 -0
- data/lib/rubygame/color/models/base.rb +106 -0
- data/lib/rubygame/color/models/hsl.rb +153 -0
- data/lib/rubygame/color/models/hsv.rb +149 -0
- data/lib/rubygame/color/models/rgb.rb +78 -0
- data/lib/rubygame/color/palettes/css.rb +49 -0
- data/lib/rubygame/color/palettes/palette.rb +100 -0
- data/lib/rubygame/color/palettes/x11.rb +177 -0
- data/lib/rubygame/color.rb +79 -0
- data/lib/rubygame/constants.rb +238 -0
- data/lib/rubygame/event.rb +313 -0
- data/lib/rubygame/ftor.rb +370 -0
- data/lib/rubygame/hotspot.rb +265 -0
- data/lib/rubygame/keyconstants.rb +237 -0
- data/lib/rubygame/mediabag.rb +94 -0
- data/lib/rubygame/queue.rb +288 -0
- data/lib/rubygame/rect.rb +612 -0
- data/lib/rubygame/sfont.rb +223 -0
- data/lib/rubygame/sprite.rb +511 -0
- data/lib/rubygame.rb +41 -0
- data/samples/FreeSans.ttf +0 -0
- data/samples/GPL.txt +340 -0
- data/samples/README +40 -0
- data/samples/chimp.bmp +0 -0
- data/samples/chimp.rb +313 -0
- data/samples/demo_gl.rb +151 -0
- data/samples/demo_gl_tex.rb +197 -0
- data/samples/demo_music.rb +75 -0
- data/samples/demo_rubygame.rb +284 -0
- data/samples/demo_sfont.rb +52 -0
- data/samples/demo_ttf.rb +193 -0
- data/samples/demo_utf8.rb +53 -0
- data/samples/fist.bmp +0 -0
- data/samples/load_and_blit.rb +22 -0
- data/samples/panda.png +0 -0
- data/samples/punch.wav +0 -0
- data/samples/ruby.png +0 -0
- data/samples/song.ogg +0 -0
- data/samples/term16.png +0 -0
- data/samples/whiff.wav +0 -0
- metadata +152 -0
@@ -0,0 +1,599 @@
|
|
1
|
+
/*
|
2
|
+
* Interface to SDL_ttf library, for rendering TrueType Fonts to Surfaces.
|
3
|
+
*--
|
4
|
+
* Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
5
|
+
* Copyright (C) 2004-2007 John Croisant
|
6
|
+
*
|
7
|
+
* This library is free software; you can redistribute it and/or
|
8
|
+
* modify it under the terms of the GNU Lesser General Public
|
9
|
+
* License as published by the Free Software Foundation; either
|
10
|
+
* version 2.1 of the License, or (at your option) any later version.
|
11
|
+
*
|
12
|
+
* This library is distributed in the hope that it will be useful,
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
* Lesser General Public License for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Lesser General Public
|
18
|
+
* License along with this library; if not, write to the Free Software
|
19
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
*++
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include "rubygame_shared.h"
|
24
|
+
#include "rubygame_ttf.h"
|
25
|
+
#include "rubygame_surface.h"
|
26
|
+
|
27
|
+
void Rubygame_Init_TTF();
|
28
|
+
VALUE cTTF;
|
29
|
+
|
30
|
+
VALUE rbgm_ttf_setup(VALUE);
|
31
|
+
VALUE rbgm_ttf_quit(VALUE);
|
32
|
+
VALUE rbgm_ttf_new(VALUE, VALUE, VALUE);
|
33
|
+
|
34
|
+
VALUE rbgm_ttf_getbold(VALUE);
|
35
|
+
VALUE rbgm_ttf_setbold(VALUE, VALUE);
|
36
|
+
|
37
|
+
VALUE rbgm_ttf_getitalic(VALUE);
|
38
|
+
VALUE rbgm_ttf_setitalic(VALUE, VALUE);
|
39
|
+
|
40
|
+
VALUE rbgm_ttf_getunderline(VALUE);
|
41
|
+
VALUE rbgm_ttf_setunderline(VALUE, VALUE);
|
42
|
+
|
43
|
+
VALUE rbgm_ttf_height(VALUE);
|
44
|
+
VALUE rbgm_ttf_ascent(VALUE);
|
45
|
+
VALUE rbgm_ttf_descent(VALUE);
|
46
|
+
VALUE rbgm_ttf_lineskip(VALUE);
|
47
|
+
|
48
|
+
VALUE rbgm_ttf_sizetext(VALUE, VALUE);
|
49
|
+
VALUE rbgm_ttf_size_utf8(VALUE, VALUE);
|
50
|
+
VALUE rbgm_ttf_size_unicode(VALUE, VALUE);
|
51
|
+
|
52
|
+
VALUE rbgm_ttf_render(int, VALUE*, VALUE);
|
53
|
+
VALUE rbgm_ttf_render_utf8(int , VALUE*, VALUE);
|
54
|
+
VALUE rbgm_ttf_render_unicode(int , VALUE*, VALUE);
|
55
|
+
|
56
|
+
/*
|
57
|
+
* call-seq:
|
58
|
+
* setup -> nil
|
59
|
+
*
|
60
|
+
* Attempt to setup the TTF class for use by initializing SDL_ttf.
|
61
|
+
* This *must* be called before the TTF class can be used.
|
62
|
+
* Raises SDLError if there is a problem initializing SDL_ttf.
|
63
|
+
*/
|
64
|
+
VALUE rbgm_ttf_setup(VALUE module)
|
65
|
+
{
|
66
|
+
if(!TTF_WasInit() && TTF_Init()!=0)
|
67
|
+
rb_raise(eSDLError,"could not setup TTF class: %s",TTF_GetError());
|
68
|
+
return Qnil;
|
69
|
+
}
|
70
|
+
|
71
|
+
/*
|
72
|
+
* call-seq:
|
73
|
+
* quit -> nil
|
74
|
+
*
|
75
|
+
* Clean up and quit SDL_ttf, making the TTF class unusable as a result
|
76
|
+
* (until it is setup again). This does not need to be called before Rubygame
|
77
|
+
* exits, as it will be done automatically.
|
78
|
+
*/
|
79
|
+
VALUE rbgm_ttf_quit(VALUE module)
|
80
|
+
{
|
81
|
+
if(TTF_WasInit())
|
82
|
+
TTF_Quit();
|
83
|
+
return Qnil;
|
84
|
+
}
|
85
|
+
|
86
|
+
/*
|
87
|
+
* call-seq:
|
88
|
+
* new( file, size ) -> TTF
|
89
|
+
*
|
90
|
+
* Create a new TTF object, which can render text to a Surface with a
|
91
|
+
* particular font style and size.
|
92
|
+
*
|
93
|
+
* This function takes these arguments:
|
94
|
+
* file:: filename of the TrueType font to use. Should be a +TTF+ or
|
95
|
+
* +FON+ file.
|
96
|
+
* size:: point size (based on 72DPI). (That means the height in pixels from
|
97
|
+
* the bottom of the descent to the top of the ascent.)
|
98
|
+
*/
|
99
|
+
VALUE rbgm_ttf_new(VALUE class, VALUE vfile, VALUE vsize)
|
100
|
+
{
|
101
|
+
VALUE self;
|
102
|
+
TTF_Font *font;
|
103
|
+
|
104
|
+
if(!TTF_WasInit())
|
105
|
+
rb_raise(eSDLError,"Font module must be initialized before making new font.");
|
106
|
+
font = TTF_OpenFont(StringValuePtr(vfile), NUM2INT(vsize));
|
107
|
+
if(font == NULL)
|
108
|
+
rb_raise(eSDLError,"could not load font: %s",TTF_GetError());
|
109
|
+
|
110
|
+
self = Data_Wrap_Struct(cTTF,0,TTF_CloseFont,font);
|
111
|
+
return self;
|
112
|
+
}
|
113
|
+
|
114
|
+
/* :nodoc: */
|
115
|
+
VALUE rbgm_ttf_initialize(int argc, VALUE *argv, VALUE self)
|
116
|
+
{
|
117
|
+
return self;
|
118
|
+
}
|
119
|
+
|
120
|
+
|
121
|
+
/*--
|
122
|
+
* Checks to see if the TTF font wrapped in the self VALUE has the style in the parameter style.
|
123
|
+
* ++
|
124
|
+
*/
|
125
|
+
static VALUE RBGM_ttf_get_style(VALUE self, int style)
|
126
|
+
{
|
127
|
+
TTF_Font *font;
|
128
|
+
int mystyle;
|
129
|
+
|
130
|
+
Data_Get_Struct(self, TTF_Font, font);
|
131
|
+
mystyle = TTF_GetFontStyle(font);
|
132
|
+
|
133
|
+
if ((mystyle & style) == style) return Qtrue;
|
134
|
+
return Qfalse;
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
/*--
|
139
|
+
* Sets or unsets the style in int style for the TTF font wrapped in the self VALUE,
|
140
|
+
* using enable to determine what to do. If enable is Qtrue, the style is set, if it is
|
141
|
+
* Qfalse, the style is unset.
|
142
|
+
* ++
|
143
|
+
*/
|
144
|
+
static VALUE RBGM_ttf_set_style(VALUE self, VALUE enable, int style)
|
145
|
+
{
|
146
|
+
int oldstyle;
|
147
|
+
TTF_Font *font;
|
148
|
+
|
149
|
+
Data_Get_Struct(self,TTF_Font,font);
|
150
|
+
oldstyle = TTF_GetFontStyle(font);
|
151
|
+
|
152
|
+
if(((oldstyle & style) ==style) && !RTEST(enable))
|
153
|
+
{ /* The style is set but we want to remove it. */
|
154
|
+
TTF_SetFontStyle(font,oldstyle^style);
|
155
|
+
return Qtrue;
|
156
|
+
/* The old value */
|
157
|
+
}
|
158
|
+
else if( RTEST(enable) )
|
159
|
+
{ /* The style is not set and we want to add it. */
|
160
|
+
TTF_SetFontStyle(font,oldstyle|style);
|
161
|
+
return Qfalse;
|
162
|
+
/* The old value */
|
163
|
+
}
|
164
|
+
|
165
|
+
return enable;
|
166
|
+
}
|
167
|
+
|
168
|
+
/* call-seq:
|
169
|
+
* bold -> Bool
|
170
|
+
*
|
171
|
+
* True if bolding is enabled for the font.
|
172
|
+
*/
|
173
|
+
VALUE rbgm_ttf_getbold(VALUE self)
|
174
|
+
{
|
175
|
+
return RBGM_ttf_get_style(self, TTF_STYLE_BOLD);
|
176
|
+
}
|
177
|
+
|
178
|
+
/* call-seq:
|
179
|
+
* bold = value -> Bool
|
180
|
+
*
|
181
|
+
* Set whether bolding is enabled for this font. Returns the old value.
|
182
|
+
*/
|
183
|
+
VALUE rbgm_ttf_setbold(VALUE self, VALUE bold)
|
184
|
+
{
|
185
|
+
return RBGM_ttf_set_style(self, bold, TTF_STYLE_BOLD);
|
186
|
+
}
|
187
|
+
|
188
|
+
/* call-seq:
|
189
|
+
* italic -> Bool
|
190
|
+
*
|
191
|
+
* True if italicizing is enabled for the font.
|
192
|
+
*/
|
193
|
+
VALUE rbgm_ttf_getitalic(VALUE self)
|
194
|
+
{
|
195
|
+
return RBGM_ttf_get_style(self, TTF_STYLE_ITALIC);
|
196
|
+
}
|
197
|
+
|
198
|
+
/* call-seq:
|
199
|
+
* italic = value -> Bool
|
200
|
+
*
|
201
|
+
* Set whether italicizing is enabled for this font. Returns the old value.
|
202
|
+
*/
|
203
|
+
VALUE rbgm_ttf_setitalic(VALUE self,VALUE italic)
|
204
|
+
{
|
205
|
+
return RBGM_ttf_set_style(self, italic, TTF_STYLE_ITALIC);
|
206
|
+
}
|
207
|
+
|
208
|
+
/* call-seq:
|
209
|
+
* underline -> Bool
|
210
|
+
*
|
211
|
+
* True if underlining is enabled for the font.
|
212
|
+
*/
|
213
|
+
VALUE rbgm_ttf_getunderline(VALUE self)
|
214
|
+
{
|
215
|
+
return RBGM_ttf_get_style(self, TTF_STYLE_UNDERLINE);
|
216
|
+
}
|
217
|
+
|
218
|
+
/* call-seq:
|
219
|
+
* underline = value -> Bool
|
220
|
+
*
|
221
|
+
* Set whether underlining is enabled for this font. Returns the old value.
|
222
|
+
*/
|
223
|
+
VALUE rbgm_ttf_setunderline(VALUE self, VALUE underline)
|
224
|
+
{
|
225
|
+
return RBGM_ttf_set_style(self, underline, TTF_STYLE_UNDERLINE);
|
226
|
+
}
|
227
|
+
|
228
|
+
/* call-seq:
|
229
|
+
* height -> Integer
|
230
|
+
*
|
231
|
+
* Return the biggest height (bottom to top; in pixels) of all glyphs in the
|
232
|
+
* font.
|
233
|
+
*/
|
234
|
+
VALUE rbgm_ttf_height(VALUE self)
|
235
|
+
{
|
236
|
+
TTF_Font *font;
|
237
|
+
Data_Get_Struct(self,TTF_Font,font);
|
238
|
+
return INT2NUM(TTF_FontHeight(font));
|
239
|
+
}
|
240
|
+
|
241
|
+
/* call-seq:
|
242
|
+
* ascent -> Integer
|
243
|
+
*
|
244
|
+
* Return the biggest ascent (baseline to top; in pixels) of all glyphs in
|
245
|
+
* the font.
|
246
|
+
*/
|
247
|
+
VALUE rbgm_ttf_ascent(VALUE self)
|
248
|
+
{
|
249
|
+
TTF_Font *font;
|
250
|
+
Data_Get_Struct(self,TTF_Font,font);
|
251
|
+
return INT2NUM(TTF_FontAscent(font));
|
252
|
+
}
|
253
|
+
|
254
|
+
/* call-seq:
|
255
|
+
* descent -> Integer
|
256
|
+
*
|
257
|
+
* Return the biggest descent (baseline to bottom; in pixels) of all glyphs in
|
258
|
+
* the font.
|
259
|
+
*/
|
260
|
+
VALUE rbgm_ttf_descent(VALUE self)
|
261
|
+
{
|
262
|
+
TTF_Font *font;
|
263
|
+
Data_Get_Struct(self,TTF_Font,font);
|
264
|
+
return INT2NUM(TTF_FontDescent(font));
|
265
|
+
}
|
266
|
+
|
267
|
+
/* call-seq:
|
268
|
+
* lineskip -> Integer
|
269
|
+
*
|
270
|
+
* Return the recommended distance (in pixels) from a point on a line of text
|
271
|
+
* to the same point on the line of text below it.
|
272
|
+
*/
|
273
|
+
VALUE rbgm_ttf_lineskip(VALUE self)
|
274
|
+
{
|
275
|
+
TTF_Font *font;
|
276
|
+
Data_Get_Struct(self,TTF_Font,font);
|
277
|
+
return INT2NUM(TTF_FontLineSkip(font));
|
278
|
+
}
|
279
|
+
|
280
|
+
/*
|
281
|
+
* call-seq:
|
282
|
+
* size_text(text) -> [ width, height ]
|
283
|
+
*
|
284
|
+
* The width and height the text would be if
|
285
|
+
* it were rendered, without the overhead of
|
286
|
+
* actually rendering it.
|
287
|
+
*/
|
288
|
+
VALUE rbgm_ttf_sizetext(VALUE self, VALUE string)
|
289
|
+
{
|
290
|
+
TTF_Font *font;
|
291
|
+
int w;
|
292
|
+
int h;
|
293
|
+
VALUE result;
|
294
|
+
Data_Get_Struct(self, TTF_Font,font);
|
295
|
+
result = rb_ary_new();
|
296
|
+
|
297
|
+
TTF_SizeText(font,StringValuePtr(string),&w,&h);
|
298
|
+
|
299
|
+
rb_ary_push(result, INT2NUM(w));
|
300
|
+
rb_ary_push(result, INT2NUM(h));
|
301
|
+
|
302
|
+
return result;
|
303
|
+
}
|
304
|
+
|
305
|
+
/*
|
306
|
+
* call-seq:
|
307
|
+
* size_utf8(text) -> [ width, height ]
|
308
|
+
*
|
309
|
+
* The width and height the UTF-8 encoded text would be if
|
310
|
+
* it were rendered, without the overhead of
|
311
|
+
* actually rendering it.
|
312
|
+
*/
|
313
|
+
|
314
|
+
VALUE rbgm_ttf_size_utf8(VALUE self, VALUE string)
|
315
|
+
{
|
316
|
+
TTF_Font *font;
|
317
|
+
int w;
|
318
|
+
int h;
|
319
|
+
VALUE result;
|
320
|
+
Data_Get_Struct(self, TTF_Font,font);
|
321
|
+
result = rb_ary_new();
|
322
|
+
|
323
|
+
TTF_SizeUTF8(font,StringValuePtr(string),&w,&h);
|
324
|
+
|
325
|
+
rb_ary_push(result, INT2NUM(w));
|
326
|
+
rb_ary_push(result, INT2NUM(h));
|
327
|
+
|
328
|
+
return result;
|
329
|
+
}
|
330
|
+
|
331
|
+
/*
|
332
|
+
* call-seq:
|
333
|
+
* size_unicode(text) -> [ width, height ]
|
334
|
+
*
|
335
|
+
* The width and height the UNICODE encoded text would be if
|
336
|
+
* it were rendered, without the overhead of
|
337
|
+
* actually rendering it.
|
338
|
+
*/
|
339
|
+
|
340
|
+
VALUE rbgm_ttf_size_unicode(VALUE self, VALUE string)
|
341
|
+
{
|
342
|
+
TTF_Font *font;
|
343
|
+
int w;
|
344
|
+
int h;
|
345
|
+
VALUE result;
|
346
|
+
Data_Get_Struct(self, TTF_Font,font);
|
347
|
+
result = rb_ary_new();
|
348
|
+
TTF_SizeUNICODE(font,(Uint16*)StringValuePtr(string),&w,&h);
|
349
|
+
|
350
|
+
rb_ary_push(result, INT2NUM(w));
|
351
|
+
rb_ary_push(result, INT2NUM(h));
|
352
|
+
|
353
|
+
return result;
|
354
|
+
}
|
355
|
+
|
356
|
+
|
357
|
+
/*
|
358
|
+
*--
|
359
|
+
* TODO: Refactor/integrate #render, #render_utf8, and #render_unicode
|
360
|
+
*++
|
361
|
+
*/
|
362
|
+
|
363
|
+
/* call-seq:
|
364
|
+
* render(string, aa, fg, bg) -> Surface
|
365
|
+
*
|
366
|
+
* Renders a string to a Surface with the font's style and the given color(s).
|
367
|
+
*
|
368
|
+
* This method takes these arguments:
|
369
|
+
* string:: the text string to render
|
370
|
+
* aa:: Use anti-aliasing if true. Enabling this makes the text
|
371
|
+
* look much nicer (smooth curves), but is much slower.
|
372
|
+
* fg:: the color to render the text, in the form [r,g,b]
|
373
|
+
* bg:: the color to use as a background for the text. This option can
|
374
|
+
* be omitted to have a transparent background.
|
375
|
+
*/
|
376
|
+
VALUE rbgm_ttf_render(int argc, VALUE *argv, VALUE self)
|
377
|
+
{
|
378
|
+
SDL_Surface *surf;
|
379
|
+
TTF_Font *font;
|
380
|
+
SDL_Color fore, back; /* foreground and background colors */
|
381
|
+
VALUE vstring, vaa, vfg, vbg;
|
382
|
+
|
383
|
+
rb_scan_args(argc, argv, "31", &vstring, &vaa, &vfg, &vbg);
|
384
|
+
|
385
|
+
Data_Get_Struct(self,TTF_Font,font);
|
386
|
+
|
387
|
+
fore = make_sdl_color(vfg);
|
388
|
+
|
389
|
+
if( RTEST(vbg) )
|
390
|
+
{
|
391
|
+
back = make_sdl_color(vbg);
|
392
|
+
}
|
393
|
+
|
394
|
+
if( RTEST(vaa) ) /* anti-aliasing enabled */
|
395
|
+
{
|
396
|
+
if( RTEST(vbg) ) /* background color provided */
|
397
|
+
surf = TTF_RenderText_Shaded(font,StringValuePtr(vstring),fore,back);
|
398
|
+
else /* no background color */
|
399
|
+
surf = TTF_RenderText_Blended(font,StringValuePtr(vstring),fore);
|
400
|
+
}
|
401
|
+
else /* anti-aliasing not enabled */
|
402
|
+
{
|
403
|
+
if( RTEST(vbg) ) /* background color provided */
|
404
|
+
{
|
405
|
+
/* remove colorkey, set color index 0 to background color */
|
406
|
+
surf = TTF_RenderText_Solid(font,StringValuePtr(vstring),fore);
|
407
|
+
SDL_SetColors(surf,&back,0,1);
|
408
|
+
SDL_SetColorKey(surf,0,0);
|
409
|
+
}
|
410
|
+
else /* no background color */
|
411
|
+
{
|
412
|
+
surf = TTF_RenderText_Solid(font,StringValuePtr(vstring),fore);
|
413
|
+
}
|
414
|
+
}
|
415
|
+
|
416
|
+
if(surf==NULL)
|
417
|
+
rb_raise(eSDLError,"could not render font object: %s",TTF_GetError());
|
418
|
+
return Data_Wrap_Struct(cSurface,0,SDL_FreeSurface,surf);
|
419
|
+
}
|
420
|
+
|
421
|
+
|
422
|
+
/* call-seq:
|
423
|
+
* render_utf8(string, aa, fg, bg) -> Surface
|
424
|
+
*
|
425
|
+
* Renders a string to a Surface with the font's style and the given color(s).
|
426
|
+
*
|
427
|
+
* This method takes these arguments:
|
428
|
+
* string:: the text string to render
|
429
|
+
* aa:: Use anti-aliasing if true. Enabling this makes the text
|
430
|
+
* look much nicer (smooth curves), but is much slower.
|
431
|
+
* fg:: the color to render the text, in the form [r,g,b]
|
432
|
+
* bg:: the color to use as a background for the text. This option can
|
433
|
+
* be omitted to have a transparent background.
|
434
|
+
*/
|
435
|
+
VALUE rbgm_ttf_render_utf8(int argc, VALUE *argv, VALUE self)
|
436
|
+
{
|
437
|
+
SDL_Surface *surf;
|
438
|
+
TTF_Font *font;
|
439
|
+
SDL_Color fore, back; /* foreground and background colors */
|
440
|
+
VALUE vstring, vaa, vfg, vbg;
|
441
|
+
|
442
|
+
rb_scan_args(argc, argv, "31", &vstring, &vaa, &vfg, &vbg);
|
443
|
+
|
444
|
+
Data_Get_Struct(self,TTF_Font,font);
|
445
|
+
|
446
|
+
fore = make_sdl_color(vfg);
|
447
|
+
|
448
|
+
if( RTEST(vbg) )
|
449
|
+
{
|
450
|
+
back = make_sdl_color(vbg);
|
451
|
+
}
|
452
|
+
|
453
|
+
if( RTEST(vaa) ) /* anti-aliasing enabled */
|
454
|
+
{
|
455
|
+
if( RTEST(vbg) ) /* background color provided */
|
456
|
+
surf = TTF_RenderUTF8_Shaded(font,StringValuePtr(vstring),fore,back);
|
457
|
+
else /* no background color */
|
458
|
+
surf = TTF_RenderUTF8_Blended(font,StringValuePtr(vstring),fore);
|
459
|
+
}
|
460
|
+
else /* anti-aliasing not enabled */
|
461
|
+
{
|
462
|
+
if( RTEST(vbg) ) /* background color provided */
|
463
|
+
{
|
464
|
+
/* remove colorkey, set color index 0 to background color */
|
465
|
+
surf = TTF_RenderUTF8_Solid(font,StringValuePtr(vstring),fore);
|
466
|
+
SDL_SetColors(surf,&back,0,1);
|
467
|
+
SDL_SetColorKey(surf,0,0);
|
468
|
+
}
|
469
|
+
else /* no background color */
|
470
|
+
{
|
471
|
+
surf = TTF_RenderUTF8_Solid(font,StringValuePtr(vstring),fore);
|
472
|
+
}
|
473
|
+
}
|
474
|
+
|
475
|
+
if(surf==NULL)
|
476
|
+
rb_raise(eSDLError,"could not render font object: %s",TTF_GetError());
|
477
|
+
return Data_Wrap_Struct(cSurface,0,SDL_FreeSurface,surf);
|
478
|
+
}
|
479
|
+
|
480
|
+
/* call-seq:
|
481
|
+
* render_unicode(string, aa, fg, bg) -> Surface
|
482
|
+
*
|
483
|
+
* Renders a string to a Surface with the font's style and the given color(s).
|
484
|
+
*
|
485
|
+
* This method takes these arguments:
|
486
|
+
* string:: the text string to render
|
487
|
+
* aa:: Use anti-aliasing if true. Enabling this makes the text
|
488
|
+
* look much nicer (smooth curves), but is much slower.
|
489
|
+
* fg:: the color to render the text, in the form [r,g,b]
|
490
|
+
* bg:: the color to use as a background for the text. This option can
|
491
|
+
* be omitted to have a transparent background.
|
492
|
+
*/
|
493
|
+
VALUE rbgm_ttf_render_unicode(int argc, VALUE *argv, VALUE self)
|
494
|
+
{
|
495
|
+
/* TODO:... ->unicode */
|
496
|
+
SDL_Surface *surf;
|
497
|
+
TTF_Font *font;
|
498
|
+
SDL_Color fore, back; /* foreground and background colors */
|
499
|
+
VALUE vstring, vaa, vfg, vbg;
|
500
|
+
|
501
|
+
rb_scan_args(argc, argv, "31", &vstring, &vaa, &vfg, &vbg);
|
502
|
+
|
503
|
+
Data_Get_Struct(self,TTF_Font,font);
|
504
|
+
|
505
|
+
fore = make_sdl_color(vfg);
|
506
|
+
|
507
|
+
if( RTEST(vbg) )
|
508
|
+
{
|
509
|
+
back = make_sdl_color(vbg);
|
510
|
+
}
|
511
|
+
|
512
|
+
if( RTEST(vaa) ) /* anti-aliasing enabled */
|
513
|
+
{
|
514
|
+
if( RTEST(vbg) ) /* background color provided */
|
515
|
+
surf = TTF_RenderUNICODE_Shaded(font,(Uint16*)StringValuePtr(vstring),fore,back);
|
516
|
+
else /* no background color */
|
517
|
+
surf = TTF_RenderUNICODE_Blended(font,(Uint16*)StringValuePtr(vstring),fore);
|
518
|
+
}
|
519
|
+
else /* anti-aliasing not enabled */
|
520
|
+
{
|
521
|
+
if( RTEST(vbg) ) /* background color provided */
|
522
|
+
{
|
523
|
+
/* remove colorkey, set color index 0 to background color */
|
524
|
+
surf = TTF_RenderUNICODE_Solid(font,(Uint16*)StringValuePtr(vstring),fore);
|
525
|
+
SDL_SetColors(surf,&back,0,1);
|
526
|
+
SDL_SetColorKey(surf,0,0);
|
527
|
+
}
|
528
|
+
else /* no background color */
|
529
|
+
{
|
530
|
+
surf = TTF_RenderUNICODE_Solid(font,(Uint16*)StringValuePtr(vstring),fore);
|
531
|
+
}
|
532
|
+
}
|
533
|
+
|
534
|
+
if(surf==NULL)
|
535
|
+
rb_raise(eSDLError,"could not render font object: %s",TTF_GetError());
|
536
|
+
return Data_Wrap_Struct(cSurface,0,SDL_FreeSurface,surf);
|
537
|
+
}
|
538
|
+
|
539
|
+
/*
|
540
|
+
* Document-class: Rubygame::TTF
|
541
|
+
*
|
542
|
+
* TTF provides an interface to SDL_ttf, allowing TrueType Font files to be
|
543
|
+
* loaded and used to render text to Surfaces.
|
544
|
+
*
|
545
|
+
* The TTF class *must* be initialized with the #setup method before any
|
546
|
+
* TTF objects can be created or used.
|
547
|
+
*
|
548
|
+
* This class is only usable if Rubygame was compiled with the SDL_ttf
|
549
|
+
* library. You may test if this feature is available with the #usable?
|
550
|
+
* method. If you need more flexibility, you can check the library version
|
551
|
+
* that Rubygame was compiled against with the #version method.
|
552
|
+
*/
|
553
|
+
void Init_rubygame_ttf()
|
554
|
+
{
|
555
|
+
#if 0
|
556
|
+
mRubygame = rb_define_module("Rubygame");
|
557
|
+
#endif
|
558
|
+
|
559
|
+
Init_rubygame_shared();
|
560
|
+
|
561
|
+
rb_hash_aset(rb_ivar_get(mRubygame,rb_intern("VERSIONS")),
|
562
|
+
ID2SYM(rb_intern("sdl_ttf")),
|
563
|
+
rb_ary_new3(3,
|
564
|
+
INT2NUM(SDL_TTF_MAJOR_VERSION),
|
565
|
+
INT2NUM(SDL_TTF_MINOR_VERSION),
|
566
|
+
INT2NUM(SDL_TTF_PATCHLEVEL)));
|
567
|
+
|
568
|
+
|
569
|
+
cTTF = rb_define_class_under(mRubygame,"TTF",rb_cObject);
|
570
|
+
|
571
|
+
rb_define_singleton_method(cTTF,"new",rbgm_ttf_new,2);
|
572
|
+
rb_define_singleton_method(cTTF,"setup",rbgm_ttf_setup,0);
|
573
|
+
rb_define_singleton_method(cTTF,"quit",rbgm_ttf_quit,0);
|
574
|
+
|
575
|
+
rb_define_method(cTTF,"initialize",rbgm_ttf_initialize,-1);
|
576
|
+
rb_define_method(cTTF,"bold",rbgm_ttf_getbold,0);
|
577
|
+
rb_define_method(cTTF,"bold=",rbgm_ttf_setbold,1);
|
578
|
+
rb_define_alias( cTTF,"b","bold");
|
579
|
+
rb_define_alias( cTTF,"b=","bold=");
|
580
|
+
rb_define_method(cTTF,"italic",rbgm_ttf_getitalic,0);
|
581
|
+
rb_define_method(cTTF,"italic=",rbgm_ttf_setitalic,1);
|
582
|
+
rb_define_alias( cTTF,"i","italic");
|
583
|
+
rb_define_alias( cTTF,"i=","italic=");
|
584
|
+
rb_define_method(cTTF,"underline",rbgm_ttf_getunderline,0);
|
585
|
+
rb_define_method(cTTF,"underline=",rbgm_ttf_setunderline,1);
|
586
|
+
rb_define_alias( cTTF,"u","underline");
|
587
|
+
rb_define_alias( cTTF,"u=","underline=");
|
588
|
+
rb_define_method(cTTF,"height",rbgm_ttf_height,0);
|
589
|
+
rb_define_method(cTTF,"ascent",rbgm_ttf_ascent,0);
|
590
|
+
rb_define_method(cTTF,"descent",rbgm_ttf_descent,0);
|
591
|
+
rb_define_method(cTTF,"line_skip",rbgm_ttf_lineskip,0);
|
592
|
+
rb_define_method(cTTF,"size_text",rbgm_ttf_sizetext,1);
|
593
|
+
rb_define_method(cTTF,"size_utf8",rbgm_ttf_size_utf8, 1);
|
594
|
+
rb_define_method(cTTF,"size_unicode",rbgm_ttf_size_unicode, 1);
|
595
|
+
rb_define_method(cTTF,"render",rbgm_ttf_render,-1);
|
596
|
+
rb_define_method(cTTF,"render_utf8",rbgm_ttf_render_utf8,-1);
|
597
|
+
rb_define_method(cTTF,"render_unicode",rbgm_ttf_render_unicode,-1);
|
598
|
+
|
599
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
/*
|
2
|
+
* Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
3
|
+
* Copyright (C) 2004-2007 John Croisant
|
4
|
+
*
|
5
|
+
* This library is free software; you can redistribute it and/or
|
6
|
+
* modify it under the terms of the GNU Lesser General Public
|
7
|
+
* License as published by the Free Software Foundation; either
|
8
|
+
* version 2.1 of the License, or (at your option) any later version.
|
9
|
+
*
|
10
|
+
* This library is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
* Lesser General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU Lesser General Public
|
16
|
+
* License along with this library; if not, write to the Free Software
|
17
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
|
21
|
+
#ifndef _RUBYGAME_TTF_H
|
22
|
+
#define _RUBYGAME_TTF_H
|
23
|
+
|
24
|
+
#include "SDL_ttf.h"
|
25
|
+
|
26
|
+
#ifndef SDL_TTF_MAJOR_VERSION
|
27
|
+
#define SDL_TTF_MAJOR_VERSION 0
|
28
|
+
#endif
|
29
|
+
|
30
|
+
#ifndef SDL_TTF_MINOR_VERSION
|
31
|
+
#define SDL_TTF_MINOR_VERSION 0
|
32
|
+
#endif
|
33
|
+
|
34
|
+
#ifndef SDL_TTF_PATCHLEVEL
|
35
|
+
#define SDL_TTF_PATCHLEVEL 0
|
36
|
+
#endif
|
37
|
+
|
38
|
+
extern void Init_rubygame_ttf();
|
39
|
+
|
40
|
+
extern VALUE cTTF;
|
41
|
+
|
42
|
+
extern VALUE rbgm_ttf_setup(VALUE);
|
43
|
+
extern VALUE rbgm_ttf_quit(VALUE);
|
44
|
+
extern VALUE rbgm_ttf_new(VALUE, VALUE, VALUE);
|
45
|
+
extern VALUE rbgm_ttf_initialize(int, VALUE*, VALUE);
|
46
|
+
|
47
|
+
extern VALUE rbgm_ttf_getbold(VALUE);
|
48
|
+
extern VALUE rbgm_ttf_setbold(VALUE, VALUE);
|
49
|
+
|
50
|
+
extern VALUE rbgm_ttf_getitalic(VALUE);
|
51
|
+
extern VALUE rbgm_ttf_setitalic(VALUE, VALUE);
|
52
|
+
|
53
|
+
extern VALUE rbgm_ttf_getunderline(VALUE);
|
54
|
+
extern VALUE rbgm_ttf_setunderline(VALUE, VALUE);
|
55
|
+
|
56
|
+
extern VALUE rbgm_ttf_height(VALUE);
|
57
|
+
extern VALUE rbgm_ttf_ascent(VALUE);
|
58
|
+
extern VALUE rbgm_ttf_descent(VALUE);
|
59
|
+
extern VALUE rbgm_ttf_lineskip(VALUE);
|
60
|
+
|
61
|
+
extern VALUE rbgm_ttf_sizetext(VALUE, VALUE);
|
62
|
+
extern VALUE rbgm_ttf_size_utf8(VALUE, VALUE);
|
63
|
+
extern VALUE rbgm_ttf_size_unicode(VALUE, VALUE);
|
64
|
+
|
65
|
+
extern VALUE rbgm_ttf_render(int, VALUE*, VALUE);
|
66
|
+
extern VALUE rbgm_ttf_render_utf8(int , VALUE*, VALUE);
|
67
|
+
extern VALUE rbgm_ttf_render_unicode(int , VALUE*, VALUE);
|
68
|
+
|
69
|
+
#endif
|
Binary file
|
Binary file
|