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/shape.c
CHANGED
|
@@ -15,38 +15,37 @@
|
|
|
15
15
|
#include "core/macros.h"
|
|
16
16
|
|
|
17
17
|
typedef struct {
|
|
18
|
-
sfShape
|
|
18
|
+
sfShape* shape;
|
|
19
19
|
VALUE rb_self;
|
|
20
20
|
VALUE rb_texture;
|
|
21
21
|
} CustomShape;
|
|
22
22
|
|
|
23
23
|
static VALUE rb_cCustomShape;
|
|
24
24
|
|
|
25
|
-
static void CustomShape_mark(void
|
|
26
|
-
CustomShape
|
|
25
|
+
static void CustomShape_mark(void* ptr) {
|
|
26
|
+
CustomShape* shape = ptr;
|
|
27
27
|
|
|
28
28
|
rb_gc_mark(shape->rb_self);
|
|
29
29
|
rb_gc_mark(shape->rb_texture);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
static void CustomShape_free(void
|
|
33
|
-
sfShape_destroy(((CustomShape
|
|
32
|
+
static void CustomShape_free(void* ptr) {
|
|
33
|
+
sfShape_destroy(((CustomShape*)ptr)->shape);
|
|
34
34
|
free(ptr);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
static const rb_data_type_t CustomShape_data_type = {
|
|
38
38
|
.wrap_struct_name = "SFML::Shape",
|
|
39
39
|
.function = {.dmark = CustomShape_mark, .dfree = CustomShape_free, .dsize = NULL},
|
|
40
|
-
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
41
|
-
};
|
|
40
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
42
41
|
|
|
43
|
-
static CustomShape
|
|
44
|
-
CustomShape
|
|
42
|
+
static CustomShape* Get_CustomShape(VALUE self) {
|
|
43
|
+
CustomShape* ptr;
|
|
45
44
|
TypedData_Get_Struct(self, CustomShape, &CustomShape_data_type, ptr);
|
|
46
45
|
return ptr;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
static sfShape
|
|
48
|
+
static sfShape* Get_CustomShape_Struct(VALUE self) {
|
|
50
49
|
return Get_CustomShape(self)->shape;
|
|
51
50
|
}
|
|
52
51
|
|
|
@@ -54,53 +53,57 @@ static sfShape *Get_CustomShape_Struct(VALUE self) {
|
|
|
54
53
|
C++ (SFML), so exceptions are contained and reported as a degenerate
|
|
55
54
|
shape instead of unwinding into foreign frames. */
|
|
56
55
|
static VALUE CustomShape_get_point_count_body(VALUE v) {
|
|
57
|
-
CustomShape
|
|
56
|
+
CustomShape* shape = (CustomShape*)v;
|
|
58
57
|
|
|
59
58
|
return rb_funcall(shape->rb_self, rb_intern("point_count"), 0);
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
static size_t CustomShape_get_point_count(void
|
|
63
|
-
CustomShape
|
|
61
|
+
static size_t CustomShape_get_point_count(void* userData) {
|
|
62
|
+
CustomShape* shape = userData;
|
|
64
63
|
int state = 0;
|
|
65
|
-
VALUE count = rb_protect(CustomShape_get_point_count_body, (VALUE)
|
|
64
|
+
VALUE count = rb_protect(CustomShape_get_point_count_body, (VALUE)shape, &state);
|
|
66
65
|
|
|
67
66
|
if (state) {
|
|
68
67
|
rb_set_errinfo(Qnil);
|
|
69
68
|
return 0;
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
return (size_t)
|
|
71
|
+
return (size_t)NUM2SIZET(count);
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
typedef struct {
|
|
76
|
-
CustomShape
|
|
75
|
+
CustomShape* shape;
|
|
77
76
|
size_t index;
|
|
78
77
|
} PointContext;
|
|
79
78
|
|
|
80
79
|
static VALUE CustomShape_get_point_body(VALUE v) {
|
|
81
|
-
PointContext
|
|
80
|
+
PointContext* ctx = (PointContext*)v;
|
|
82
81
|
|
|
83
82
|
return rb_funcall(ctx->shape->rb_self, rb_intern("point"), 1, SIZET2NUM(ctx->index));
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
static sfVector2f CustomShape_get_point(size_t index, void
|
|
87
|
-
CustomShape
|
|
85
|
+
static sfVector2f CustomShape_get_point(size_t index, void* userData) {
|
|
86
|
+
CustomShape* shape = userData;
|
|
88
87
|
PointContext ctx = {.shape = shape, .index = index};
|
|
89
88
|
int state = 0;
|
|
90
|
-
VALUE point = rb_protect(CustomShape_get_point_body, (VALUE)
|
|
89
|
+
VALUE point = rb_protect(CustomShape_get_point_body, (VALUE)&ctx, &state);
|
|
91
90
|
|
|
92
91
|
if (state) {
|
|
93
92
|
rb_set_errinfo(Qnil);
|
|
94
|
-
return (sfVector2f)
|
|
93
|
+
return (sfVector2f){0, 0};
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
return vec2f_from_rb(point);
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
static VALUE
|
|
101
|
-
CustomShape
|
|
99
|
+
static VALUE CustomShape_alloc(VALUE klass) {
|
|
100
|
+
CustomShape* ptr = malloc(sizeof(CustomShape));
|
|
102
101
|
VALUE self;
|
|
103
102
|
|
|
103
|
+
if (ptr == NULL) {
|
|
104
|
+
rb_raise(rb_eNoMemError, "failed to allocate shape");
|
|
105
|
+
}
|
|
106
|
+
|
|
104
107
|
ptr->rb_self = Qnil;
|
|
105
108
|
ptr->rb_texture = Qnil;
|
|
106
109
|
ptr->shape = sfShape_create(CustomShape_get_point_count, CustomShape_get_point, ptr);
|
|
@@ -116,99 +119,250 @@ static VALUE CustomShape_new(VALUE klass) {
|
|
|
116
119
|
return self;
|
|
117
120
|
}
|
|
118
121
|
|
|
122
|
+
/* call-seq:
|
|
123
|
+
* Shape.new -> Shape
|
|
124
|
+
*
|
|
125
|
+
* A base class meant to be subclassed: override #point_count and #point(i)
|
|
126
|
+
* in Ruby to define the shape's geometry, then call #update! whenever it
|
|
127
|
+
* changes.
|
|
128
|
+
*
|
|
129
|
+
* @return [Shape]
|
|
130
|
+
*/
|
|
131
|
+
static VALUE CustomShape_initialize(VALUE self) {
|
|
132
|
+
return self;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* call-seq: update! -> self
|
|
136
|
+
*
|
|
137
|
+
* Recomputes the shape's geometry by calling back into the subclass's
|
|
138
|
+
* #point_count and #point(i). Call this whenever the shape's points
|
|
139
|
+
* change.
|
|
140
|
+
*
|
|
141
|
+
* @return [self]
|
|
142
|
+
*/
|
|
119
143
|
static VALUE CustomShape_update(VALUE self) {
|
|
120
144
|
sfShape_update(Get_CustomShape_Struct(self));
|
|
121
145
|
return self;
|
|
122
146
|
}
|
|
123
147
|
|
|
148
|
+
/* call-seq: position -> Vector2
|
|
149
|
+
*
|
|
150
|
+
* Returns the object's position.
|
|
151
|
+
*
|
|
152
|
+
* @return [Vector2]
|
|
153
|
+
*/
|
|
124
154
|
static VALUE CustomShape_get_position(VALUE self) {
|
|
125
155
|
return vec2f_to_rb(sfShape_getPosition(Get_CustomShape_Struct(self)));
|
|
126
156
|
}
|
|
127
157
|
|
|
158
|
+
/* call-seq:
|
|
159
|
+
* position=(value) -> Vector2
|
|
160
|
+
*
|
|
161
|
+
* Sets the object's position.
|
|
162
|
+
*
|
|
163
|
+
* @return [Vector2] +value+
|
|
164
|
+
*/
|
|
128
165
|
static VALUE CustomShape_set_position(VALUE self, VALUE rb_position) {
|
|
129
166
|
sfShape_setPosition(Get_CustomShape_Struct(self), vec2f_from_rb(rb_position));
|
|
130
167
|
return rb_position;
|
|
131
168
|
}
|
|
132
169
|
|
|
170
|
+
/* call-seq: rotation -> Float
|
|
171
|
+
*
|
|
172
|
+
* Returns the object's rotation, in degrees.
|
|
173
|
+
*
|
|
174
|
+
* @return [Float]
|
|
175
|
+
*/
|
|
133
176
|
static VALUE CustomShape_get_rotation(VALUE self) {
|
|
134
177
|
return DBL2NUM(sfShape_getRotation(Get_CustomShape_Struct(self)));
|
|
135
178
|
}
|
|
136
179
|
|
|
180
|
+
/* call-seq:
|
|
181
|
+
* rotation=(value) -> Float
|
|
182
|
+
*
|
|
183
|
+
* Sets the object's rotation, in degrees.
|
|
184
|
+
*
|
|
185
|
+
* @return [Float] +value+
|
|
186
|
+
*/
|
|
137
187
|
static VALUE CustomShape_set_rotation(VALUE self, VALUE rb_rotation) {
|
|
138
188
|
sfShape_setRotation(Get_CustomShape_Struct(self), NUM2DBL(rb_rotation));
|
|
139
189
|
return rb_rotation;
|
|
140
190
|
}
|
|
141
191
|
|
|
192
|
+
/* call-seq: scale -> Vector2
|
|
193
|
+
*
|
|
194
|
+
* Returns the object's scale factors.
|
|
195
|
+
*
|
|
196
|
+
* @return [Vector2]
|
|
197
|
+
*/
|
|
142
198
|
static VALUE CustomShape_get_scale(VALUE self) {
|
|
143
199
|
return vec2f_to_rb(sfShape_getScale(Get_CustomShape_Struct(self)));
|
|
144
200
|
}
|
|
145
201
|
|
|
202
|
+
/* call-seq:
|
|
203
|
+
* scale=(value) -> Vector2
|
|
204
|
+
*
|
|
205
|
+
* Sets the object's scale factors.
|
|
206
|
+
*
|
|
207
|
+
* @return [Vector2] +value+
|
|
208
|
+
*/
|
|
146
209
|
static VALUE CustomShape_set_scale(VALUE self, VALUE rb_scale) {
|
|
147
210
|
sfShape_setScale(Get_CustomShape_Struct(self), vec2f_from_rb(rb_scale));
|
|
148
211
|
return rb_scale;
|
|
149
212
|
}
|
|
150
213
|
|
|
214
|
+
/* call-seq: origin -> Vector2
|
|
215
|
+
*
|
|
216
|
+
* Returns the object's origin.
|
|
217
|
+
*
|
|
218
|
+
* @return [Vector2]
|
|
219
|
+
*/
|
|
151
220
|
static VALUE CustomShape_get_origin(VALUE self) {
|
|
152
221
|
return vec2f_to_rb(sfShape_getOrigin(Get_CustomShape_Struct(self)));
|
|
153
222
|
}
|
|
154
223
|
|
|
224
|
+
/* call-seq:
|
|
225
|
+
* origin=(value) -> Vector2
|
|
226
|
+
*
|
|
227
|
+
* Sets the object's origin.
|
|
228
|
+
*
|
|
229
|
+
* @return [Vector2] +value+
|
|
230
|
+
*/
|
|
155
231
|
static VALUE CustomShape_set_origin(VALUE self, VALUE rb_origin) {
|
|
156
232
|
sfShape_setOrigin(Get_CustomShape_Struct(self), vec2f_from_rb(rb_origin));
|
|
157
233
|
return rb_origin;
|
|
158
234
|
}
|
|
159
235
|
|
|
236
|
+
/* call-seq: move(offset) -> self
|
|
237
|
+
*
|
|
238
|
+
* Moves the object by +offset+.
|
|
239
|
+
*
|
|
240
|
+
* @return [self]
|
|
241
|
+
*/
|
|
160
242
|
static VALUE CustomShape_move(VALUE self, VALUE rb_offset) {
|
|
161
243
|
sfShape_move(Get_CustomShape_Struct(self), vec2f_from_rb(rb_offset));
|
|
162
244
|
return self;
|
|
163
245
|
}
|
|
164
246
|
|
|
247
|
+
/* call-seq: rotate(angle) -> self
|
|
248
|
+
*
|
|
249
|
+
* Rotates the object by +angle+ degrees.
|
|
250
|
+
*
|
|
251
|
+
* @return [self]
|
|
252
|
+
*/
|
|
165
253
|
static VALUE CustomShape_rotate(VALUE self, VALUE rb_angle) {
|
|
166
254
|
sfShape_rotate(Get_CustomShape_Struct(self), NUM2DBL(rb_angle));
|
|
167
255
|
return self;
|
|
168
256
|
}
|
|
169
257
|
|
|
258
|
+
/* call-seq:
|
|
259
|
+
* scale!(factors) -> self
|
|
260
|
+
*
|
|
261
|
+
* Scales the object by +factors+ relative to its current scale.
|
|
262
|
+
*
|
|
263
|
+
* @return [self]
|
|
264
|
+
*/
|
|
170
265
|
static VALUE CustomShape_scale(VALUE self, VALUE rb_factors) {
|
|
171
266
|
sfShape_scale(Get_CustomShape_Struct(self), vec2f_from_rb(rb_factors));
|
|
172
267
|
return self;
|
|
173
268
|
}
|
|
174
269
|
|
|
270
|
+
/* call-seq: transform -> Array
|
|
271
|
+
*
|
|
272
|
+
* Also available as #matrix.
|
|
273
|
+
*
|
|
274
|
+
* @return [Array] the 3x3 row-major transform matrix
|
|
275
|
+
*/
|
|
175
276
|
static VALUE CustomShape_get_transform(VALUE self) {
|
|
176
277
|
return Transform_MatrixToArray(sfShape_getTransform(Get_CustomShape_Struct(self)).matrix);
|
|
177
278
|
}
|
|
178
279
|
|
|
280
|
+
/* call-seq: inverse_transform -> Array
|
|
281
|
+
*
|
|
282
|
+
* Returns the 3x3 row-major inverse of the object's transform matrix.
|
|
283
|
+
*
|
|
284
|
+
* @return [Array] the 3x3 row-major inverse transform matrix
|
|
285
|
+
*/
|
|
179
286
|
static VALUE CustomShape_get_inverse_transform(VALUE self) {
|
|
180
|
-
return Transform_MatrixToArray(
|
|
287
|
+
return Transform_MatrixToArray(
|
|
288
|
+
sfShape_getInverseTransform(Get_CustomShape_Struct(self)).matrix);
|
|
181
289
|
}
|
|
182
290
|
|
|
291
|
+
/* call-seq: fill_color -> Color
|
|
292
|
+
*
|
|
293
|
+
* Returns the shape's fill color.
|
|
294
|
+
*
|
|
295
|
+
* @return [Color]
|
|
296
|
+
*/
|
|
183
297
|
static VALUE CustomShape_get_fill_color(VALUE self) {
|
|
184
298
|
return color_to_rb(sfShape_getFillColor(Get_CustomShape_Struct(self)));
|
|
185
299
|
}
|
|
186
300
|
|
|
301
|
+
/* call-seq:
|
|
302
|
+
* fill_color=(value) -> Color
|
|
303
|
+
*
|
|
304
|
+
* Sets the shape's fill color.
|
|
305
|
+
*
|
|
306
|
+
* @return [Color] +value+
|
|
307
|
+
*/
|
|
187
308
|
static VALUE CustomShape_set_fill_color(VALUE self, VALUE rb_color) {
|
|
188
309
|
sfShape_setFillColor(Get_CustomShape_Struct(self), color_from_rb(rb_color));
|
|
189
310
|
return rb_color;
|
|
190
311
|
}
|
|
191
312
|
|
|
313
|
+
/* call-seq: outline_color -> Color
|
|
314
|
+
*
|
|
315
|
+
* Returns the shape's outline color.
|
|
316
|
+
*
|
|
317
|
+
* @return [Color]
|
|
318
|
+
*/
|
|
192
319
|
static VALUE CustomShape_get_outline_color(VALUE self) {
|
|
193
320
|
return color_to_rb(sfShape_getOutlineColor(Get_CustomShape_Struct(self)));
|
|
194
321
|
}
|
|
195
322
|
|
|
323
|
+
/* call-seq:
|
|
324
|
+
* outline_color=(value) -> Color
|
|
325
|
+
*
|
|
326
|
+
* Sets the shape's outline color.
|
|
327
|
+
*
|
|
328
|
+
* @return [Color] +value+
|
|
329
|
+
*/
|
|
196
330
|
static VALUE CustomShape_set_outline_color(VALUE self, VALUE rb_color) {
|
|
197
331
|
sfShape_setOutlineColor(Get_CustomShape_Struct(self), color_from_rb(rb_color));
|
|
198
332
|
return rb_color;
|
|
199
333
|
}
|
|
200
334
|
|
|
335
|
+
/* call-seq: outline_thickness -> Float
|
|
336
|
+
*
|
|
337
|
+
* Returns the shape's outline thickness.
|
|
338
|
+
*
|
|
339
|
+
* @return [Float]
|
|
340
|
+
*/
|
|
201
341
|
static VALUE CustomShape_get_outline_thickness(VALUE self) {
|
|
202
342
|
return DBL2NUM(sfShape_getOutlineThickness(Get_CustomShape_Struct(self)));
|
|
203
343
|
}
|
|
204
344
|
|
|
345
|
+
/* call-seq:
|
|
346
|
+
* outline_thickness=(value) -> Float
|
|
347
|
+
*
|
|
348
|
+
* Sets the shape's outline thickness.
|
|
349
|
+
*
|
|
350
|
+
* @return [Float] +value+
|
|
351
|
+
*/
|
|
205
352
|
static VALUE CustomShape_set_outline_thickness(VALUE self, VALUE rb_thickness) {
|
|
206
353
|
sfShape_setOutlineThickness(Get_CustomShape_Struct(self), NUM2DBL(rb_thickness));
|
|
207
354
|
return rb_thickness;
|
|
208
355
|
}
|
|
209
356
|
|
|
357
|
+
/* call-seq:
|
|
358
|
+
* texture=(value) -> Texture or nil
|
|
359
|
+
*
|
|
360
|
+
* Sets the object's texture.
|
|
361
|
+
*
|
|
362
|
+
* @return [Texture, nil] +value+
|
|
363
|
+
*/
|
|
210
364
|
static VALUE CustomShape_set_texture(VALUE self, VALUE rb_texture) {
|
|
211
|
-
CustomShape
|
|
365
|
+
CustomShape* ptr = Get_CustomShape(self);
|
|
212
366
|
|
|
213
367
|
if (NIL_P(rb_texture)) {
|
|
214
368
|
ptr->rb_texture = Qnil;
|
|
@@ -226,52 +380,131 @@ static VALUE CustomShape_set_texture(VALUE self, VALUE rb_texture) {
|
|
|
226
380
|
return rb_texture;
|
|
227
381
|
}
|
|
228
382
|
|
|
383
|
+
/* call-seq: texture -> Texture or nil
|
|
384
|
+
*
|
|
385
|
+
* Returns the object's texture, or +nil+ if it has none.
|
|
386
|
+
*
|
|
387
|
+
* @return [Texture, nil]
|
|
388
|
+
*/
|
|
229
389
|
static VALUE CustomShape_get_texture(VALUE self) {
|
|
230
390
|
return Get_CustomShape(self)->rb_texture;
|
|
231
391
|
}
|
|
232
392
|
|
|
393
|
+
/* call-seq: texture_rect -> Rect
|
|
394
|
+
*
|
|
395
|
+
* Returns the sub-rectangle of the texture displayed on the object.
|
|
396
|
+
*
|
|
397
|
+
* @return [Rect] the sub-rectangle of the texture displayed on the shape
|
|
398
|
+
*/
|
|
233
399
|
static VALUE CustomShape_get_texture_rect(VALUE self) {
|
|
234
400
|
return int_rect_to_rb(sfShape_getTextureRect(Get_CustomShape_Struct(self)));
|
|
235
401
|
}
|
|
236
402
|
|
|
403
|
+
/* call-seq:
|
|
404
|
+
* texture_rect=(value) -> Rect
|
|
405
|
+
*
|
|
406
|
+
* Sets the sub-rectangle of the texture displayed on the object.
|
|
407
|
+
*
|
|
408
|
+
* @return [Rect] +value+
|
|
409
|
+
*/
|
|
237
410
|
static VALUE CustomShape_set_texture_rect(VALUE self, VALUE rb_rect) {
|
|
238
411
|
sfShape_setTextureRect(Get_CustomShape_Struct(self), int_rect_from_rb(rb_rect));
|
|
239
412
|
return rb_rect;
|
|
240
413
|
}
|
|
241
414
|
|
|
415
|
+
/* call-seq: geometric_center -> Vector2
|
|
416
|
+
*
|
|
417
|
+
* Returns the local position of the shape's geometric center.
|
|
418
|
+
*
|
|
419
|
+
* @return [Vector2] the local position of the shape's geometric center
|
|
420
|
+
*/
|
|
242
421
|
static VALUE CustomShape_get_geometric_center(VALUE self) {
|
|
243
422
|
return vec2f_to_rb(sfShape_getGeometricCenter(Get_CustomShape_Struct(self)));
|
|
244
423
|
}
|
|
245
424
|
|
|
425
|
+
/* call-seq: local_bounds -> Rect
|
|
426
|
+
*
|
|
427
|
+
* Returns the bounding box in local (untransformed) coordinates.
|
|
428
|
+
*
|
|
429
|
+
* @return [Rect] the bounding box in local (untransformed) coordinates
|
|
430
|
+
*/
|
|
246
431
|
static VALUE CustomShape_get_local_bounds(VALUE self) {
|
|
247
432
|
return rect_to_rb(sfShape_getLocalBounds(Get_CustomShape_Struct(self)));
|
|
248
433
|
}
|
|
249
434
|
|
|
435
|
+
/* call-seq: global_bounds -> Rect
|
|
436
|
+
*
|
|
437
|
+
* Returns the bounding box after the transform is applied.
|
|
438
|
+
*
|
|
439
|
+
* @return [Rect] the bounding box after transform is applied
|
|
440
|
+
*/
|
|
250
441
|
static VALUE CustomShape_get_global_bounds(VALUE self) {
|
|
251
442
|
return rect_to_rb(sfShape_getGlobalBounds(Get_CustomShape_Struct(self)));
|
|
252
443
|
}
|
|
253
444
|
|
|
445
|
+
/* call-seq:
|
|
446
|
+
* draw(target, state) -> nil
|
|
447
|
+
*
|
|
448
|
+
* Draws the object onto +target+ using the given render +state+.
|
|
449
|
+
*
|
|
450
|
+
* @return [nil]
|
|
451
|
+
*/
|
|
254
452
|
static VALUE CustomShape_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
255
|
-
|
|
256
|
-
raise_invalid_argument_class(Get_Klass_Target());
|
|
257
|
-
}
|
|
453
|
+
TargetView view = Get_RenderTarget_View(rb_target);
|
|
258
454
|
|
|
259
455
|
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
|
|
260
456
|
raise_invalid_argument_class(Get_Klass_RenderState());
|
|
261
457
|
}
|
|
262
458
|
|
|
263
|
-
TARGET_DRAW(
|
|
459
|
+
TARGET_DRAW(view, sfRenderWindow_drawShape, sfRenderTexture_drawShape,
|
|
264
460
|
Get_CustomShape_Struct(self), Get_RenderState_Struct(rb_state));
|
|
265
461
|
|
|
266
462
|
return Qnil;
|
|
267
463
|
}
|
|
268
464
|
|
|
269
|
-
|
|
270
|
-
|
|
465
|
+
/* Document-class: SFML::Shape
|
|
466
|
+
* A base class for user-defined shapes. Subclass it and implement
|
|
467
|
+
* #point_count and #point(index) in Ruby to describe the shape's geometry,
|
|
468
|
+
* then call #update! after construction and whenever the points change.
|
|
469
|
+
* Drawable, transformable and stylable like the other SFML shapes.
|
|
470
|
+
* Includes Drawable.
|
|
471
|
+
*
|
|
472
|
+
* @!attribute position
|
|
473
|
+
* The object's position.
|
|
474
|
+
* @return [Vector2]
|
|
475
|
+
* @!attribute rotation
|
|
476
|
+
* The object's rotation, in degrees.
|
|
477
|
+
* @return [Float]
|
|
478
|
+
* @!attribute scale
|
|
479
|
+
* The object's scale factors.
|
|
480
|
+
* @return [Vector2]
|
|
481
|
+
* @!attribute origin
|
|
482
|
+
* The object's origin.
|
|
483
|
+
* @return [Vector2]
|
|
484
|
+
* @!attribute fill_color
|
|
485
|
+
* The object's fill color.
|
|
486
|
+
* @return [Color]
|
|
487
|
+
* @!attribute outline_color
|
|
488
|
+
* The object's outline color.
|
|
489
|
+
* @return [Color]
|
|
490
|
+
* @!attribute outline_thickness
|
|
491
|
+
* The object's outline thickness.
|
|
492
|
+
* @return [Float]
|
|
493
|
+
* @!attribute texture
|
|
494
|
+
* The object's texture, or +nil+ if it has none.
|
|
495
|
+
* @return [Texture, nil]
|
|
496
|
+
* @!attribute texture_rect
|
|
497
|
+
* The sub-rectangle of the texture displayed on the object.
|
|
498
|
+
* @return [Rect]
|
|
499
|
+
*/
|
|
500
|
+
void Init_Shape(VALUE rb_mSFML) {
|
|
501
|
+
rb_cCustomShape = rb_define_class_under(rb_mSFML, "Shape", rb_cObject);
|
|
502
|
+
|
|
503
|
+
rb_define_alloc_func(rb_cCustomShape, CustomShape_alloc);
|
|
271
504
|
|
|
272
505
|
rb_include_module(rb_cCustomShape, Get_Module_Drawable());
|
|
273
506
|
|
|
274
|
-
|
|
507
|
+
rb_define_method(rb_cCustomShape, "initialize", CustomShape_initialize, 0);
|
|
275
508
|
|
|
276
509
|
rb_define_method(rb_cCustomShape, "update!", CustomShape_update, 0);
|
|
277
510
|
rb_define_method(rb_cCustomShape, "position", CustomShape_get_position, 0);
|