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,302 @@
|
|
|
1
|
+
#include "graphics/rectangle.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
|
|
6
|
+
#include "graphics/circle.h"
|
|
7
|
+
#include "graphics/drawable.h"
|
|
8
|
+
#include "graphics/target.h"
|
|
9
|
+
#include "graphics/render_state.h"
|
|
10
|
+
#include "graphics/transform.h"
|
|
11
|
+
#include "graphics/color.h"
|
|
12
|
+
#include "graphics/rect.h"
|
|
13
|
+
#include "graphics/texture.h"
|
|
14
|
+
#include "system/vec2.h"
|
|
15
|
+
#include "core/exceptions.h"
|
|
16
|
+
#include "core/macros.h"
|
|
17
|
+
|
|
18
|
+
typedef struct {
|
|
19
|
+
sfRectangleShape *shape;
|
|
20
|
+
VALUE rb_texture;
|
|
21
|
+
} RectangleShape;
|
|
22
|
+
|
|
23
|
+
static VALUE rb_cRectangleShape;
|
|
24
|
+
|
|
25
|
+
static void RectangleShape_mark(void *ptr) {
|
|
26
|
+
rb_gc_mark(((RectangleShape *) ptr)->rb_texture);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static void RectangleShape_free(void *ptr) {
|
|
30
|
+
sfRectangleShape_destroy(((RectangleShape *) ptr)->shape);
|
|
31
|
+
free(ptr);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static const rb_data_type_t RectangleShape_data_type = {
|
|
35
|
+
.wrap_struct_name = "SFML::RectangleShape",
|
|
36
|
+
.function = {.dmark = RectangleShape_mark, .dfree = RectangleShape_free, .dsize = NULL},
|
|
37
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
static RectangleShape *Get_RectangleShape(VALUE self) {
|
|
41
|
+
RectangleShape *ptr;
|
|
42
|
+
TypedData_Get_Struct(self, RectangleShape, &RectangleShape_data_type, ptr);
|
|
43
|
+
return ptr;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static sfRectangleShape *Get_RectangleShape_Struct(VALUE self) {
|
|
47
|
+
return Get_RectangleShape(self)->shape;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static VALUE RectangleShape_wrap(VALUE klass, sfRectangleShape *shape) {
|
|
51
|
+
RectangleShape *ptr;
|
|
52
|
+
|
|
53
|
+
if (shape == NULL) {
|
|
54
|
+
rb_raise(rb_eRuntimeError, "failed to create rectangle shape");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
ptr = malloc(sizeof(RectangleShape));
|
|
58
|
+
ptr->shape = shape;
|
|
59
|
+
ptr->rb_texture = Qnil;
|
|
60
|
+
|
|
61
|
+
return TypedData_Wrap_Struct(klass, &RectangleShape_data_type, ptr);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static VALUE RectangleShape_new(int argc, VALUE *argv, VALUE klass) {
|
|
65
|
+
sfRectangleShape *shape = sfRectangleShape_create();
|
|
66
|
+
VALUE rb_size;
|
|
67
|
+
|
|
68
|
+
rb_scan_args(argc, argv, "01", &rb_size);
|
|
69
|
+
|
|
70
|
+
if (!NIL_P(rb_size)) {
|
|
71
|
+
sfRectangleShape_setSize(shape, vec2f_from_rb(rb_size));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return RectangleShape_wrap(klass, shape);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static VALUE RectangleShape_copy(VALUE self) {
|
|
78
|
+
RectangleShape *ptr = Get_RectangleShape(self);
|
|
79
|
+
VALUE copy = RectangleShape_wrap(Get_Klass_RectangleShape(), sfRectangleShape_copy(ptr->shape));
|
|
80
|
+
|
|
81
|
+
if (!NIL_P(ptr->rb_texture)) {
|
|
82
|
+
RectangleShape *copy_ptr = Get_RectangleShape(copy);
|
|
83
|
+
|
|
84
|
+
copy_ptr->rb_texture = ptr->rb_texture;
|
|
85
|
+
sfRectangleShape_setTexture(copy_ptr->shape, Get_Texture_Struct(ptr->rb_texture), false);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return copy;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static VALUE RectangleShape_get_size(VALUE self) {
|
|
92
|
+
return vec2f_to_rb(sfRectangleShape_getSize(Get_RectangleShape_Struct(self)));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static VALUE RectangleShape_set_size(VALUE self, VALUE rb_size) {
|
|
96
|
+
sfRectangleShape_setSize(Get_RectangleShape_Struct(self), vec2f_from_rb(rb_size));
|
|
97
|
+
return rb_size;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static VALUE RectangleShape_get_position(VALUE self) {
|
|
101
|
+
return vec2f_to_rb(sfRectangleShape_getPosition(Get_RectangleShape_Struct(self)));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static VALUE RectangleShape_set_position(VALUE self, VALUE rb_position) {
|
|
105
|
+
sfRectangleShape_setPosition(Get_RectangleShape_Struct(self), vec2f_from_rb(rb_position));
|
|
106
|
+
return rb_position;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static VALUE RectangleShape_get_rotation(VALUE self) {
|
|
110
|
+
return DBL2NUM(sfRectangleShape_getRotation(Get_RectangleShape_Struct(self)));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static VALUE RectangleShape_set_rotation(VALUE self, VALUE rb_rotation) {
|
|
114
|
+
sfRectangleShape_setRotation(Get_RectangleShape_Struct(self), NUM2DBL(rb_rotation));
|
|
115
|
+
return rb_rotation;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static VALUE RectangleShape_get_scale(VALUE self) {
|
|
119
|
+
return vec2f_to_rb(sfRectangleShape_getScale(Get_RectangleShape_Struct(self)));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static VALUE RectangleShape_set_scale(VALUE self, VALUE rb_scale) {
|
|
123
|
+
sfRectangleShape_setScale(Get_RectangleShape_Struct(self), vec2f_from_rb(rb_scale));
|
|
124
|
+
return rb_scale;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static VALUE RectangleShape_get_origin(VALUE self) {
|
|
128
|
+
return vec2f_to_rb(sfRectangleShape_getOrigin(Get_RectangleShape_Struct(self)));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static VALUE RectangleShape_set_origin(VALUE self, VALUE rb_origin) {
|
|
132
|
+
sfRectangleShape_setOrigin(Get_RectangleShape_Struct(self), vec2f_from_rb(rb_origin));
|
|
133
|
+
return rb_origin;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static VALUE RectangleShape_move(VALUE self, VALUE rb_offset) {
|
|
137
|
+
sfRectangleShape_move(Get_RectangleShape_Struct(self), vec2f_from_rb(rb_offset));
|
|
138
|
+
return self;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static VALUE RectangleShape_rotate(VALUE self, VALUE rb_angle) {
|
|
142
|
+
sfRectangleShape_rotate(Get_RectangleShape_Struct(self), NUM2DBL(rb_angle));
|
|
143
|
+
return self;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static VALUE RectangleShape_scale(VALUE self, VALUE rb_factors) {
|
|
147
|
+
sfRectangleShape_scale(Get_RectangleShape_Struct(self), vec2f_from_rb(rb_factors));
|
|
148
|
+
return self;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static VALUE RectangleShape_get_transform(VALUE self) {
|
|
152
|
+
return Transform_MatrixToArray(sfRectangleShape_getTransform(Get_RectangleShape_Struct(self)).matrix);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static VALUE RectangleShape_get_inverse_transform(VALUE self) {
|
|
156
|
+
return Transform_MatrixToArray(sfRectangleShape_getInverseTransform(Get_RectangleShape_Struct(self)).matrix);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static VALUE RectangleShape_get_fill_color(VALUE self) {
|
|
160
|
+
return color_to_rb(sfRectangleShape_getFillColor(Get_RectangleShape_Struct(self)));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static VALUE RectangleShape_set_fill_color(VALUE self, VALUE rb_color) {
|
|
164
|
+
sfRectangleShape_setFillColor(Get_RectangleShape_Struct(self), color_from_rb(rb_color));
|
|
165
|
+
return rb_color;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
static VALUE RectangleShape_get_outline_color(VALUE self) {
|
|
169
|
+
return color_to_rb(sfRectangleShape_getOutlineColor(Get_RectangleShape_Struct(self)));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
static VALUE RectangleShape_set_outline_color(VALUE self, VALUE rb_color) {
|
|
173
|
+
sfRectangleShape_setOutlineColor(Get_RectangleShape_Struct(self), color_from_rb(rb_color));
|
|
174
|
+
return rb_color;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
static VALUE RectangleShape_get_outline_thickness(VALUE self) {
|
|
178
|
+
return DBL2NUM(sfRectangleShape_getOutlineThickness(Get_RectangleShape_Struct(self)));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
static VALUE RectangleShape_set_outline_thickness(VALUE self, VALUE rb_thickness) {
|
|
182
|
+
sfRectangleShape_setOutlineThickness(Get_RectangleShape_Struct(self), NUM2DBL(rb_thickness));
|
|
183
|
+
return rb_thickness;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
static VALUE RectangleShape_set_texture(VALUE self, VALUE rb_texture) {
|
|
187
|
+
RectangleShape *ptr = Get_RectangleShape(self);
|
|
188
|
+
bool reset_rect = false;
|
|
189
|
+
|
|
190
|
+
if (NIL_P(rb_texture)) {
|
|
191
|
+
ptr->rb_texture = Qnil;
|
|
192
|
+
sfRectangleShape_setTexture(ptr->shape, NULL, reset_rect);
|
|
193
|
+
return rb_texture;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (!rb_obj_is_kind_of(rb_texture, Get_Klass_Texture())) {
|
|
197
|
+
raise_invalid_argument_class(Get_Klass_Texture());
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
ptr->rb_texture = rb_texture;
|
|
201
|
+
sfRectangleShape_setTexture(ptr->shape, Get_Texture_Struct(rb_texture), reset_rect);
|
|
202
|
+
|
|
203
|
+
return rb_texture;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
static VALUE RectangleShape_get_texture(VALUE self) {
|
|
207
|
+
return Get_RectangleShape(self)->rb_texture;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
static VALUE RectangleShape_get_texture_rect(VALUE self) {
|
|
211
|
+
return int_rect_to_rb(sfRectangleShape_getTextureRect(Get_RectangleShape_Struct(self)));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
static VALUE RectangleShape_set_texture_rect(VALUE self, VALUE rb_rect) {
|
|
215
|
+
sfRectangleShape_setTextureRect(Get_RectangleShape_Struct(self), int_rect_from_rb(rb_rect));
|
|
216
|
+
return rb_rect;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
static VALUE RectangleShape_get_point_count(VALUE self) {
|
|
220
|
+
return SIZET2NUM(sfRectangleShape_getPointCount(Get_RectangleShape_Struct(self)));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
static VALUE RectangleShape_get_point(VALUE self, VALUE rb_index) {
|
|
224
|
+
return vec2f_to_rb(sfRectangleShape_getPoint(Get_RectangleShape_Struct(self), (size_t) NUM2SIZET(rb_index)));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
static VALUE RectangleShape_get_geometric_center(VALUE self) {
|
|
228
|
+
return vec2f_to_rb(sfRectangleShape_getGeometricCenter(Get_RectangleShape_Struct(self)));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
static VALUE RectangleShape_get_local_bounds(VALUE self) {
|
|
232
|
+
return rect_to_rb(sfRectangleShape_getLocalBounds(Get_RectangleShape_Struct(self)));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
static VALUE RectangleShape_get_global_bounds(VALUE self) {
|
|
236
|
+
return rect_to_rb(sfRectangleShape_getGlobalBounds(Get_RectangleShape_Struct(self)));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
static VALUE RectangleShape_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
240
|
+
if (!rb_obj_is_kind_of(rb_target, Get_Klass_Target())) {
|
|
241
|
+
raise_invalid_argument_class(Get_Klass_Target());
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
|
|
245
|
+
raise_invalid_argument_class(Get_Klass_RenderState());
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
TARGET_DRAW(Get_Target_Struct(rb_target), sfRenderWindow_drawRectangleShape,
|
|
249
|
+
sfRenderTexture_drawRectangleShape, Get_RectangleShape_Struct(self),
|
|
250
|
+
Get_RenderState_Struct(rb_state));
|
|
251
|
+
|
|
252
|
+
return Qnil;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
void Init_RectangleShape(VALUE rb_module) {
|
|
256
|
+
rb_cRectangleShape = rb_define_class_under(rb_module, "RectangleShape", rb_cObject);
|
|
257
|
+
|
|
258
|
+
rb_include_module(rb_cRectangleShape, Get_Module_Drawable());
|
|
259
|
+
|
|
260
|
+
rb_define_singleton_method(rb_cRectangleShape, "new", RectangleShape_new, -1);
|
|
261
|
+
|
|
262
|
+
rb_define_method(rb_cRectangleShape, "copy", RectangleShape_copy, 0);
|
|
263
|
+
|
|
264
|
+
rb_define_method(rb_cRectangleShape, "size", RectangleShape_get_size, 0);
|
|
265
|
+
rb_define_method(rb_cRectangleShape, "position", RectangleShape_get_position, 0);
|
|
266
|
+
rb_define_method(rb_cRectangleShape, "rotation", RectangleShape_get_rotation, 0);
|
|
267
|
+
rb_define_method(rb_cRectangleShape, "scale", RectangleShape_get_scale, 0);
|
|
268
|
+
rb_define_method(rb_cRectangleShape, "origin", RectangleShape_get_origin, 0);
|
|
269
|
+
rb_define_method(rb_cRectangleShape, "fill_color", RectangleShape_get_fill_color, 0);
|
|
270
|
+
rb_define_method(rb_cRectangleShape, "outline_color", RectangleShape_get_outline_color, 0);
|
|
271
|
+
rb_define_method(rb_cRectangleShape, "outline_thickness", RectangleShape_get_outline_thickness, 0);
|
|
272
|
+
rb_define_method(rb_cRectangleShape, "texture", RectangleShape_get_texture, 0);
|
|
273
|
+
rb_define_method(rb_cRectangleShape, "texture_rect", RectangleShape_get_texture_rect, 0);
|
|
274
|
+
rb_define_method(rb_cRectangleShape, "point_count", RectangleShape_get_point_count, 0);
|
|
275
|
+
rb_define_method(rb_cRectangleShape, "point", RectangleShape_get_point, 1);
|
|
276
|
+
rb_define_method(rb_cRectangleShape, "geometric_center", RectangleShape_get_geometric_center, 0);
|
|
277
|
+
rb_define_method(rb_cRectangleShape, "local_bounds", RectangleShape_get_local_bounds, 0);
|
|
278
|
+
rb_define_method(rb_cRectangleShape, "global_bounds", RectangleShape_get_global_bounds, 0);
|
|
279
|
+
rb_define_method(rb_cRectangleShape, "transform", RectangleShape_get_transform, 0);
|
|
280
|
+
rb_define_method(rb_cRectangleShape, "inverse_transform", RectangleShape_get_inverse_transform, 0);
|
|
281
|
+
rb_define_method(rb_cRectangleShape, "matrix", RectangleShape_get_transform, 0);
|
|
282
|
+
|
|
283
|
+
rb_define_method(rb_cRectangleShape, "size=", RectangleShape_set_size, 1);
|
|
284
|
+
rb_define_method(rb_cRectangleShape, "position=", RectangleShape_set_position, 1);
|
|
285
|
+
rb_define_method(rb_cRectangleShape, "rotation=", RectangleShape_set_rotation, 1);
|
|
286
|
+
rb_define_method(rb_cRectangleShape, "scale=", RectangleShape_set_scale, 1);
|
|
287
|
+
rb_define_method(rb_cRectangleShape, "origin=", RectangleShape_set_origin, 1);
|
|
288
|
+
rb_define_method(rb_cRectangleShape, "fill_color=", RectangleShape_set_fill_color, 1);
|
|
289
|
+
rb_define_method(rb_cRectangleShape, "outline_color=", RectangleShape_set_outline_color, 1);
|
|
290
|
+
rb_define_method(rb_cRectangleShape, "outline_thickness=", RectangleShape_set_outline_thickness, 1);
|
|
291
|
+
rb_define_method(rb_cRectangleShape, "texture=", RectangleShape_set_texture, 1);
|
|
292
|
+
rb_define_method(rb_cRectangleShape, "texture_rect=", RectangleShape_set_texture_rect, 1);
|
|
293
|
+
|
|
294
|
+
rb_define_method(rb_cRectangleShape, "move", RectangleShape_move, 1);
|
|
295
|
+
rb_define_method(rb_cRectangleShape, "rotate", RectangleShape_rotate, 1);
|
|
296
|
+
rb_define_method(rb_cRectangleShape, "scale!", RectangleShape_scale, 1);
|
|
297
|
+
rb_define_method(rb_cRectangleShape, "draw", RectangleShape_draw, 2);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
VALUE Get_Klass_RectangleShape(void) {
|
|
301
|
+
return rb_cRectangleShape;
|
|
302
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
#include "graphics/render_state.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
|
|
6
|
+
#include "graphics/transform.h"
|
|
7
|
+
#include "graphics/blend_mode.h"
|
|
8
|
+
#include "graphics/stencil_mode.h"
|
|
9
|
+
#include "graphics/enums.h"
|
|
10
|
+
#include "graphics/texture.h"
|
|
11
|
+
#include "graphics/shader.h"
|
|
12
|
+
#include "core/exceptions.h"
|
|
13
|
+
#include "core/macros.h"
|
|
14
|
+
|
|
15
|
+
/* The wrapped struct holds Ruby references (texture, shader) alongside the C
|
|
16
|
+
states, so the data type needs a dmark. The C struct is a member rather than
|
|
17
|
+
the whole allocation so those references have somewhere to live. */
|
|
18
|
+
typedef struct {
|
|
19
|
+
sfRenderStates c;
|
|
20
|
+
VALUE rb_texture;
|
|
21
|
+
VALUE rb_shader;
|
|
22
|
+
} RenderStates;
|
|
23
|
+
|
|
24
|
+
static VALUE rb_cRenderState;
|
|
25
|
+
|
|
26
|
+
static void RenderStates_mark(void* ptr) {
|
|
27
|
+
RenderStates* states = ptr;
|
|
28
|
+
|
|
29
|
+
rb_gc_mark(states->rb_texture);
|
|
30
|
+
rb_gc_mark(states->rb_shader);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static void RenderStates_free(void* ptr) {
|
|
34
|
+
free(ptr);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static const rb_data_type_t RenderStates_data_type = {
|
|
38
|
+
.wrap_struct_name = "SFML::RenderState",
|
|
39
|
+
.function = {.dmark = RenderStates_mark, .dfree = RenderStates_free, .dsize = NULL},
|
|
40
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
41
|
+
|
|
42
|
+
static RenderStates* RenderStates_create(void) {
|
|
43
|
+
RenderStates* states = malloc(sizeof(RenderStates));
|
|
44
|
+
|
|
45
|
+
/* Copy the defaults rather than filling fields by hand: CSFML 2 left the
|
|
46
|
+
struct smaller, and spelling fields out is how stencilMode and
|
|
47
|
+
coordinateType ended up uninitialised under CSFML 3. */
|
|
48
|
+
states->c = sfRenderStates_default;
|
|
49
|
+
states->rb_texture = Qnil;
|
|
50
|
+
states->rb_shader = Qnil;
|
|
51
|
+
|
|
52
|
+
return states;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static VALUE RenderStates_wrap(VALUE klass, RenderStates* states) {
|
|
56
|
+
return TypedData_Wrap_Struct(klass, &RenderStates_data_type, states);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static VALUE RenderStates_new(int argc, VALUE* argv, VALUE klass) {
|
|
60
|
+
RenderStates* states;
|
|
61
|
+
VALUE self;
|
|
62
|
+
|
|
63
|
+
if (argc > 1) {
|
|
64
|
+
raise_invalid_arguments_excepted(1, argc);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
states = RenderStates_create();
|
|
68
|
+
|
|
69
|
+
if (argc == 1) {
|
|
70
|
+
states->c.transform = Transform_ArrayToTransform(argv[0]);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
self = RenderStates_wrap(klass, states);
|
|
74
|
+
|
|
75
|
+
return self;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static VALUE RenderStates_set_transform(VALUE self, VALUE rb_matrix) {
|
|
79
|
+
sfRenderStates* states = Get_RenderState_Struct(self);
|
|
80
|
+
|
|
81
|
+
states->transform = Transform_ArrayToTransform(rb_matrix);
|
|
82
|
+
|
|
83
|
+
return self;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static VALUE RenderStates_get_transform(VALUE self) {
|
|
87
|
+
return Transform_MatrixToArray(Get_RenderState_Struct(self)->transform.matrix);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static VALUE RenderStates_get_blend_mode(VALUE self) {
|
|
91
|
+
return blend_mode_to_rb(Get_RenderState_Struct(self)->blendMode);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static VALUE RenderStates_set_blend_mode(VALUE self, VALUE rb_mode) {
|
|
95
|
+
Get_RenderState_Struct(self)->blendMode = blend_mode_from_rb(rb_mode);
|
|
96
|
+
return rb_mode;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static VALUE RenderStates_get_stencil_mode(VALUE self) {
|
|
100
|
+
return stencil_mode_to_rb(Get_RenderState_Struct(self)->stencilMode);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static VALUE RenderStates_set_stencil_mode(VALUE self, VALUE rb_mode) {
|
|
104
|
+
Get_RenderState_Struct(self)->stencilMode = stencil_mode_from_rb(rb_mode);
|
|
105
|
+
return rb_mode;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
static VALUE RenderStates_get_coordinate_type(VALUE self) {
|
|
109
|
+
return ID2SYM(rb_intern(coordinate_type_name(Get_RenderState_Struct(self)->coordinateType)));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static VALUE RenderStates_set_coordinate_type(VALUE self, VALUE rb_type) {
|
|
113
|
+
Get_RenderState_Struct(self)->coordinateType = coordinate_type_from_rb(rb_type);
|
|
114
|
+
return rb_type;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* sfRenderStates is the first member, so its address is the wrapper's. */
|
|
118
|
+
static RenderStates* Get_RenderStates_Wrapper(VALUE self) {
|
|
119
|
+
return (RenderStates*)Get_RenderState_Struct(self);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static VALUE RenderStates_get_texture(VALUE self) {
|
|
123
|
+
return Get_RenderStates_Wrapper(self)->rb_texture;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static VALUE RenderStates_set_texture(VALUE self, VALUE rb_texture) {
|
|
127
|
+
RenderStates* states = Get_RenderStates_Wrapper(self);
|
|
128
|
+
|
|
129
|
+
if (NIL_P(rb_texture)) {
|
|
130
|
+
states->rb_texture = Qnil;
|
|
131
|
+
states->c.texture = NULL;
|
|
132
|
+
return rb_texture;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!rb_obj_is_kind_of(rb_texture, Get_Klass_Texture())) {
|
|
136
|
+
raise_invalid_argument_class(Get_Klass_Texture());
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
states->rb_texture = rb_texture;
|
|
140
|
+
states->c.texture = Get_Texture_Struct(rb_texture);
|
|
141
|
+
|
|
142
|
+
return rb_texture;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
static VALUE RenderStates_get_shader(VALUE self) {
|
|
146
|
+
return Get_RenderStates_Wrapper(self)->rb_shader;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
static VALUE RenderStates_set_shader(VALUE self, VALUE rb_shader) {
|
|
150
|
+
RenderStates* states = Get_RenderStates_Wrapper(self);
|
|
151
|
+
|
|
152
|
+
if (NIL_P(rb_shader)) {
|
|
153
|
+
states->rb_shader = Qnil;
|
|
154
|
+
states->c.shader = NULL;
|
|
155
|
+
return rb_shader;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!rb_obj_is_kind_of(rb_shader, Get_Klass_Shader())) {
|
|
159
|
+
raise_invalid_argument_class(Get_Klass_Shader());
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
states->rb_shader = rb_shader;
|
|
163
|
+
states->c.shader = Get_Shader_Struct(rb_shader);
|
|
164
|
+
|
|
165
|
+
return rb_shader;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
void Init_RenderState(VALUE rb_module) {
|
|
169
|
+
rb_cRenderState = rb_define_class_under(rb_module, "RenderState", rb_cObject);
|
|
170
|
+
|
|
171
|
+
rb_define_singleton_method(rb_cRenderState, "new", RenderStates_new, -1);
|
|
172
|
+
|
|
173
|
+
// setters
|
|
174
|
+
rb_define_method(rb_cRenderState, "transform=", RenderStates_set_transform, 1);
|
|
175
|
+
rb_define_method(rb_cRenderState, "matrix=", RenderStates_set_transform, 1);
|
|
176
|
+
rb_define_method(rb_cRenderState, "blend_mode=", RenderStates_set_blend_mode, 1);
|
|
177
|
+
rb_define_method(rb_cRenderState, "stencil_mode=", RenderStates_set_stencil_mode, 1);
|
|
178
|
+
rb_define_method(rb_cRenderState, "coordinate_type=", RenderStates_set_coordinate_type, 1);
|
|
179
|
+
rb_define_method(rb_cRenderState, "texture=", RenderStates_set_texture, 1);
|
|
180
|
+
rb_define_method(rb_cRenderState, "shader=", RenderStates_set_shader, 1);
|
|
181
|
+
|
|
182
|
+
// getters
|
|
183
|
+
rb_define_method(rb_cRenderState, "transform", RenderStates_get_transform, 0);
|
|
184
|
+
rb_define_method(rb_cRenderState, "matrix", RenderStates_get_transform, 0);
|
|
185
|
+
rb_define_method(rb_cRenderState, "blend_mode", RenderStates_get_blend_mode, 0);
|
|
186
|
+
rb_define_method(rb_cRenderState, "stencil_mode", RenderStates_get_stencil_mode, 0);
|
|
187
|
+
rb_define_method(rb_cRenderState, "coordinate_type", RenderStates_get_coordinate_type, 0);
|
|
188
|
+
rb_define_method(rb_cRenderState, "texture", RenderStates_get_texture, 0);
|
|
189
|
+
rb_define_method(rb_cRenderState, "shader", RenderStates_get_shader, 0);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
sfRenderStates* Get_RenderState_Struct(VALUE self) {
|
|
193
|
+
RenderStates* states;
|
|
194
|
+
TypedData_Get_Struct(self, RenderStates, &RenderStates_data_type, states);
|
|
195
|
+
return &states->c;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
VALUE Get_Klass_RenderState(void) {
|
|
199
|
+
return rb_cRenderState;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
VALUE Get_New_RenderState(void) {
|
|
203
|
+
return RenderStates_wrap(Get_Klass_RenderState(), RenderStates_create());
|
|
204
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#ifndef SFML_RB_GRAPHICS_RENDER_STATE_H
|
|
2
|
+
#define SFML_RB_GRAPHICS_RENDER_STATE_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include "core/sfml.h"
|
|
7
|
+
|
|
8
|
+
#define DefaultMatrix3x3() {1, 0, 0, 0, 1, 0, 0, 0, 1}
|
|
9
|
+
|
|
10
|
+
void Init_RenderState(VALUE rb_module);
|
|
11
|
+
|
|
12
|
+
sfRenderStates *Get_RenderState_Struct(VALUE self);
|
|
13
|
+
|
|
14
|
+
VALUE Get_Klass_RenderState(void);
|
|
15
|
+
|
|
16
|
+
VALUE Get_New_RenderState(void);
|
|
17
|
+
|
|
18
|
+
#endif //SFML_RB_GRAPHICS_RENDER_STATE_H
|