ray 0.0.0.pre2 → 0.0.1
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/.gitignore +1 -0
- data/.rspec +3 -0
- data/README.md +62 -0
- data/Rakefile +33 -23
- data/VERSION +1 -1
- data/ext/audio.c +473 -0
- data/ext/color.c +4 -4
- data/ext/event.c +25 -3
- data/ext/extconf.rb +35 -22
- data/ext/font.c +287 -0
- data/ext/image.c +682 -33
- data/ext/joystick.c +9 -9
- data/ext/ray.c +166 -55
- data/ext/ray.h +120 -9
- data/ext/ray_osx.m +161 -0
- data/ext/rect.c +31 -4
- data/lib/ray/audio.rb +52 -0
- data/lib/ray/color.rb +16 -0
- data/lib/ray/dsl.rb +1 -3
- data/lib/ray/dsl/event.rb +1 -39
- data/lib/ray/dsl/event_listener.rb +38 -0
- data/lib/ray/dsl/event_runner.rb +3 -1
- data/lib/ray/dsl/event_translator.rb +74 -8
- data/lib/ray/dsl/handler.rb +3 -33
- data/lib/ray/dsl/matcher.rb +129 -23
- data/lib/ray/font.rb +108 -0
- data/lib/ray/font_set.rb +37 -0
- data/lib/ray/game.rb +171 -34
- data/lib/ray/helper.rb +43 -5
- data/lib/ray/image.rb +90 -3
- data/lib/ray/image_set.rb +35 -0
- data/lib/ray/joystick.rb +30 -0
- data/lib/ray/music_set.rb +35 -0
- data/lib/ray/ray.rb +17 -9
- data/lib/ray/rect.rb +51 -0
- data/lib/ray/resource_set.rb +92 -0
- data/lib/ray/scene.rb +220 -51
- data/lib/ray/sound_set.rb +35 -0
- data/lib/ray/sprite.rb +184 -0
- data/psp/ext.c +4 -0
- data/samples/hello_world/hello.rb +35 -0
- data/samples/hello_world/hello_dsl.rb +24 -0
- data/samples/pong/pong.rb +128 -0
- data/samples/sokoban/level_1 +7 -0
- data/samples/sokoban/sokoban.rb +370 -0
- data/spec/ray/audio_spec.rb +146 -0
- data/spec/ray/color_spec.rb +13 -0
- data/spec/ray/event_spec.rb +57 -168
- data/spec/ray/font_spec.rb +93 -0
- data/spec/ray/image_set_spec.rb +48 -0
- data/spec/ray/image_spec.rb +130 -44
- data/spec/ray/joystick_spec.rb +13 -9
- data/spec/ray/matcher_spec.rb +32 -55
- data/spec/ray/ray_spec.rb +33 -31
- data/spec/ray/rect_spec.rb +80 -0
- data/spec/ray/resource_set_spec.rb +105 -0
- data/spec/ray/sprite_spec.rb +163 -0
- data/spec/res/VeraMono.ttf +0 -0
- data/spec/res/aqua2.bmp +0 -0
- data/spec/res/pop.wav +0 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +8 -0
- data/yard_ext.rb +91 -0
- metadata +104 -38
- data/bin/ray +0 -5
- data/bin/ray_irb +0 -4
- data/ext/SDLMain.h +0 -17
- data/ext/SDLMain.m +0 -381
- data/lib/ray/config.rb +0 -84
- data/lib/ray/dsl/converter.rb +0 -65
- data/lib/ray/dsl/listener.rb +0 -30
- data/lib/ray/dsl/type.rb +0 -58
- data/spec/ray/config_spec.rb +0 -90
- data/spec/ray/conversion_spec.rb +0 -43
- data/spec/ray/type_spec.rb +0 -17
- data/spec_runner.rb +0 -27
data/ext/color.c
CHANGED
@@ -55,7 +55,7 @@ VALUE ray_init_color(int argc, VALUE *argv, VALUE self) {
|
|
55
55
|
return Qnil;
|
56
56
|
}
|
57
57
|
|
58
|
-
/* @return [Integer] red
|
58
|
+
/* @return [Integer] red intensity */
|
59
59
|
VALUE ray_color_r(VALUE self) {
|
60
60
|
ray_color *ret;
|
61
61
|
Data_Get_Struct(self, ray_color, ret);
|
@@ -63,7 +63,7 @@ VALUE ray_color_r(VALUE self) {
|
|
63
63
|
return INT2FIX(ret->r);
|
64
64
|
}
|
65
65
|
|
66
|
-
/* @return [Integer] green
|
66
|
+
/* @return [Integer] green intensity */
|
67
67
|
VALUE ray_color_g(VALUE self) {
|
68
68
|
ray_color *ret;
|
69
69
|
Data_Get_Struct(self, ray_color, ret);
|
@@ -71,7 +71,7 @@ VALUE ray_color_g(VALUE self) {
|
|
71
71
|
return INT2FIX(ret->g);
|
72
72
|
}
|
73
73
|
|
74
|
-
/* @return [Integer] blue
|
74
|
+
/* @return [Integer] blue intensity */
|
75
75
|
VALUE ray_color_b(VALUE self) {
|
76
76
|
ray_color *ret;
|
77
77
|
Data_Get_Struct(self, ray_color, ret);
|
@@ -79,7 +79,7 @@ VALUE ray_color_b(VALUE self) {
|
|
79
79
|
return INT2FIX(ret->b);
|
80
80
|
}
|
81
81
|
|
82
|
-
/* @return [Integer] alpha
|
82
|
+
/* @return [Integer] alpha intensity */
|
83
83
|
VALUE ray_color_a(VALUE self) {
|
84
84
|
ray_color *ret;
|
85
85
|
Data_Get_Struct(self, ray_color, ret);
|
data/ext/event.c
CHANGED
@@ -26,7 +26,7 @@ VALUE ray_alloc_event(VALUE self) {
|
|
26
26
|
}
|
27
27
|
|
28
28
|
/*
|
29
|
-
Creates the event according to
|
29
|
+
Creates the event according to the next event of the stack.
|
30
30
|
*/
|
31
31
|
VALUE ray_init_event(VALUE self) {
|
32
32
|
SDL_Event *event = ray_rb2event(self);
|
@@ -105,10 +105,11 @@ VALUE ray_event_mod_keys(VALUE self) {
|
|
105
105
|
}
|
106
106
|
|
107
107
|
/*
|
108
|
-
@return [Integer, nil] A mask of the focus states, for active
|
108
|
+
@return [Integer, nil] A mask of the focus states, for active events
|
109
|
+
(when type is TYPE_ACTIVEEVENT)
|
109
110
|
*/
|
110
111
|
VALUE ray_event_focus_state(VALUE self) {
|
111
|
-
|
112
|
+
SDL_Event *ev = ray_rb2event(self);
|
112
113
|
if (ev->type != SDL_ACTIVEEVENT)
|
113
114
|
return Qnil;
|
114
115
|
return INT2FIX(ev->active.state);
|
@@ -200,6 +201,24 @@ VALUE ray_event_joystick_button(VALUE self) {
|
|
200
201
|
return Qnil;
|
201
202
|
}
|
202
203
|
|
204
|
+
/* @return [Integer, nil] The new width of the window */
|
205
|
+
VALUE ray_event_window_w(VALUE self) {
|
206
|
+
SDL_Event *ev = ray_rb2event(self);
|
207
|
+
if (ev->type == SDL_VIDEORESIZE)
|
208
|
+
return INT2FIX(ev->resize.w);
|
209
|
+
|
210
|
+
return Qnil;
|
211
|
+
}
|
212
|
+
|
213
|
+
/* @return [Integer, nil] The new height of the window */
|
214
|
+
VALUE ray_event_window_h(VALUE self) {
|
215
|
+
SDL_Event *ev = ray_rb2event(self);
|
216
|
+
if (ev->type == SDL_VIDEORESIZE)
|
217
|
+
return INT2FIX(ev->resize.h);
|
218
|
+
|
219
|
+
return Qnil;
|
220
|
+
}
|
221
|
+
|
203
222
|
void Init_ray_event() {
|
204
223
|
ray_cEvent = rb_define_class_under(ray_mRay, "Event", rb_cObject);
|
205
224
|
rb_define_alloc_func(ray_cEvent, ray_alloc_event);
|
@@ -228,6 +247,9 @@ void Init_ray_event() {
|
|
228
247
|
rb_define_method(ray_cEvent, "axis_value", ray_event_axis_value, 0);
|
229
248
|
rb_define_method(ray_cEvent, "joystick_button", ray_event_joystick_button, 0);
|
230
249
|
|
250
|
+
rb_define_method(ray_cEvent, "window_w", ray_event_window_w, 0);
|
251
|
+
rb_define_method(ray_cEvent, "window_h", ray_event_window_h, 0);
|
252
|
+
|
231
253
|
rb_define_const(ray_cEvent, "TYPE_NOEVENT", INT2FIX(SDL_NOEVENT));
|
232
254
|
rb_define_const(ray_cEvent, "TYPE_ACTIVEEVENT", INT2FIX(SDL_ACTIVEEVENT));
|
233
255
|
rb_define_const(ray_cEvent, "TYPE_KEYDOWN", INT2FIX(SDL_KEYDOWN));
|
data/ext/extconf.rb
CHANGED
@@ -36,8 +36,22 @@ def have_framework(name)
|
|
36
36
|
ret
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
39
|
+
def have_sdl_ext(name, header)
|
40
|
+
if res = have_framework(name)
|
41
|
+
ending = header.upcase.tr('/', '_').gsub(/\.H$/, "_H")
|
42
|
+
$CFLAGS << " -DHAVE_#{ending}"
|
43
|
+
|
44
|
+
return res
|
45
|
+
end
|
46
|
+
|
47
|
+
if res = have_library(name)
|
48
|
+
unless have_header(header) or have_header("SDL/#{header}")
|
49
|
+
return false
|
50
|
+
end
|
51
|
+
|
52
|
+
return res
|
53
|
+
end
|
54
|
+
end
|
41
55
|
|
42
56
|
$CFLAGS << " -pedantic -Wall -std=c99 -Wno-unused-parameter"
|
43
57
|
|
@@ -60,16 +74,25 @@ unless RUBY_PLATFORM =~ /darwin/
|
|
60
74
|
have_header("SDL/SDL_image.h") or have_header("SDL_image.h")
|
61
75
|
end
|
62
76
|
|
77
|
+
if have_library("SDL_gfx")
|
78
|
+
have_header("SDL/SDL_rotozoom.h") or have_header("SDL_rotozoom.h")
|
79
|
+
end
|
80
|
+
|
81
|
+
if have_library("SDL_ttf")
|
82
|
+
have_header("SDL/SDL_ttf.h") or have_header("SDL_ttf.h")
|
83
|
+
end
|
84
|
+
|
85
|
+
if have_library("SDL_mixer")
|
86
|
+
have_header("SDL/SDL_mixer.h") or have_header("SDL_mixer.h")
|
87
|
+
end
|
88
|
+
|
63
89
|
create_makefile("ray_ext")
|
64
90
|
|
65
|
-
data = File.read("Makefile").gsub("
|
91
|
+
data = File.read("Makefile").gsub("ray_osx.o", "")
|
66
92
|
open("Makefile", 'w') { |f| f.write(data) }
|
67
93
|
else
|
68
|
-
|
69
|
-
|
70
|
-
"implementation that does not implement ruby_run"
|
71
|
-
exit 1
|
72
|
-
end
|
94
|
+
$CFLAGS << " #{ENV["CFLAGS"]}"
|
95
|
+
$LDFLAGS << " #{ENV["LDFLAGS"]}"
|
73
96
|
|
74
97
|
$CFLAGS << " -DRAY_USE_FRAMEWORK"
|
75
98
|
|
@@ -79,20 +102,10 @@ else
|
|
79
102
|
exit 1
|
80
103
|
end
|
81
104
|
|
82
|
-
|
83
|
-
|
84
|
-
|
105
|
+
have_sdl_ext("SDL_image", "SDL_image.h")
|
106
|
+
have_sdl_ext("SDL_gfx", "SDL_rotozoom.h")
|
107
|
+
have_sdl_ext("SDL_ttf", "SDL_ttf.h")
|
108
|
+
have_sdl_ext("SDL_mixer", "SDL_mixer.h")
|
85
109
|
|
86
110
|
create_makefile("ray_ext")
|
87
111
|
end
|
88
|
-
|
89
|
-
if has_run or has_run_node
|
90
|
-
open("Makefile", 'a') do |file|
|
91
|
-
file.puts "ray: $(OBJS)"
|
92
|
-
file.puts "\t$(CC) -o ray $(OBJS) $(LIBPATH) $(DLDFLAGS) " +
|
93
|
-
"$(LOCAL_LIBS) $(LIBS) -lruby"
|
94
|
-
end
|
95
|
-
|
96
|
-
data = File.read("Makefile").gsub("all:", "all: ray")
|
97
|
-
open("Makefile", 'w') { |f| f.write(data) }
|
98
|
-
end
|
data/ext/font.c
ADDED
@@ -0,0 +1,287 @@
|
|
1
|
+
#include "ray.h"
|
2
|
+
|
3
|
+
#ifdef HAVE_SDL_TTF
|
4
|
+
|
5
|
+
enum ray_encoding {
|
6
|
+
RAY_ENCODING_LATIN1,
|
7
|
+
RAY_ENCODING_UTF8,
|
8
|
+
RAY_ENCODING_UNICODE
|
9
|
+
};
|
10
|
+
|
11
|
+
VALUE ray_cFont = Qnil;
|
12
|
+
|
13
|
+
TTF_Font *ray_rb2font(VALUE object) {
|
14
|
+
if (!RAY_IS_A(object, ray_cFont)) {
|
15
|
+
rb_raise(rb_eTypeError, "Can't convert %s into Ray::Font",
|
16
|
+
RAY_OBJ_CLASSNAME(object));
|
17
|
+
}
|
18
|
+
|
19
|
+
ray_font *ptr = NULL;
|
20
|
+
Data_Get_Struct(object, ray_font, ptr);
|
21
|
+
|
22
|
+
return ptr->font;
|
23
|
+
}
|
24
|
+
|
25
|
+
void ray_free_font(ray_font *font) {
|
26
|
+
if (font->font) TTF_CloseFont(font->font);
|
27
|
+
free(font);
|
28
|
+
}
|
29
|
+
|
30
|
+
VALUE ray_alloc_font(VALUE self) {
|
31
|
+
ray_font *ptr = malloc(sizeof(ray_font));
|
32
|
+
VALUE ret = Data_Wrap_Struct(self, 0, ray_free_font, ptr);
|
33
|
+
|
34
|
+
ptr->font = NULL;
|
35
|
+
return ret;
|
36
|
+
}
|
37
|
+
|
38
|
+
void ray_init_font_with_filename(VALUE self, VALUE filename, int size) {
|
39
|
+
ray_font *font = NULL;
|
40
|
+
Data_Get_Struct(self, ray_font, font);
|
41
|
+
|
42
|
+
font->font = TTF_OpenFont(StringValuePtr(filename), size);
|
43
|
+
if (!font->font) {
|
44
|
+
rb_raise(rb_eRuntimeError, "Could not load the font (%s)",
|
45
|
+
TTF_GetError());
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
void ray_init_font_with_io(VALUE self, VALUE io, int size) {
|
50
|
+
ray_font *font = NULL;
|
51
|
+
Data_Get_Struct(self, ray_font, font);
|
52
|
+
|
53
|
+
VALUE string = rb_funcall2(io, RAY_METH("read"), 0, NULL);
|
54
|
+
char *content = StringValuePtr(string);
|
55
|
+
|
56
|
+
SDL_RWops *data = SDL_RWFromMem(content, (int)RSTRING_LEN(string));
|
57
|
+
if (!data) {
|
58
|
+
rb_raise(rb_eRuntimeError, "Could not create image data (%s)",
|
59
|
+
SDL_GetError());
|
60
|
+
}
|
61
|
+
|
62
|
+
font->font = TTF_OpenFontRW(data, 1, size);
|
63
|
+
if (!font->font) {
|
64
|
+
printf("Could not load the font (%s)\n", TTF_GetError());
|
65
|
+
rb_raise(rb_eRuntimeError, "Could not load the font (%s)",
|
66
|
+
TTF_GetError());
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
/*
|
71
|
+
Creates a new font.
|
72
|
+
|
73
|
+
@param [String, #read] arg Filename of the font or IO object containing
|
74
|
+
the content of the font.
|
75
|
+
@param [Integer] size Point size (based on 72DPI).
|
76
|
+
*/
|
77
|
+
VALUE ray_init_font(VALUE self, VALUE arg, VALUE size) {
|
78
|
+
if (rb_respond_to(arg, RAY_METH("to_str")))
|
79
|
+
ray_init_font_with_filename(self, rb_String(arg), NUM2INT(size));
|
80
|
+
else if (rb_respond_to(arg, RAY_METH("read")))
|
81
|
+
ray_init_font_with_io(self, arg, NUM2INT(size));
|
82
|
+
else {
|
83
|
+
rb_raise(rb_eTypeError, "Can't convert %s into String",
|
84
|
+
RAY_OBJ_CLASSNAME(arg));
|
85
|
+
}
|
86
|
+
|
87
|
+
return Qnil;
|
88
|
+
}
|
89
|
+
|
90
|
+
/*
|
91
|
+
@return [Integer] Bitmask describing the style of the font.
|
92
|
+
STYLE_NORMAL for a normal font.
|
93
|
+
*/
|
94
|
+
VALUE ray_font_style(VALUE self) {
|
95
|
+
TTF_Font *font = ray_rb2font(self);
|
96
|
+
return INT2FIX(TTF_GetFontStyle(font));
|
97
|
+
}
|
98
|
+
|
99
|
+
/* Sets the font style. */
|
100
|
+
VALUE ray_font_set_style(VALUE self, VALUE style) {
|
101
|
+
TTF_Font *font = ray_rb2font(self);
|
102
|
+
TTF_SetFontStyle(font, NUM2INT(style));
|
103
|
+
return style;
|
104
|
+
}
|
105
|
+
|
106
|
+
/* @return [Integer] the height of the font */
|
107
|
+
VALUE ray_font_height(VALUE self) {
|
108
|
+
TTF_Font *font = ray_rb2font(self);
|
109
|
+
return INT2FIX(TTF_FontHeight(font));
|
110
|
+
}
|
111
|
+
|
112
|
+
/* @return [Integer] the recommended spacing between lines for this font */
|
113
|
+
VALUE ray_font_line_skip(VALUE self) {
|
114
|
+
TTF_Font *font = ray_rb2font(self);
|
115
|
+
return INT2FIX(TTF_FontLineSkip(font));
|
116
|
+
}
|
117
|
+
|
118
|
+
/*
|
119
|
+
@overload size_of(text, encoding = nil)
|
120
|
+
@param [Symbol, nil] encoding nil (for Latin1), :latin1, :utf8, or :unicode.
|
121
|
+
@return [Ray::Rect] Size of the text.
|
122
|
+
*/
|
123
|
+
VALUE ray_font_size_of(int argc, VALUE *argv, VALUE self) {
|
124
|
+
TTF_Font *font = ray_rb2font(self);
|
125
|
+
|
126
|
+
VALUE string = Qnil, encoding = Qnil;
|
127
|
+
rb_scan_args(argc, argv, "11", &string, &encoding);
|
128
|
+
|
129
|
+
char *c_string = StringValuePtr(string);
|
130
|
+
|
131
|
+
int w, h;
|
132
|
+
|
133
|
+
if (NIL_P(encoding) || encoding == RAY_SYM("latin1"))
|
134
|
+
TTF_SizeText(font, c_string, &w, &h);
|
135
|
+
else if (encoding == RAY_SYM("utf8"))
|
136
|
+
TTF_SizeUTF8(font, c_string, &w, &h);
|
137
|
+
else if (encoding == RAY_SYM("unicode"))
|
138
|
+
TTF_SizeUNICODE(font, (uint16_t*)c_string, &w, &h);
|
139
|
+
else
|
140
|
+
rb_raise(rb_eArgError, "Invalid encoding.");
|
141
|
+
|
142
|
+
SDL_Rect rect = {0, 0, w, h};
|
143
|
+
return ray_rect2rb(rect);
|
144
|
+
}
|
145
|
+
|
146
|
+
/*
|
147
|
+
@overload draw(string, opts = {})
|
148
|
+
@param [String] string The string which should be drawn.
|
149
|
+
|
150
|
+
@option opts [Symbol] :mode Drawing mode. :solid (fastest),
|
151
|
+
:shaded (requires a background set
|
152
|
+
with :background) or :blended
|
153
|
+
@option opts [Symbol] :encoding :latin1, :utf8, or :unicode. Defaults
|
154
|
+
to :latin1.
|
155
|
+
@option opts [Ray::Color] :color Color to draw the text in. Defaults to
|
156
|
+
white.
|
157
|
+
@option opts [Ray::Color] :background The background color in :shaded mode.
|
158
|
+
defaults to black.
|
159
|
+
@option opts [Ray::Image] :on The image to draw on. In this case,
|
160
|
+
it will directly draw instead of returning
|
161
|
+
an image containing nothing but the string.
|
162
|
+
@option opts [Ray::Rect, Array<Integer>] :to, :at where to draw on the image.
|
163
|
+
|
164
|
+
@return The surface it drew the string on.
|
165
|
+
*/
|
166
|
+
VALUE ray_font_draw(int argc, VALUE *argv, VALUE self) {
|
167
|
+
VALUE string, hash;
|
168
|
+
rb_scan_args(argc, argv, "11", &string, &hash);
|
169
|
+
|
170
|
+
if (NIL_P(hash))
|
171
|
+
hash = rb_hash_new();
|
172
|
+
|
173
|
+
TTF_Font *font = ray_rb2font(self);
|
174
|
+
|
175
|
+
char *c_string = StringValuePtr(string);
|
176
|
+
|
177
|
+
/* solid, shaded, blended */
|
178
|
+
VALUE drawing_mode = rb_hash_aref(hash, RAY_SYM("mode"));
|
179
|
+
|
180
|
+
VALUE encoding = rb_hash_aref(hash, RAY_SYM("encoding"));
|
181
|
+
int c_encoding = 0;
|
182
|
+
|
183
|
+
if (NIL_P(encoding) || encoding == RAY_SYM("latin1"))
|
184
|
+
c_encoding = RAY_ENCODING_LATIN1;
|
185
|
+
else if (encoding == RAY_SYM("utf8"))
|
186
|
+
c_encoding = RAY_ENCODING_UTF8;
|
187
|
+
else if (encoding == RAY_SYM("unicode"))
|
188
|
+
c_encoding = RAY_ENCODING_UNICODE;
|
189
|
+
else
|
190
|
+
rb_raise(rb_eArgError, "Invalid encoding.");
|
191
|
+
|
192
|
+
VALUE rb_color = rb_hash_aref(hash, RAY_SYM("color"));
|
193
|
+
ray_color c_color = {255, 255, 255, 255};
|
194
|
+
if (!NIL_P(rb_color))
|
195
|
+
c_color = ray_rb2col(rb_color);
|
196
|
+
|
197
|
+
SDL_Color color = {c_color.r, c_color.g, c_color.b};
|
198
|
+
|
199
|
+
SDL_Surface *surface = NULL;
|
200
|
+
|
201
|
+
if (NIL_P(drawing_mode) || drawing_mode == RAY_SYM("solid")) {
|
202
|
+
if (c_encoding == RAY_ENCODING_LATIN1)
|
203
|
+
surface = TTF_RenderText_Solid(font, c_string, color);
|
204
|
+
else if (c_encoding == RAY_ENCODING_UTF8)
|
205
|
+
surface = TTF_RenderUTF8_Solid(font, c_string, color);
|
206
|
+
else
|
207
|
+
surface = TTF_RenderUNICODE_Solid(font, (uint16_t*)c_string, color);
|
208
|
+
}
|
209
|
+
else if (drawing_mode == RAY_SYM("shaded")) {
|
210
|
+
VALUE rb_bg = rb_hash_aref(hash, RAY_SYM("background"));
|
211
|
+
ray_color c_bg = {0, 0, 0, 255};
|
212
|
+
if (!NIL_P(rb_bg))
|
213
|
+
c_bg = ray_rb2col(rb_bg);
|
214
|
+
SDL_Color bg = {c_bg.r, c_bg.g, c_bg.b};
|
215
|
+
|
216
|
+
if (c_encoding == RAY_ENCODING_LATIN1)
|
217
|
+
surface = TTF_RenderText_Shaded(font, c_string, color, bg);
|
218
|
+
else if (c_encoding == RAY_ENCODING_UTF8)
|
219
|
+
surface = TTF_RenderUTF8_Shaded(font, c_string, color, bg);
|
220
|
+
else
|
221
|
+
surface = TTF_RenderUNICODE_Shaded(font, (uint16_t*)c_string, color, bg);
|
222
|
+
}
|
223
|
+
else if (drawing_mode == RAY_SYM("blended")) {
|
224
|
+
if (c_encoding == RAY_ENCODING_LATIN1)
|
225
|
+
surface = TTF_RenderText_Blended(font, c_string, color);
|
226
|
+
else if (c_encoding == RAY_ENCODING_UTF8)
|
227
|
+
surface = TTF_RenderUTF8_Blended(font, c_string, color);
|
228
|
+
else
|
229
|
+
surface = TTF_RenderUNICODE_Blended(font, (uint16_t*)c_string, color);
|
230
|
+
}
|
231
|
+
else
|
232
|
+
rb_raise(rb_eArgError, "Invalid drawing mode.");
|
233
|
+
|
234
|
+
if (!surface) {
|
235
|
+
rb_raise(rb_eRuntimeError, "Could not drawstring (%s)",
|
236
|
+
TTF_GetError());
|
237
|
+
}
|
238
|
+
|
239
|
+
VALUE on = rb_hash_aref(hash, RAY_SYM("on"));
|
240
|
+
if (NIL_P(on))
|
241
|
+
return ray_create_gc_image(surface);
|
242
|
+
|
243
|
+
SDL_Surface *target = ray_rb2surface(on);
|
244
|
+
|
245
|
+
VALUE rb_rect = rb_hash_aref(hash, RAY_SYM("at"));
|
246
|
+
if (NIL_P(rb_rect))
|
247
|
+
rb_rect = rb_hash_aref(hash, RAY_SYM("to"));
|
248
|
+
|
249
|
+
SDL_Rect rect;
|
250
|
+
|
251
|
+
if (RTEST(rb_obj_is_kind_of(rb_rect, ray_cRect)))
|
252
|
+
rect = ray_rb2rect(rb_rect);
|
253
|
+
else if (RTEST(rb_obj_is_kind_of(rb_rect, rb_cArray)))
|
254
|
+
rect = ray_rb2rect(rb_apply(ray_cRect, RAY_METH("new"), rb_rect));
|
255
|
+
else {
|
256
|
+
rb_raise(rb_eTypeError, "Can't convert %s into Ray::Rect",
|
257
|
+
RAY_OBJ_CLASSNAME(rb_rect));
|
258
|
+
}
|
259
|
+
|
260
|
+
SDL_BlitSurface(surface, NULL, target, &rect);
|
261
|
+
SDL_FreeSurface(surface);
|
262
|
+
|
263
|
+
return on;
|
264
|
+
}
|
265
|
+
|
266
|
+
void Init_ray_font() {
|
267
|
+
ray_cFont = rb_define_class_under(ray_mRay, "Font", rb_cObject);
|
268
|
+
rb_define_alloc_func(ray_cFont, ray_alloc_font);
|
269
|
+
rb_define_method(ray_cFont, "initialize", ray_init_font, 2);
|
270
|
+
|
271
|
+
rb_define_method(ray_cFont, "style", ray_font_style, 0);
|
272
|
+
rb_define_method(ray_cFont, "style=", ray_font_set_style, 1);
|
273
|
+
|
274
|
+
rb_define_method(ray_cFont, "height", ray_font_height, 0);
|
275
|
+
rb_define_method(ray_cFont, "line_skip", ray_font_line_skip, 0);
|
276
|
+
|
277
|
+
rb_define_method(ray_cFont, "size_of", ray_font_size_of, -1);
|
278
|
+
|
279
|
+
rb_define_method(ray_cFont, "draw", ray_font_draw, -1);
|
280
|
+
|
281
|
+
rb_define_const(ray_cFont, "STYLE_NORMAL", INT2FIX(TTF_STYLE_NORMAL));
|
282
|
+
rb_define_const(ray_cFont, "STYLE_ITALIC", INT2FIX(TTF_STYLE_ITALIC));
|
283
|
+
rb_define_const(ray_cFont, "STYLE_BOLD", INT2FIX(TTF_STYLE_BOLD));
|
284
|
+
rb_define_const(ray_cFont, "STYLE_UNDERLINE", INT2FIX(TTF_STYLE_UNDERLINE));
|
285
|
+
}
|
286
|
+
|
287
|
+
#endif
|