sfml3-rb 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +9 -0
- data/CHANGELOG.md +43 -17
- data/README.md +97 -29
- data/ext/audio/audio_enums.c +58 -20
- data/ext/audio/listener.c +89 -6
- data/ext/audio/music.c +206 -5
- data/ext/audio/sound.c +175 -5
- data/ext/audio/sound_buffer.c +189 -47
- data/ext/audio/sound_buffer_recorder.c +83 -16
- data/ext/audio/sound_recorder.c +172 -52
- data/ext/audio/sound_source_cone.c +108 -29
- data/ext/audio/sound_stream.c +178 -5
- data/ext/core/exceptions.c +10 -8
- data/ext/core/unicode.c +12 -2
- data/ext/ext.c +4 -0
- data/ext/graphics/blend_mode.c +203 -53
- data/ext/graphics/circle.c +271 -4
- data/ext/graphics/color.c +240 -90
- data/ext/graphics/drawable.c +15 -4
- data/ext/graphics/font.c +138 -25
- data/ext/graphics/glyph.c +31 -8
- data/ext/graphics/image.c +180 -37
- data/ext/graphics/polygon.c +293 -26
- data/ext/graphics/rect.c +211 -54
- data/ext/graphics/rectangle.c +279 -26
- data/ext/graphics/render_state.c +116 -2
- data/ext/graphics/render_texture.c +163 -2
- data/ext/graphics/shader.c +283 -17
- data/ext/graphics/shape.c +252 -26
- data/ext/graphics/sprite.c +216 -25
- data/ext/graphics/stencil_mode.c +148 -39
- data/ext/graphics/target.c +67 -22
- data/ext/graphics/target.h +15 -15
- data/ext/graphics/text.c +306 -6
- data/ext/graphics/texture.c +257 -3
- data/ext/graphics/transform.c +178 -5
- data/ext/graphics/transformable.c +126 -2
- data/ext/graphics/vertex.c +79 -2
- data/ext/graphics/vertex_array.c +128 -16
- data/ext/graphics/vertex_buffer.c +124 -2
- data/ext/graphics/view.c +130 -2
- data/ext/network/ftp.c +249 -10
- data/ext/network/http.c +156 -38
- data/ext/network/ip_address.c +107 -26
- data/ext/network/network_enums.c +248 -141
- data/ext/network/packet.c +273 -39
- data/ext/network/socket_selector.c +91 -19
- data/ext/network/tcp_listener.c +75 -16
- data/ext/network/tcp_socket.c +128 -25
- data/ext/network/udp_socket.c +122 -26
- data/ext/ports.rb +7 -0
- data/ext/system/buffer.c +41 -12
- data/ext/system/clock.c +68 -9
- data/ext/system/input_stream.c +94 -42
- data/ext/system/sleep.c +10 -2
- data/ext/system/time.c +172 -34
- data/ext/system/vec2.c +156 -35
- data/ext/system/vec3.c +166 -35
- data/ext/window/clipboard.c +47 -17
- data/ext/window/context.c +59 -9
- data/ext/window/context_settings.c +116 -38
- data/ext/window/cursor.c +39 -9
- data/ext/window/event.c +163 -42
- data/ext/window/joystick.c +69 -3
- data/ext/window/keyboard.c +168 -116
- data/ext/window/mouse.c +36 -2
- data/ext/window/sensor.c +28 -2
- data/ext/window/touch.c +20 -2
- data/ext/window/video_mode.c +90 -19
- data/ext/window/vulkan.c +34 -6
- data/ext/window/window.c +340 -16
- data/lib/sfml/version.rb +1 -1
- data/sig/audio/audio_enums.rbs +30 -0
- data/sig/audio/listener.rbs +16 -0
- data/sig/audio/music.rbs +56 -0
- data/sig/audio/sound.rbs +51 -0
- data/sig/audio/sound_buffer.rbs +17 -0
- data/sig/audio/sound_buffer_recorder.rbs +14 -0
- data/sig/audio/sound_recorder.rbs +17 -0
- data/sig/audio/sound_source_cone.rbs +14 -0
- data/sig/audio/sound_stream.rbs +51 -0
- data/sig/graphics/blend_mode.rbs +29 -0
- data/sig/graphics/circle.rbs +44 -0
- data/sig/graphics/color.rbs +39 -0
- data/sig/graphics/drawable.rbs +5 -0
- data/sig/graphics/font.rbs +20 -0
- data/sig/graphics/glyph.rbs +7 -0
- data/sig/graphics/image.rbs +22 -0
- data/sig/graphics/polygon.rbs +42 -0
- data/sig/graphics/rect.rbs +33 -0
- data/sig/graphics/rectangle.rbs +42 -0
- data/sig/graphics/render_state.rbs +21 -0
- data/sig/graphics/render_texture.rbs +37 -0
- data/sig/graphics/shader.rbs +39 -0
- data/sig/graphics/shape.rbs +38 -0
- data/sig/graphics/sprite.rbs +34 -0
- data/sig/graphics/stencil_mode.rbs +18 -0
- data/sig/graphics/target.rbs +10 -0
- data/sig/graphics/text.rbs +48 -0
- data/sig/graphics/texture.rbs +34 -0
- data/sig/graphics/transform.rbs +37 -0
- data/sig/graphics/transformable.rbs +25 -0
- data/sig/graphics/vertex.rbs +17 -0
- data/sig/graphics/vertex_array.rbs +17 -0
- data/sig/graphics/vertex_buffer.rbs +22 -0
- data/sig/graphics/view.rbs +24 -0
- data/sig/network/ftp.rbs +46 -0
- data/sig/network/http.rbs +27 -0
- data/sig/network/ip_address.rbs +22 -0
- data/sig/network/network_enums.rbs +95 -0
- data/sig/network/packet.rbs +40 -0
- data/sig/network/socket_selector.rbs +14 -0
- data/sig/network/tcp_listener.rbs +13 -0
- data/sig/network/tcp_socket.rbs +18 -0
- data/sig/network/udp_socket.rbs +17 -0
- data/sig/system/buffer.rbs +11 -0
- data/sig/system/clock.rbs +13 -0
- data/sig/system/input_stream.rbs +7 -0
- data/sig/system/sleep.rbs +3 -0
- data/sig/system/time.rbs +28 -0
- data/sig/system/vec2.rbs +26 -0
- data/sig/system/vec3.rbs +27 -0
- data/sig/window/clipboard.rbs +8 -0
- data/sig/window/context.rbs +11 -0
- data/sig/window/context_settings.rbs +20 -0
- data/sig/window/cursor.rbs +6 -0
- data/sig/window/event.rbs +20 -0
- data/sig/window/joystick.rbs +15 -0
- data/sig/window/keyboard.rbs +10 -0
- data/sig/window/mouse.rbs +9 -0
- data/sig/window/sensor.rbs +8 -0
- data/sig/window/touch.rbs +6 -0
- data/sig/window/video_mode.rbs +16 -0
- data/sig/window/vulkan.rbs +7 -0
- data/sig/window/window.rbs +57 -0
- metadata +66 -2
data/ext/graphics/stencil_mode.c
CHANGED
|
@@ -13,26 +13,23 @@ typedef struct {
|
|
|
13
13
|
|
|
14
14
|
static VALUE rb_cStencilMode;
|
|
15
15
|
|
|
16
|
-
static const char
|
|
17
|
-
|
|
18
|
-
};
|
|
16
|
+
static const char* comparison_names[] = {"never", "less", "less_equal", "greater",
|
|
17
|
+
"greater_equal", "equal", "not_equal", "always"};
|
|
19
18
|
|
|
20
|
-
static const char
|
|
21
|
-
|
|
22
|
-
};
|
|
19
|
+
static const char* operation_names[] = {"keep", "zero", "replace",
|
|
20
|
+
"increment", "decrement", "invert"};
|
|
23
21
|
|
|
24
|
-
static void StencilMode_free(void
|
|
22
|
+
static void StencilMode_free(void* ptr) {
|
|
25
23
|
free(ptr);
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
static const rb_data_type_t StencilMode_data_type = {
|
|
29
27
|
.wrap_struct_name = "SFML::StencilMode",
|
|
30
28
|
.function = {.dmark = NULL, .dfree = StencilMode_free, .dsize = NULL},
|
|
31
|
-
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
32
|
-
};
|
|
29
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
33
30
|
|
|
34
31
|
static VALUE StencilMode_wrap(sfStencilMode mode) {
|
|
35
|
-
StencilMode
|
|
32
|
+
StencilMode* ptr = malloc(sizeof(StencilMode));
|
|
36
33
|
|
|
37
34
|
ptr->mode = mode;
|
|
38
35
|
|
|
@@ -43,15 +40,15 @@ static sfStencilComparison comparison_from_rb(VALUE rb_value) {
|
|
|
43
40
|
size_t i;
|
|
44
41
|
|
|
45
42
|
if (RB_INTEGER_TYPE_P(rb_value)) {
|
|
46
|
-
return (sfStencilComparison)
|
|
43
|
+
return (sfStencilComparison)NUM2INT(rb_value);
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
if (SYMBOL_P(rb_value)) {
|
|
50
|
-
const char
|
|
47
|
+
const char* name = rb_id2name(SYM2ID(rb_value));
|
|
51
48
|
|
|
52
49
|
for (i = 0; i < sizeof(comparison_names) / sizeof(comparison_names[0]); i++) {
|
|
53
50
|
if (strcmp(name, comparison_names[i]) == 0) {
|
|
54
|
-
return (sfStencilComparison)
|
|
51
|
+
return (sfStencilComparison)i;
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
}
|
|
@@ -64,15 +61,15 @@ static sfStencilUpdateOperation operation_from_rb(VALUE rb_value) {
|
|
|
64
61
|
size_t i;
|
|
65
62
|
|
|
66
63
|
if (RB_INTEGER_TYPE_P(rb_value)) {
|
|
67
|
-
return (sfStencilUpdateOperation)
|
|
64
|
+
return (sfStencilUpdateOperation)NUM2INT(rb_value);
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
if (SYMBOL_P(rb_value)) {
|
|
71
|
-
const char
|
|
68
|
+
const char* name = rb_id2name(SYM2ID(rb_value));
|
|
72
69
|
|
|
73
70
|
for (i = 0; i < sizeof(operation_names) / sizeof(operation_names[0]); i++) {
|
|
74
71
|
if (strcmp(name, operation_names[i]) == 0) {
|
|
75
|
-
return (sfStencilUpdateOperation)
|
|
72
|
+
return (sfStencilUpdateOperation)i;
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
75
|
}
|
|
@@ -81,16 +78,28 @@ static sfStencilUpdateOperation operation_from_rb(VALUE rb_value) {
|
|
|
81
78
|
return sfStencilUpdateOperationKeep;
|
|
82
79
|
}
|
|
83
80
|
|
|
84
|
-
|
|
81
|
+
/* call-seq:
|
|
82
|
+
* StencilMode.new -> StencilMode
|
|
83
|
+
* StencilMode.new(comparison, update_operation, reference, mask, stencil_only) -> StencilMode
|
|
84
|
+
*
|
|
85
|
+
* With no arguments, builds the default stencil mode (always passes,
|
|
86
|
+
* doesn't modify the stencil buffer). +comparison+ and +update_operation+
|
|
87
|
+
* accept either a Symbol (see #comparison and #update_operation) or the
|
|
88
|
+
* matching CSFML Integer constant.
|
|
89
|
+
*
|
|
90
|
+
* @return [StencilMode]
|
|
91
|
+
* @raise [ArgumentError] if given an argument count other than 0 or 5
|
|
92
|
+
*/
|
|
93
|
+
static VALUE StencilMode_new(int argc, VALUE* argv, VALUE klass) {
|
|
85
94
|
VALUE self;
|
|
86
|
-
StencilMode
|
|
95
|
+
StencilMode* ptr;
|
|
87
96
|
sfStencilMode mode = sfStencilMode_default;
|
|
88
97
|
|
|
89
98
|
if (argc == 5) {
|
|
90
99
|
mode.stencilComparison = comparison_from_rb(argv[0]);
|
|
91
100
|
mode.stencilUpdateOperation = operation_from_rb(argv[1]);
|
|
92
|
-
mode.stencilReference.value = (unsigned int)
|
|
93
|
-
mode.stencilMask.value = (unsigned int)
|
|
101
|
+
mode.stencilReference.value = (unsigned int)NUM2UINT(argv[2]);
|
|
102
|
+
mode.stencilMask.value = (unsigned int)NUM2UINT(argv[3]);
|
|
94
103
|
mode.stencilOnly = RTEST(argv[4]);
|
|
95
104
|
} else if (argc != 0) {
|
|
96
105
|
raise_invalid_arguments_excepted(5, argc);
|
|
@@ -104,72 +113,172 @@ static VALUE StencilMode_new(int argc, VALUE *argv, VALUE klass) {
|
|
|
104
113
|
return self;
|
|
105
114
|
}
|
|
106
115
|
|
|
116
|
+
/* call-seq: comparison -> Symbol
|
|
117
|
+
*
|
|
118
|
+
* Returns the comparison used against the stencil buffer.
|
|
119
|
+
*
|
|
120
|
+
* @return [Symbol] one of :never, :less, :less_equal, :greater,
|
|
121
|
+
* :greater_equal, :equal, :not_equal, :always
|
|
122
|
+
*/
|
|
107
123
|
static VALUE StencilMode_get_comparison(VALUE self) {
|
|
108
|
-
return ID2SYM(rb_intern(
|
|
124
|
+
return ID2SYM(rb_intern(
|
|
125
|
+
comparison_names[((StencilMode*)Get_StencilMode_Struct(self))->mode.stencilComparison]));
|
|
109
126
|
}
|
|
110
127
|
|
|
128
|
+
/* call-seq: update_operation -> Symbol
|
|
129
|
+
*
|
|
130
|
+
* Returns the operation applied when the stencil test passes or fails.
|
|
131
|
+
*
|
|
132
|
+
* @return [Symbol] one of :keep, :zero, :replace, :increment, :decrement,
|
|
133
|
+
* :invert
|
|
134
|
+
*/
|
|
111
135
|
static VALUE StencilMode_get_operation(VALUE self) {
|
|
112
|
-
sfStencilMode mode = ((StencilMode
|
|
136
|
+
sfStencilMode mode = ((StencilMode*)Get_StencilMode_Struct(self))->mode;
|
|
113
137
|
|
|
114
138
|
return ID2SYM(rb_intern(operation_names[mode.stencilUpdateOperation]));
|
|
115
139
|
}
|
|
116
140
|
|
|
141
|
+
/* call-seq: reference -> Integer
|
|
142
|
+
*
|
|
143
|
+
* Returns the reference value compared against the stencil buffer.
|
|
144
|
+
*
|
|
145
|
+
* @return [Integer]
|
|
146
|
+
*/
|
|
117
147
|
static VALUE StencilMode_get_reference(VALUE self) {
|
|
118
|
-
return UINT2NUM(((StencilMode
|
|
148
|
+
return UINT2NUM(((StencilMode*)Get_StencilMode_Struct(self))->mode.stencilReference.value);
|
|
119
149
|
}
|
|
120
150
|
|
|
151
|
+
/* call-seq: mask -> Integer
|
|
152
|
+
*
|
|
153
|
+
* Returns the bitmask applied to the stencil values.
|
|
154
|
+
*
|
|
155
|
+
* @return [Integer]
|
|
156
|
+
*/
|
|
121
157
|
static VALUE StencilMode_get_mask(VALUE self) {
|
|
122
|
-
return UINT2NUM(((StencilMode
|
|
158
|
+
return UINT2NUM(((StencilMode*)Get_StencilMode_Struct(self))->mode.stencilMask.value);
|
|
123
159
|
}
|
|
124
160
|
|
|
161
|
+
/* call-seq: stencil_only -> true or false
|
|
162
|
+
*
|
|
163
|
+
* Returns +true+ if only the stencil buffer is written to.
|
|
164
|
+
*
|
|
165
|
+
* @return [Boolean]
|
|
166
|
+
*/
|
|
125
167
|
static VALUE StencilMode_get_only(VALUE self) {
|
|
126
|
-
return BOOL2RB(((StencilMode
|
|
168
|
+
return BOOL2RB(((StencilMode*)Get_StencilMode_Struct(self))->mode.stencilOnly);
|
|
127
169
|
}
|
|
128
170
|
|
|
171
|
+
/* call-seq:
|
|
172
|
+
* comparison=(value) -> Symbol or Integer
|
|
173
|
+
*
|
|
174
|
+
* Sets the comparison used against the stencil buffer.
|
|
175
|
+
*
|
|
176
|
+
* @return [Symbol, Integer] +value+
|
|
177
|
+
*/
|
|
129
178
|
static VALUE StencilMode_set_comparison(VALUE self, VALUE rb_value) {
|
|
130
|
-
((StencilMode
|
|
179
|
+
((StencilMode*)Get_StencilMode_Struct(self))->mode.stencilComparison =
|
|
180
|
+
comparison_from_rb(rb_value);
|
|
131
181
|
return rb_value;
|
|
132
182
|
}
|
|
133
183
|
|
|
184
|
+
/* call-seq:
|
|
185
|
+
* update_operation=(value) -> Symbol or Integer
|
|
186
|
+
*
|
|
187
|
+
* Sets the operation applied when the stencil test passes or fails.
|
|
188
|
+
*
|
|
189
|
+
* @return [Symbol, Integer] +value+
|
|
190
|
+
*/
|
|
134
191
|
static VALUE StencilMode_set_operation(VALUE self, VALUE rb_value) {
|
|
135
|
-
((StencilMode
|
|
192
|
+
((StencilMode*)Get_StencilMode_Struct(self))->mode.stencilUpdateOperation =
|
|
193
|
+
operation_from_rb(rb_value);
|
|
136
194
|
return rb_value;
|
|
137
195
|
}
|
|
138
196
|
|
|
197
|
+
/* call-seq:
|
|
198
|
+
* reference=(value) -> Integer
|
|
199
|
+
*
|
|
200
|
+
* Sets the reference value compared against the stencil buffer.
|
|
201
|
+
*
|
|
202
|
+
* @return [Integer] +value+
|
|
203
|
+
*/
|
|
139
204
|
static VALUE StencilMode_set_reference(VALUE self, VALUE rb_value) {
|
|
140
|
-
((StencilMode
|
|
205
|
+
((StencilMode*)Get_StencilMode_Struct(self))->mode.stencilReference.value =
|
|
206
|
+
(unsigned int)NUM2UINT(rb_value);
|
|
141
207
|
return rb_value;
|
|
142
208
|
}
|
|
143
209
|
|
|
210
|
+
/* call-seq:
|
|
211
|
+
* mask=(value) -> Integer
|
|
212
|
+
*
|
|
213
|
+
* Sets the bitmask applied to the stencil values.
|
|
214
|
+
*
|
|
215
|
+
* @return [Integer] +value+
|
|
216
|
+
*/
|
|
144
217
|
static VALUE StencilMode_set_mask(VALUE self, VALUE rb_value) {
|
|
145
|
-
((StencilMode
|
|
218
|
+
((StencilMode*)Get_StencilMode_Struct(self))->mode.stencilMask.value =
|
|
219
|
+
(unsigned int)NUM2UINT(rb_value);
|
|
146
220
|
return rb_value;
|
|
147
221
|
}
|
|
148
222
|
|
|
223
|
+
/* call-seq:
|
|
224
|
+
* stencil_only=(value) -> true or false
|
|
225
|
+
*
|
|
226
|
+
* Enables or disables writing only to the stencil buffer.
|
|
227
|
+
*
|
|
228
|
+
* @return [Boolean] +value+
|
|
229
|
+
*/
|
|
149
230
|
static VALUE StencilMode_set_only(VALUE self, VALUE rb_value) {
|
|
150
|
-
((StencilMode
|
|
231
|
+
((StencilMode*)Get_StencilMode_Struct(self))->mode.stencilOnly = RTEST(rb_value);
|
|
151
232
|
return rb_value;
|
|
152
233
|
}
|
|
153
234
|
|
|
235
|
+
/* call-seq:
|
|
236
|
+
* self == other -> true or false
|
|
237
|
+
*
|
|
238
|
+
* Returns +true+ if the two objects are equal.
|
|
239
|
+
*
|
|
240
|
+
* @return [Boolean]
|
|
241
|
+
*/
|
|
154
242
|
static VALUE StencilMode_eql(VALUE self, VALUE rb_other) {
|
|
155
|
-
sfStencilMode a = ((StencilMode
|
|
243
|
+
sfStencilMode a = ((StencilMode*)Get_StencilMode_Struct(self))->mode;
|
|
156
244
|
sfStencilMode b;
|
|
157
245
|
|
|
158
246
|
if (!rb_obj_is_kind_of(rb_other, rb_cStencilMode)) {
|
|
159
247
|
return Qfalse;
|
|
160
248
|
}
|
|
161
249
|
|
|
162
|
-
b = ((StencilMode
|
|
250
|
+
b = ((StencilMode*)Get_StencilMode_Struct(rb_other))->mode;
|
|
163
251
|
|
|
164
252
|
return BOOL2RB(a.stencilComparison == b.stencilComparison &&
|
|
165
253
|
a.stencilUpdateOperation == b.stencilUpdateOperation &&
|
|
166
254
|
a.stencilReference.value == b.stencilReference.value &&
|
|
167
|
-
a.stencilMask.value == b.stencilMask.value &&
|
|
168
|
-
a.stencilOnly == b.stencilOnly);
|
|
255
|
+
a.stencilMask.value == b.stencilMask.value && a.stencilOnly == b.stencilOnly);
|
|
169
256
|
}
|
|
170
257
|
|
|
171
|
-
|
|
172
|
-
|
|
258
|
+
/* Document-class: SFML::StencilMode
|
|
259
|
+
* Configures how the stencil buffer is used and updated when drawing,
|
|
260
|
+
* carried on RenderState#stencil_mode.
|
|
261
|
+
*
|
|
262
|
+
* @!attribute comparison
|
|
263
|
+
* The comparison used against the stencil buffer.
|
|
264
|
+
* @return [Symbol] one of :never, :less, :less_equal, :greater,
|
|
265
|
+
* :greater_equal, :equal, :not_equal, :always
|
|
266
|
+
* @!attribute update_operation
|
|
267
|
+
* The operation applied when the stencil test passes or fails.
|
|
268
|
+
* @return [Symbol] one of :keep, :zero, :replace, :increment, :decrement,
|
|
269
|
+
* :invert
|
|
270
|
+
* @!attribute reference
|
|
271
|
+
* The reference value compared against the stencil buffer.
|
|
272
|
+
* @return [Integer]
|
|
273
|
+
* @!attribute mask
|
|
274
|
+
* The bitmask applied to the stencil values.
|
|
275
|
+
* @return [Integer]
|
|
276
|
+
* @!attribute stencil_only
|
|
277
|
+
* Whether only the stencil buffer is written to.
|
|
278
|
+
* @return [Boolean]
|
|
279
|
+
*/
|
|
280
|
+
void Init_StencilMode(VALUE rb_mSFML) {
|
|
281
|
+
rb_cStencilMode = rb_define_class_under(rb_mSFML, "StencilMode", rb_cObject);
|
|
173
282
|
|
|
174
283
|
rb_define_singleton_method(rb_cStencilMode, "new", StencilMode_new, -1);
|
|
175
284
|
|
|
@@ -192,15 +301,15 @@ VALUE Get_Klass_StencilMode(void) {
|
|
|
192
301
|
return rb_cStencilMode;
|
|
193
302
|
}
|
|
194
303
|
|
|
195
|
-
void
|
|
196
|
-
StencilMode
|
|
304
|
+
void* Get_StencilMode_Struct(VALUE self) {
|
|
305
|
+
StencilMode* ptr;
|
|
197
306
|
TypedData_Get_Struct(self, StencilMode, &StencilMode_data_type, ptr);
|
|
198
307
|
return ptr;
|
|
199
308
|
}
|
|
200
309
|
|
|
201
310
|
sfStencilMode stencil_mode_from_rb(VALUE rb_mode) {
|
|
202
311
|
if (rb_obj_is_kind_of(rb_mode, rb_cStencilMode)) {
|
|
203
|
-
return ((StencilMode
|
|
312
|
+
return ((StencilMode*)Get_StencilMode_Struct(rb_mode))->mode;
|
|
204
313
|
}
|
|
205
314
|
|
|
206
315
|
return sfStencilMode_default;
|
data/ext/graphics/target.c
CHANGED
|
@@ -12,34 +12,46 @@
|
|
|
12
12
|
|
|
13
13
|
static VALUE rb_cTarget;
|
|
14
14
|
|
|
15
|
-
static Target
|
|
16
|
-
Target
|
|
15
|
+
static Target* Target_create(TargetType type, void* handle, VALUE rb_source) {
|
|
16
|
+
Target* target = malloc(sizeof(Target));
|
|
17
17
|
|
|
18
18
|
target->type = type;
|
|
19
19
|
target->handle = handle;
|
|
20
|
+
target->rb_source = rb_source;
|
|
20
21
|
|
|
21
22
|
return target;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
static void
|
|
25
|
+
static void RenderTarget_mark(void* ptr) {
|
|
26
|
+
rb_gc_mark(((Target*)ptr)->rb_source);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static void RenderTarget_free(void* ptr) {
|
|
25
30
|
free(ptr);
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
static const rb_data_type_t RenderTarget_data_type = {
|
|
29
34
|
.wrap_struct_name = "SFML::Target",
|
|
30
|
-
.function = {.dmark =
|
|
31
|
-
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
.function = {.dmark = RenderTarget_mark, .dfree = RenderTarget_free, .dsize = NULL},
|
|
36
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
37
|
+
|
|
38
|
+
/* call-seq:
|
|
39
|
+
* Target.new(window) -> Target
|
|
40
|
+
*
|
|
41
|
+
* Wraps +window+ (a Window) as a generic render target.
|
|
42
|
+
*
|
|
43
|
+
* @return [Target]
|
|
44
|
+
* @raise [TypeError] if +window+ is not a Window
|
|
45
|
+
*/
|
|
34
46
|
static VALUE RenderTarget_new(VALUE klass, VALUE rb_window) {
|
|
35
47
|
VALUE self;
|
|
36
|
-
Target
|
|
48
|
+
Target* target;
|
|
37
49
|
|
|
38
50
|
if (!rb_obj_is_kind_of(rb_window, Get_Klass_Window())) {
|
|
39
51
|
raise_invalid_argument_class(Get_Klass_Window());
|
|
40
52
|
}
|
|
41
53
|
|
|
42
|
-
target = Target_create(SFML_TARGET_WINDOW, Get_Window_Struct(rb_window));
|
|
54
|
+
target = Target_create(SFML_TARGET_WINDOW, Get_Window_Struct(rb_window), rb_window);
|
|
43
55
|
self = TypedData_Wrap_Struct(klass, &RenderTarget_data_type, target);
|
|
44
56
|
|
|
45
57
|
rb_obj_call_init(self, 0, NULL);
|
|
@@ -51,6 +63,15 @@ static VALUE RenderTarget_init(VALUE self) {
|
|
|
51
63
|
return self;
|
|
52
64
|
}
|
|
53
65
|
|
|
66
|
+
/* call-seq:
|
|
67
|
+
* draw(drawable, state) -> void
|
|
68
|
+
*
|
|
69
|
+
* Draws +drawable+ (any object responding to +#draw+, i.e. including
|
|
70
|
+
* Drawable) onto this target using +state+ (a RenderState).
|
|
71
|
+
*
|
|
72
|
+
* @return [nil]
|
|
73
|
+
* @raise [TypeError] if +state+ is not a RenderState
|
|
74
|
+
*/
|
|
54
75
|
static VALUE RenderTarget_draw(VALUE self, VALUE rb_drawable, VALUE rb_state) {
|
|
55
76
|
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
|
|
56
77
|
raise_invalid_argument_class(Get_Klass_RenderState());
|
|
@@ -59,37 +80,60 @@ static VALUE RenderTarget_draw(VALUE self, VALUE rb_drawable, VALUE rb_state) {
|
|
|
59
80
|
return rb_funcall(rb_drawable, rb_intern("draw"), 2, self, rb_state);
|
|
60
81
|
}
|
|
61
82
|
|
|
83
|
+
/* call-seq:
|
|
84
|
+
* view=(value) -> nil
|
|
85
|
+
*
|
|
86
|
+
* Sets the target's current view.
|
|
87
|
+
*
|
|
88
|
+
* @return [nil]
|
|
89
|
+
* @raise [TypeError] if +value+ is not a View
|
|
90
|
+
*/
|
|
62
91
|
static VALUE RenderTarget_set_view(VALUE self, VALUE rb_view) {
|
|
63
|
-
Target
|
|
92
|
+
Target* target = Get_Target_Struct(self);
|
|
64
93
|
|
|
65
94
|
if (!rb_obj_is_kind_of(rb_view, Get_Klass_View())) {
|
|
66
95
|
raise_invalid_argument_class(Get_Klass_View());
|
|
67
96
|
}
|
|
68
97
|
|
|
69
98
|
if (target->type == SFML_TARGET_WINDOW) {
|
|
70
|
-
sfRenderWindow_setView((sfRenderWindow
|
|
99
|
+
sfRenderWindow_setView((sfRenderWindow*)target->handle, Get_View_Struct(rb_view));
|
|
71
100
|
} else {
|
|
72
|
-
sfRenderTexture_setView((sfRenderTexture
|
|
101
|
+
sfRenderTexture_setView((sfRenderTexture*)target->handle, Get_View_Struct(rb_view));
|
|
73
102
|
}
|
|
74
103
|
|
|
75
104
|
return Qnil;
|
|
76
105
|
}
|
|
77
106
|
|
|
107
|
+
/* call-seq: view -> View
|
|
108
|
+
*
|
|
109
|
+
* Returns the target's current view.
|
|
110
|
+
*
|
|
111
|
+
* @return [View] a copy of the target's current view
|
|
112
|
+
*/
|
|
78
113
|
static VALUE RenderTarget_get_view(VALUE self) {
|
|
79
|
-
Target
|
|
80
|
-
sfView
|
|
114
|
+
Target* target = Get_Target_Struct(self);
|
|
115
|
+
sfView* view;
|
|
81
116
|
|
|
82
117
|
if (target->type == SFML_TARGET_WINDOW) {
|
|
83
|
-
view = sfView_copy(sfRenderWindow_getView((sfRenderWindow
|
|
118
|
+
view = sfView_copy(sfRenderWindow_getView((sfRenderWindow*)target->handle));
|
|
84
119
|
} else {
|
|
85
|
-
view = sfView_copy(sfRenderTexture_getView((sfRenderTexture
|
|
120
|
+
view = sfView_copy(sfRenderTexture_getView((sfRenderTexture*)target->handle));
|
|
86
121
|
}
|
|
87
122
|
|
|
88
123
|
return Get_Casting_View(view);
|
|
89
124
|
}
|
|
90
125
|
|
|
91
|
-
|
|
92
|
-
|
|
126
|
+
/* Document-class: SFML::Target
|
|
127
|
+
* A generic handle onto whatever can be drawn to -- a Window or a
|
|
128
|
+
* RenderTexture -- used by Drawable#draw so drawable objects don't need to
|
|
129
|
+
* know which concrete kind of target they're being drawn onto.
|
|
130
|
+
*
|
|
131
|
+
* @!attribute view
|
|
132
|
+
* The target's current view.
|
|
133
|
+
* @return [View]
|
|
134
|
+
*/
|
|
135
|
+
void Init_Target(VALUE rb_mSFML) {
|
|
136
|
+
rb_cTarget = rb_define_class_under(rb_mSFML, "Target", rb_cObject);
|
|
93
137
|
|
|
94
138
|
rb_define_singleton_method(rb_cTarget, "new", RenderTarget_new, 1);
|
|
95
139
|
|
|
@@ -108,8 +152,8 @@ VALUE Get_Klass_Target(void) {
|
|
|
108
152
|
return rb_cTarget;
|
|
109
153
|
}
|
|
110
154
|
|
|
111
|
-
Target
|
|
112
|
-
Target
|
|
155
|
+
Target* Get_Target_Struct(VALUE self) {
|
|
156
|
+
Target* ptr;
|
|
113
157
|
TypedData_Get_Struct(self, Target, &RenderTarget_data_type, ptr);
|
|
114
158
|
return ptr;
|
|
115
159
|
}
|
|
@@ -120,13 +164,14 @@ VALUE Get_New_Target(VALUE rb_window) {
|
|
|
120
164
|
|
|
121
165
|
VALUE Get_New_Target_From_RenderTexture(VALUE rb_render_texture) {
|
|
122
166
|
VALUE self;
|
|
123
|
-
Target
|
|
167
|
+
Target* target;
|
|
124
168
|
|
|
125
169
|
if (!rb_obj_is_kind_of(rb_render_texture, Get_Klass_RenderTexture())) {
|
|
126
170
|
raise_invalid_argument_class(Get_Klass_RenderTexture());
|
|
127
171
|
}
|
|
128
172
|
|
|
129
|
-
target = Target_create(SFML_TARGET_TEXTURE, Get_RenderTexture_Struct(rb_render_texture)
|
|
173
|
+
target = Target_create(SFML_TARGET_TEXTURE, Get_RenderTexture_Struct(rb_render_texture),
|
|
174
|
+
rb_render_texture);
|
|
130
175
|
self = TypedData_Wrap_Struct(rb_cTarget, &RenderTarget_data_type, target);
|
|
131
176
|
|
|
132
177
|
return self;
|
data/ext/graphics/target.h
CHANGED
|
@@ -5,36 +5,36 @@
|
|
|
5
5
|
|
|
6
6
|
#include "core/sfml.h"
|
|
7
7
|
|
|
8
|
-
typedef enum {
|
|
9
|
-
SFML_TARGET_WINDOW,
|
|
10
|
-
SFML_TARGET_TEXTURE
|
|
11
|
-
} TargetType;
|
|
8
|
+
typedef enum { SFML_TARGET_WINDOW, SFML_TARGET_TEXTURE } TargetType;
|
|
12
9
|
|
|
13
10
|
typedef struct {
|
|
14
11
|
TargetType type;
|
|
15
|
-
void
|
|
12
|
+
void* handle;
|
|
13
|
+
/* The Window/RenderTexture `handle` is borrowed from, kept alive for as
|
|
14
|
+
long as this Target references it -- see Target_mark in target.c. */
|
|
15
|
+
VALUE rb_source;
|
|
16
16
|
} Target;
|
|
17
17
|
|
|
18
18
|
/* Dispatch a draw call to whichever underlying render surface this target
|
|
19
19
|
wraps. Pass NULL states to use the defaults; never hand CSFML a NULL. */
|
|
20
|
-
#define TARGET_DRAW(target, window_fn, texture_fn, object, states)
|
|
21
|
-
do {
|
|
22
|
-
const sfRenderStates
|
|
23
|
-
if ((target)->type == SFML_TARGET_WINDOW) {
|
|
24
|
-
window_fn((sfRenderWindow
|
|
25
|
-
} else {
|
|
26
|
-
texture_fn((sfRenderTexture
|
|
27
|
-
}
|
|
20
|
+
#define TARGET_DRAW(target, window_fn, texture_fn, object, states) \
|
|
21
|
+
do { \
|
|
22
|
+
const sfRenderStates* sfml_states = (states) ? (states) : &sfRenderStates_default; \
|
|
23
|
+
if ((target)->type == SFML_TARGET_WINDOW) { \
|
|
24
|
+
window_fn((sfRenderWindow*)(target)->handle, (object), sfml_states); \
|
|
25
|
+
} else { \
|
|
26
|
+
texture_fn((sfRenderTexture*)(target)->handle, (object), sfml_states); \
|
|
27
|
+
} \
|
|
28
28
|
} while (0)
|
|
29
29
|
|
|
30
30
|
void Init_Target(VALUE rb_module);
|
|
31
31
|
|
|
32
32
|
VALUE Get_Klass_Target(void);
|
|
33
33
|
|
|
34
|
-
Target
|
|
34
|
+
Target* Get_Target_Struct(VALUE self);
|
|
35
35
|
|
|
36
36
|
VALUE Get_New_Target(VALUE rb_window);
|
|
37
37
|
|
|
38
38
|
VALUE Get_New_Target_From_RenderTexture(VALUE rb_render_texture);
|
|
39
39
|
|
|
40
|
-
#endif //SFML_RB_GRAPHICS_TARGET_H
|
|
40
|
+
#endif // SFML_RB_GRAPHICS_TARGET_H
|