rubygame 2.3.0-x86-mswin32-60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. data/CREDITS +60 -0
  2. data/LICENSE +504 -0
  3. data/NEWS +252 -0
  4. data/README +123 -0
  5. data/ROADMAP +109 -0
  6. data/Rakefile +440 -0
  7. data/doc/extended_readme.rdoc +49 -0
  8. data/doc/getting_started.rdoc +47 -0
  9. data/doc/macosx_install.rdoc +70 -0
  10. data/doc/windows_install.rdoc +123 -0
  11. data/ext/rubygame/rubygame_core.so +0 -0
  12. data/ext/rubygame/rubygame_event.c +644 -0
  13. data/ext/rubygame/rubygame_event.h +48 -0
  14. data/ext/rubygame/rubygame_event.obj +0 -0
  15. data/ext/rubygame/rubygame_gfx.c +942 -0
  16. data/ext/rubygame/rubygame_gfx.h +101 -0
  17. data/ext/rubygame/rubygame_gfx.obj +0 -0
  18. data/ext/rubygame/rubygame_gfx.so +0 -0
  19. data/ext/rubygame/rubygame_gl.c +154 -0
  20. data/ext/rubygame/rubygame_gl.h +32 -0
  21. data/ext/rubygame/rubygame_gl.obj +0 -0
  22. data/ext/rubygame/rubygame_image.c +252 -0
  23. data/ext/rubygame/rubygame_image.h +41 -0
  24. data/ext/rubygame/rubygame_image.obj +0 -0
  25. data/ext/rubygame/rubygame_image.so +0 -0
  26. data/ext/rubygame/rubygame_joystick.c +247 -0
  27. data/ext/rubygame/rubygame_joystick.h +41 -0
  28. data/ext/rubygame/rubygame_joystick.obj +0 -0
  29. data/ext/rubygame/rubygame_main.c +155 -0
  30. data/ext/rubygame/rubygame_main.h +36 -0
  31. data/ext/rubygame/rubygame_main.obj +0 -0
  32. data/ext/rubygame/rubygame_mixer.c +1024 -0
  33. data/ext/rubygame/rubygame_mixer.h +36 -0
  34. data/ext/rubygame/rubygame_mixer.obj +0 -0
  35. data/ext/rubygame/rubygame_mixer.so +0 -0
  36. data/ext/rubygame/rubygame_music.c +1017 -0
  37. data/ext/rubygame/rubygame_music.h +29 -0
  38. data/ext/rubygame/rubygame_music.obj +0 -0
  39. data/ext/rubygame/rubygame_screen.c +448 -0
  40. data/ext/rubygame/rubygame_screen.h +43 -0
  41. data/ext/rubygame/rubygame_screen.obj +0 -0
  42. data/ext/rubygame/rubygame_shared.c +272 -0
  43. data/ext/rubygame/rubygame_shared.h +68 -0
  44. data/ext/rubygame/rubygame_shared.obj +0 -0
  45. data/ext/rubygame/rubygame_sound.c +863 -0
  46. data/ext/rubygame/rubygame_sound.h +29 -0
  47. data/ext/rubygame/rubygame_sound.obj +0 -0
  48. data/ext/rubygame/rubygame_surface.c +1151 -0
  49. data/ext/rubygame/rubygame_surface.h +62 -0
  50. data/ext/rubygame/rubygame_surface.obj +0 -0
  51. data/ext/rubygame/rubygame_time.c +183 -0
  52. data/ext/rubygame/rubygame_time.h +32 -0
  53. data/ext/rubygame/rubygame_time.obj +0 -0
  54. data/ext/rubygame/rubygame_ttf.c +599 -0
  55. data/ext/rubygame/rubygame_ttf.h +69 -0
  56. data/ext/rubygame/rubygame_ttf.obj +0 -0
  57. data/ext/rubygame/rubygame_ttf.so +0 -0
  58. data/lib/rubygame.rb +41 -0
  59. data/lib/rubygame/clock.rb +128 -0
  60. data/lib/rubygame/color.rb +79 -0
  61. data/lib/rubygame/color/models/base.rb +111 -0
  62. data/lib/rubygame/color/models/hsl.rb +153 -0
  63. data/lib/rubygame/color/models/hsv.rb +149 -0
  64. data/lib/rubygame/color/models/rgb.rb +78 -0
  65. data/lib/rubygame/color/palettes/css.rb +49 -0
  66. data/lib/rubygame/color/palettes/palette.rb +100 -0
  67. data/lib/rubygame/color/palettes/x11.rb +177 -0
  68. data/lib/rubygame/constants.rb +238 -0
  69. data/lib/rubygame/event.rb +313 -0
  70. data/lib/rubygame/ftor.rb +370 -0
  71. data/lib/rubygame/hotspot.rb +265 -0
  72. data/lib/rubygame/keyconstants.rb +237 -0
  73. data/lib/rubygame/mediabag.rb +94 -0
  74. data/lib/rubygame/named_resource.rb +254 -0
  75. data/lib/rubygame/queue.rb +288 -0
  76. data/lib/rubygame/rect.rb +612 -0
  77. data/lib/rubygame/sfont.rb +223 -0
  78. data/lib/rubygame/sprite.rb +511 -0
  79. data/samples/FreeSans.ttf +0 -0
  80. data/samples/GPL.txt +340 -0
  81. data/samples/README +40 -0
  82. data/samples/chimp.bmp +0 -0
  83. data/samples/chimp.rb +302 -0
  84. data/samples/demo_gl.rb +151 -0
  85. data/samples/demo_gl_tex.rb +197 -0
  86. data/samples/demo_music.rb +77 -0
  87. data/samples/demo_rubygame.rb +296 -0
  88. data/samples/demo_sfont.rb +52 -0
  89. data/samples/demo_ttf.rb +193 -0
  90. data/samples/demo_utf8.rb +53 -0
  91. data/samples/fist.bmp +0 -0
  92. data/samples/load_and_blit.rb +22 -0
  93. data/samples/panda.png +0 -0
  94. data/samples/punch.wav +0 -0
  95. data/samples/ruby.png +0 -0
  96. data/samples/song.ogg +0 -0
  97. data/samples/term16.png +0 -0
  98. data/samples/whiff.wav +0 -0
  99. metadata +164 -0
@@ -0,0 +1,62 @@
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
Binary file
@@ -0,0 +1,183 @@
1
+ /*
2
+ * Functions for getting the time since initialization and delaying execution
3
+ * for a specified amounts of time.
4
+ *
5
+ * --
6
+ *
7
+ * Rubygame -- Ruby code and bindings to SDL to facilitate game creation
8
+ * Copyright (C) 2004-2007 John Croisant
9
+ *
10
+ * This library is free software; you can redistribute it and/or
11
+ * modify it under the terms of the GNU Lesser General Public
12
+ * License as published by the Free Software Foundation; either
13
+ * version 2.1 of the License, or (at your option) any later version.
14
+ *
15
+ * This library is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
+ * Lesser General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU Lesser General Public
21
+ * License along with this library; if not, write to the Free Software
22
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
+ *
24
+ * ++
25
+ */
26
+
27
+ #include "rubygame_shared.h"
28
+ #include "rubygame_time.h"
29
+
30
+ void Rubygame_Init_Time();
31
+
32
+ VALUE cClock;
33
+
34
+ VALUE rbgm_time_wait(VALUE, VALUE);
35
+ VALUE rbgm_time_delay(int, VALUE*, VALUE);
36
+ VALUE rbgm_time_getticks(VALUE);
37
+
38
+
39
+ /* NOTICE: if you change this value "officially", don't forget to update the
40
+ * documentation for rbgm_time_delay!!
41
+ */
42
+ #define WORST_CLOCK_ACCURACY 12
43
+
44
+
45
+ /*
46
+ * call-seq:
47
+ * wait( time ) -> Integer
48
+ *
49
+ * time:: how many milliseconds to wait.
50
+ *
51
+ * Wait approximately the given time (the accuracy depends upon processor
52
+ * scheduling, but 10ms is common). Returns the actual delay time, in
53
+ * milliseconds. This method is less CPU-intensive than #delay, but is
54
+ * slightly less accurate.
55
+ *
56
+ * The Rubygame timer system will be initialized when you call this function,
57
+ * if it has not been already.
58
+ *
59
+ */
60
+ VALUE rbgm_time_wait(VALUE module, VALUE milliseconds)
61
+ {
62
+ Uint32 start, delay;
63
+
64
+ if(!SDL_WasInit(SDL_INIT_TIMER))
65
+ if(SDL_InitSubSystem(SDL_INIT_TIMER))
66
+ rb_raise(eSDLError,"Could not initialize timer system: %s",\
67
+ SDL_GetError());
68
+
69
+ delay = NUM2UINT(milliseconds);
70
+ start = SDL_GetTicks();
71
+ SDL_Delay(delay);
72
+ return INT2NUM(SDL_GetTicks() - start);
73
+ }
74
+
75
+ /*--
76
+ * From pygame code, with a few modifications:
77
+ * - takes 'accuracy' argument
78
+ * - ruby syntax for raising exceptions
79
+ *++
80
+ */
81
+ static int accurate_delay(int ticks,int accuracy)
82
+ {
83
+ int funcstart, delay;
84
+ if(ticks <= 0)
85
+ return 0;
86
+
87
+ if(!SDL_WasInit(SDL_INIT_TIMER))
88
+ {
89
+ if(SDL_InitSubSystem(SDL_INIT_TIMER))
90
+ {
91
+ rb_raise(eSDLError,"Could not initialize timer system: %s",\
92
+ SDL_GetError());
93
+ }
94
+ }
95
+
96
+ funcstart = SDL_GetTicks();
97
+ if(ticks >= accuracy)
98
+ {
99
+ delay = (ticks - 2) - (ticks % accuracy);
100
+ if(delay >= accuracy)
101
+ {
102
+ SDL_Delay(delay);
103
+ }
104
+ }
105
+ do{
106
+ delay = ticks - (SDL_GetTicks() - funcstart);
107
+ }while(delay > 0);
108
+
109
+ return SDL_GetTicks() - funcstart;
110
+ }
111
+
112
+ /*
113
+ * call-seq:
114
+ * delay( time, gran=12 ) -> Integer
115
+ *
116
+ * time:: how many milliseconds to delay.
117
+ * gran:: the granularity (in milliseconds) to assume for the system. A
118
+ * smaller value should use less CPU time, but if it's lower than the
119
+ * actual system granularity, this function might wait too long. The
120
+ * default, 12 ms, has a fairly low risk of over-waiting for many
121
+ * systems.
122
+
123
+ * Use the CPU to more accurately wait for the given period. Returns the
124
+ * actual delay time, in milliseconds. This function is more accurate than
125
+ * #wait, but is also somewhat more CPU-intensive.
126
+ *
127
+ * The Rubygame timer system will be initialized when you call this function,
128
+ * if it has not been already.
129
+ *
130
+ */
131
+ VALUE rbgm_time_delay(int argc, VALUE *argv, VALUE module)
132
+ {
133
+ int ticks, goal, accuracy;
134
+ VALUE vtime, vgran;
135
+
136
+ rb_scan_args(argc,argv,"11", &vtime, &vgran);
137
+
138
+ goal = NUM2INT(vtime);
139
+ if(goal < 0)
140
+ goal = 0;
141
+
142
+ if( RTEST(vgran) )
143
+ accuracy = NUM2INT(vgran);
144
+ else
145
+ accuracy = WORST_CLOCK_ACCURACY;
146
+
147
+ ticks = accurate_delay(goal,accuracy);
148
+
149
+ return INT2NUM(ticks);
150
+ }
151
+
152
+ /*
153
+ * call-seq:
154
+ * runtime -> Integer
155
+ *
156
+ * Return the number of milliseconds since the Rubygame timer system
157
+ * was initialized.
158
+ *
159
+ * The Rubygame timer system will be initialized when you call this function,
160
+ * if it has not been already.
161
+ */
162
+ VALUE rbgm_time_getticks( VALUE module )
163
+ {
164
+ if(!SDL_WasInit(SDL_INIT_TIMER))
165
+ if(SDL_InitSubSystem(SDL_INIT_TIMER))
166
+ rb_raise(eSDLError,"Could not initialize timer system: %s",\
167
+ SDL_GetError());
168
+ return INT2NUM(SDL_GetTicks());
169
+ }
170
+
171
+ void Rubygame_Init_Time()
172
+ {
173
+ #if 0
174
+ mRubygame = rb_define_module("Rubygame");
175
+ #endif
176
+
177
+ /* Clock class */
178
+ cClock = rb_define_class_under(mRubygame,"Clock",rb_cObject);
179
+ /* Clock class methods */
180
+ rb_define_singleton_method(cClock,"wait",rbgm_time_wait,1);
181
+ rb_define_singleton_method(cClock,"delay",rbgm_time_delay,-1);
182
+ rb_define_singleton_method(cClock,"runtime",rbgm_time_getticks,0);
183
+ }
@@ -0,0 +1,32 @@
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_TIME_H
22
+ #define _RUBYGAME_TIME_H
23
+
24
+ extern void Rubygame_Init_Time();
25
+
26
+ extern VALUE cClock;
27
+
28
+ extern VALUE rbgm_time_wait(VALUE, VALUE);
29
+ extern VALUE rbgm_time_delay(int, VALUE*, VALUE);
30
+ extern VALUE rbgm_time_getticks(VALUE);
31
+
32
+ #endif
Binary file
@@ -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
+ }