sfml3-rb 0.2.2 → 0.3.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.
- checksums.yaml +4 -4
- data/.yardopts +9 -0
- data/CHANGELOG.md +67 -16
- data/README.md +123 -32
- data/TODO.md +18 -11
- data/ext/audio/audio_enums.c +58 -20
- data/ext/audio/listener.c +89 -6
- data/ext/audio/music.c +212 -5
- data/ext/audio/sound.c +218 -9
- data/ext/audio/sound_buffer.c +197 -47
- data/ext/audio/sound_buffer_recorder.c +90 -18
- data/ext/audio/sound_recorder.c +188 -58
- data/ext/audio/sound_source_cone.c +127 -33
- data/ext/audio/sound_stream.c +204 -21
- data/ext/core/exceptions.c +10 -8
- data/ext/core/unicode.c +12 -2
- data/ext/ext.c +8 -0
- data/ext/graphics/blend_mode.c +218 -60
- data/ext/graphics/circle.c +300 -16
- data/ext/graphics/color.c +253 -94
- data/ext/graphics/drawable.c +16 -4
- data/ext/graphics/font.c +144 -25
- data/ext/graphics/glyph.c +38 -8
- data/ext/graphics/image.c +205 -41
- data/ext/graphics/polygon.c +317 -30
- data/ext/graphics/rect.c +225 -60
- data/ext/graphics/rectangle.c +307 -35
- data/ext/graphics/render_state.c +124 -12
- data/ext/graphics/render_texture.c +191 -14
- data/ext/graphics/render_window.c +55 -0
- data/ext/graphics/render_window.h +10 -0
- data/ext/graphics/shader.c +289 -17
- data/ext/graphics/shape.c +265 -32
- data/ext/graphics/sprite.c +245 -30
- data/ext/graphics/stencil_mode.c +163 -46
- data/ext/graphics/target.c +121 -43
- data/ext/graphics/target.h +31 -17
- data/ext/graphics/text.c +339 -19
- data/ext/graphics/texture.c +291 -6
- data/ext/graphics/transform.c +178 -5
- data/ext/graphics/transformable.c +127 -12
- data/ext/graphics/vertex.c +98 -6
- data/ext/graphics/vertex_array.c +142 -21
- data/ext/graphics/vertex_buffer.c +154 -12
- data/ext/graphics/view.c +140 -6
- data/ext/network/ftp.c +278 -12
- data/ext/network/http.c +179 -44
- data/ext/network/ip_address.c +127 -35
- data/ext/network/network_enums.c +248 -141
- data/ext/network/packet.c +280 -41
- data/ext/network/socket_selector.c +98 -21
- data/ext/network/tcp_listener.c +82 -18
- data/ext/network/tcp_socket.c +135 -27
- data/ext/network/udp_socket.c +129 -28
- data/ext/ports.rb +7 -0
- data/ext/system/buffer.c +47 -16
- data/ext/system/clock.c +77 -12
- data/ext/system/input_stream.c +113 -51
- data/ext/system/sleep.c +10 -2
- data/ext/system/time.c +182 -40
- data/ext/system/vec2.c +166 -39
- data/ext/system/vec3.c +177 -39
- data/ext/window/clipboard.c +47 -17
- data/ext/window/context.c +66 -13
- data/ext/window/context_settings.c +132 -42
- data/ext/window/cursor.c +45 -9
- data/ext/window/event.c +164 -53
- data/ext/window/joystick.c +69 -3
- data/ext/window/keyboard.c +168 -116
- data/ext/window/mouse.c +64 -13
- data/ext/window/sensor.c +28 -2
- data/ext/window/touch.c +32 -12
- data/ext/window/video_mode.c +93 -31
- data/ext/window/vulkan.c +34 -6
- data/ext/window/window.c +228 -229
- data/ext/window/window.h +4 -4
- data/ext/window/window_base.c +251 -0
- data/ext/window/window_base.h +43 -0
- data/ext/window/window_base.inc +236 -0
- data/lib/sfml/version.rb +1 -1
- data/sig/audio/audio_enums.rbs +30 -0
- data/sig/audio/listener.rbs +16 -0
- data/sig/audio/music.rbs +56 -0
- data/sig/audio/sound.rbs +51 -0
- data/sig/audio/sound_buffer.rbs +17 -0
- data/sig/audio/sound_buffer_recorder.rbs +14 -0
- data/sig/audio/sound_recorder.rbs +17 -0
- data/sig/audio/sound_source_cone.rbs +14 -0
- data/sig/audio/sound_stream.rbs +51 -0
- data/sig/graphics/blend_mode.rbs +29 -0
- data/sig/graphics/circle.rbs +44 -0
- data/sig/graphics/color.rbs +39 -0
- data/sig/graphics/drawable.rbs +5 -0
- data/sig/graphics/font.rbs +20 -0
- data/sig/graphics/glyph.rbs +7 -0
- data/sig/graphics/image.rbs +22 -0
- data/sig/graphics/polygon.rbs +42 -0
- data/sig/graphics/rect.rbs +33 -0
- data/sig/graphics/rectangle.rbs +42 -0
- data/sig/graphics/render_state.rbs +21 -0
- data/sig/graphics/render_target.rbs +18 -0
- data/sig/graphics/render_texture.rbs +39 -0
- data/sig/graphics/render_window.rbs +7 -0
- data/sig/graphics/shader.rbs +39 -0
- data/sig/graphics/shape.rbs +38 -0
- data/sig/graphics/sprite.rbs +34 -0
- data/sig/graphics/stencil_mode.rbs +18 -0
- data/sig/graphics/target.rbs +8 -0
- data/sig/graphics/text.rbs +48 -0
- data/sig/graphics/texture.rbs +34 -0
- data/sig/graphics/transform.rbs +37 -0
- data/sig/graphics/transformable.rbs +25 -0
- data/sig/graphics/vertex.rbs +17 -0
- data/sig/graphics/vertex_array.rbs +17 -0
- data/sig/graphics/vertex_buffer.rbs +22 -0
- data/sig/graphics/view.rbs +23 -0
- data/sig/network/ftp.rbs +46 -0
- data/sig/network/http.rbs +27 -0
- data/sig/network/ip_address.rbs +22 -0
- data/sig/network/network_enums.rbs +95 -0
- data/sig/network/packet.rbs +40 -0
- data/sig/network/socket_selector.rbs +14 -0
- data/sig/network/tcp_listener.rbs +13 -0
- data/sig/network/tcp_socket.rbs +18 -0
- data/sig/network/udp_socket.rbs +17 -0
- data/sig/sfml/version.rbs +3 -0
- data/sig/system/buffer.rbs +11 -0
- data/sig/system/clock.rbs +13 -0
- data/sig/system/input_stream.rbs +7 -0
- data/sig/system/sleep.rbs +3 -0
- data/sig/system/time.rbs +28 -0
- data/sig/system/vec2.rbs +26 -0
- data/sig/system/vec3.rbs +27 -0
- data/sig/window/clipboard.rbs +8 -0
- data/sig/window/context.rbs +11 -0
- data/sig/window/context_settings.rbs +20 -0
- data/sig/window/cursor.rbs +6 -0
- data/sig/window/event.rbs +20 -0
- data/sig/window/joystick.rbs +15 -0
- data/sig/window/keyboard.rbs +10 -0
- data/sig/window/mouse.rbs +9 -0
- data/sig/window/sensor.rbs +8 -0
- data/sig/window/touch.rbs +6 -0
- data/sig/window/video_mode.rbs +16 -0
- data/sig/window/vulkan.rbs +7 -0
- data/sig/window/window.rbs +34 -0
- data/sig/window/window_base.rbs +33 -0
- metadata +76 -3
data/ext/graphics/font.c
CHANGED
|
@@ -10,17 +10,16 @@
|
|
|
10
10
|
|
|
11
11
|
static VALUE rb_cFont;
|
|
12
12
|
|
|
13
|
-
static void Font_free(void
|
|
13
|
+
static void Font_free(void* ptr) {
|
|
14
14
|
sfFont_destroy(ptr);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
static const rb_data_type_t Font_data_type = {
|
|
18
18
|
.wrap_struct_name = "SFML::Font",
|
|
19
19
|
.function = {.dmark = NULL, .dfree = Font_free, .dsize = NULL},
|
|
20
|
-
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
21
|
-
};
|
|
20
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
22
21
|
|
|
23
|
-
static VALUE Font_wrap(VALUE klass, sfFont
|
|
22
|
+
static VALUE Font_wrap(VALUE klass, sfFont* font) {
|
|
24
23
|
if (font == NULL) {
|
|
25
24
|
rb_raise(rb_eRuntimeError, "failed to load font");
|
|
26
25
|
}
|
|
@@ -28,30 +27,69 @@ static VALUE Font_wrap(VALUE klass, sfFont *font) {
|
|
|
28
27
|
return TypedData_Wrap_Struct(klass, &Font_data_type, font);
|
|
29
28
|
}
|
|
30
29
|
|
|
30
|
+
/* call-seq:
|
|
31
|
+
* Font.from_file(path) -> Font
|
|
32
|
+
*
|
|
33
|
+
* Loads a font from the font file at +filename+.
|
|
34
|
+
*
|
|
35
|
+
* @return [Font]
|
|
36
|
+
* @raise [RuntimeError] if the file cannot be loaded
|
|
37
|
+
*/
|
|
31
38
|
static VALUE Font_from_file(VALUE klass, VALUE rb_path) {
|
|
32
39
|
return Font_wrap(klass, sfFont_createFromFile(StringValueCStr(rb_path)));
|
|
33
40
|
}
|
|
34
41
|
|
|
42
|
+
/* call-seq:
|
|
43
|
+
* Font.from_memory(data) -> Font
|
|
44
|
+
*
|
|
45
|
+
* Loads a font from an in-memory font file buffer.
|
|
46
|
+
*
|
|
47
|
+
* @return [Font]
|
|
48
|
+
* @raise [RuntimeError] if the font data cannot be parsed
|
|
49
|
+
*/
|
|
35
50
|
static VALUE Font_from_memory(VALUE klass, VALUE rb_data) {
|
|
36
51
|
StringValue(rb_data);
|
|
37
52
|
|
|
38
|
-
return Font_wrap(klass,
|
|
53
|
+
return Font_wrap(klass,
|
|
54
|
+
sfFont_createFromMemory(RSTRING_PTR(rb_data), (size_t)RSTRING_LEN(rb_data)));
|
|
39
55
|
}
|
|
40
56
|
|
|
57
|
+
/* call-seq:
|
|
58
|
+
* Font.from_stream(stream) -> Font
|
|
59
|
+
*
|
|
60
|
+
* +stream+ is any object responding to the InputStream protocol (see
|
|
61
|
+
* InputStream).
|
|
62
|
+
*
|
|
63
|
+
* @return [Font]
|
|
64
|
+
* @raise [RuntimeError] if the font cannot be loaded
|
|
65
|
+
*/
|
|
41
66
|
static VALUE Font_from_stream(VALUE klass, VALUE rb_stream) {
|
|
42
67
|
VALUE holder = Qnil;
|
|
43
|
-
sfInputStream
|
|
68
|
+
sfInputStream* stream = input_stream_from_rb(rb_stream, &holder);
|
|
44
69
|
|
|
45
|
-
(void)
|
|
70
|
+
(void)holder;
|
|
46
71
|
|
|
47
72
|
return Font_wrap(klass, sfFont_createFromStream(stream));
|
|
48
73
|
}
|
|
49
74
|
|
|
75
|
+
/* call-seq: copy -> Font
|
|
76
|
+
*
|
|
77
|
+
* Returns a deep copy of the object.
|
|
78
|
+
*
|
|
79
|
+
* @return [Font] an independent copy
|
|
80
|
+
*/
|
|
50
81
|
static VALUE Font_copy(VALUE self) {
|
|
51
82
|
return Font_wrap(Get_Klass_Font(), sfFont_copy(Get_Font_Struct(self)));
|
|
52
83
|
}
|
|
53
84
|
|
|
54
|
-
|
|
85
|
+
/* call-seq:
|
|
86
|
+
* glyph(codepoint, size, bold=false, outline_thickness=0) -> Glyph
|
|
87
|
+
*
|
|
88
|
+
* Returns the glyph for +codepoint+ at the given +character_size+.
|
|
89
|
+
*
|
|
90
|
+
* @return [Glyph]
|
|
91
|
+
*/
|
|
92
|
+
static VALUE Font_get_glyph(int argc, VALUE* argv, VALUE self) {
|
|
55
93
|
VALUE rb_codepoint, rb_size, rb_bold, rb_outline;
|
|
56
94
|
bool bold = false;
|
|
57
95
|
float outline = 0;
|
|
@@ -66,58 +104,139 @@ static VALUE Font_get_glyph(int argc, VALUE *argv, VALUE self) {
|
|
|
66
104
|
outline = NUM2DBL(rb_outline);
|
|
67
105
|
}
|
|
68
106
|
|
|
69
|
-
return glyph_from_c(sfFont_getGlyph(Get_Font_Struct(self), (uint32_t)
|
|
70
|
-
(unsigned int)
|
|
107
|
+
return glyph_from_c(sfFont_getGlyph(Get_Font_Struct(self), (uint32_t)NUM2UINT(rb_codepoint),
|
|
108
|
+
(unsigned int)NUM2UINT(rb_size), bold, outline));
|
|
71
109
|
}
|
|
72
110
|
|
|
111
|
+
/* call-seq: has_glyph?(codepoint) -> true or false
|
|
112
|
+
*
|
|
113
|
+
* Returns +true+ if the font contains a glyph for +codepoint+.
|
|
114
|
+
*
|
|
115
|
+
* @return [Boolean] whether this font has a glyph for the given Unicode
|
|
116
|
+
* codepoint
|
|
117
|
+
*/
|
|
73
118
|
static VALUE Font_has_glyph(VALUE self, VALUE rb_codepoint) {
|
|
74
|
-
return BOOL2RB(sfFont_hasGlyph(Get_Font_Struct(self), (uint32_t)
|
|
119
|
+
return BOOL2RB(sfFont_hasGlyph(Get_Font_Struct(self), (uint32_t)NUM2UINT(rb_codepoint)));
|
|
75
120
|
}
|
|
76
121
|
|
|
122
|
+
/* call-seq: kerning(first, second, size) -> Float
|
|
123
|
+
*
|
|
124
|
+
* Returns the kerning between two code points at the given size.
|
|
125
|
+
*
|
|
126
|
+
* @return [Float] the kerning offset between two consecutive glyphs at the
|
|
127
|
+
* given character size
|
|
128
|
+
*/
|
|
77
129
|
static VALUE Font_get_kerning(VALUE self, VALUE rb_first, VALUE rb_second, VALUE rb_size) {
|
|
78
|
-
return DBL2NUM(sfFont_getKerning(Get_Font_Struct(self), (uint32_t)
|
|
79
|
-
(uint32_t)
|
|
130
|
+
return DBL2NUM(sfFont_getKerning(Get_Font_Struct(self), (uint32_t)NUM2UINT(rb_first),
|
|
131
|
+
(uint32_t)NUM2UINT(rb_second),
|
|
132
|
+
(unsigned int)NUM2UINT(rb_size)));
|
|
80
133
|
}
|
|
81
134
|
|
|
135
|
+
/* call-seq: bold_kerning(first, second, size) -> Float
|
|
136
|
+
*
|
|
137
|
+
* Returns the kerning of the bold variant between two code points.
|
|
138
|
+
*
|
|
139
|
+
* @return [Float] the kerning offset between two consecutive bold glyphs at
|
|
140
|
+
* the given character size
|
|
141
|
+
*/
|
|
82
142
|
static VALUE Font_get_bold_kerning(VALUE self, VALUE rb_first, VALUE rb_second, VALUE rb_size) {
|
|
83
|
-
return DBL2NUM(sfFont_getBoldKerning(Get_Font_Struct(self), (uint32_t)
|
|
84
|
-
(uint32_t)
|
|
143
|
+
return DBL2NUM(sfFont_getBoldKerning(Get_Font_Struct(self), (uint32_t)NUM2UINT(rb_first),
|
|
144
|
+
(uint32_t)NUM2UINT(rb_second),
|
|
145
|
+
(unsigned int)NUM2UINT(rb_size)));
|
|
85
146
|
}
|
|
86
147
|
|
|
148
|
+
/* call-seq: line_spacing(size) -> Float
|
|
149
|
+
*
|
|
150
|
+
* Returns the line spacing for the given character size.
|
|
151
|
+
*
|
|
152
|
+
* @return [Float] the distance between two consecutive lines at the given
|
|
153
|
+
* character size
|
|
154
|
+
*/
|
|
87
155
|
static VALUE Font_get_line_spacing(VALUE self, VALUE rb_size) {
|
|
88
|
-
return DBL2NUM(sfFont_getLineSpacing(Get_Font_Struct(self), (unsigned int)
|
|
156
|
+
return DBL2NUM(sfFont_getLineSpacing(Get_Font_Struct(self), (unsigned int)NUM2UINT(rb_size)));
|
|
89
157
|
}
|
|
90
158
|
|
|
159
|
+
/* call-seq: underline_position(size) -> Float
|
|
160
|
+
*
|
|
161
|
+
* Returns the position of the underline for the given size.
|
|
162
|
+
*
|
|
163
|
+
* @return [Float] the position of the underline, relative to the baseline,
|
|
164
|
+
* at the given character size
|
|
165
|
+
*/
|
|
91
166
|
static VALUE Font_get_underline_position(VALUE self, VALUE rb_size) {
|
|
92
|
-
return DBL2NUM(
|
|
167
|
+
return DBL2NUM(
|
|
168
|
+
sfFont_getUnderlinePosition(Get_Font_Struct(self), (unsigned int)NUM2UINT(rb_size)));
|
|
93
169
|
}
|
|
94
170
|
|
|
171
|
+
/* call-seq: underline_thickness(size) -> Float
|
|
172
|
+
*
|
|
173
|
+
* Returns the thickness of the underline for the given size.
|
|
174
|
+
*
|
|
175
|
+
* @return [Float] the thickness of the underline at the given character size
|
|
176
|
+
*/
|
|
95
177
|
static VALUE Font_get_underline_thickness(VALUE self, VALUE rb_size) {
|
|
96
|
-
return DBL2NUM(
|
|
178
|
+
return DBL2NUM(
|
|
179
|
+
sfFont_getUnderlineThickness(Get_Font_Struct(self), (unsigned int)NUM2UINT(rb_size)));
|
|
97
180
|
}
|
|
98
181
|
|
|
182
|
+
/* call-seq: texture(size) -> Texture
|
|
183
|
+
*
|
|
184
|
+
* Returns the texture atlas holding rendered glyphs for the given size.
|
|
185
|
+
*
|
|
186
|
+
* @return [Texture] the texture atlas holding rendered glyphs for the given
|
|
187
|
+
* character size. Owned by the font; do not modify or free it directly.
|
|
188
|
+
*/
|
|
99
189
|
static VALUE Font_get_texture(VALUE self, VALUE rb_size) {
|
|
100
|
-
return texture_from_borrowed(
|
|
101
|
-
|
|
190
|
+
return texture_from_borrowed(
|
|
191
|
+
sfFont_getTexture((sfFont*)Get_Font_Struct(self), (unsigned int)NUM2UINT(rb_size)));
|
|
102
192
|
}
|
|
103
193
|
|
|
194
|
+
/* call-seq:
|
|
195
|
+
* smooth=(value) -> Boolean
|
|
196
|
+
*
|
|
197
|
+
* Enables or disables smooth rendering.
|
|
198
|
+
*
|
|
199
|
+
* @return [Boolean] +value+
|
|
200
|
+
*/
|
|
104
201
|
static VALUE Font_set_smooth(VALUE self, VALUE rb_smooth) {
|
|
105
|
-
sfFont_setSmooth((sfFont
|
|
202
|
+
sfFont_setSmooth((sfFont*)Get_Font_Struct(self), RTEST(rb_smooth));
|
|
106
203
|
return rb_smooth;
|
|
107
204
|
}
|
|
108
205
|
|
|
206
|
+
/* call-seq: smooth? -> true or false
|
|
207
|
+
*
|
|
208
|
+
* Returns +true+ if smooth rendering is enabled.
|
|
209
|
+
*
|
|
210
|
+
* @return [Boolean]
|
|
211
|
+
*/
|
|
109
212
|
static VALUE Font_is_smooth(VALUE self) {
|
|
110
213
|
return BOOL2RB(sfFont_isSmooth(Get_Font_Struct(self)));
|
|
111
214
|
}
|
|
112
215
|
|
|
216
|
+
/* call-seq: info -> String
|
|
217
|
+
*
|
|
218
|
+
* Returns the font's family name.
|
|
219
|
+
*
|
|
220
|
+
* @return [String] the font family name
|
|
221
|
+
*/
|
|
113
222
|
static VALUE Font_get_info(VALUE self) {
|
|
114
223
|
sfFontInfo info = sfFont_getInfo(Get_Font_Struct(self));
|
|
115
224
|
|
|
116
225
|
return rb_str_new_cstr(info.family != NULL ? info.family : "");
|
|
117
226
|
}
|
|
118
227
|
|
|
119
|
-
|
|
120
|
-
|
|
228
|
+
static VALUE Font_alloc(VALUE klass) {
|
|
229
|
+
(void)klass;
|
|
230
|
+
rb_raise(rb_eNotImpError, "use Font.from_file, Font.from_memory or Font.from_stream");
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/* Document-class: SFML::Font
|
|
234
|
+
* A font face used to render text, loaded from a file, memory buffer or
|
|
235
|
+
* stream. Glyphs are rasterized and cached lazily per character size.
|
|
236
|
+
*/
|
|
237
|
+
void Init_Font(VALUE rb_mSFML) {
|
|
238
|
+
rb_cFont = rb_define_class_under(rb_mSFML, "Font", rb_cObject);
|
|
239
|
+
rb_define_alloc_func(rb_cFont, Font_alloc);
|
|
121
240
|
|
|
122
241
|
rb_define_singleton_method(rb_cFont, "from_file", Font_from_file, 1);
|
|
123
242
|
rb_define_singleton_method(rb_cFont, "from_memory", Font_from_memory, 1);
|
|
@@ -141,8 +260,8 @@ VALUE Get_Klass_Font(void) {
|
|
|
141
260
|
return rb_cFont;
|
|
142
261
|
}
|
|
143
262
|
|
|
144
|
-
const sfFont
|
|
145
|
-
sfFont
|
|
263
|
+
const sfFont* Get_Font_Struct(VALUE self) {
|
|
264
|
+
sfFont* ptr;
|
|
146
265
|
TypedData_Get_Struct(self, sfFont, &Font_data_type, ptr);
|
|
147
266
|
return ptr;
|
|
148
267
|
}
|
data/ext/graphics/glyph.c
CHANGED
|
@@ -11,44 +11,74 @@ typedef struct {
|
|
|
11
11
|
|
|
12
12
|
static VALUE rb_cGlyph;
|
|
13
13
|
|
|
14
|
-
static void Glyph_free(void
|
|
14
|
+
static void Glyph_free(void* ptr) {
|
|
15
15
|
free(ptr);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
static const rb_data_type_t Glyph_data_type = {
|
|
19
19
|
.wrap_struct_name = "SFML::Glyph",
|
|
20
20
|
.function = {.dmark = NULL, .dfree = Glyph_free, .dsize = NULL},
|
|
21
|
-
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
22
|
-
};
|
|
21
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
23
22
|
|
|
24
23
|
VALUE glyph_from_c(sfGlyph glyph) {
|
|
25
|
-
Glyph
|
|
24
|
+
Glyph* ptr = malloc(sizeof(Glyph));
|
|
26
25
|
|
|
27
26
|
ptr->glyph = glyph;
|
|
28
27
|
|
|
29
28
|
return TypedData_Wrap_Struct(rb_cGlyph, &Glyph_data_type, ptr);
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
static Glyph
|
|
33
|
-
Glyph
|
|
31
|
+
static Glyph* Get_Glyph(VALUE self) {
|
|
32
|
+
Glyph* ptr;
|
|
34
33
|
TypedData_Get_Struct(self, Glyph, &Glyph_data_type, ptr);
|
|
35
34
|
return ptr;
|
|
36
35
|
}
|
|
37
36
|
|
|
37
|
+
/* call-seq: advance -> Float
|
|
38
|
+
*
|
|
39
|
+
* Returns the glyph's horizontal advance.
|
|
40
|
+
*
|
|
41
|
+
* @return [Float] the horizontal offset to advance to the next character
|
|
42
|
+
*/
|
|
38
43
|
static VALUE Glyph_get_advance(VALUE self) {
|
|
39
44
|
return DBL2NUM(Get_Glyph(self)->glyph.advance);
|
|
40
45
|
}
|
|
41
46
|
|
|
47
|
+
/* call-seq: bounds -> Rect
|
|
48
|
+
*
|
|
49
|
+
* Returns the glyph's bounding box.
|
|
50
|
+
*
|
|
51
|
+
* @return [Rect] the glyph's bounding box, relative to the baseline and
|
|
52
|
+
* the cursor position
|
|
53
|
+
*/
|
|
42
54
|
static VALUE Glyph_get_bounds(VALUE self) {
|
|
43
55
|
return rect_to_rb(Get_Glyph(self)->glyph.bounds);
|
|
44
56
|
}
|
|
45
57
|
|
|
58
|
+
/* call-seq: texture_rect -> Rect
|
|
59
|
+
*
|
|
60
|
+
* Returns the sub-rectangle of the texture displayed on the object.
|
|
61
|
+
*
|
|
62
|
+
* @return [Rect] the sub-rectangle of the font's texture holding this
|
|
63
|
+
* glyph's pixels
|
|
64
|
+
*/
|
|
46
65
|
static VALUE Glyph_get_texture_rect(VALUE self) {
|
|
47
66
|
return int_rect_to_rb(Get_Glyph(self)->glyph.textureRect);
|
|
48
67
|
}
|
|
49
68
|
|
|
50
|
-
|
|
51
|
-
|
|
69
|
+
static VALUE Glyph_alloc(VALUE klass) {
|
|
70
|
+
(void)klass;
|
|
71
|
+
rb_raise(rb_eNotImpError,
|
|
72
|
+
"glyph objects are returned by Font#glyph and cannot be constructed directly");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Document-class: SFML::Glyph
|
|
76
|
+
* A single character's rendering metrics and texture location, as returned
|
|
77
|
+
* by Font#glyph. Read-only.
|
|
78
|
+
*/
|
|
79
|
+
void Init_Glyph(VALUE rb_mSFML) {
|
|
80
|
+
rb_cGlyph = rb_define_class_under(rb_mSFML, "Glyph", rb_cObject);
|
|
81
|
+
rb_define_alloc_func(rb_cGlyph, Glyph_alloc);
|
|
52
82
|
|
|
53
83
|
rb_define_method(rb_cGlyph, "advance", Glyph_get_advance, 0);
|
|
54
84
|
rb_define_method(rb_cGlyph, "bounds", Glyph_get_bounds, 0);
|