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,300 @@
|
|
|
1
|
+
#include "graphics/polygon.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
|
+
sfConvexShape *shape;
|
|
19
|
+
VALUE rb_texture;
|
|
20
|
+
} ConvexShape;
|
|
21
|
+
|
|
22
|
+
static VALUE rb_cConvexShape;
|
|
23
|
+
|
|
24
|
+
static void ConvexShape_mark(void *ptr) {
|
|
25
|
+
rb_gc_mark(((ConvexShape *) ptr)->rb_texture);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static void ConvexShape_free(void *ptr) {
|
|
29
|
+
sfConvexShape_destroy(((ConvexShape *) ptr)->shape);
|
|
30
|
+
free(ptr);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static const rb_data_type_t ConvexShape_data_type = {
|
|
34
|
+
.wrap_struct_name = "SFML::ConvexShape",
|
|
35
|
+
.function = {.dmark = ConvexShape_mark, .dfree = ConvexShape_free, .dsize = NULL},
|
|
36
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
static ConvexShape *Get_ConvexShape(VALUE self) {
|
|
40
|
+
ConvexShape *ptr;
|
|
41
|
+
TypedData_Get_Struct(self, ConvexShape, &ConvexShape_data_type, ptr);
|
|
42
|
+
return ptr;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static sfConvexShape *Get_ConvexShape_Struct(VALUE self) {
|
|
46
|
+
return Get_ConvexShape(self)->shape;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static VALUE ConvexShape_wrap(VALUE klass, sfConvexShape *shape) {
|
|
50
|
+
ConvexShape *ptr;
|
|
51
|
+
|
|
52
|
+
if (shape == NULL) {
|
|
53
|
+
rb_raise(rb_eRuntimeError, "failed to create convex shape");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
ptr = malloc(sizeof(ConvexShape));
|
|
57
|
+
ptr->shape = shape;
|
|
58
|
+
ptr->rb_texture = Qnil;
|
|
59
|
+
|
|
60
|
+
return TypedData_Wrap_Struct(klass, &ConvexShape_data_type, ptr);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static VALUE ConvexShape_new(int argc, VALUE *argv, VALUE klass) {
|
|
64
|
+
sfConvexShape *shape = sfConvexShape_create();
|
|
65
|
+
VALUE rb_point_count;
|
|
66
|
+
|
|
67
|
+
rb_scan_args(argc, argv, "01", &rb_point_count);
|
|
68
|
+
|
|
69
|
+
if (!NIL_P(rb_point_count)) {
|
|
70
|
+
sfConvexShape_setPointCount(shape, (size_t) NUM2SIZET(rb_point_count));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return ConvexShape_wrap(klass, shape);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static VALUE ConvexShape_copy(VALUE self) {
|
|
77
|
+
ConvexShape *ptr = Get_ConvexShape(self);
|
|
78
|
+
VALUE copy = ConvexShape_wrap(Get_Klass_ConvexShape(), sfConvexShape_copy(ptr->shape));
|
|
79
|
+
|
|
80
|
+
if (!NIL_P(ptr->rb_texture)) {
|
|
81
|
+
ConvexShape *copy_ptr = Get_ConvexShape(copy);
|
|
82
|
+
|
|
83
|
+
copy_ptr->rb_texture = ptr->rb_texture;
|
|
84
|
+
sfConvexShape_setTexture(copy_ptr->shape, Get_Texture_Struct(ptr->rb_texture), false);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return copy;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static VALUE ConvexShape_get_point_count(VALUE self) {
|
|
91
|
+
return SIZET2NUM(sfConvexShape_getPointCount(Get_ConvexShape_Struct(self)));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static VALUE ConvexShape_set_point_count(VALUE self, VALUE rb_count) {
|
|
95
|
+
sfConvexShape_setPointCount(Get_ConvexShape_Struct(self), (size_t) NUM2SIZET(rb_count));
|
|
96
|
+
return rb_count;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static VALUE ConvexShape_get_point(VALUE self, VALUE rb_index) {
|
|
100
|
+
return vec2f_to_rb(sfConvexShape_getPoint(Get_ConvexShape_Struct(self), (size_t) NUM2SIZET(rb_index)));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static VALUE ConvexShape_set_point(VALUE self, VALUE rb_index, VALUE rb_point) {
|
|
104
|
+
sfConvexShape_setPoint(Get_ConvexShape_Struct(self), (size_t) NUM2SIZET(rb_index), vec2f_from_rb(rb_point));
|
|
105
|
+
return rb_point;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
static VALUE ConvexShape_get_position(VALUE self) {
|
|
109
|
+
return vec2f_to_rb(sfConvexShape_getPosition(Get_ConvexShape_Struct(self)));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static VALUE ConvexShape_set_position(VALUE self, VALUE rb_position) {
|
|
113
|
+
sfConvexShape_setPosition(Get_ConvexShape_Struct(self), vec2f_from_rb(rb_position));
|
|
114
|
+
return rb_position;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static VALUE ConvexShape_get_rotation(VALUE self) {
|
|
118
|
+
return DBL2NUM(sfConvexShape_getRotation(Get_ConvexShape_Struct(self)));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static VALUE ConvexShape_set_rotation(VALUE self, VALUE rb_rotation) {
|
|
122
|
+
sfConvexShape_setRotation(Get_ConvexShape_Struct(self), NUM2DBL(rb_rotation));
|
|
123
|
+
return rb_rotation;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static VALUE ConvexShape_get_scale(VALUE self) {
|
|
127
|
+
return vec2f_to_rb(sfConvexShape_getScale(Get_ConvexShape_Struct(self)));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static VALUE ConvexShape_set_scale(VALUE self, VALUE rb_scale) {
|
|
131
|
+
sfConvexShape_setScale(Get_ConvexShape_Struct(self), vec2f_from_rb(rb_scale));
|
|
132
|
+
return rb_scale;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static VALUE ConvexShape_get_origin(VALUE self) {
|
|
136
|
+
return vec2f_to_rb(sfConvexShape_getOrigin(Get_ConvexShape_Struct(self)));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static VALUE ConvexShape_set_origin(VALUE self, VALUE rb_origin) {
|
|
140
|
+
sfConvexShape_setOrigin(Get_ConvexShape_Struct(self), vec2f_from_rb(rb_origin));
|
|
141
|
+
return rb_origin;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static VALUE ConvexShape_move(VALUE self, VALUE rb_offset) {
|
|
145
|
+
sfConvexShape_move(Get_ConvexShape_Struct(self), vec2f_from_rb(rb_offset));
|
|
146
|
+
return self;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
static VALUE ConvexShape_rotate(VALUE self, VALUE rb_angle) {
|
|
150
|
+
sfConvexShape_rotate(Get_ConvexShape_Struct(self), NUM2DBL(rb_angle));
|
|
151
|
+
return self;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
static VALUE ConvexShape_scale(VALUE self, VALUE rb_factors) {
|
|
155
|
+
sfConvexShape_scale(Get_ConvexShape_Struct(self), vec2f_from_rb(rb_factors));
|
|
156
|
+
return self;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static VALUE ConvexShape_get_transform(VALUE self) {
|
|
160
|
+
return Transform_MatrixToArray(sfConvexShape_getTransform(Get_ConvexShape_Struct(self)).matrix);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static VALUE ConvexShape_get_inverse_transform(VALUE self) {
|
|
164
|
+
return Transform_MatrixToArray(sfConvexShape_getInverseTransform(Get_ConvexShape_Struct(self)).matrix);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
static VALUE ConvexShape_get_fill_color(VALUE self) {
|
|
168
|
+
return color_to_rb(sfConvexShape_getFillColor(Get_ConvexShape_Struct(self)));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
static VALUE ConvexShape_set_fill_color(VALUE self, VALUE rb_color) {
|
|
172
|
+
sfConvexShape_setFillColor(Get_ConvexShape_Struct(self), color_from_rb(rb_color));
|
|
173
|
+
return rb_color;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
static VALUE ConvexShape_get_outline_color(VALUE self) {
|
|
177
|
+
return color_to_rb(sfConvexShape_getOutlineColor(Get_ConvexShape_Struct(self)));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
static VALUE ConvexShape_set_outline_color(VALUE self, VALUE rb_color) {
|
|
181
|
+
sfConvexShape_setOutlineColor(Get_ConvexShape_Struct(self), color_from_rb(rb_color));
|
|
182
|
+
return rb_color;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
static VALUE ConvexShape_get_outline_thickness(VALUE self) {
|
|
186
|
+
return DBL2NUM(sfConvexShape_getOutlineThickness(Get_ConvexShape_Struct(self)));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
static VALUE ConvexShape_set_outline_thickness(VALUE self, VALUE rb_thickness) {
|
|
190
|
+
sfConvexShape_setOutlineThickness(Get_ConvexShape_Struct(self), NUM2DBL(rb_thickness));
|
|
191
|
+
return rb_thickness;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
static VALUE ConvexShape_set_texture(VALUE self, VALUE rb_texture) {
|
|
195
|
+
ConvexShape *ptr = Get_ConvexShape(self);
|
|
196
|
+
|
|
197
|
+
if (NIL_P(rb_texture)) {
|
|
198
|
+
ptr->rb_texture = Qnil;
|
|
199
|
+
sfConvexShape_setTexture(ptr->shape, NULL, false);
|
|
200
|
+
return rb_texture;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (!rb_obj_is_kind_of(rb_texture, Get_Klass_Texture())) {
|
|
204
|
+
raise_invalid_argument_class(Get_Klass_Texture());
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
ptr->rb_texture = rb_texture;
|
|
208
|
+
sfConvexShape_setTexture(ptr->shape, Get_Texture_Struct(rb_texture), false);
|
|
209
|
+
|
|
210
|
+
return rb_texture;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
static VALUE ConvexShape_get_texture(VALUE self) {
|
|
214
|
+
return Get_ConvexShape(self)->rb_texture;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
static VALUE ConvexShape_get_texture_rect(VALUE self) {
|
|
218
|
+
return int_rect_to_rb(sfConvexShape_getTextureRect(Get_ConvexShape_Struct(self)));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
static VALUE ConvexShape_set_texture_rect(VALUE self, VALUE rb_rect) {
|
|
222
|
+
sfConvexShape_setTextureRect(Get_ConvexShape_Struct(self), int_rect_from_rb(rb_rect));
|
|
223
|
+
return rb_rect;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
static VALUE ConvexShape_get_geometric_center(VALUE self) {
|
|
227
|
+
return vec2f_to_rb(sfConvexShape_getGeometricCenter(Get_ConvexShape_Struct(self)));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
static VALUE ConvexShape_get_local_bounds(VALUE self) {
|
|
231
|
+
return rect_to_rb(sfConvexShape_getLocalBounds(Get_ConvexShape_Struct(self)));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
static VALUE ConvexShape_get_global_bounds(VALUE self) {
|
|
235
|
+
return rect_to_rb(sfConvexShape_getGlobalBounds(Get_ConvexShape_Struct(self)));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static VALUE ConvexShape_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
239
|
+
if (!rb_obj_is_kind_of(rb_target, Get_Klass_Target())) {
|
|
240
|
+
raise_invalid_argument_class(Get_Klass_Target());
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
|
|
244
|
+
raise_invalid_argument_class(Get_Klass_RenderState());
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
TARGET_DRAW(Get_Target_Struct(rb_target), sfRenderWindow_drawConvexShape, sfRenderTexture_drawConvexShape,
|
|
248
|
+
Get_ConvexShape_Struct(self), Get_RenderState_Struct(rb_state));
|
|
249
|
+
|
|
250
|
+
return Qnil;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
void Init_ConvexShape(VALUE rb_module) {
|
|
254
|
+
rb_cConvexShape = rb_define_class_under(rb_module, "ConvexShape", rb_cObject);
|
|
255
|
+
|
|
256
|
+
rb_include_module(rb_cConvexShape, Get_Module_Drawable());
|
|
257
|
+
|
|
258
|
+
rb_define_singleton_method(rb_cConvexShape, "new", ConvexShape_new, -1);
|
|
259
|
+
|
|
260
|
+
rb_define_method(rb_cConvexShape, "copy", ConvexShape_copy, 0);
|
|
261
|
+
|
|
262
|
+
rb_define_method(rb_cConvexShape, "point_count", ConvexShape_get_point_count, 0);
|
|
263
|
+
rb_define_method(rb_cConvexShape, "point", ConvexShape_get_point, 1);
|
|
264
|
+
rb_define_method(rb_cConvexShape, "position", ConvexShape_get_position, 0);
|
|
265
|
+
rb_define_method(rb_cConvexShape, "rotation", ConvexShape_get_rotation, 0);
|
|
266
|
+
rb_define_method(rb_cConvexShape, "scale", ConvexShape_get_scale, 0);
|
|
267
|
+
rb_define_method(rb_cConvexShape, "origin", ConvexShape_get_origin, 0);
|
|
268
|
+
rb_define_method(rb_cConvexShape, "fill_color", ConvexShape_get_fill_color, 0);
|
|
269
|
+
rb_define_method(rb_cConvexShape, "outline_color", ConvexShape_get_outline_color, 0);
|
|
270
|
+
rb_define_method(rb_cConvexShape, "outline_thickness", ConvexShape_get_outline_thickness, 0);
|
|
271
|
+
rb_define_method(rb_cConvexShape, "texture", ConvexShape_get_texture, 0);
|
|
272
|
+
rb_define_method(rb_cConvexShape, "texture_rect", ConvexShape_get_texture_rect, 0);
|
|
273
|
+
rb_define_method(rb_cConvexShape, "geometric_center", ConvexShape_get_geometric_center, 0);
|
|
274
|
+
rb_define_method(rb_cConvexShape, "local_bounds", ConvexShape_get_local_bounds, 0);
|
|
275
|
+
rb_define_method(rb_cConvexShape, "global_bounds", ConvexShape_get_global_bounds, 0);
|
|
276
|
+
rb_define_method(rb_cConvexShape, "transform", ConvexShape_get_transform, 0);
|
|
277
|
+
rb_define_method(rb_cConvexShape, "inverse_transform", ConvexShape_get_inverse_transform, 0);
|
|
278
|
+
rb_define_method(rb_cConvexShape, "matrix", ConvexShape_get_transform, 0);
|
|
279
|
+
|
|
280
|
+
rb_define_method(rb_cConvexShape, "point_count=", ConvexShape_set_point_count, 1);
|
|
281
|
+
rb_define_method(rb_cConvexShape, "set_point", ConvexShape_set_point, 2);
|
|
282
|
+
rb_define_method(rb_cConvexShape, "position=", ConvexShape_set_position, 1);
|
|
283
|
+
rb_define_method(rb_cConvexShape, "rotation=", ConvexShape_set_rotation, 1);
|
|
284
|
+
rb_define_method(rb_cConvexShape, "scale=", ConvexShape_set_scale, 1);
|
|
285
|
+
rb_define_method(rb_cConvexShape, "origin=", ConvexShape_set_origin, 1);
|
|
286
|
+
rb_define_method(rb_cConvexShape, "fill_color=", ConvexShape_set_fill_color, 1);
|
|
287
|
+
rb_define_method(rb_cConvexShape, "outline_color=", ConvexShape_set_outline_color, 1);
|
|
288
|
+
rb_define_method(rb_cConvexShape, "outline_thickness=", ConvexShape_set_outline_thickness, 1);
|
|
289
|
+
rb_define_method(rb_cConvexShape, "texture=", ConvexShape_set_texture, 1);
|
|
290
|
+
rb_define_method(rb_cConvexShape, "texture_rect=", ConvexShape_set_texture_rect, 1);
|
|
291
|
+
|
|
292
|
+
rb_define_method(rb_cConvexShape, "move", ConvexShape_move, 1);
|
|
293
|
+
rb_define_method(rb_cConvexShape, "rotate", ConvexShape_rotate, 1);
|
|
294
|
+
rb_define_method(rb_cConvexShape, "scale!", ConvexShape_scale, 1);
|
|
295
|
+
rb_define_method(rb_cConvexShape, "draw", ConvexShape_draw, 2);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
VALUE Get_Klass_ConvexShape(void) {
|
|
299
|
+
return rb_cConvexShape;
|
|
300
|
+
}
|
data/ext/graphics/rect.c
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
#include "graphics/rect.h"
|
|
2
|
+
|
|
3
|
+
#include <stdio.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
|
|
6
|
+
#include "core/exceptions.h"
|
|
7
|
+
#include "core/macros.h"
|
|
8
|
+
#include "system/vec2.h"
|
|
9
|
+
|
|
10
|
+
typedef struct {
|
|
11
|
+
sfFloatRect rect;
|
|
12
|
+
} Rect;
|
|
13
|
+
|
|
14
|
+
static VALUE rb_cRect;
|
|
15
|
+
|
|
16
|
+
static void Rect_free(void *ptr) {
|
|
17
|
+
free(ptr);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static const rb_data_type_t Rect_data_type = {
|
|
21
|
+
.wrap_struct_name = "SFML::Rect",
|
|
22
|
+
.function = {.dmark = NULL, .dfree = Rect_free, .dsize = NULL},
|
|
23
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
static VALUE Rect_wrap(sfFloatRect rect) {
|
|
27
|
+
Rect *ptr = malloc(sizeof(Rect));
|
|
28
|
+
|
|
29
|
+
ptr->rect = rect;
|
|
30
|
+
|
|
31
|
+
return TypedData_Wrap_Struct(rb_cRect, &Rect_data_type, ptr);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static VALUE Rect_new(int argc, VALUE *argv, VALUE klass) {
|
|
35
|
+
VALUE self;
|
|
36
|
+
Rect *ptr;
|
|
37
|
+
sfFloatRect rect = {{0, 0}, {0, 0}};
|
|
38
|
+
|
|
39
|
+
if (argc == 1 && rb_obj_is_kind_of(argv[0], rb_cRect)) {
|
|
40
|
+
rect = ((Rect *) Get_Rect_Struct(argv[0]))->rect;
|
|
41
|
+
} else if (argc == 1 && RB_TYPE_P(argv[0], T_ARRAY)) {
|
|
42
|
+
rect = rect_from_rb(argv[0]);
|
|
43
|
+
} else if (argc == 2) {
|
|
44
|
+
rect = (sfFloatRect) {
|
|
45
|
+
{(float) NUM2DBL(argv[0]), (float) NUM2DBL(argv[1])},
|
|
46
|
+
{0, 0}
|
|
47
|
+
};
|
|
48
|
+
} else if (argc == 4) {
|
|
49
|
+
rect = (sfFloatRect) {
|
|
50
|
+
{(float) NUM2DBL(argv[0]), (float) NUM2DBL(argv[1])},
|
|
51
|
+
{(float) NUM2DBL(argv[2]), (float) NUM2DBL(argv[3])}
|
|
52
|
+
};
|
|
53
|
+
} else if (argc != 0) {
|
|
54
|
+
raise_invalid_arguments_excepted(4, argc);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
ptr = malloc(sizeof(Rect));
|
|
58
|
+
ptr->rect = rect;
|
|
59
|
+
|
|
60
|
+
self = TypedData_Wrap_Struct(klass, &Rect_data_type, ptr);
|
|
61
|
+
|
|
62
|
+
return self;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static VALUE Rect_get_left(VALUE self) {
|
|
66
|
+
return DBL2NUM(((Rect *) Get_Rect_Struct(self))->rect.position.x);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static VALUE Rect_get_top(VALUE self) {
|
|
70
|
+
return DBL2NUM(((Rect *) Get_Rect_Struct(self))->rect.position.y);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static VALUE Rect_get_width(VALUE self) {
|
|
74
|
+
return DBL2NUM(((Rect *) Get_Rect_Struct(self))->rect.size.x);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static VALUE Rect_get_height(VALUE self) {
|
|
78
|
+
return DBL2NUM(((Rect *) Get_Rect_Struct(self))->rect.size.y);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static VALUE Rect_set_left(VALUE self, VALUE rb_value) {
|
|
82
|
+
((Rect *) Get_Rect_Struct(self))->rect.position.x = NUM2DBL(rb_value);
|
|
83
|
+
return rb_value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static VALUE Rect_set_top(VALUE self, VALUE rb_value) {
|
|
87
|
+
((Rect *) Get_Rect_Struct(self))->rect.position.y = NUM2DBL(rb_value);
|
|
88
|
+
return rb_value;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static VALUE Rect_set_width(VALUE self, VALUE rb_value) {
|
|
92
|
+
((Rect *) Get_Rect_Struct(self))->rect.size.x = NUM2DBL(rb_value);
|
|
93
|
+
return rb_value;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static VALUE Rect_set_height(VALUE self, VALUE rb_value) {
|
|
97
|
+
((Rect *) Get_Rect_Struct(self))->rect.size.y = NUM2DBL(rb_value);
|
|
98
|
+
return rb_value;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static VALUE Rect_get_position(VALUE self) {
|
|
102
|
+
sfFloatRect rect = ((Rect *) Get_Rect_Struct(self))->rect;
|
|
103
|
+
|
|
104
|
+
return vec2f_to_rb(rect.position);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static VALUE Rect_get_size(VALUE self) {
|
|
108
|
+
sfFloatRect rect = ((Rect *) Get_Rect_Struct(self))->rect;
|
|
109
|
+
|
|
110
|
+
return vec2f_to_rb(rect.size);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static VALUE Rect_set_position(VALUE self, VALUE rb_position) {
|
|
114
|
+
((Rect *) Get_Rect_Struct(self))->rect.position = vec2f_from_rb(rb_position);
|
|
115
|
+
return rb_position;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static VALUE Rect_set_size(VALUE self, VALUE rb_size) {
|
|
119
|
+
((Rect *) Get_Rect_Struct(self))->rect.size = vec2f_from_rb(rb_size);
|
|
120
|
+
return rb_size;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static VALUE Rect_contains(int argc, VALUE *argv, VALUE self) {
|
|
124
|
+
sfFloatRect rect = ((Rect *) Get_Rect_Struct(self))->rect;
|
|
125
|
+
sfVector2f point;
|
|
126
|
+
|
|
127
|
+
if (argc == 1) {
|
|
128
|
+
point = vec2f_from_rb(argv[0]);
|
|
129
|
+
} else if (argc == 2) {
|
|
130
|
+
point = (sfVector2f) {(float) NUM2DBL(argv[0]), (float) NUM2DBL(argv[1])};
|
|
131
|
+
} else {
|
|
132
|
+
raise_invalid_arguments_excepted(2, argc);
|
|
133
|
+
return Qfalse;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return BOOL2RB(sfFloatRect_contains(&rect, point));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static VALUE Rect_intersection(VALUE self, VALUE rb_other) {
|
|
140
|
+
sfFloatRect a = ((Rect *) Get_Rect_Struct(self))->rect;
|
|
141
|
+
sfFloatRect b = rect_from_rb(rb_other);
|
|
142
|
+
sfFloatRect intersection;
|
|
143
|
+
|
|
144
|
+
if (sfFloatRect_intersects(&a, &b, &intersection)) {
|
|
145
|
+
return Rect_wrap(intersection);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return Qnil;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static VALUE Rect_intersects(VALUE self, VALUE rb_other) {
|
|
152
|
+
return BOOL2RB(Rect_intersection(self, rb_other) != Qnil);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static VALUE Rect_to_a(VALUE self) {
|
|
156
|
+
sfFloatRect rect = ((Rect *) Get_Rect_Struct(self))->rect;
|
|
157
|
+
|
|
158
|
+
return rb_ary_new_from_args(4, DBL2NUM(rect.position.x), DBL2NUM(rect.position.y),
|
|
159
|
+
DBL2NUM(rect.size.x), DBL2NUM(rect.size.y));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
static VALUE Rect_each(VALUE self) {
|
|
163
|
+
VALUE array = Rect_to_a(self);
|
|
164
|
+
long i;
|
|
165
|
+
|
|
166
|
+
for (i = 0; i < 4; i++) {
|
|
167
|
+
rb_yield(rb_ary_entry(array, i));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return self;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
static VALUE Rect_eql(VALUE self, VALUE rb_other) {
|
|
174
|
+
sfFloatRect a = ((Rect *) Get_Rect_Struct(self))->rect;
|
|
175
|
+
sfFloatRect b;
|
|
176
|
+
|
|
177
|
+
if (rb_obj_is_kind_of(rb_other, rb_cRect)) {
|
|
178
|
+
b = ((Rect *) Get_Rect_Struct(rb_other))->rect;
|
|
179
|
+
} else if (RB_TYPE_P(rb_other, T_ARRAY) && RARRAY_LEN(rb_other) >= 4) {
|
|
180
|
+
b = rect_from_rb(rb_other);
|
|
181
|
+
} else {
|
|
182
|
+
return Qfalse;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return BOOL2RB(a.position.x == b.position.x && a.position.y == b.position.y &&
|
|
186
|
+
a.size.x == b.size.x && a.size.y == b.size.y);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
static VALUE Rect_to_s(VALUE self) {
|
|
190
|
+
sfFloatRect rect = ((Rect *) Get_Rect_Struct(self))->rect;
|
|
191
|
+
char buffer[96];
|
|
192
|
+
|
|
193
|
+
snprintf(buffer, sizeof(buffer), "(%g, %g, %g, %g)", rect.position.x, rect.position.y, rect.size.x, rect.size.y);
|
|
194
|
+
|
|
195
|
+
return rb_str_new2(buffer);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
void Init_Rect(VALUE rb_module) {
|
|
199
|
+
rb_cRect = rb_define_class_under(rb_module, "Rect", rb_cObject);
|
|
200
|
+
|
|
201
|
+
rb_include_module(rb_cRect, rb_mEnumerable);
|
|
202
|
+
|
|
203
|
+
rb_define_singleton_method(rb_cRect, "new", Rect_new, -1);
|
|
204
|
+
|
|
205
|
+
rb_define_method(rb_cRect, "left", Rect_get_left, 0);
|
|
206
|
+
rb_define_method(rb_cRect, "top", Rect_get_top, 0);
|
|
207
|
+
rb_define_method(rb_cRect, "width", Rect_get_width, 0);
|
|
208
|
+
rb_define_method(rb_cRect, "height", Rect_get_height, 0);
|
|
209
|
+
rb_define_method(rb_cRect, "left=", Rect_set_left, 1);
|
|
210
|
+
rb_define_method(rb_cRect, "top=", Rect_set_top, 1);
|
|
211
|
+
rb_define_method(rb_cRect, "width=", Rect_set_width, 1);
|
|
212
|
+
rb_define_method(rb_cRect, "height=", Rect_set_height, 1);
|
|
213
|
+
|
|
214
|
+
rb_define_method(rb_cRect, "position", Rect_get_position, 0);
|
|
215
|
+
rb_define_method(rb_cRect, "size", Rect_get_size, 0);
|
|
216
|
+
rb_define_method(rb_cRect, "position=", Rect_set_position, 1);
|
|
217
|
+
rb_define_method(rb_cRect, "size=", Rect_set_size, 1);
|
|
218
|
+
|
|
219
|
+
rb_define_method(rb_cRect, "contains?", Rect_contains, -1);
|
|
220
|
+
rb_define_method(rb_cRect, "intersects?", Rect_intersects, 1);
|
|
221
|
+
rb_define_method(rb_cRect, "intersection", Rect_intersection, 1);
|
|
222
|
+
|
|
223
|
+
rb_define_method(rb_cRect, "to_a", Rect_to_a, 0);
|
|
224
|
+
rb_define_method(rb_cRect, "to_ary", Rect_to_a, 0);
|
|
225
|
+
rb_define_method(rb_cRect, "each", Rect_each, 0);
|
|
226
|
+
rb_define_method(rb_cRect, "==", Rect_eql, 1);
|
|
227
|
+
rb_define_method(rb_cRect, "to_s", Rect_to_s, 0);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
VALUE Get_Klass_Rect(void) {
|
|
231
|
+
return rb_cRect;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
void *Get_Rect_Struct(VALUE self) {
|
|
235
|
+
Rect *ptr;
|
|
236
|
+
TypedData_Get_Struct(self, Rect, &Rect_data_type, ptr);
|
|
237
|
+
return ptr;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
sfFloatRect rect_from_rb(VALUE rb_rect) {
|
|
241
|
+
if (rb_obj_is_kind_of(rb_rect, rb_cRect)) {
|
|
242
|
+
return ((Rect *) Get_Rect_Struct(rb_rect))->rect;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (RB_TYPE_P(rb_rect, T_ARRAY)) {
|
|
246
|
+
if (RARRAY_LEN(rb_rect) < 4) {
|
|
247
|
+
raise_invalid_array_length(4);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return (sfFloatRect) {
|
|
251
|
+
{(float) NUM2DBL(rb_ary_entry(rb_rect, 0)), (float) NUM2DBL(rb_ary_entry(rb_rect, 1))},
|
|
252
|
+
{(float) NUM2DBL(rb_ary_entry(rb_rect, 2)), (float) NUM2DBL(rb_ary_entry(rb_rect, 3))}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
raise_invalid_argument_class(rb_cRect);
|
|
257
|
+
|
|
258
|
+
return (sfFloatRect) {{0, 0}, {0, 0}};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
VALUE rect_to_rb(sfFloatRect c_rect) {
|
|
262
|
+
return Rect_wrap(c_rect);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
sfIntRect int_rect_from_rb(VALUE rb_rect) {
|
|
266
|
+
sfFloatRect rect = rect_from_rb(rb_rect);
|
|
267
|
+
|
|
268
|
+
return (sfIntRect) {
|
|
269
|
+
{(int) rect.position.x, (int) rect.position.y},
|
|
270
|
+
{(int) rect.size.x, (int) rect.size.y}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
VALUE int_rect_to_rb(sfIntRect c_rect) {
|
|
275
|
+
return Rect_wrap((sfFloatRect) {
|
|
276
|
+
{(float) c_rect.position.x, (float) c_rect.position.y},
|
|
277
|
+
{(float) c_rect.size.x, (float) c_rect.size.y}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
void Rect_check(VALUE rb_rect) {
|
|
282
|
+
if (rb_obj_is_kind_of(rb_rect, rb_cRect) || RB_TYPE_P(rb_rect, T_ARRAY)) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
raise_invalid_argument_class(rb_cRect);
|
|
287
|
+
}
|
data/ext/graphics/rect.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#ifndef SFML_RB_GRAPHICS_RECT_H
|
|
2
|
+
#define SFML_RB_GRAPHICS_RECT_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include "core/sfml.h"
|
|
7
|
+
|
|
8
|
+
#define RECT_UNPACK(c_rect) (c_rect).position.x, (c_rect).position.y, (c_rect).size.x, (c_rect).size.y
|
|
9
|
+
|
|
10
|
+
#define RECT_C2RB(c_rect) rect_to_rb(c_rect)
|
|
11
|
+
|
|
12
|
+
#define RECT_RB2C(rb_rect) rect_from_rb(rb_rect)
|
|
13
|
+
|
|
14
|
+
void Init_Rect(VALUE rb_module);
|
|
15
|
+
|
|
16
|
+
VALUE Get_Klass_Rect(void);
|
|
17
|
+
|
|
18
|
+
void *Get_Rect_Struct(VALUE self);
|
|
19
|
+
|
|
20
|
+
sfFloatRect rect_from_rb(VALUE rb_rect);
|
|
21
|
+
|
|
22
|
+
VALUE rect_to_rb(sfFloatRect c_rect);
|
|
23
|
+
|
|
24
|
+
sfIntRect int_rect_from_rb(VALUE rb_rect);
|
|
25
|
+
|
|
26
|
+
VALUE int_rect_to_rb(sfIntRect c_rect);
|
|
27
|
+
|
|
28
|
+
void Rect_check(VALUE rb_rect);
|
|
29
|
+
|
|
30
|
+
#endif //SFML_RB_GRAPHICS_RECT_H
|