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
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
#include "graphics/shape.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
|
|
6
|
+
#include "graphics/drawable.h"
|
|
7
|
+
#include "graphics/target.h"
|
|
8
|
+
#include "graphics/render_state.h"
|
|
9
|
+
#include "graphics/transform.h"
|
|
10
|
+
#include "graphics/color.h"
|
|
11
|
+
#include "graphics/rect.h"
|
|
12
|
+
#include "graphics/texture.h"
|
|
13
|
+
#include "system/vec2.h"
|
|
14
|
+
#include "core/exceptions.h"
|
|
15
|
+
#include "core/macros.h"
|
|
16
|
+
|
|
17
|
+
typedef struct {
|
|
18
|
+
sfShape *shape;
|
|
19
|
+
VALUE rb_self;
|
|
20
|
+
VALUE rb_texture;
|
|
21
|
+
} CustomShape;
|
|
22
|
+
|
|
23
|
+
static VALUE rb_cCustomShape;
|
|
24
|
+
|
|
25
|
+
static void CustomShape_mark(void *ptr) {
|
|
26
|
+
CustomShape *shape = ptr;
|
|
27
|
+
|
|
28
|
+
rb_gc_mark(shape->rb_self);
|
|
29
|
+
rb_gc_mark(shape->rb_texture);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static void CustomShape_free(void *ptr) {
|
|
33
|
+
sfShape_destroy(((CustomShape *) ptr)->shape);
|
|
34
|
+
free(ptr);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static const rb_data_type_t CustomShape_data_type = {
|
|
38
|
+
.wrap_struct_name = "SFML::Shape",
|
|
39
|
+
.function = {.dmark = CustomShape_mark, .dfree = CustomShape_free, .dsize = NULL},
|
|
40
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
static CustomShape *Get_CustomShape(VALUE self) {
|
|
44
|
+
CustomShape *ptr;
|
|
45
|
+
TypedData_Get_Struct(self, CustomShape, &CustomShape_data_type, ptr);
|
|
46
|
+
return ptr;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static sfShape *Get_CustomShape_Struct(VALUE self) {
|
|
50
|
+
return Get_CustomShape(self)->shape;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Point access is defined in Ruby, and these callbacks are reached through
|
|
54
|
+
C++ (SFML), so exceptions are contained and reported as a degenerate
|
|
55
|
+
shape instead of unwinding into foreign frames. */
|
|
56
|
+
static VALUE CustomShape_get_point_count_body(VALUE v) {
|
|
57
|
+
CustomShape *shape = (CustomShape *) v;
|
|
58
|
+
|
|
59
|
+
return rb_funcall(shape->rb_self, rb_intern("point_count"), 0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static size_t CustomShape_get_point_count(void *userData) {
|
|
63
|
+
CustomShape *shape = userData;
|
|
64
|
+
int state = 0;
|
|
65
|
+
VALUE count = rb_protect(CustomShape_get_point_count_body, (VALUE) shape, &state);
|
|
66
|
+
|
|
67
|
+
if (state) {
|
|
68
|
+
rb_set_errinfo(Qnil);
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (size_t) NUM2SIZET(count);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
typedef struct {
|
|
76
|
+
CustomShape *shape;
|
|
77
|
+
size_t index;
|
|
78
|
+
} PointContext;
|
|
79
|
+
|
|
80
|
+
static VALUE CustomShape_get_point_body(VALUE v) {
|
|
81
|
+
PointContext *ctx = (PointContext *) v;
|
|
82
|
+
|
|
83
|
+
return rb_funcall(ctx->shape->rb_self, rb_intern("point"), 1, SIZET2NUM(ctx->index));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static sfVector2f CustomShape_get_point(size_t index, void *userData) {
|
|
87
|
+
CustomShape *shape = userData;
|
|
88
|
+
PointContext ctx = {.shape = shape, .index = index};
|
|
89
|
+
int state = 0;
|
|
90
|
+
VALUE point = rb_protect(CustomShape_get_point_body, (VALUE) &ctx, &state);
|
|
91
|
+
|
|
92
|
+
if (state) {
|
|
93
|
+
rb_set_errinfo(Qnil);
|
|
94
|
+
return (sfVector2f) {0, 0};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return vec2f_from_rb(point);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static VALUE CustomShape_new(VALUE klass) {
|
|
101
|
+
CustomShape *ptr = malloc(sizeof(CustomShape));
|
|
102
|
+
VALUE self;
|
|
103
|
+
|
|
104
|
+
ptr->rb_self = Qnil;
|
|
105
|
+
ptr->rb_texture = Qnil;
|
|
106
|
+
ptr->shape = sfShape_create(CustomShape_get_point_count, CustomShape_get_point, ptr);
|
|
107
|
+
|
|
108
|
+
if (ptr->shape == NULL) {
|
|
109
|
+
free(ptr);
|
|
110
|
+
rb_raise(rb_eRuntimeError, "failed to create shape");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
self = TypedData_Wrap_Struct(klass, &CustomShape_data_type, ptr);
|
|
114
|
+
ptr->rb_self = self;
|
|
115
|
+
|
|
116
|
+
return self;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static VALUE CustomShape_update(VALUE self) {
|
|
120
|
+
sfShape_update(Get_CustomShape_Struct(self));
|
|
121
|
+
return self;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
static VALUE CustomShape_get_position(VALUE self) {
|
|
125
|
+
return vec2f_to_rb(sfShape_getPosition(Get_CustomShape_Struct(self)));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
static VALUE CustomShape_set_position(VALUE self, VALUE rb_position) {
|
|
129
|
+
sfShape_setPosition(Get_CustomShape_Struct(self), vec2f_from_rb(rb_position));
|
|
130
|
+
return rb_position;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static VALUE CustomShape_get_rotation(VALUE self) {
|
|
134
|
+
return DBL2NUM(sfShape_getRotation(Get_CustomShape_Struct(self)));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static VALUE CustomShape_set_rotation(VALUE self, VALUE rb_rotation) {
|
|
138
|
+
sfShape_setRotation(Get_CustomShape_Struct(self), NUM2DBL(rb_rotation));
|
|
139
|
+
return rb_rotation;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
static VALUE CustomShape_get_scale(VALUE self) {
|
|
143
|
+
return vec2f_to_rb(sfShape_getScale(Get_CustomShape_Struct(self)));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static VALUE CustomShape_set_scale(VALUE self, VALUE rb_scale) {
|
|
147
|
+
sfShape_setScale(Get_CustomShape_Struct(self), vec2f_from_rb(rb_scale));
|
|
148
|
+
return rb_scale;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static VALUE CustomShape_get_origin(VALUE self) {
|
|
152
|
+
return vec2f_to_rb(sfShape_getOrigin(Get_CustomShape_Struct(self)));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static VALUE CustomShape_set_origin(VALUE self, VALUE rb_origin) {
|
|
156
|
+
sfShape_setOrigin(Get_CustomShape_Struct(self), vec2f_from_rb(rb_origin));
|
|
157
|
+
return rb_origin;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
static VALUE CustomShape_move(VALUE self, VALUE rb_offset) {
|
|
161
|
+
sfShape_move(Get_CustomShape_Struct(self), vec2f_from_rb(rb_offset));
|
|
162
|
+
return self;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
static VALUE CustomShape_rotate(VALUE self, VALUE rb_angle) {
|
|
166
|
+
sfShape_rotate(Get_CustomShape_Struct(self), NUM2DBL(rb_angle));
|
|
167
|
+
return self;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static VALUE CustomShape_scale(VALUE self, VALUE rb_factors) {
|
|
171
|
+
sfShape_scale(Get_CustomShape_Struct(self), vec2f_from_rb(rb_factors));
|
|
172
|
+
return self;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static VALUE CustomShape_get_transform(VALUE self) {
|
|
176
|
+
return Transform_MatrixToArray(sfShape_getTransform(Get_CustomShape_Struct(self)).matrix);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
static VALUE CustomShape_get_inverse_transform(VALUE self) {
|
|
180
|
+
return Transform_MatrixToArray(sfShape_getInverseTransform(Get_CustomShape_Struct(self)).matrix);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
static VALUE CustomShape_get_fill_color(VALUE self) {
|
|
184
|
+
return color_to_rb(sfShape_getFillColor(Get_CustomShape_Struct(self)));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
static VALUE CustomShape_set_fill_color(VALUE self, VALUE rb_color) {
|
|
188
|
+
sfShape_setFillColor(Get_CustomShape_Struct(self), color_from_rb(rb_color));
|
|
189
|
+
return rb_color;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
static VALUE CustomShape_get_outline_color(VALUE self) {
|
|
193
|
+
return color_to_rb(sfShape_getOutlineColor(Get_CustomShape_Struct(self)));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
static VALUE CustomShape_set_outline_color(VALUE self, VALUE rb_color) {
|
|
197
|
+
sfShape_setOutlineColor(Get_CustomShape_Struct(self), color_from_rb(rb_color));
|
|
198
|
+
return rb_color;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
static VALUE CustomShape_get_outline_thickness(VALUE self) {
|
|
202
|
+
return DBL2NUM(sfShape_getOutlineThickness(Get_CustomShape_Struct(self)));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
static VALUE CustomShape_set_outline_thickness(VALUE self, VALUE rb_thickness) {
|
|
206
|
+
sfShape_setOutlineThickness(Get_CustomShape_Struct(self), NUM2DBL(rb_thickness));
|
|
207
|
+
return rb_thickness;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
static VALUE CustomShape_set_texture(VALUE self, VALUE rb_texture) {
|
|
211
|
+
CustomShape *ptr = Get_CustomShape(self);
|
|
212
|
+
|
|
213
|
+
if (NIL_P(rb_texture)) {
|
|
214
|
+
ptr->rb_texture = Qnil;
|
|
215
|
+
sfShape_setTexture(ptr->shape, NULL, false);
|
|
216
|
+
return rb_texture;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (!rb_obj_is_kind_of(rb_texture, Get_Klass_Texture())) {
|
|
220
|
+
raise_invalid_argument_class(Get_Klass_Texture());
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
ptr->rb_texture = rb_texture;
|
|
224
|
+
sfShape_setTexture(ptr->shape, Get_Texture_Struct(rb_texture), false);
|
|
225
|
+
|
|
226
|
+
return rb_texture;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
static VALUE CustomShape_get_texture(VALUE self) {
|
|
230
|
+
return Get_CustomShape(self)->rb_texture;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
static VALUE CustomShape_get_texture_rect(VALUE self) {
|
|
234
|
+
return int_rect_to_rb(sfShape_getTextureRect(Get_CustomShape_Struct(self)));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
static VALUE CustomShape_set_texture_rect(VALUE self, VALUE rb_rect) {
|
|
238
|
+
sfShape_setTextureRect(Get_CustomShape_Struct(self), int_rect_from_rb(rb_rect));
|
|
239
|
+
return rb_rect;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
static VALUE CustomShape_get_geometric_center(VALUE self) {
|
|
243
|
+
return vec2f_to_rb(sfShape_getGeometricCenter(Get_CustomShape_Struct(self)));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
static VALUE CustomShape_get_local_bounds(VALUE self) {
|
|
247
|
+
return rect_to_rb(sfShape_getLocalBounds(Get_CustomShape_Struct(self)));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
static VALUE CustomShape_get_global_bounds(VALUE self) {
|
|
251
|
+
return rect_to_rb(sfShape_getGlobalBounds(Get_CustomShape_Struct(self)));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
static VALUE CustomShape_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
255
|
+
if (!rb_obj_is_kind_of(rb_target, Get_Klass_Target())) {
|
|
256
|
+
raise_invalid_argument_class(Get_Klass_Target());
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
|
|
260
|
+
raise_invalid_argument_class(Get_Klass_RenderState());
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
TARGET_DRAW(Get_Target_Struct(rb_target), sfRenderWindow_drawShape, sfRenderTexture_drawShape,
|
|
264
|
+
Get_CustomShape_Struct(self), Get_RenderState_Struct(rb_state));
|
|
265
|
+
|
|
266
|
+
return Qnil;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
void Init_Shape(VALUE rb_module) {
|
|
270
|
+
rb_cCustomShape = rb_define_class_under(rb_module, "Shape", rb_cObject);
|
|
271
|
+
|
|
272
|
+
rb_include_module(rb_cCustomShape, Get_Module_Drawable());
|
|
273
|
+
|
|
274
|
+
rb_define_singleton_method(rb_cCustomShape, "new", CustomShape_new, 0);
|
|
275
|
+
|
|
276
|
+
rb_define_method(rb_cCustomShape, "update!", CustomShape_update, 0);
|
|
277
|
+
rb_define_method(rb_cCustomShape, "position", CustomShape_get_position, 0);
|
|
278
|
+
rb_define_method(rb_cCustomShape, "rotation", CustomShape_get_rotation, 0);
|
|
279
|
+
rb_define_method(rb_cCustomShape, "scale", CustomShape_get_scale, 0);
|
|
280
|
+
rb_define_method(rb_cCustomShape, "origin", CustomShape_get_origin, 0);
|
|
281
|
+
rb_define_method(rb_cCustomShape, "fill_color", CustomShape_get_fill_color, 0);
|
|
282
|
+
rb_define_method(rb_cCustomShape, "outline_color", CustomShape_get_outline_color, 0);
|
|
283
|
+
rb_define_method(rb_cCustomShape, "outline_thickness", CustomShape_get_outline_thickness, 0);
|
|
284
|
+
rb_define_method(rb_cCustomShape, "texture", CustomShape_get_texture, 0);
|
|
285
|
+
rb_define_method(rb_cCustomShape, "texture_rect", CustomShape_get_texture_rect, 0);
|
|
286
|
+
rb_define_method(rb_cCustomShape, "geometric_center", CustomShape_get_geometric_center, 0);
|
|
287
|
+
rb_define_method(rb_cCustomShape, "local_bounds", CustomShape_get_local_bounds, 0);
|
|
288
|
+
rb_define_method(rb_cCustomShape, "global_bounds", CustomShape_get_global_bounds, 0);
|
|
289
|
+
rb_define_method(rb_cCustomShape, "transform", CustomShape_get_transform, 0);
|
|
290
|
+
rb_define_method(rb_cCustomShape, "inverse_transform", CustomShape_get_inverse_transform, 0);
|
|
291
|
+
rb_define_method(rb_cCustomShape, "matrix", CustomShape_get_transform, 0);
|
|
292
|
+
|
|
293
|
+
rb_define_method(rb_cCustomShape, "position=", CustomShape_set_position, 1);
|
|
294
|
+
rb_define_method(rb_cCustomShape, "rotation=", CustomShape_set_rotation, 1);
|
|
295
|
+
rb_define_method(rb_cCustomShape, "scale=", CustomShape_set_scale, 1);
|
|
296
|
+
rb_define_method(rb_cCustomShape, "origin=", CustomShape_set_origin, 1);
|
|
297
|
+
rb_define_method(rb_cCustomShape, "fill_color=", CustomShape_set_fill_color, 1);
|
|
298
|
+
rb_define_method(rb_cCustomShape, "outline_color=", CustomShape_set_outline_color, 1);
|
|
299
|
+
rb_define_method(rb_cCustomShape, "outline_thickness=", CustomShape_set_outline_thickness, 1);
|
|
300
|
+
rb_define_method(rb_cCustomShape, "texture=", CustomShape_set_texture, 1);
|
|
301
|
+
rb_define_method(rb_cCustomShape, "texture_rect=", CustomShape_set_texture_rect, 1);
|
|
302
|
+
|
|
303
|
+
rb_define_method(rb_cCustomShape, "move", CustomShape_move, 1);
|
|
304
|
+
rb_define_method(rb_cCustomShape, "rotate", CustomShape_rotate, 1);
|
|
305
|
+
rb_define_method(rb_cCustomShape, "scale!", CustomShape_scale, 1);
|
|
306
|
+
rb_define_method(rb_cCustomShape, "draw", CustomShape_draw, 2);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
VALUE Get_Klass_Shape(void) {
|
|
310
|
+
return rb_cCustomShape;
|
|
311
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
#include "graphics/sprite.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
|
|
6
|
+
#include "graphics/drawable.h"
|
|
7
|
+
#include "graphics/target.h"
|
|
8
|
+
#include "graphics/render_state.h"
|
|
9
|
+
#include "graphics/transform.h"
|
|
10
|
+
#include "graphics/color.h"
|
|
11
|
+
#include "graphics/rect.h"
|
|
12
|
+
#include "graphics/texture.h"
|
|
13
|
+
#include "system/vec2.h"
|
|
14
|
+
#include "core/exceptions.h"
|
|
15
|
+
#include "core/macros.h"
|
|
16
|
+
|
|
17
|
+
typedef struct {
|
|
18
|
+
sfSprite *sprite;
|
|
19
|
+
VALUE rb_texture;
|
|
20
|
+
} Sprite;
|
|
21
|
+
|
|
22
|
+
static VALUE rb_cSprite;
|
|
23
|
+
|
|
24
|
+
static void Sprite_mark(void *ptr) {
|
|
25
|
+
rb_gc_mark(((Sprite *) ptr)->rb_texture);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static void Sprite_free(void *ptr) {
|
|
29
|
+
sfSprite_destroy(((Sprite *) ptr)->sprite);
|
|
30
|
+
free(ptr);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static const rb_data_type_t Sprite_data_type = {
|
|
34
|
+
.wrap_struct_name = "SFML::Sprite",
|
|
35
|
+
.function = {.dmark = Sprite_mark, .dfree = Sprite_free, .dsize = NULL},
|
|
36
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
static Sprite *Get_Sprite(VALUE self) {
|
|
40
|
+
Sprite *ptr;
|
|
41
|
+
TypedData_Get_Struct(self, Sprite, &Sprite_data_type, ptr);
|
|
42
|
+
return ptr;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static sfSprite *Get_Sprite_Struct(VALUE self) {
|
|
46
|
+
return Get_Sprite(self)->sprite;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static VALUE Sprite_wrap(VALUE klass, sfSprite *sprite) {
|
|
50
|
+
Sprite *ptr;
|
|
51
|
+
|
|
52
|
+
if (sprite == NULL) {
|
|
53
|
+
rb_raise(rb_eRuntimeError, "failed to create sprite");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
ptr = malloc(sizeof(Sprite));
|
|
57
|
+
ptr->sprite = sprite;
|
|
58
|
+
ptr->rb_texture = Qnil;
|
|
59
|
+
|
|
60
|
+
return TypedData_Wrap_Struct(klass, &Sprite_data_type, ptr);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static VALUE Sprite_new(int argc, VALUE *argv, VALUE klass) {
|
|
64
|
+
VALUE rb_texture, self;
|
|
65
|
+
Sprite *ptr;
|
|
66
|
+
|
|
67
|
+
rb_scan_args(argc, argv, "01", &rb_texture);
|
|
68
|
+
|
|
69
|
+
if (!NIL_P(rb_texture) && !rb_obj_is_kind_of(rb_texture, Get_Klass_Texture())) {
|
|
70
|
+
raise_invalid_argument_class(Get_Klass_Texture());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
ptr = malloc(sizeof(Sprite));
|
|
74
|
+
ptr->sprite = sfSprite_create(NIL_P(rb_texture) ? NULL : Get_Texture_Struct(rb_texture));
|
|
75
|
+
ptr->rb_texture = NIL_P(rb_texture) ? Qnil : rb_texture;
|
|
76
|
+
|
|
77
|
+
self = TypedData_Wrap_Struct(klass, &Sprite_data_type, ptr);
|
|
78
|
+
|
|
79
|
+
return self;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static VALUE Sprite_copy(VALUE self) {
|
|
83
|
+
Sprite *ptr = Get_Sprite(self);
|
|
84
|
+
|
|
85
|
+
return Sprite_wrap(Get_Klass_Sprite(), sfSprite_copy(ptr->sprite));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static VALUE Sprite_set_texture(VALUE self, VALUE rb_texture) {
|
|
89
|
+
Sprite *ptr = Get_Sprite(self);
|
|
90
|
+
|
|
91
|
+
if (NIL_P(rb_texture)) {
|
|
92
|
+
ptr->rb_texture = Qnil;
|
|
93
|
+
sfSprite_setTexture(ptr->sprite, NULL, false);
|
|
94
|
+
return rb_texture;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!rb_obj_is_kind_of(rb_texture, Get_Klass_Texture())) {
|
|
98
|
+
raise_invalid_argument_class(Get_Klass_Texture());
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
ptr->rb_texture = rb_texture;
|
|
102
|
+
sfSprite_setTexture(ptr->sprite, Get_Texture_Struct(rb_texture), false);
|
|
103
|
+
|
|
104
|
+
return rb_texture;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static VALUE Sprite_get_texture(VALUE self) {
|
|
108
|
+
return Get_Sprite(self)->rb_texture;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
static VALUE Sprite_get_texture_rect(VALUE self) {
|
|
112
|
+
return int_rect_to_rb(sfSprite_getTextureRect(Get_Sprite_Struct(self)));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static VALUE Sprite_set_texture_rect(VALUE self, VALUE rb_rect) {
|
|
116
|
+
sfSprite_setTextureRect(Get_Sprite_Struct(self), int_rect_from_rb(rb_rect));
|
|
117
|
+
return rb_rect;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static VALUE Sprite_get_color(VALUE self) {
|
|
121
|
+
return color_to_rb(sfSprite_getColor(Get_Sprite_Struct(self)));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
static VALUE Sprite_set_color(VALUE self, VALUE rb_color) {
|
|
125
|
+
sfSprite_setColor(Get_Sprite_Struct(self), color_from_rb(rb_color));
|
|
126
|
+
return rb_color;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static VALUE Sprite_get_position(VALUE self) {
|
|
130
|
+
return vec2f_to_rb(sfSprite_getPosition(Get_Sprite_Struct(self)));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static VALUE Sprite_set_position(VALUE self, VALUE rb_position) {
|
|
134
|
+
sfSprite_setPosition(Get_Sprite_Struct(self), vec2f_from_rb(rb_position));
|
|
135
|
+
return rb_position;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
static VALUE Sprite_get_rotation(VALUE self) {
|
|
139
|
+
return DBL2NUM(sfSprite_getRotation(Get_Sprite_Struct(self)));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
static VALUE Sprite_set_rotation(VALUE self, VALUE rb_rotation) {
|
|
143
|
+
sfSprite_setRotation(Get_Sprite_Struct(self), NUM2DBL(rb_rotation));
|
|
144
|
+
return rb_rotation;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static VALUE Sprite_get_scale(VALUE self) {
|
|
148
|
+
return vec2f_to_rb(sfSprite_getScale(Get_Sprite_Struct(self)));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static VALUE Sprite_set_scale(VALUE self, VALUE rb_scale) {
|
|
152
|
+
sfSprite_setScale(Get_Sprite_Struct(self), vec2f_from_rb(rb_scale));
|
|
153
|
+
return rb_scale;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
static VALUE Sprite_get_origin(VALUE self) {
|
|
157
|
+
return vec2f_to_rb(sfSprite_getOrigin(Get_Sprite_Struct(self)));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
static VALUE Sprite_set_origin(VALUE self, VALUE rb_origin) {
|
|
161
|
+
sfSprite_setOrigin(Get_Sprite_Struct(self), vec2f_from_rb(rb_origin));
|
|
162
|
+
return rb_origin;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
static VALUE Sprite_move(VALUE self, VALUE rb_offset) {
|
|
166
|
+
sfSprite_move(Get_Sprite_Struct(self), vec2f_from_rb(rb_offset));
|
|
167
|
+
return self;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static VALUE Sprite_rotate(VALUE self, VALUE rb_angle) {
|
|
171
|
+
sfSprite_rotate(Get_Sprite_Struct(self), NUM2DBL(rb_angle));
|
|
172
|
+
return self;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static VALUE Sprite_scale(VALUE self, VALUE rb_factors) {
|
|
176
|
+
sfSprite_scale(Get_Sprite_Struct(self), vec2f_from_rb(rb_factors));
|
|
177
|
+
return self;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
static VALUE Sprite_get_transform(VALUE self) {
|
|
181
|
+
return Transform_MatrixToArray(sfSprite_getTransform(Get_Sprite_Struct(self)).matrix);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
static VALUE Sprite_get_inverse_transform(VALUE self) {
|
|
185
|
+
return Transform_MatrixToArray(sfSprite_getInverseTransform(Get_Sprite_Struct(self)).matrix);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
static VALUE Sprite_get_local_bounds(VALUE self) {
|
|
189
|
+
return rect_to_rb(sfSprite_getLocalBounds(Get_Sprite_Struct(self)));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
static VALUE Sprite_get_global_bounds(VALUE self) {
|
|
193
|
+
return rect_to_rb(sfSprite_getGlobalBounds(Get_Sprite_Struct(self)));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
static VALUE Sprite_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
197
|
+
if (!rb_obj_is_kind_of(rb_target, Get_Klass_Target())) {
|
|
198
|
+
raise_invalid_argument_class(Get_Klass_Target());
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
|
|
202
|
+
raise_invalid_argument_class(Get_Klass_RenderState());
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
TARGET_DRAW(Get_Target_Struct(rb_target), sfRenderWindow_drawSprite, sfRenderTexture_drawSprite,
|
|
206
|
+
Get_Sprite_Struct(self), Get_RenderState_Struct(rb_state));
|
|
207
|
+
|
|
208
|
+
return Qnil;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
void Init_Sprite(VALUE rb_module) {
|
|
212
|
+
rb_cSprite = rb_define_class_under(rb_module, "Sprite", rb_cObject);
|
|
213
|
+
|
|
214
|
+
rb_include_module(rb_cSprite, Get_Module_Drawable());
|
|
215
|
+
|
|
216
|
+
rb_define_singleton_method(rb_cSprite, "new", Sprite_new, -1);
|
|
217
|
+
|
|
218
|
+
rb_define_method(rb_cSprite, "copy", Sprite_copy, 0);
|
|
219
|
+
|
|
220
|
+
rb_define_method(rb_cSprite, "texture", Sprite_get_texture, 0);
|
|
221
|
+
rb_define_method(rb_cSprite, "texture_rect", Sprite_get_texture_rect, 0);
|
|
222
|
+
rb_define_method(rb_cSprite, "color", Sprite_get_color, 0);
|
|
223
|
+
rb_define_method(rb_cSprite, "position", Sprite_get_position, 0);
|
|
224
|
+
rb_define_method(rb_cSprite, "rotation", Sprite_get_rotation, 0);
|
|
225
|
+
rb_define_method(rb_cSprite, "scale", Sprite_get_scale, 0);
|
|
226
|
+
rb_define_method(rb_cSprite, "origin", Sprite_get_origin, 0);
|
|
227
|
+
rb_define_method(rb_cSprite, "transform", Sprite_get_transform, 0);
|
|
228
|
+
rb_define_method(rb_cSprite, "inverse_transform", Sprite_get_inverse_transform, 0);
|
|
229
|
+
rb_define_method(rb_cSprite, "matrix", Sprite_get_transform, 0);
|
|
230
|
+
rb_define_method(rb_cSprite, "local_bounds", Sprite_get_local_bounds, 0);
|
|
231
|
+
rb_define_method(rb_cSprite, "global_bounds", Sprite_get_global_bounds, 0);
|
|
232
|
+
|
|
233
|
+
rb_define_method(rb_cSprite, "texture=", Sprite_set_texture, 1);
|
|
234
|
+
rb_define_method(rb_cSprite, "texture_rect=", Sprite_set_texture_rect, 1);
|
|
235
|
+
rb_define_method(rb_cSprite, "color=", Sprite_set_color, 1);
|
|
236
|
+
rb_define_method(rb_cSprite, "position=", Sprite_set_position, 1);
|
|
237
|
+
rb_define_method(rb_cSprite, "rotation=", Sprite_set_rotation, 1);
|
|
238
|
+
rb_define_method(rb_cSprite, "scale=", Sprite_set_scale, 1);
|
|
239
|
+
rb_define_method(rb_cSprite, "origin=", Sprite_set_origin, 1);
|
|
240
|
+
|
|
241
|
+
rb_define_method(rb_cSprite, "move", Sprite_move, 1);
|
|
242
|
+
rb_define_method(rb_cSprite, "rotate", Sprite_rotate, 1);
|
|
243
|
+
rb_define_method(rb_cSprite, "scale!", Sprite_scale, 1);
|
|
244
|
+
rb_define_method(rb_cSprite, "draw", Sprite_draw, 2);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
VALUE Get_Klass_Sprite(void) {
|
|
248
|
+
return rb_cSprite;
|
|
249
|
+
}
|