sfml3-rb 0.2.2 → 0.3.0
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 +43 -17
- data/README.md +97 -29
- data/ext/audio/audio_enums.c +58 -20
- data/ext/audio/listener.c +89 -6
- data/ext/audio/music.c +206 -5
- data/ext/audio/sound.c +175 -5
- data/ext/audio/sound_buffer.c +189 -47
- data/ext/audio/sound_buffer_recorder.c +83 -16
- data/ext/audio/sound_recorder.c +172 -52
- data/ext/audio/sound_source_cone.c +108 -29
- data/ext/audio/sound_stream.c +178 -5
- data/ext/core/exceptions.c +10 -8
- data/ext/core/unicode.c +12 -2
- data/ext/ext.c +4 -0
- data/ext/graphics/blend_mode.c +203 -53
- data/ext/graphics/circle.c +271 -4
- data/ext/graphics/color.c +240 -90
- data/ext/graphics/drawable.c +15 -4
- data/ext/graphics/font.c +138 -25
- data/ext/graphics/glyph.c +31 -8
- data/ext/graphics/image.c +180 -37
- data/ext/graphics/polygon.c +293 -26
- data/ext/graphics/rect.c +211 -54
- data/ext/graphics/rectangle.c +279 -26
- data/ext/graphics/render_state.c +116 -2
- data/ext/graphics/render_texture.c +163 -2
- data/ext/graphics/shader.c +283 -17
- data/ext/graphics/shape.c +252 -26
- data/ext/graphics/sprite.c +216 -25
- data/ext/graphics/stencil_mode.c +148 -39
- data/ext/graphics/target.c +67 -22
- data/ext/graphics/target.h +15 -15
- data/ext/graphics/text.c +306 -6
- data/ext/graphics/texture.c +257 -3
- data/ext/graphics/transform.c +178 -5
- data/ext/graphics/transformable.c +126 -2
- data/ext/graphics/vertex.c +79 -2
- data/ext/graphics/vertex_array.c +128 -16
- data/ext/graphics/vertex_buffer.c +124 -2
- data/ext/graphics/view.c +130 -2
- data/ext/network/ftp.c +249 -10
- data/ext/network/http.c +156 -38
- data/ext/network/ip_address.c +107 -26
- data/ext/network/network_enums.c +248 -141
- data/ext/network/packet.c +273 -39
- data/ext/network/socket_selector.c +91 -19
- data/ext/network/tcp_listener.c +75 -16
- data/ext/network/tcp_socket.c +128 -25
- data/ext/network/udp_socket.c +122 -26
- data/ext/ports.rb +7 -0
- data/ext/system/buffer.c +41 -12
- data/ext/system/clock.c +68 -9
- data/ext/system/input_stream.c +94 -42
- data/ext/system/sleep.c +10 -2
- data/ext/system/time.c +172 -34
- data/ext/system/vec2.c +156 -35
- data/ext/system/vec3.c +166 -35
- data/ext/window/clipboard.c +47 -17
- data/ext/window/context.c +59 -9
- data/ext/window/context_settings.c +116 -38
- data/ext/window/cursor.c +39 -9
- data/ext/window/event.c +163 -42
- data/ext/window/joystick.c +69 -3
- data/ext/window/keyboard.c +168 -116
- data/ext/window/mouse.c +36 -2
- data/ext/window/sensor.c +28 -2
- data/ext/window/touch.c +20 -2
- data/ext/window/video_mode.c +90 -19
- data/ext/window/vulkan.c +34 -6
- data/ext/window/window.c +340 -16
- 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_texture.rbs +37 -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 +10 -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 +24 -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/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 +57 -0
- metadata +66 -2
data/ext/system/vec3.c
CHANGED
|
@@ -12,19 +12,31 @@ typedef struct {
|
|
|
12
12
|
|
|
13
13
|
static VALUE rb_cVector3;
|
|
14
14
|
|
|
15
|
-
static void Vector3_free(void
|
|
15
|
+
static void Vector3_free(void* ptr) {
|
|
16
16
|
free(ptr);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
static const rb_data_type_t Vector3_data_type = {
|
|
20
20
|
.wrap_struct_name = "SFML::Vector3",
|
|
21
21
|
.function = {.dmark = NULL, .dfree = Vector3_free, .dsize = NULL},
|
|
22
|
-
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
23
|
+
|
|
24
|
+
/* call-seq:
|
|
25
|
+
* Vector3.new -> Vector3(0, 0, 0)
|
|
26
|
+
* Vector3.new(x, y, z) -> Vector3(x, y, z)
|
|
27
|
+
* Vector3.new([x, y, z]) -> Vector3(x, y, z)
|
|
28
|
+
* Vector3.new(other_vector3) -> copy of +other_vector3+
|
|
29
|
+
*
|
|
30
|
+
* Creates a new 3D vector from three coordinates, a 3-element Array, or
|
|
31
|
+
* another Vector3.
|
|
32
|
+
*
|
|
33
|
+
* @return [Vector3]
|
|
34
|
+
* @raise [ArgumentError] if given an Array shorter than 3 elements, or an
|
|
35
|
+
* argument count other than 0, 1 or 3
|
|
36
|
+
*/
|
|
37
|
+
static VALUE Vector3_new(int argc, VALUE* argv, VALUE klass) {
|
|
26
38
|
VALUE self;
|
|
27
|
-
Vector3
|
|
39
|
+
Vector3* ptr;
|
|
28
40
|
float x = 0;
|
|
29
41
|
float y = 0;
|
|
30
42
|
float z = 0;
|
|
@@ -51,6 +63,11 @@ static VALUE Vector3_new(int argc, VALUE *argv, VALUE klass) {
|
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
ptr = malloc(sizeof(Vector3));
|
|
66
|
+
|
|
67
|
+
if (ptr == NULL) {
|
|
68
|
+
rb_raise(rb_eNoMemError, "failed to allocate vector");
|
|
69
|
+
}
|
|
70
|
+
|
|
54
71
|
ptr->vec.x = x;
|
|
55
72
|
ptr->vec.y = y;
|
|
56
73
|
ptr->vec.z = z;
|
|
@@ -60,41 +77,92 @@ static VALUE Vector3_new(int argc, VALUE *argv, VALUE klass) {
|
|
|
60
77
|
return self;
|
|
61
78
|
}
|
|
62
79
|
|
|
80
|
+
/* call-seq: x -> Float
|
|
81
|
+
*
|
|
82
|
+
* Returns the X component of the vector.
|
|
83
|
+
*
|
|
84
|
+
* @return [Float] the X component
|
|
85
|
+
*/
|
|
63
86
|
static VALUE Vector3_get_x(VALUE self) {
|
|
64
|
-
return DBL2NUM(((Vector3
|
|
87
|
+
return DBL2NUM(((Vector3*)Get_Vector3_Struct(self))->vec.x);
|
|
65
88
|
}
|
|
66
89
|
|
|
90
|
+
/* call-seq: y -> Float
|
|
91
|
+
*
|
|
92
|
+
* Returns the Y component of the vector.
|
|
93
|
+
*
|
|
94
|
+
* @return [Float] the Y component
|
|
95
|
+
*/
|
|
67
96
|
static VALUE Vector3_get_y(VALUE self) {
|
|
68
|
-
return DBL2NUM(((Vector3
|
|
97
|
+
return DBL2NUM(((Vector3*)Get_Vector3_Struct(self))->vec.y);
|
|
69
98
|
}
|
|
70
99
|
|
|
100
|
+
/* call-seq: z -> Float
|
|
101
|
+
*
|
|
102
|
+
* Returns the Z component of the vector.
|
|
103
|
+
*
|
|
104
|
+
* @return [Float] the Z component
|
|
105
|
+
*/
|
|
71
106
|
static VALUE Vector3_get_z(VALUE self) {
|
|
72
|
-
return DBL2NUM(((Vector3
|
|
107
|
+
return DBL2NUM(((Vector3*)Get_Vector3_Struct(self))->vec.z);
|
|
73
108
|
}
|
|
74
109
|
|
|
110
|
+
/* call-seq:
|
|
111
|
+
* x=(value) -> Float
|
|
112
|
+
*
|
|
113
|
+
* Sets the X component. +value+ is any Float-convertible number.
|
|
114
|
+
*
|
|
115
|
+
* @return [Float] +value+
|
|
116
|
+
*/
|
|
75
117
|
static VALUE Vector3_set_x(VALUE self, VALUE rb_x) {
|
|
76
|
-
((Vector3
|
|
118
|
+
((Vector3*)Get_Vector3_Struct(self))->vec.x = NUM2DBL(rb_x);
|
|
77
119
|
return rb_x;
|
|
78
120
|
}
|
|
79
121
|
|
|
122
|
+
/* call-seq:
|
|
123
|
+
* y=(value) -> Float
|
|
124
|
+
*
|
|
125
|
+
* Sets the Y component. +value+ is any Float-convertible number.
|
|
126
|
+
*
|
|
127
|
+
* @return [Float] +value+
|
|
128
|
+
*/
|
|
80
129
|
static VALUE Vector3_set_y(VALUE self, VALUE rb_y) {
|
|
81
|
-
((Vector3
|
|
130
|
+
((Vector3*)Get_Vector3_Struct(self))->vec.y = NUM2DBL(rb_y);
|
|
82
131
|
return rb_y;
|
|
83
132
|
}
|
|
84
133
|
|
|
134
|
+
/* call-seq:
|
|
135
|
+
* z=(value) -> Float
|
|
136
|
+
*
|
|
137
|
+
* Sets the Z component. +value+ is any Float-convertible number.
|
|
138
|
+
*
|
|
139
|
+
* @return [Float] +value+
|
|
140
|
+
*/
|
|
85
141
|
static VALUE Vector3_set_z(VALUE self, VALUE rb_z) {
|
|
86
|
-
((Vector3
|
|
142
|
+
((Vector3*)Get_Vector3_Struct(self))->vec.z = NUM2DBL(rb_z);
|
|
87
143
|
return rb_z;
|
|
88
144
|
}
|
|
89
145
|
|
|
146
|
+
/* call-seq: to_a -> Array
|
|
147
|
+
*
|
|
148
|
+
* Returns the vector's components as a three-element Array.
|
|
149
|
+
*
|
|
150
|
+
* @return [Array<Float>] +[x, y, z]+
|
|
151
|
+
*/
|
|
90
152
|
static VALUE Vector3_to_a(VALUE self) {
|
|
91
|
-
Vector3
|
|
153
|
+
Vector3* vec = Get_Vector3_Struct(self);
|
|
92
154
|
|
|
93
155
|
return rb_ary_new_from_args(3, DBL2NUM(vec->vec.x), DBL2NUM(vec->vec.y), DBL2NUM(vec->vec.z));
|
|
94
156
|
}
|
|
95
157
|
|
|
158
|
+
/* call-seq: each { |component| ... } -> self
|
|
159
|
+
*
|
|
160
|
+
* Yields +x+, +y+, then +z+.
|
|
161
|
+
*
|
|
162
|
+
* @return [self]
|
|
163
|
+
*/
|
|
96
164
|
static VALUE Vector3_each(VALUE self) {
|
|
97
|
-
Vector3
|
|
165
|
+
Vector3* vec = Get_Vector3_Struct(self);
|
|
98
166
|
|
|
99
167
|
rb_yield(DBL2NUM(vec->vec.x));
|
|
100
168
|
rb_yield(DBL2NUM(vec->vec.y));
|
|
@@ -103,16 +171,29 @@ static VALUE Vector3_each(VALUE self) {
|
|
|
103
171
|
return self;
|
|
104
172
|
}
|
|
105
173
|
|
|
174
|
+
/* call-seq: size -> Integer
|
|
175
|
+
*
|
|
176
|
+
* Returns the number of components, always 3.
|
|
177
|
+
*
|
|
178
|
+
* @return [Integer] always 3
|
|
179
|
+
*/
|
|
106
180
|
static VALUE Vector3_size(VALUE self) {
|
|
107
181
|
return INT2NUM(3);
|
|
108
182
|
}
|
|
109
183
|
|
|
184
|
+
/* call-seq:
|
|
185
|
+
* self == other -> true or false
|
|
186
|
+
*
|
|
187
|
+
* +other+ may be a Vector3 or a 3-element Array.
|
|
188
|
+
*
|
|
189
|
+
* @return [Boolean]
|
|
190
|
+
*/
|
|
110
191
|
static VALUE Vector3_eql(VALUE self, VALUE rb_other) {
|
|
111
|
-
Vector3
|
|
192
|
+
Vector3* a = Get_Vector3_Struct(self);
|
|
112
193
|
sfVector3f b;
|
|
113
194
|
|
|
114
195
|
if (rb_obj_is_kind_of(rb_other, rb_cVector3)) {
|
|
115
|
-
b = ((Vector3
|
|
196
|
+
b = ((Vector3*)Get_Vector3_Struct(rb_other))->vec;
|
|
116
197
|
} else if (RB_TYPE_P(rb_other, T_ARRAY) && RARRAY_LEN(rb_other) >= 3) {
|
|
117
198
|
b = vec3f_from_rb(rb_other);
|
|
118
199
|
} else {
|
|
@@ -122,29 +203,56 @@ static VALUE Vector3_eql(VALUE self, VALUE rb_other) {
|
|
|
122
203
|
return BOOL2RB(a->vec.x == b.x && a->vec.y == b.y && a->vec.z == b.z);
|
|
123
204
|
}
|
|
124
205
|
|
|
206
|
+
/* call-seq:
|
|
207
|
+
* self + other -> Vector3
|
|
208
|
+
*
|
|
209
|
+
* +other+ may be a Vector3 or a 3-element Array.
|
|
210
|
+
*
|
|
211
|
+
* @return [Vector3] componentwise sum
|
|
212
|
+
*/
|
|
125
213
|
static VALUE Vector3_add(VALUE self, VALUE rb_other) {
|
|
126
|
-
Vector3
|
|
214
|
+
Vector3* a = Get_Vector3_Struct(self);
|
|
127
215
|
sfVector3f b = vec3f_from_rb(rb_other);
|
|
128
216
|
|
|
129
|
-
return vec3f_to_rb((sfVector3f)
|
|
217
|
+
return vec3f_to_rb((sfVector3f){a->vec.x + b.x, a->vec.y + b.y, a->vec.z + b.z});
|
|
130
218
|
}
|
|
131
219
|
|
|
220
|
+
/* call-seq:
|
|
221
|
+
* self - other -> Vector3
|
|
222
|
+
*
|
|
223
|
+
* +other+ may be a Vector3 or a 3-element Array.
|
|
224
|
+
*
|
|
225
|
+
* @return [Vector3] componentwise difference
|
|
226
|
+
*/
|
|
132
227
|
static VALUE Vector3_sub(VALUE self, VALUE rb_other) {
|
|
133
|
-
Vector3
|
|
228
|
+
Vector3* a = Get_Vector3_Struct(self);
|
|
134
229
|
sfVector3f b = vec3f_from_rb(rb_other);
|
|
135
230
|
|
|
136
|
-
return vec3f_to_rb((sfVector3f)
|
|
231
|
+
return vec3f_to_rb((sfVector3f){a->vec.x - b.x, a->vec.y - b.y, a->vec.z - b.z});
|
|
137
232
|
}
|
|
138
233
|
|
|
234
|
+
/* call-seq:
|
|
235
|
+
* self * scalar -> Vector3
|
|
236
|
+
*
|
|
237
|
+
* Multiplies all three components by +scalar+.
|
|
238
|
+
*
|
|
239
|
+
* @return [Vector3]
|
|
240
|
+
*/
|
|
139
241
|
static VALUE Vector3_mul(VALUE self, VALUE rb_scalar) {
|
|
140
|
-
Vector3
|
|
242
|
+
Vector3* a = Get_Vector3_Struct(self);
|
|
141
243
|
float scalar = NUM2DBL(rb_scalar);
|
|
142
244
|
|
|
143
|
-
return vec3f_to_rb((sfVector3f)
|
|
245
|
+
return vec3f_to_rb((sfVector3f){a->vec.x * scalar, a->vec.y * scalar, a->vec.z * scalar});
|
|
144
246
|
}
|
|
145
247
|
|
|
248
|
+
/* call-seq: to_s -> String
|
|
249
|
+
*
|
|
250
|
+
* Returns a human-readable +"(x, y, z)"+ representation.
|
|
251
|
+
*
|
|
252
|
+
* @return [String] +"(x, y, z)"+
|
|
253
|
+
*/
|
|
146
254
|
static VALUE Vector3_to_s(VALUE self) {
|
|
147
|
-
Vector3
|
|
255
|
+
Vector3* a = Get_Vector3_Struct(self);
|
|
148
256
|
char buffer[96];
|
|
149
257
|
|
|
150
258
|
snprintf(buffer, sizeof(buffer), "(%g, %g, %g)", a->vec.x, a->vec.y, a->vec.z);
|
|
@@ -152,8 +260,29 @@ static VALUE Vector3_to_s(VALUE self) {
|
|
|
152
260
|
return rb_str_new2(buffer);
|
|
153
261
|
}
|
|
154
262
|
|
|
155
|
-
|
|
156
|
-
|
|
263
|
+
/* Document-class: SFML::Vector3
|
|
264
|
+
* A 3D vector of floats, used for positions, sizes and directions in 3D
|
|
265
|
+
* space (e.g. Listener and SoundSource position/direction/velocity).
|
|
266
|
+
*
|
|
267
|
+
* Includes +Enumerable+ and behaves like a 3-element sequence: it responds to
|
|
268
|
+
* #each and #to_a, and can be compared or combined with a plain
|
|
269
|
+
* +[x, y, z]+ Array anywhere a Vector3 is accepted.
|
|
270
|
+
*
|
|
271
|
+
* @!attribute x
|
|
272
|
+
* Returns the X component.
|
|
273
|
+
*
|
|
274
|
+
* @return [Float] the X component
|
|
275
|
+
* @!attribute y
|
|
276
|
+
* Returns the Y component.
|
|
277
|
+
*
|
|
278
|
+
* @return [Float] the Y component
|
|
279
|
+
* @!attribute z
|
|
280
|
+
* Returns the Z component.
|
|
281
|
+
*
|
|
282
|
+
* @return [Float] the Z component
|
|
283
|
+
*/
|
|
284
|
+
void Init_Vector3(VALUE rb_mSFML) {
|
|
285
|
+
rb_cVector3 = rb_define_class_under(rb_mSFML, "Vector3", rb_cObject);
|
|
157
286
|
|
|
158
287
|
rb_include_module(rb_cVector3, rb_mEnumerable);
|
|
159
288
|
|
|
@@ -182,15 +311,15 @@ VALUE Get_Klass_Vector3(void) {
|
|
|
182
311
|
return rb_cVector3;
|
|
183
312
|
}
|
|
184
313
|
|
|
185
|
-
void
|
|
186
|
-
Vector3
|
|
314
|
+
void* Get_Vector3_Struct(VALUE self) {
|
|
315
|
+
Vector3* ptr;
|
|
187
316
|
TypedData_Get_Struct(self, Vector3, &Vector3_data_type, ptr);
|
|
188
317
|
return ptr;
|
|
189
318
|
}
|
|
190
319
|
|
|
191
320
|
sfVector3f vec3f_from_rb(VALUE rb_vec) {
|
|
192
321
|
if (rb_obj_is_kind_of(rb_vec, rb_cVector3)) {
|
|
193
|
-
return ((Vector3
|
|
322
|
+
return ((Vector3*)Get_Vector3_Struct(rb_vec))->vec;
|
|
194
323
|
}
|
|
195
324
|
|
|
196
325
|
if (RB_TYPE_P(rb_vec, T_ARRAY)) {
|
|
@@ -198,20 +327,22 @@ sfVector3f vec3f_from_rb(VALUE rb_vec) {
|
|
|
198
327
|
raise_invalid_array_length(3);
|
|
199
328
|
}
|
|
200
329
|
|
|
201
|
-
return (sfVector3f)
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
(float) NUM2DBL(rb_ary_entry(rb_vec, 2))
|
|
205
|
-
};
|
|
330
|
+
return (sfVector3f){(float)NUM2DBL(rb_ary_entry(rb_vec, 0)),
|
|
331
|
+
(float)NUM2DBL(rb_ary_entry(rb_vec, 1)),
|
|
332
|
+
(float)NUM2DBL(rb_ary_entry(rb_vec, 2))};
|
|
206
333
|
}
|
|
207
334
|
|
|
208
335
|
raise_invalid_argument_class(rb_cVector3);
|
|
209
336
|
|
|
210
|
-
return (sfVector3f)
|
|
337
|
+
return (sfVector3f){0, 0, 0};
|
|
211
338
|
}
|
|
212
339
|
|
|
213
340
|
VALUE vec3f_to_rb(sfVector3f c_vec) {
|
|
214
|
-
Vector3
|
|
341
|
+
Vector3* ptr = malloc(sizeof(Vector3));
|
|
342
|
+
|
|
343
|
+
if (ptr == NULL) {
|
|
344
|
+
rb_raise(rb_eNoMemError, "failed to allocate vector");
|
|
345
|
+
}
|
|
215
346
|
|
|
216
347
|
ptr->vec = c_vec;
|
|
217
348
|
|
data/ext/window/clipboard.c
CHANGED
|
@@ -5,41 +5,61 @@
|
|
|
5
5
|
|
|
6
6
|
#include "core/sfml.h"
|
|
7
7
|
|
|
8
|
-
static void unicode_char_to_utf8(sfChar32 code, char buffer[4], int
|
|
8
|
+
static void unicode_char_to_utf8(sfChar32 code, char buffer[4], int* length) {
|
|
9
9
|
if (code < 0x80) {
|
|
10
|
-
buffer[0] = (char)
|
|
10
|
+
buffer[0] = (char)code;
|
|
11
11
|
*length = 1;
|
|
12
12
|
} else if (code < 0x800) {
|
|
13
|
-
buffer[0] = (char)
|
|
14
|
-
buffer[1] = (char)
|
|
13
|
+
buffer[0] = (char)(0xC0 | (code >> 6));
|
|
14
|
+
buffer[1] = (char)(0x80 | (code & 0x3F));
|
|
15
15
|
*length = 2;
|
|
16
16
|
} else if (code < 0x10000) {
|
|
17
|
-
buffer[0] = (char)
|
|
18
|
-
buffer[1] = (char)
|
|
19
|
-
buffer[2] = (char)
|
|
17
|
+
buffer[0] = (char)(0xE0 | (code >> 12));
|
|
18
|
+
buffer[1] = (char)(0x80 | ((code >> 6) & 0x3F));
|
|
19
|
+
buffer[2] = (char)(0x80 | (code & 0x3F));
|
|
20
20
|
*length = 3;
|
|
21
21
|
} else {
|
|
22
|
-
buffer[0] = (char)
|
|
23
|
-
buffer[1] = (char)
|
|
24
|
-
buffer[2] = (char)
|
|
25
|
-
buffer[3] = (char)
|
|
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
26
|
*length = 4;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/* call-seq: string -> String
|
|
31
|
+
*
|
|
32
|
+
* Returns the current system clipboard contents as a plain String.
|
|
33
|
+
*
|
|
34
|
+
* @return [String] the current system clipboard contents
|
|
35
|
+
*/
|
|
30
36
|
static VALUE Clipboard_get_string(VALUE module) {
|
|
31
|
-
const char
|
|
37
|
+
const char* string = sfClipboard_getString();
|
|
32
38
|
|
|
33
39
|
return rb_utf8_str_new_cstr(string != NULL ? string : "");
|
|
34
40
|
}
|
|
35
41
|
|
|
42
|
+
/* call-seq:
|
|
43
|
+
* string=(value) -> String
|
|
44
|
+
*
|
|
45
|
+
* Sets the system clipboard to +value+.
|
|
46
|
+
*
|
|
47
|
+
* @return [String] +value+
|
|
48
|
+
*/
|
|
36
49
|
static VALUE Clipboard_set_string(VALUE module, VALUE rb_text) {
|
|
37
50
|
sfClipboard_setString(StringValueCStr(rb_text));
|
|
38
51
|
return rb_text;
|
|
39
52
|
}
|
|
40
53
|
|
|
54
|
+
/* call-seq: unicode_string -> String
|
|
55
|
+
*
|
|
56
|
+
* Returns the current system clipboard contents, decoding UTF-32 to UTF-8.
|
|
57
|
+
*
|
|
58
|
+
* @return [String] the current system clipboard contents, decoded from
|
|
59
|
+
* UTF-32 to a UTF-8 Ruby String
|
|
60
|
+
*/
|
|
41
61
|
static VALUE Clipboard_get_unicode_string(VALUE module) {
|
|
42
|
-
const sfChar32
|
|
62
|
+
const sfChar32* chars = sfClipboard_getUnicodeString();
|
|
43
63
|
VALUE string = rb_utf8_str_new("", 0);
|
|
44
64
|
|
|
45
65
|
if (chars == NULL) {
|
|
@@ -57,10 +77,17 @@ static VALUE Clipboard_get_unicode_string(VALUE module) {
|
|
|
57
77
|
return string;
|
|
58
78
|
}
|
|
59
79
|
|
|
80
|
+
/* call-seq:
|
|
81
|
+
* unicode_string=(value) -> String
|
|
82
|
+
*
|
|
83
|
+
* Sets the system clipboard to +value+, encoding it to UTF-32 first.
|
|
84
|
+
*
|
|
85
|
+
* @return [String] +value+
|
|
86
|
+
*/
|
|
60
87
|
static VALUE Clipboard_set_unicode_string(VALUE module, VALUE rb_text) {
|
|
61
88
|
VALUE codepoints;
|
|
62
89
|
long count;
|
|
63
|
-
sfChar32
|
|
90
|
+
sfChar32* chars;
|
|
64
91
|
|
|
65
92
|
StringValue(rb_text);
|
|
66
93
|
codepoints = rb_funcall(rb_text, rb_intern("codepoints"), 0);
|
|
@@ -68,7 +95,7 @@ static VALUE Clipboard_set_unicode_string(VALUE module, VALUE rb_text) {
|
|
|
68
95
|
chars = ALLOC_N(sfChar32, count + 1);
|
|
69
96
|
|
|
70
97
|
for (long i = 0; i < count; i++) {
|
|
71
|
-
chars[i] = (sfChar32)
|
|
98
|
+
chars[i] = (sfChar32)NUM2UINT(rb_ary_entry(codepoints, i));
|
|
72
99
|
}
|
|
73
100
|
|
|
74
101
|
chars[count] = 0;
|
|
@@ -79,8 +106,11 @@ static VALUE Clipboard_set_unicode_string(VALUE module, VALUE rb_text) {
|
|
|
79
106
|
return rb_text;
|
|
80
107
|
}
|
|
81
108
|
|
|
82
|
-
|
|
83
|
-
|
|
109
|
+
/* Document-module: SFML::Clipboard
|
|
110
|
+
* Access to the system clipboard, as plain text or Unicode text.
|
|
111
|
+
*/
|
|
112
|
+
void Init_Clipboard(VALUE rb_mSFML) {
|
|
113
|
+
VALUE rb_mClipboard = rb_define_module_under(rb_mSFML, "Clipboard");
|
|
84
114
|
|
|
85
115
|
rb_define_module_function(rb_mClipboard, "string", Clipboard_get_string, 0);
|
|
86
116
|
rb_define_module_function(rb_mClipboard, "string=", Clipboard_set_string, 1);
|
data/ext/window/context.c
CHANGED
|
@@ -8,24 +8,31 @@
|
|
|
8
8
|
|
|
9
9
|
static VALUE rb_cContext;
|
|
10
10
|
|
|
11
|
-
static void Context_free(void
|
|
11
|
+
static void Context_free(void* ptr) {
|
|
12
12
|
sfContext_destroy(ptr);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
static const rb_data_type_t Context_data_type = {
|
|
16
16
|
.wrap_struct_name = "SFML::Context",
|
|
17
17
|
.function = {.dmark = NULL, .dfree = Context_free, .dsize = NULL},
|
|
18
|
-
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
19
|
-
};
|
|
18
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
20
19
|
|
|
21
|
-
static sfContext
|
|
22
|
-
sfContext
|
|
20
|
+
static sfContext* Get_Context_Struct(VALUE self) {
|
|
21
|
+
sfContext* ptr;
|
|
23
22
|
TypedData_Get_Struct(self, sfContext, &Context_data_type, ptr);
|
|
24
23
|
return ptr;
|
|
25
24
|
}
|
|
26
25
|
|
|
26
|
+
/* call-seq:
|
|
27
|
+
* Context.new -> Context
|
|
28
|
+
*
|
|
29
|
+
* Creates and activates a new OpenGL context on the current thread.
|
|
30
|
+
*
|
|
31
|
+
* @return [Context]
|
|
32
|
+
* @raise [RuntimeError] if context creation fails
|
|
33
|
+
*/
|
|
27
34
|
static VALUE Context_new(VALUE klass) {
|
|
28
|
-
sfContext
|
|
35
|
+
sfContext* context = sfContext_create();
|
|
29
36
|
VALUE self;
|
|
30
37
|
|
|
31
38
|
if (context == NULL) {
|
|
@@ -37,28 +44,71 @@ static VALUE Context_new(VALUE klass) {
|
|
|
37
44
|
return self;
|
|
38
45
|
}
|
|
39
46
|
|
|
47
|
+
/* call-seq:
|
|
48
|
+
* extension_available?(name) -> true or false
|
|
49
|
+
*
|
|
50
|
+
* Returns +true+ if the OpenGL extension +name+ is available in the currently
|
|
51
|
+
* active context.
|
|
52
|
+
*
|
|
53
|
+
* @return [Boolean] whether the OpenGL extension +name+ is available in the
|
|
54
|
+
* currently active context
|
|
55
|
+
*/
|
|
40
56
|
static VALUE Context_extension_available(VALUE klass, VALUE rb_name) {
|
|
41
57
|
return BOOL2RB(sfContext_isExtensionAvailable(StringValueCStr(rb_name)));
|
|
42
58
|
}
|
|
43
59
|
|
|
60
|
+
/* call-seq:
|
|
61
|
+
* active=(value) -> true or false
|
|
62
|
+
*
|
|
63
|
+
* Activates or deactivates this context as the current one on the calling
|
|
64
|
+
* thread.
|
|
65
|
+
*
|
|
66
|
+
* @return [Boolean] whether activation succeeded
|
|
67
|
+
*/
|
|
44
68
|
static VALUE Context_set_active(VALUE self, VALUE rb_active) {
|
|
45
69
|
return BOOL2RB(sfContext_setActive(Get_Context_Struct(self), RTEST(rb_active)));
|
|
46
70
|
}
|
|
47
71
|
|
|
72
|
+
/* call-seq:
|
|
73
|
+
* function(name) -> Integer
|
|
74
|
+
*
|
|
75
|
+
* Returns the address of the OpenGL function +name+ as an Integer, or 0 when
|
|
76
|
+
* it is not available.
|
|
77
|
+
*
|
|
78
|
+
* @return [Integer] the address of the OpenGL function +name+, as a raw
|
|
79
|
+
* pointer value, or 0 if it is not available
|
|
80
|
+
*/
|
|
48
81
|
static VALUE Context_get_function(VALUE klass, VALUE rb_name) {
|
|
49
|
-
return ULL2NUM((unsigned long long)
|
|
82
|
+
return ULL2NUM((unsigned long long)(uintptr_t)sfContext_getFunction(StringValueCStr(rb_name)));
|
|
50
83
|
}
|
|
51
84
|
|
|
85
|
+
/* call-seq: settings -> ContextSettings
|
|
86
|
+
*
|
|
87
|
+
* Returns the settings this context was created with.
|
|
88
|
+
*
|
|
89
|
+
* @return [ContextSettings] the settings this context was created with
|
|
90
|
+
*/
|
|
52
91
|
static VALUE Context_get_settings(VALUE self) {
|
|
53
92
|
return context_settings_to_rb(sfContext_getSettings(Get_Context_Struct(self)));
|
|
54
93
|
}
|
|
55
94
|
|
|
95
|
+
/* call-seq: active_context_id -> Integer
|
|
96
|
+
*
|
|
97
|
+
* Returns the unique identifier of the currently active context on the
|
|
98
|
+
* calling thread, or 0 if none is active.
|
|
99
|
+
*
|
|
100
|
+
* @return [Integer] the unique identifier of the currently active context on
|
|
101
|
+
* the calling thread, or 0 if none is active
|
|
102
|
+
*/
|
|
56
103
|
static VALUE Context_active_context_id(VALUE klass) {
|
|
57
104
|
return ULL2NUM(sfContext_getActiveContextId());
|
|
58
105
|
}
|
|
59
106
|
|
|
60
|
-
|
|
61
|
-
|
|
107
|
+
/* Document-class: SFML::Context
|
|
108
|
+
* A raw OpenGL context, usable off-screen or on a thread without a Window.
|
|
109
|
+
*/
|
|
110
|
+
void Init_Context(VALUE rb_mSFML) {
|
|
111
|
+
rb_cContext = rb_define_class_under(rb_mSFML, "Context", rb_cObject);
|
|
62
112
|
|
|
63
113
|
rb_define_singleton_method(rb_cContext, "new", Context_new, 0);
|
|
64
114
|
rb_define_singleton_method(rb_cContext, "extension_available?", Context_extension_available, 1);
|