rubygame 2.5.3 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/CREDITS +6 -4
  2. data/NEWS +79 -0
  3. data/README +55 -72
  4. data/ROADMAP +20 -13
  5. data/doc/custom_sdl_load_paths.rdoc +79 -0
  6. data/doc/getting_started.rdoc +65 -36
  7. data/doc/keyboard_symbols.rdoc +243 -0
  8. data/doc/macosx_install.rdoc +49 -35
  9. data/doc/windows_install.rdoc +36 -108
  10. data/lib/rubygame.rb +62 -24
  11. data/lib/rubygame/audio.rb +147 -0
  12. data/lib/rubygame/clock.rb +164 -1
  13. data/lib/rubygame/color.rb +40 -7
  14. data/lib/rubygame/color/models/hsl.rb +1 -1
  15. data/lib/rubygame/color/models/hsv.rb +1 -1
  16. data/lib/rubygame/color/models/rgb.rb +1 -1
  17. data/lib/rubygame/color/palettes/css.rb +1 -3
  18. data/lib/rubygame/color/palettes/x11.rb +1 -2
  19. data/lib/rubygame/constants.rb +297 -0
  20. data/lib/rubygame/deprecated_mixer.rb +555 -0
  21. data/lib/rubygame/event.rb +122 -6
  22. data/lib/rubygame/event_handler.rb +3 -1
  23. data/lib/rubygame/event_hook.rb +6 -2
  24. data/lib/rubygame/event_triggers.rb +1 -1
  25. data/lib/rubygame/events.rb +416 -1
  26. data/lib/rubygame/ftor.rb +1 -7
  27. data/lib/rubygame/gfx.rb +583 -0
  28. data/lib/rubygame/gl.rb +107 -0
  29. data/lib/rubygame/image.rb +140 -0
  30. data/lib/rubygame/joystick.rb +184 -0
  31. data/lib/rubygame/main.rb +82 -0
  32. data/lib/rubygame/mediabag.rb +1 -1
  33. data/lib/rubygame/mixer.rb +30 -0
  34. data/lib/rubygame/music.rb +493 -0
  35. data/lib/rubygame/queue.rb +3 -1
  36. data/lib/rubygame/rect.rb +9 -9
  37. data/lib/rubygame/screen.rb +357 -0
  38. data/lib/rubygame/shared.rb +40 -4
  39. data/lib/rubygame/sound.rb +428 -0
  40. data/lib/rubygame/surface.rb +626 -0
  41. data/lib/rubygame/ttf.rb +311 -0
  42. data/samples/FreeSans.ttf +0 -0
  43. data/samples/README +6 -5
  44. data/samples/demo_draw.rb +1 -1
  45. data/samples/demo_gl.rb +3 -1
  46. data/samples/demo_gl_tex.rb +4 -2
  47. data/samples/demo_rubygame.rb +114 -105
  48. data/samples/demo_sfont.rb +1 -1
  49. data/samples/demo_ttf.rb +3 -1
  50. data/samples/demo_utf8.rb +1 -1
  51. data/samples/image_viewer.rb +118 -0
  52. data/samples/load_and_blit.rb +1 -1
  53. data/samples/rubygame.png +0 -0
  54. metadata +34 -40
  55. data/Rakefile +0 -537
  56. data/doc/extended_readme.rdoc +0 -49
  57. data/ext/body/rubygame_body.so +0 -0
  58. data/ext/rubygame/rubygame_clock.c +0 -301
  59. data/ext/rubygame/rubygame_clock.h +0 -32
  60. data/ext/rubygame/rubygame_event.c +0 -760
  61. data/ext/rubygame/rubygame_event.h +0 -48
  62. data/ext/rubygame/rubygame_event2.c +0 -661
  63. data/ext/rubygame/rubygame_event2.h +0 -29
  64. data/ext/rubygame/rubygame_gfx.c +0 -942
  65. data/ext/rubygame/rubygame_gfx.h +0 -101
  66. data/ext/rubygame/rubygame_gl.c +0 -154
  67. data/ext/rubygame/rubygame_gl.h +0 -32
  68. data/ext/rubygame/rubygame_image.c +0 -252
  69. data/ext/rubygame/rubygame_image.h +0 -41
  70. data/ext/rubygame/rubygame_joystick.c +0 -336
  71. data/ext/rubygame/rubygame_joystick.h +0 -41
  72. data/ext/rubygame/rubygame_main.c +0 -158
  73. data/ext/rubygame/rubygame_main.h +0 -36
  74. data/ext/rubygame/rubygame_mixer.c +0 -1024
  75. data/ext/rubygame/rubygame_mixer.h +0 -36
  76. data/ext/rubygame/rubygame_music.c +0 -1017
  77. data/ext/rubygame/rubygame_music.h +0 -29
  78. data/ext/rubygame/rubygame_screen.c +0 -572
  79. data/ext/rubygame/rubygame_screen.h +0 -45
  80. data/ext/rubygame/rubygame_shared.c +0 -269
  81. data/ext/rubygame/rubygame_shared.h +0 -69
  82. data/ext/rubygame/rubygame_sound.c +0 -863
  83. data/ext/rubygame/rubygame_sound.h +0 -29
  84. data/ext/rubygame/rubygame_surface.c +0 -1153
  85. data/ext/rubygame/rubygame_surface.h +0 -62
  86. data/ext/rubygame/rubygame_ttf.c +0 -599
  87. data/ext/rubygame/rubygame_ttf.h +0 -69
  88. data/samples/keys.rb +0 -52
@@ -1,62 +0,0 @@
1
- /*
2
- * rubygame -- ruby library to make game programming fun.
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
-
22
- #ifndef _RUBYGAME_SURFACE_H
23
- #define _RUBYGAME_SURFACE_H
24
-
25
- extern void Rubygame_Init_Surface();
26
-
27
- extern VALUE rbgm_surface_new(int, VALUE*, VALUE);
28
-
29
- extern VALUE rbgm_surface_get_w(VALUE);
30
- extern VALUE rbgm_surface_get_h(VALUE);
31
- extern VALUE rbgm_surface_get_size(VALUE);
32
-
33
- extern VALUE rbgm_surface_get_depth(VALUE);
34
- extern VALUE rbgm_surface_get_flags(VALUE);
35
- extern VALUE rbgm_surface_get_masks(VALUE);
36
-
37
- extern VALUE rbgm_surface_get_alpha(VALUE);
38
- extern VALUE rbgm_surface_set_alpha(int, VALUE*, VALUE);
39
-
40
- extern VALUE rbgm_surface_get_colorkey(VALUE);
41
- extern VALUE rbgm_surface_set_colorkey(int, VALUE*, VALUE);
42
-
43
- extern VALUE rbgm_surface_blit(int, VALUE*, VALUE);
44
-
45
- extern VALUE rbgm_surface_fill(int, VALUE*, VALUE);
46
-
47
- extern VALUE rbgm_surface_getat(int, VALUE*, VALUE);
48
-
49
- extern VALUE rbgm_surface_pixels(VALUE);
50
-
51
- extern VALUE rbgm_surface_get_cliprect(VALUE);
52
- extern VALUE rbgm_surface_set_cliprect(VALUE, VALUE);
53
-
54
- extern VALUE rbgm_surface_convert(int, VALUE*, VALUE);
55
- extern VALUE rbgm_surface_displayformat(VALUE);
56
- extern VALUE rbgm_surface_displayformatalpha(VALUE);
57
-
58
- extern VALUE rbgm_image_savebmp(VALUE, VALUE);
59
-
60
- extern VALUE rbgm_transform_flip(VALUE, VALUE, VALUE);
61
-
62
- #endif
@@ -1,599 +0,0 @@
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
- }