sfml3-rb 0.0.1 → 0.2.2
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/CHANGELOG.md +342 -0
- data/README.md +51 -14
- data/TODO.md +199 -0
- data/ext/audio/audio_enums.c +131 -0
- data/ext/audio/audio_enums.h +18 -0
- data/ext/audio/effect_processor.c +233 -0
- data/ext/audio/effect_processor.h +25 -0
- data/ext/audio/listener.c +83 -0
- data/ext/audio/listener.h +8 -0
- data/ext/audio/music.c +174 -0
- data/ext/audio/music.h +14 -0
- data/ext/audio/sound.c +139 -0
- data/ext/audio/sound.h +14 -0
- data/ext/audio/sound_buffer.c +274 -0
- data/ext/audio/sound_buffer.h +18 -0
- data/ext/audio/sound_buffer_recorder.c +109 -0
- data/ext/audio/sound_buffer_recorder.h +14 -0
- data/ext/audio/sound_recorder.c +268 -0
- data/ext/audio/sound_recorder.h +14 -0
- data/ext/audio/sound_source.h +13 -0
- data/ext/audio/sound_source.inc +271 -0
- data/ext/audio/sound_source_cone.c +138 -0
- data/ext/audio/sound_source_cone.h +20 -0
- data/ext/audio/sound_stream.c +294 -0
- data/ext/audio/sound_stream.h +14 -0
- data/ext/{exceptions.c → core/exceptions.c} +10 -8
- data/ext/{ext → core}/exceptions.h +3 -3
- data/ext/core/foreign_thread.c +149 -0
- data/ext/core/foreign_thread.h +31 -0
- data/ext/core/macros.h +8 -0
- data/ext/{ext → core}/sfml.h +5 -3
- data/ext/core/unicode.c +46 -0
- data/ext/core/unicode.h +25 -0
- data/ext/ext.c +125 -14
- data/ext/extconf.rb +51 -6
- data/ext/graphics/blend_mode.c +261 -0
- data/ext/graphics/blend_mode.h +18 -0
- data/ext/graphics/circle.c +319 -0
- data/ext/{ext/klass/drawable → graphics}/circle.h +3 -3
- data/ext/graphics/color.c +318 -0
- data/ext/graphics/color.h +37 -0
- data/ext/{drawable.c → graphics/drawable.c} +11 -11
- data/ext/graphics/drawable.h +10 -0
- data/ext/graphics/enums.c +123 -0
- data/ext/graphics/enums.h +20 -0
- data/ext/graphics/font.c +148 -0
- data/ext/graphics/font.h +14 -0
- data/ext/graphics/glyph.c +60 -0
- data/ext/graphics/glyph.h +14 -0
- data/ext/graphics/image.c +205 -0
- data/ext/graphics/image.h +16 -0
- data/ext/graphics/polygon.c +300 -0
- data/ext/graphics/polygon.h +10 -0
- data/ext/graphics/rect.c +287 -0
- data/ext/graphics/rect.h +30 -0
- data/ext/graphics/rectangle.c +302 -0
- data/ext/graphics/rectangle.h +10 -0
- data/ext/graphics/render_state.c +204 -0
- data/ext/graphics/render_state.h +18 -0
- data/ext/graphics/render_target.inc +181 -0
- data/ext/graphics/render_texture.c +182 -0
- data/ext/graphics/render_texture.h +14 -0
- data/ext/graphics/shader.c +540 -0
- data/ext/graphics/shader.h +14 -0
- data/ext/graphics/shape.c +311 -0
- data/ext/graphics/shape.h +10 -0
- data/ext/graphics/sprite.c +249 -0
- data/ext/graphics/sprite.h +10 -0
- data/ext/graphics/stencil_mode.c +211 -0
- data/ext/graphics/stencil_mode.h +18 -0
- data/ext/graphics/target.c +133 -0
- data/ext/graphics/target.h +40 -0
- data/ext/graphics/text.c +344 -0
- data/ext/graphics/text.h +10 -0
- data/ext/graphics/texture.c +379 -0
- data/ext/graphics/texture.h +16 -0
- data/ext/graphics/transform.c +372 -0
- data/ext/graphics/transform.h +35 -0
- data/ext/{transformable.c → graphics/transformable.c} +168 -144
- data/ext/{ext/klass → graphics}/transformable.h +3 -3
- data/ext/graphics/vertex.c +179 -0
- data/ext/graphics/vertex.h +23 -0
- data/ext/graphics/vertex_array.c +127 -0
- data/ext/graphics/vertex_array.h +10 -0
- data/ext/graphics/vertex_buffer.c +211 -0
- data/ext/graphics/vertex_buffer.h +14 -0
- data/ext/{view.c → graphics/view.c} +168 -169
- data/ext/{ext/klass → graphics}/view.h +3 -3
- data/ext/network/ftp.c +405 -0
- data/ext/network/ftp.h +20 -0
- data/ext/network/http.c +243 -0
- data/ext/network/http.h +18 -0
- data/ext/network/ip_address.c +164 -0
- data/ext/network/ip_address.h +20 -0
- data/ext/network/network_enums.c +298 -0
- data/ext/network/network_enums.h +26 -0
- data/ext/network/packet.c +189 -0
- data/ext/network/packet.h +14 -0
- data/ext/network/socket_selector.c +142 -0
- data/ext/network/socket_selector.h +14 -0
- data/ext/network/tcp_listener.c +115 -0
- data/ext/network/tcp_listener.h +14 -0
- data/ext/network/tcp_socket.c +199 -0
- data/ext/network/tcp_socket.h +17 -0
- data/ext/network/udp_socket.c +190 -0
- data/ext/network/udp_socket.h +14 -0
- data/ext/ports.rb +97 -21
- data/ext/system/buffer.c +77 -0
- data/ext/system/buffer.h +14 -0
- data/ext/system/clock.c +100 -0
- data/ext/{ext/klass → system}/clock.h +3 -3
- data/ext/system/input_stream.c +229 -0
- data/ext/system/input_stream.h +23 -0
- data/ext/system/sleep.c +16 -0
- data/ext/system/sleep.h +8 -0
- data/ext/system/time.c +218 -0
- data/ext/system/time.h +18 -0
- data/ext/system/vec2.c +251 -0
- data/ext/system/vec2.h +55 -0
- data/ext/system/vec3.c +219 -0
- data/ext/system/vec3.h +18 -0
- data/ext/window/clipboard.c +89 -0
- data/ext/window/clipboard.h +8 -0
- data/ext/window/context.c +70 -0
- data/ext/window/context.h +8 -0
- data/ext/window/context_settings.c +220 -0
- data/ext/window/context_settings.h +18 -0
- data/ext/window/cursor.c +56 -0
- data/ext/window/cursor.h +14 -0
- data/ext/window/event.c +216 -0
- data/ext/window/event.h +14 -0
- data/ext/{event_name.c → window/event_name.c} +2 -2
- data/ext/window/event_name.h +8 -0
- data/ext/window/input_enums.c +261 -0
- data/ext/window/input_enums.h +36 -0
- data/ext/window/joystick.c +60 -0
- data/ext/window/joystick.h +8 -0
- data/ext/{keyboard.c → window/keyboard.c} +74 -2
- data/ext/window/keyboard.h +12 -0
- data/ext/window/mouse.c +70 -0
- data/ext/window/mouse.h +8 -0
- data/ext/window/sensor.c +30 -0
- data/ext/window/sensor.h +8 -0
- data/ext/window/touch.c +49 -0
- data/ext/window/touch.h +8 -0
- data/ext/window/video_mode.c +133 -0
- data/ext/window/video_mode.h +14 -0
- data/ext/window/vulkan.c +44 -0
- data/ext/window/vulkan.h +8 -0
- data/ext/window/window.c +414 -0
- data/ext/{ext/klass → window}/window.h +3 -3
- data/lib/sfml/version.rb +4 -2
- data/lib/sfml.rb +2 -0
- metadata +163 -56
- data/ext/circle.c +0 -198
- data/ext/clock.c +0 -65
- data/ext/color.c +0 -43
- data/ext/event.c +0 -148
- data/ext/ext/klass/color.h +0 -26
- data/ext/ext/klass/drawable/image.h +0 -4
- data/ext/ext/klass/drawable/polygon.h +0 -4
- data/ext/ext/klass/drawable/rectangle.h +0 -4
- data/ext/ext/klass/drawable/sprite.h +0 -4
- data/ext/ext/klass/drawable/texture.h +0 -4
- data/ext/ext/klass/event/event_name.h +0 -8
- data/ext/ext/klass/event.h +0 -12
- data/ext/ext/klass/keyboard.h +0 -8
- data/ext/ext/klass/render_state.h +0 -16
- data/ext/ext/klass/target.h +0 -18
- data/ext/ext/klass/transform.h +0 -17
- data/ext/ext/klass/video_mode.h +0 -12
- data/ext/ext/module/drawable/drawable.h +0 -10
- data/ext/ext/module/transform.h +0 -18
- data/ext/ext/module.h +0 -10
- data/ext/ext/rect.h +0 -16
- data/ext/ext/style_name.h +0 -11
- data/ext/ext/vec2.h +0 -38
- data/ext/image.c +0 -5
- data/ext/polygon.c +0 -5
- data/ext/rect.c +0 -26
- data/ext/rectangle.c +0 -5
- data/ext/render_state.c +0 -109
- data/ext/sprite.c +0 -5
- data/ext/style_name.c +0 -15
- data/ext/target.c +0 -106
- data/ext/texture.c +0 -5
- data/ext/transform.c +0 -107
- data/ext/vec2.c +0 -42
- data/ext/video_mode.c +0 -78
- data/ext/window.c +0 -274
data/ext/system/vec2.c
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
#include "system/vec2.h"
|
|
2
|
+
|
|
3
|
+
#include <math.h>
|
|
4
|
+
#include <stdio.h>
|
|
5
|
+
#include <stdlib.h>
|
|
6
|
+
|
|
7
|
+
#include "core/exceptions.h"
|
|
8
|
+
#include "core/macros.h"
|
|
9
|
+
|
|
10
|
+
typedef struct {
|
|
11
|
+
sfVector2f vec;
|
|
12
|
+
} Vector2;
|
|
13
|
+
|
|
14
|
+
static VALUE rb_cVector2;
|
|
15
|
+
|
|
16
|
+
static void Vector2_free(void *ptr) {
|
|
17
|
+
free(ptr);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static const rb_data_type_t Vector2_data_type = {
|
|
21
|
+
.wrap_struct_name = "SFML::Vector2",
|
|
22
|
+
.function = {.dmark = NULL, .dfree = Vector2_free, .dsize = NULL},
|
|
23
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
static VALUE Vector2_new(int argc, VALUE *argv, VALUE klass) {
|
|
27
|
+
VALUE self;
|
|
28
|
+
Vector2 *ptr;
|
|
29
|
+
float x = 0;
|
|
30
|
+
float y = 0;
|
|
31
|
+
|
|
32
|
+
if (argc == 1 && rb_obj_is_kind_of(argv[0], rb_cVector2)) {
|
|
33
|
+
ptr = Get_Vector2_Struct(argv[0]);
|
|
34
|
+
x = ptr->vec.x;
|
|
35
|
+
y = ptr->vec.y;
|
|
36
|
+
} else if (argc == 1 && RB_TYPE_P(argv[0], T_ARRAY)) {
|
|
37
|
+
if (RARRAY_LEN(argv[0]) < 2) {
|
|
38
|
+
raise_invalid_array_length(2);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
x = NUM2DBL(rb_ary_entry(argv[0], 0));
|
|
42
|
+
y = NUM2DBL(rb_ary_entry(argv[0], 1));
|
|
43
|
+
} else if (argc == 2) {
|
|
44
|
+
x = NUM2DBL(argv[0]);
|
|
45
|
+
y = NUM2DBL(argv[1]);
|
|
46
|
+
} else if (argc != 0) {
|
|
47
|
+
raise_invalid_arguments_excepted(2, argc);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
ptr = malloc(sizeof(Vector2));
|
|
51
|
+
ptr->vec.x = x;
|
|
52
|
+
ptr->vec.y = y;
|
|
53
|
+
|
|
54
|
+
self = TypedData_Wrap_Struct(klass, &Vector2_data_type, ptr);
|
|
55
|
+
|
|
56
|
+
return self;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static VALUE Vector2_get_x(VALUE self) {
|
|
60
|
+
return DBL2NUM(((Vector2 *) Get_Vector2_Struct(self))->vec.x);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static VALUE Vector2_get_y(VALUE self) {
|
|
64
|
+
return DBL2NUM(((Vector2 *) Get_Vector2_Struct(self))->vec.y);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static VALUE Vector2_set_x(VALUE self, VALUE rb_x) {
|
|
68
|
+
((Vector2 *) Get_Vector2_Struct(self))->vec.x = NUM2DBL(rb_x);
|
|
69
|
+
return rb_x;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static VALUE Vector2_set_y(VALUE self, VALUE rb_y) {
|
|
73
|
+
((Vector2 *) Get_Vector2_Struct(self))->vec.y = NUM2DBL(rb_y);
|
|
74
|
+
return rb_y;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static VALUE Vector2_to_a(VALUE self) {
|
|
78
|
+
Vector2 *vec = Get_Vector2_Struct(self);
|
|
79
|
+
|
|
80
|
+
return rb_ary_new_from_args(2, DBL2NUM(vec->vec.x), DBL2NUM(vec->vec.y));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static VALUE Vector2_each(VALUE self) {
|
|
84
|
+
Vector2 *vec = Get_Vector2_Struct(self);
|
|
85
|
+
|
|
86
|
+
rb_yield(DBL2NUM(vec->vec.x));
|
|
87
|
+
rb_yield(DBL2NUM(vec->vec.y));
|
|
88
|
+
|
|
89
|
+
return self;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static VALUE Vector2_aref(VALUE self, VALUE rb_index) {
|
|
93
|
+
return rb_ary_entry(Vector2_to_a(self), NUM2LONG(rb_index));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static VALUE Vector2_size(VALUE self) {
|
|
97
|
+
return INT2NUM(2);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static VALUE Vector2_eql(VALUE self, VALUE rb_other) {
|
|
101
|
+
Vector2 *a = Get_Vector2_Struct(self);
|
|
102
|
+
sfVector2f b;
|
|
103
|
+
|
|
104
|
+
if (rb_obj_is_kind_of(rb_other, rb_cVector2)) {
|
|
105
|
+
b = ((Vector2 *) Get_Vector2_Struct(rb_other))->vec;
|
|
106
|
+
} else if (RB_TYPE_P(rb_other, T_ARRAY) && RARRAY_LEN(rb_other) >= 2) {
|
|
107
|
+
b = vec2f_from_rb(rb_other);
|
|
108
|
+
} else {
|
|
109
|
+
return Qfalse;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return BOOL2RB(a->vec.x == b.x && a->vec.y == b.y);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static VALUE Vector2_add(VALUE self, VALUE rb_other) {
|
|
116
|
+
Vector2 *a = Get_Vector2_Struct(self);
|
|
117
|
+
sfVector2f b = vec2f_from_rb(rb_other);
|
|
118
|
+
|
|
119
|
+
return vec2f_to_rb((sfVector2f) {a->vec.x + b.x, a->vec.y + b.y});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static VALUE Vector2_sub(VALUE self, VALUE rb_other) {
|
|
123
|
+
Vector2 *a = Get_Vector2_Struct(self);
|
|
124
|
+
sfVector2f b = vec2f_from_rb(rb_other);
|
|
125
|
+
|
|
126
|
+
return vec2f_to_rb((sfVector2f) {a->vec.x - b.x, a->vec.y - b.y});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static VALUE Vector2_mul(VALUE self, VALUE rb_scalar) {
|
|
130
|
+
Vector2 *a = Get_Vector2_Struct(self);
|
|
131
|
+
float scalar = NUM2DBL(rb_scalar);
|
|
132
|
+
|
|
133
|
+
return vec2f_to_rb((sfVector2f) {a->vec.x * scalar, a->vec.y * scalar});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static VALUE Vector2_to_s(VALUE self) {
|
|
137
|
+
Vector2 *a = Get_Vector2_Struct(self);
|
|
138
|
+
char buffer[64];
|
|
139
|
+
|
|
140
|
+
snprintf(buffer, sizeof(buffer), "(%g, %g)", a->vec.x, a->vec.y);
|
|
141
|
+
|
|
142
|
+
return rb_str_new2(buffer);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
void Init_Vector2(VALUE rb_module) {
|
|
146
|
+
rb_cVector2 = rb_define_class_under(rb_module, "Vector2", rb_cObject);
|
|
147
|
+
|
|
148
|
+
rb_include_module(rb_cVector2, rb_mEnumerable);
|
|
149
|
+
|
|
150
|
+
rb_define_singleton_method(rb_cVector2, "new", Vector2_new, -1);
|
|
151
|
+
|
|
152
|
+
rb_define_method(rb_cVector2, "x", Vector2_get_x, 0);
|
|
153
|
+
rb_define_method(rb_cVector2, "y", Vector2_get_y, 0);
|
|
154
|
+
rb_define_method(rb_cVector2, "x=", Vector2_set_x, 1);
|
|
155
|
+
rb_define_method(rb_cVector2, "y=", Vector2_set_y, 1);
|
|
156
|
+
|
|
157
|
+
rb_define_method(rb_cVector2, "to_a", Vector2_to_a, 0);
|
|
158
|
+
rb_define_method(rb_cVector2, "to_ary", Vector2_to_a, 0);
|
|
159
|
+
rb_define_method(rb_cVector2, "each", Vector2_each, 0);
|
|
160
|
+
rb_define_method(rb_cVector2, "[]", Vector2_aref, 1);
|
|
161
|
+
rb_define_method(rb_cVector2, "size", Vector2_size, 0);
|
|
162
|
+
rb_define_method(rb_cVector2, "length", Vector2_size, 0);
|
|
163
|
+
rb_define_method(rb_cVector2, "==", Vector2_eql, 1);
|
|
164
|
+
rb_define_method(rb_cVector2, "+", Vector2_add, 1);
|
|
165
|
+
rb_define_method(rb_cVector2, "-", Vector2_sub, 1);
|
|
166
|
+
rb_define_method(rb_cVector2, "*", Vector2_mul, 1);
|
|
167
|
+
rb_define_method(rb_cVector2, "to_s", Vector2_to_s, 0);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
VALUE Get_Klass_Vector2(void) {
|
|
171
|
+
return rb_cVector2;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
void *Get_Vector2_Struct(VALUE self) {
|
|
175
|
+
Vector2 *ptr;
|
|
176
|
+
TypedData_Get_Struct(self, Vector2, &Vector2_data_type, ptr);
|
|
177
|
+
return ptr;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
sfVector2f vec2f_from_rb(VALUE rb_vec) {
|
|
181
|
+
if (rb_obj_is_kind_of(rb_vec, rb_cVector2)) {
|
|
182
|
+
return ((Vector2 *) Get_Vector2_Struct(rb_vec))->vec;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (RB_TYPE_P(rb_vec, T_ARRAY)) {
|
|
186
|
+
if (RARRAY_LEN(rb_vec) < 2) {
|
|
187
|
+
raise_invalid_array_length(2);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return (sfVector2f) {
|
|
191
|
+
(float) NUM2DBL(rb_ary_entry(rb_vec, 0)),
|
|
192
|
+
(float) NUM2DBL(rb_ary_entry(rb_vec, 1))
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
raise_invalid_argument_class(rb_cVector2);
|
|
197
|
+
|
|
198
|
+
return (sfVector2f) {0, 0};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
sfVector2i vec2i_from_rb(VALUE rb_vec) {
|
|
202
|
+
sfVector2f vec = vec2f_from_rb(rb_vec);
|
|
203
|
+
|
|
204
|
+
return (sfVector2i) {(int) vec.x, (int) vec.y};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
sfVector2u vec2u_from_rb(VALUE rb_vec) {
|
|
208
|
+
sfVector2f vec = vec2f_from_rb(rb_vec);
|
|
209
|
+
|
|
210
|
+
return (sfVector2u) {(unsigned) vec.x, (unsigned) vec.y};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
VALUE vec2f_to_rb(sfVector2f c_vec) {
|
|
214
|
+
Vector2 *ptr = malloc(sizeof(Vector2));
|
|
215
|
+
|
|
216
|
+
ptr->vec = c_vec;
|
|
217
|
+
|
|
218
|
+
return TypedData_Wrap_Struct(rb_cVector2, &Vector2_data_type, ptr);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
VALUE vec2_new(float x, float y) {
|
|
222
|
+
return vec2f_to_rb((sfVector2f) {x, y});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
void vec2_check(VALUE rb_arr) {
|
|
226
|
+
if (rb_obj_is_kind_of(rb_arr, rb_cVector2)) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (RB_TYPE_P(rb_arr, T_ARRAY) && RARRAY_LEN(rb_arr) >= 2) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
raise_invalid_array_length(2);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
VALUE vec2f_new_from_c(sfVector2f c_vec) {
|
|
238
|
+
return vec2f_to_rb(c_vec);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
sfVector2i vec2i_new_from_ruby(VALUE rb_arr) {
|
|
242
|
+
return vec2i_from_rb(rb_arr);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
sfVector2u vec2u_new_from_ruby(VALUE rb_arr) {
|
|
246
|
+
return vec2u_from_rb(rb_arr);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
sfVector2f vec2f_new_from_ruby(VALUE rb_arr) {
|
|
250
|
+
return vec2f_from_rb(rb_arr);
|
|
251
|
+
}
|
data/ext/system/vec2.h
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#ifndef SFML_RB_SYSTEM_VEC2_H
|
|
2
|
+
#define SFML_RB_SYSTEM_VEC2_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include "core/sfml.h"
|
|
7
|
+
|
|
8
|
+
#define UNPACK_VEC2(c_type, c_vec) (c_type) c_vec.x, (c_type) c_vec.y
|
|
9
|
+
|
|
10
|
+
#define VEC2_C2RB(c_vec) vec2f_to_rb((sfVector2f) { (float) (c_vec).x, (float) (c_vec).y })
|
|
11
|
+
|
|
12
|
+
#define VEC2_C2RB_T(c_type, c_vec) \
|
|
13
|
+
vec2f_to_rb((sfVector2f) { (float) (c_type) (c_vec).x, (float) (c_type) (c_vec).y })
|
|
14
|
+
|
|
15
|
+
#define VEC2_RB2C(rb_vec) vec2f_from_rb(rb_vec)
|
|
16
|
+
|
|
17
|
+
#define VEC2_RB2C_T(c_type, rb_vec) \
|
|
18
|
+
(c_type) NUM2DBL(rb_ary_entry(rb_vec, 0)), (c_type) NUM2DBL(rb_ary_entry(rb_vec, 1))
|
|
19
|
+
|
|
20
|
+
#define VEC2_SET_X(rb_vec, x) rb_ary_store(rb_vec, 0, DBL2NUM(x))
|
|
21
|
+
|
|
22
|
+
#define VEC2_SET_Y(rb_vec, y) rb_ary_store(rb_vec, 1, DBL2NUM(y))
|
|
23
|
+
|
|
24
|
+
#define VEC2_GET_X(rb_vec) NUM2DBL(rb_ary_entry(rb_vec, 0))
|
|
25
|
+
|
|
26
|
+
#define VEC2_GET_Y(rb_vec) NUM2DBL(rb_ary_entry(rb_vec, 1))
|
|
27
|
+
|
|
28
|
+
void Init_Vector2(VALUE rb_module);
|
|
29
|
+
|
|
30
|
+
VALUE Get_Klass_Vector2(void);
|
|
31
|
+
|
|
32
|
+
void *Get_Vector2_Struct(VALUE self);
|
|
33
|
+
|
|
34
|
+
sfVector2f vec2f_from_rb(VALUE rb_vec);
|
|
35
|
+
|
|
36
|
+
sfVector2i vec2i_from_rb(VALUE rb_vec);
|
|
37
|
+
|
|
38
|
+
sfVector2u vec2u_from_rb(VALUE rb_vec);
|
|
39
|
+
|
|
40
|
+
VALUE vec2f_to_rb(sfVector2f c_vec);
|
|
41
|
+
|
|
42
|
+
/* Backwards-compatible internal helpers. */
|
|
43
|
+
VALUE vec2_new(float x, float y);
|
|
44
|
+
|
|
45
|
+
void vec2_check(VALUE rb_arr);
|
|
46
|
+
|
|
47
|
+
VALUE vec2f_new_from_c(sfVector2f c_vec);
|
|
48
|
+
|
|
49
|
+
sfVector2i vec2i_new_from_ruby(VALUE rb_arr);
|
|
50
|
+
|
|
51
|
+
sfVector2u vec2u_new_from_ruby(VALUE rb_arr);
|
|
52
|
+
|
|
53
|
+
sfVector2f vec2f_new_from_ruby(VALUE rb_arr);
|
|
54
|
+
|
|
55
|
+
#endif //SFML_RB_SYSTEM_VEC2_H
|
data/ext/system/vec3.c
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
#include "system/vec3.h"
|
|
2
|
+
|
|
3
|
+
#include <stdio.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
|
|
6
|
+
#include "core/exceptions.h"
|
|
7
|
+
#include "core/macros.h"
|
|
8
|
+
|
|
9
|
+
typedef struct {
|
|
10
|
+
sfVector3f vec;
|
|
11
|
+
} Vector3;
|
|
12
|
+
|
|
13
|
+
static VALUE rb_cVector3;
|
|
14
|
+
|
|
15
|
+
static void Vector3_free(void *ptr) {
|
|
16
|
+
free(ptr);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static const rb_data_type_t Vector3_data_type = {
|
|
20
|
+
.wrap_struct_name = "SFML::Vector3",
|
|
21
|
+
.function = {.dmark = NULL, .dfree = Vector3_free, .dsize = NULL},
|
|
22
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
static VALUE Vector3_new(int argc, VALUE *argv, VALUE klass) {
|
|
26
|
+
VALUE self;
|
|
27
|
+
Vector3 *ptr;
|
|
28
|
+
float x = 0;
|
|
29
|
+
float y = 0;
|
|
30
|
+
float z = 0;
|
|
31
|
+
|
|
32
|
+
if (argc == 1 && rb_obj_is_kind_of(argv[0], rb_cVector3)) {
|
|
33
|
+
ptr = Get_Vector3_Struct(argv[0]);
|
|
34
|
+
x = ptr->vec.x;
|
|
35
|
+
y = ptr->vec.y;
|
|
36
|
+
z = ptr->vec.z;
|
|
37
|
+
} else if (argc == 1 && RB_TYPE_P(argv[0], T_ARRAY)) {
|
|
38
|
+
if (RARRAY_LEN(argv[0]) < 3) {
|
|
39
|
+
raise_invalid_array_length(3);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
x = NUM2DBL(rb_ary_entry(argv[0], 0));
|
|
43
|
+
y = NUM2DBL(rb_ary_entry(argv[0], 1));
|
|
44
|
+
z = NUM2DBL(rb_ary_entry(argv[0], 2));
|
|
45
|
+
} else if (argc == 3) {
|
|
46
|
+
x = NUM2DBL(argv[0]);
|
|
47
|
+
y = NUM2DBL(argv[1]);
|
|
48
|
+
z = NUM2DBL(argv[2]);
|
|
49
|
+
} else if (argc != 0) {
|
|
50
|
+
raise_invalid_arguments_excepted(3, argc);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
ptr = malloc(sizeof(Vector3));
|
|
54
|
+
ptr->vec.x = x;
|
|
55
|
+
ptr->vec.y = y;
|
|
56
|
+
ptr->vec.z = z;
|
|
57
|
+
|
|
58
|
+
self = TypedData_Wrap_Struct(klass, &Vector3_data_type, ptr);
|
|
59
|
+
|
|
60
|
+
return self;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static VALUE Vector3_get_x(VALUE self) {
|
|
64
|
+
return DBL2NUM(((Vector3 *) Get_Vector3_Struct(self))->vec.x);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static VALUE Vector3_get_y(VALUE self) {
|
|
68
|
+
return DBL2NUM(((Vector3 *) Get_Vector3_Struct(self))->vec.y);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static VALUE Vector3_get_z(VALUE self) {
|
|
72
|
+
return DBL2NUM(((Vector3 *) Get_Vector3_Struct(self))->vec.z);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static VALUE Vector3_set_x(VALUE self, VALUE rb_x) {
|
|
76
|
+
((Vector3 *) Get_Vector3_Struct(self))->vec.x = NUM2DBL(rb_x);
|
|
77
|
+
return rb_x;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static VALUE Vector3_set_y(VALUE self, VALUE rb_y) {
|
|
81
|
+
((Vector3 *) Get_Vector3_Struct(self))->vec.y = NUM2DBL(rb_y);
|
|
82
|
+
return rb_y;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static VALUE Vector3_set_z(VALUE self, VALUE rb_z) {
|
|
86
|
+
((Vector3 *) Get_Vector3_Struct(self))->vec.z = NUM2DBL(rb_z);
|
|
87
|
+
return rb_z;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static VALUE Vector3_to_a(VALUE self) {
|
|
91
|
+
Vector3 *vec = Get_Vector3_Struct(self);
|
|
92
|
+
|
|
93
|
+
return rb_ary_new_from_args(3, DBL2NUM(vec->vec.x), DBL2NUM(vec->vec.y), DBL2NUM(vec->vec.z));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static VALUE Vector3_each(VALUE self) {
|
|
97
|
+
Vector3 *vec = Get_Vector3_Struct(self);
|
|
98
|
+
|
|
99
|
+
rb_yield(DBL2NUM(vec->vec.x));
|
|
100
|
+
rb_yield(DBL2NUM(vec->vec.y));
|
|
101
|
+
rb_yield(DBL2NUM(vec->vec.z));
|
|
102
|
+
|
|
103
|
+
return self;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static VALUE Vector3_size(VALUE self) {
|
|
107
|
+
return INT2NUM(3);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static VALUE Vector3_eql(VALUE self, VALUE rb_other) {
|
|
111
|
+
Vector3 *a = Get_Vector3_Struct(self);
|
|
112
|
+
sfVector3f b;
|
|
113
|
+
|
|
114
|
+
if (rb_obj_is_kind_of(rb_other, rb_cVector3)) {
|
|
115
|
+
b = ((Vector3 *) Get_Vector3_Struct(rb_other))->vec;
|
|
116
|
+
} else if (RB_TYPE_P(rb_other, T_ARRAY) && RARRAY_LEN(rb_other) >= 3) {
|
|
117
|
+
b = vec3f_from_rb(rb_other);
|
|
118
|
+
} else {
|
|
119
|
+
return Qfalse;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return BOOL2RB(a->vec.x == b.x && a->vec.y == b.y && a->vec.z == b.z);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static VALUE Vector3_add(VALUE self, VALUE rb_other) {
|
|
126
|
+
Vector3 *a = Get_Vector3_Struct(self);
|
|
127
|
+
sfVector3f b = vec3f_from_rb(rb_other);
|
|
128
|
+
|
|
129
|
+
return vec3f_to_rb((sfVector3f) {a->vec.x + b.x, a->vec.y + b.y, a->vec.z + b.z});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static VALUE Vector3_sub(VALUE self, VALUE rb_other) {
|
|
133
|
+
Vector3 *a = Get_Vector3_Struct(self);
|
|
134
|
+
sfVector3f b = vec3f_from_rb(rb_other);
|
|
135
|
+
|
|
136
|
+
return vec3f_to_rb((sfVector3f) {a->vec.x - b.x, a->vec.y - b.y, a->vec.z - b.z});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static VALUE Vector3_mul(VALUE self, VALUE rb_scalar) {
|
|
140
|
+
Vector3 *a = Get_Vector3_Struct(self);
|
|
141
|
+
float scalar = NUM2DBL(rb_scalar);
|
|
142
|
+
|
|
143
|
+
return vec3f_to_rb((sfVector3f) {a->vec.x * scalar, a->vec.y * scalar, a->vec.z * scalar});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static VALUE Vector3_to_s(VALUE self) {
|
|
147
|
+
Vector3 *a = Get_Vector3_Struct(self);
|
|
148
|
+
char buffer[96];
|
|
149
|
+
|
|
150
|
+
snprintf(buffer, sizeof(buffer), "(%g, %g, %g)", a->vec.x, a->vec.y, a->vec.z);
|
|
151
|
+
|
|
152
|
+
return rb_str_new2(buffer);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
void Init_Vector3(VALUE rb_module) {
|
|
156
|
+
rb_cVector3 = rb_define_class_under(rb_module, "Vector3", rb_cObject);
|
|
157
|
+
|
|
158
|
+
rb_include_module(rb_cVector3, rb_mEnumerable);
|
|
159
|
+
|
|
160
|
+
rb_define_singleton_method(rb_cVector3, "new", Vector3_new, -1);
|
|
161
|
+
|
|
162
|
+
rb_define_method(rb_cVector3, "x", Vector3_get_x, 0);
|
|
163
|
+
rb_define_method(rb_cVector3, "y", Vector3_get_y, 0);
|
|
164
|
+
rb_define_method(rb_cVector3, "z", Vector3_get_z, 0);
|
|
165
|
+
rb_define_method(rb_cVector3, "x=", Vector3_set_x, 1);
|
|
166
|
+
rb_define_method(rb_cVector3, "y=", Vector3_set_y, 1);
|
|
167
|
+
rb_define_method(rb_cVector3, "z=", Vector3_set_z, 1);
|
|
168
|
+
|
|
169
|
+
rb_define_method(rb_cVector3, "to_a", Vector3_to_a, 0);
|
|
170
|
+
rb_define_method(rb_cVector3, "to_ary", Vector3_to_a, 0);
|
|
171
|
+
rb_define_method(rb_cVector3, "each", Vector3_each, 0);
|
|
172
|
+
rb_define_method(rb_cVector3, "size", Vector3_size, 0);
|
|
173
|
+
rb_define_method(rb_cVector3, "length", Vector3_size, 0);
|
|
174
|
+
rb_define_method(rb_cVector3, "==", Vector3_eql, 1);
|
|
175
|
+
rb_define_method(rb_cVector3, "+", Vector3_add, 1);
|
|
176
|
+
rb_define_method(rb_cVector3, "-", Vector3_sub, 1);
|
|
177
|
+
rb_define_method(rb_cVector3, "*", Vector3_mul, 1);
|
|
178
|
+
rb_define_method(rb_cVector3, "to_s", Vector3_to_s, 0);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
VALUE Get_Klass_Vector3(void) {
|
|
182
|
+
return rb_cVector3;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
void *Get_Vector3_Struct(VALUE self) {
|
|
186
|
+
Vector3 *ptr;
|
|
187
|
+
TypedData_Get_Struct(self, Vector3, &Vector3_data_type, ptr);
|
|
188
|
+
return ptr;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
sfVector3f vec3f_from_rb(VALUE rb_vec) {
|
|
192
|
+
if (rb_obj_is_kind_of(rb_vec, rb_cVector3)) {
|
|
193
|
+
return ((Vector3 *) Get_Vector3_Struct(rb_vec))->vec;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (RB_TYPE_P(rb_vec, T_ARRAY)) {
|
|
197
|
+
if (RARRAY_LEN(rb_vec) < 3) {
|
|
198
|
+
raise_invalid_array_length(3);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return (sfVector3f) {
|
|
202
|
+
(float) NUM2DBL(rb_ary_entry(rb_vec, 0)),
|
|
203
|
+
(float) NUM2DBL(rb_ary_entry(rb_vec, 1)),
|
|
204
|
+
(float) NUM2DBL(rb_ary_entry(rb_vec, 2))
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
raise_invalid_argument_class(rb_cVector3);
|
|
209
|
+
|
|
210
|
+
return (sfVector3f) {0, 0, 0};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
VALUE vec3f_to_rb(sfVector3f c_vec) {
|
|
214
|
+
Vector3 *ptr = malloc(sizeof(Vector3));
|
|
215
|
+
|
|
216
|
+
ptr->vec = c_vec;
|
|
217
|
+
|
|
218
|
+
return TypedData_Wrap_Struct(rb_cVector3, &Vector3_data_type, ptr);
|
|
219
|
+
}
|
data/ext/system/vec3.h
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#ifndef SFML_RB_SYSTEM_VEC3_H
|
|
2
|
+
#define SFML_RB_SYSTEM_VEC3_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include "core/sfml.h"
|
|
7
|
+
|
|
8
|
+
void Init_Vector3(VALUE rb_module);
|
|
9
|
+
|
|
10
|
+
VALUE Get_Klass_Vector3(void);
|
|
11
|
+
|
|
12
|
+
void *Get_Vector3_Struct(VALUE self);
|
|
13
|
+
|
|
14
|
+
sfVector3f vec3f_from_rb(VALUE rb_vec);
|
|
15
|
+
|
|
16
|
+
VALUE vec3f_to_rb(sfVector3f c_vec);
|
|
17
|
+
|
|
18
|
+
#endif //SFML_RB_SYSTEM_VEC3_H
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#include "window/clipboard.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
|
|
6
|
+
#include "core/sfml.h"
|
|
7
|
+
|
|
8
|
+
static void unicode_char_to_utf8(sfChar32 code, char buffer[4], int *length) {
|
|
9
|
+
if (code < 0x80) {
|
|
10
|
+
buffer[0] = (char) code;
|
|
11
|
+
*length = 1;
|
|
12
|
+
} else if (code < 0x800) {
|
|
13
|
+
buffer[0] = (char) (0xC0 | (code >> 6));
|
|
14
|
+
buffer[1] = (char) (0x80 | (code & 0x3F));
|
|
15
|
+
*length = 2;
|
|
16
|
+
} else if (code < 0x10000) {
|
|
17
|
+
buffer[0] = (char) (0xE0 | (code >> 12));
|
|
18
|
+
buffer[1] = (char) (0x80 | ((code >> 6) & 0x3F));
|
|
19
|
+
buffer[2] = (char) (0x80 | (code & 0x3F));
|
|
20
|
+
*length = 3;
|
|
21
|
+
} else {
|
|
22
|
+
buffer[0] = (char) (0xF0 | (code >> 18));
|
|
23
|
+
buffer[1] = (char) (0x80 | ((code >> 12) & 0x3F));
|
|
24
|
+
buffer[2] = (char) (0x80 | ((code >> 6) & 0x3F));
|
|
25
|
+
buffer[3] = (char) (0x80 | (code & 0x3F));
|
|
26
|
+
*length = 4;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static VALUE Clipboard_get_string(VALUE module) {
|
|
31
|
+
const char *string = sfClipboard_getString();
|
|
32
|
+
|
|
33
|
+
return rb_utf8_str_new_cstr(string != NULL ? string : "");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static VALUE Clipboard_set_string(VALUE module, VALUE rb_text) {
|
|
37
|
+
sfClipboard_setString(StringValueCStr(rb_text));
|
|
38
|
+
return rb_text;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static VALUE Clipboard_get_unicode_string(VALUE module) {
|
|
42
|
+
const sfChar32 *chars = sfClipboard_getUnicodeString();
|
|
43
|
+
VALUE string = rb_utf8_str_new("", 0);
|
|
44
|
+
|
|
45
|
+
if (chars == NULL) {
|
|
46
|
+
return string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
for (size_t i = 0; chars[i] != 0; i++) {
|
|
50
|
+
char buffer[4];
|
|
51
|
+
int length;
|
|
52
|
+
|
|
53
|
+
unicode_char_to_utf8(chars[i], buffer, &length);
|
|
54
|
+
rb_str_cat(string, buffer, length);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static VALUE Clipboard_set_unicode_string(VALUE module, VALUE rb_text) {
|
|
61
|
+
VALUE codepoints;
|
|
62
|
+
long count;
|
|
63
|
+
sfChar32 *chars;
|
|
64
|
+
|
|
65
|
+
StringValue(rb_text);
|
|
66
|
+
codepoints = rb_funcall(rb_text, rb_intern("codepoints"), 0);
|
|
67
|
+
count = RARRAY_LEN(codepoints);
|
|
68
|
+
chars = ALLOC_N(sfChar32, count + 1);
|
|
69
|
+
|
|
70
|
+
for (long i = 0; i < count; i++) {
|
|
71
|
+
chars[i] = (sfChar32) NUM2UINT(rb_ary_entry(codepoints, i));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
chars[count] = 0;
|
|
75
|
+
sfClipboard_setUnicodeString(chars);
|
|
76
|
+
|
|
77
|
+
xfree(chars);
|
|
78
|
+
|
|
79
|
+
return rb_text;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
void Init_Clipboard(VALUE rb_module) {
|
|
83
|
+
VALUE rb_mClipboard = rb_define_module_under(rb_module, "Clipboard");
|
|
84
|
+
|
|
85
|
+
rb_define_module_function(rb_mClipboard, "string", Clipboard_get_string, 0);
|
|
86
|
+
rb_define_module_function(rb_mClipboard, "string=", Clipboard_set_string, 1);
|
|
87
|
+
rb_define_module_function(rb_mClipboard, "unicode_string", Clipboard_get_unicode_string, 0);
|
|
88
|
+
rb_define_module_function(rb_mClipboard, "unicode_string=", Clipboard_set_unicode_string, 1);
|
|
89
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#include "window/context.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
|
|
5
|
+
#include "window/context_settings.h"
|
|
6
|
+
#include "core/macros.h"
|
|
7
|
+
#include "core/sfml.h"
|
|
8
|
+
|
|
9
|
+
static VALUE rb_cContext;
|
|
10
|
+
|
|
11
|
+
static void Context_free(void *ptr) {
|
|
12
|
+
sfContext_destroy(ptr);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static const rb_data_type_t Context_data_type = {
|
|
16
|
+
.wrap_struct_name = "SFML::Context",
|
|
17
|
+
.function = {.dmark = NULL, .dfree = Context_free, .dsize = NULL},
|
|
18
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
static sfContext *Get_Context_Struct(VALUE self) {
|
|
22
|
+
sfContext *ptr;
|
|
23
|
+
TypedData_Get_Struct(self, sfContext, &Context_data_type, ptr);
|
|
24
|
+
return ptr;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static VALUE Context_new(VALUE klass) {
|
|
28
|
+
sfContext *context = sfContext_create();
|
|
29
|
+
VALUE self;
|
|
30
|
+
|
|
31
|
+
if (context == NULL) {
|
|
32
|
+
rb_raise(rb_eRuntimeError, "failed to create context");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
self = TypedData_Wrap_Struct(klass, &Context_data_type, context);
|
|
36
|
+
|
|
37
|
+
return self;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static VALUE Context_extension_available(VALUE klass, VALUE rb_name) {
|
|
41
|
+
return BOOL2RB(sfContext_isExtensionAvailable(StringValueCStr(rb_name)));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static VALUE Context_set_active(VALUE self, VALUE rb_active) {
|
|
45
|
+
return BOOL2RB(sfContext_setActive(Get_Context_Struct(self), RTEST(rb_active)));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static VALUE Context_get_function(VALUE klass, VALUE rb_name) {
|
|
49
|
+
return ULL2NUM((unsigned long long) (uintptr_t) sfContext_getFunction(StringValueCStr(rb_name)));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static VALUE Context_get_settings(VALUE self) {
|
|
53
|
+
return context_settings_to_rb(sfContext_getSettings(Get_Context_Struct(self)));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static VALUE Context_active_context_id(VALUE klass) {
|
|
57
|
+
return ULL2NUM(sfContext_getActiveContextId());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void Init_Context(VALUE rb_module) {
|
|
61
|
+
rb_cContext = rb_define_class_under(rb_module, "Context", rb_cObject);
|
|
62
|
+
|
|
63
|
+
rb_define_singleton_method(rb_cContext, "new", Context_new, 0);
|
|
64
|
+
rb_define_singleton_method(rb_cContext, "extension_available?", Context_extension_available, 1);
|
|
65
|
+
rb_define_singleton_method(rb_cContext, "function", Context_get_function, 1);
|
|
66
|
+
rb_define_singleton_method(rb_cContext, "active_context_id", Context_active_context_id, 0);
|
|
67
|
+
|
|
68
|
+
rb_define_method(rb_cContext, "active=", Context_set_active, 1);
|
|
69
|
+
rb_define_method(rb_cContext, "settings", Context_get_settings, 0);
|
|
70
|
+
}
|