sfml3-rb 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +9 -0
- data/CHANGELOG.md +67 -16
- data/README.md +123 -32
- data/TODO.md +18 -11
- data/ext/audio/audio_enums.c +58 -20
- data/ext/audio/listener.c +89 -6
- data/ext/audio/music.c +212 -5
- data/ext/audio/sound.c +218 -9
- data/ext/audio/sound_buffer.c +197 -47
- data/ext/audio/sound_buffer_recorder.c +90 -18
- data/ext/audio/sound_recorder.c +188 -58
- data/ext/audio/sound_source_cone.c +127 -33
- data/ext/audio/sound_stream.c +204 -21
- data/ext/core/exceptions.c +10 -8
- data/ext/core/unicode.c +12 -2
- data/ext/ext.c +8 -0
- data/ext/graphics/blend_mode.c +218 -60
- data/ext/graphics/circle.c +300 -16
- data/ext/graphics/color.c +253 -94
- data/ext/graphics/drawable.c +16 -4
- data/ext/graphics/font.c +144 -25
- data/ext/graphics/glyph.c +38 -8
- data/ext/graphics/image.c +205 -41
- data/ext/graphics/polygon.c +317 -30
- data/ext/graphics/rect.c +225 -60
- data/ext/graphics/rectangle.c +307 -35
- data/ext/graphics/render_state.c +124 -12
- data/ext/graphics/render_texture.c +191 -14
- data/ext/graphics/render_window.c +55 -0
- data/ext/graphics/render_window.h +10 -0
- data/ext/graphics/shader.c +289 -17
- data/ext/graphics/shape.c +265 -32
- data/ext/graphics/sprite.c +245 -30
- data/ext/graphics/stencil_mode.c +163 -46
- data/ext/graphics/target.c +121 -43
- data/ext/graphics/target.h +31 -17
- data/ext/graphics/text.c +339 -19
- data/ext/graphics/texture.c +291 -6
- data/ext/graphics/transform.c +178 -5
- data/ext/graphics/transformable.c +127 -12
- data/ext/graphics/vertex.c +98 -6
- data/ext/graphics/vertex_array.c +142 -21
- data/ext/graphics/vertex_buffer.c +154 -12
- data/ext/graphics/view.c +140 -6
- data/ext/network/ftp.c +278 -12
- data/ext/network/http.c +179 -44
- data/ext/network/ip_address.c +127 -35
- data/ext/network/network_enums.c +248 -141
- data/ext/network/packet.c +280 -41
- data/ext/network/socket_selector.c +98 -21
- data/ext/network/tcp_listener.c +82 -18
- data/ext/network/tcp_socket.c +135 -27
- data/ext/network/udp_socket.c +129 -28
- data/ext/ports.rb +7 -0
- data/ext/system/buffer.c +47 -16
- data/ext/system/clock.c +77 -12
- data/ext/system/input_stream.c +113 -51
- data/ext/system/sleep.c +10 -2
- data/ext/system/time.c +182 -40
- data/ext/system/vec2.c +166 -39
- data/ext/system/vec3.c +177 -39
- data/ext/window/clipboard.c +47 -17
- data/ext/window/context.c +66 -13
- data/ext/window/context_settings.c +132 -42
- data/ext/window/cursor.c +45 -9
- data/ext/window/event.c +164 -53
- data/ext/window/joystick.c +69 -3
- data/ext/window/keyboard.c +168 -116
- data/ext/window/mouse.c +64 -13
- data/ext/window/sensor.c +28 -2
- data/ext/window/touch.c +32 -12
- data/ext/window/video_mode.c +93 -31
- data/ext/window/vulkan.c +34 -6
- data/ext/window/window.c +228 -229
- data/ext/window/window.h +4 -4
- data/ext/window/window_base.c +251 -0
- data/ext/window/window_base.h +43 -0
- data/ext/window/window_base.inc +236 -0
- data/lib/sfml/version.rb +1 -1
- data/sig/audio/audio_enums.rbs +30 -0
- data/sig/audio/listener.rbs +16 -0
- data/sig/audio/music.rbs +56 -0
- data/sig/audio/sound.rbs +51 -0
- data/sig/audio/sound_buffer.rbs +17 -0
- data/sig/audio/sound_buffer_recorder.rbs +14 -0
- data/sig/audio/sound_recorder.rbs +17 -0
- data/sig/audio/sound_source_cone.rbs +14 -0
- data/sig/audio/sound_stream.rbs +51 -0
- data/sig/graphics/blend_mode.rbs +29 -0
- data/sig/graphics/circle.rbs +44 -0
- data/sig/graphics/color.rbs +39 -0
- data/sig/graphics/drawable.rbs +5 -0
- data/sig/graphics/font.rbs +20 -0
- data/sig/graphics/glyph.rbs +7 -0
- data/sig/graphics/image.rbs +22 -0
- data/sig/graphics/polygon.rbs +42 -0
- data/sig/graphics/rect.rbs +33 -0
- data/sig/graphics/rectangle.rbs +42 -0
- data/sig/graphics/render_state.rbs +21 -0
- data/sig/graphics/render_target.rbs +18 -0
- data/sig/graphics/render_texture.rbs +39 -0
- data/sig/graphics/render_window.rbs +7 -0
- data/sig/graphics/shader.rbs +39 -0
- data/sig/graphics/shape.rbs +38 -0
- data/sig/graphics/sprite.rbs +34 -0
- data/sig/graphics/stencil_mode.rbs +18 -0
- data/sig/graphics/target.rbs +8 -0
- data/sig/graphics/text.rbs +48 -0
- data/sig/graphics/texture.rbs +34 -0
- data/sig/graphics/transform.rbs +37 -0
- data/sig/graphics/transformable.rbs +25 -0
- data/sig/graphics/vertex.rbs +17 -0
- data/sig/graphics/vertex_array.rbs +17 -0
- data/sig/graphics/vertex_buffer.rbs +22 -0
- data/sig/graphics/view.rbs +23 -0
- data/sig/network/ftp.rbs +46 -0
- data/sig/network/http.rbs +27 -0
- data/sig/network/ip_address.rbs +22 -0
- data/sig/network/network_enums.rbs +95 -0
- data/sig/network/packet.rbs +40 -0
- data/sig/network/socket_selector.rbs +14 -0
- data/sig/network/tcp_listener.rbs +13 -0
- data/sig/network/tcp_socket.rbs +18 -0
- data/sig/network/udp_socket.rbs +17 -0
- data/sig/sfml/version.rbs +3 -0
- data/sig/system/buffer.rbs +11 -0
- data/sig/system/clock.rbs +13 -0
- data/sig/system/input_stream.rbs +7 -0
- data/sig/system/sleep.rbs +3 -0
- data/sig/system/time.rbs +28 -0
- data/sig/system/vec2.rbs +26 -0
- data/sig/system/vec3.rbs +27 -0
- data/sig/window/clipboard.rbs +8 -0
- data/sig/window/context.rbs +11 -0
- data/sig/window/context_settings.rbs +20 -0
- data/sig/window/cursor.rbs +6 -0
- data/sig/window/event.rbs +20 -0
- data/sig/window/joystick.rbs +15 -0
- data/sig/window/keyboard.rbs +10 -0
- data/sig/window/mouse.rbs +9 -0
- data/sig/window/sensor.rbs +8 -0
- data/sig/window/touch.rbs +6 -0
- data/sig/window/video_mode.rbs +16 -0
- data/sig/window/vulkan.rbs +7 -0
- data/sig/window/window.rbs +34 -0
- data/sig/window/window_base.rbs +33 -0
- metadata +76 -3
data/ext/graphics/blend_mode.c
CHANGED
|
@@ -13,27 +13,25 @@ typedef struct {
|
|
|
13
13
|
|
|
14
14
|
static VALUE rb_cBlendMode;
|
|
15
15
|
|
|
16
|
-
static const char
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
static const char* factor_names[] = {"zero", "one",
|
|
17
|
+
"src_color", "one_minus_src_color",
|
|
18
|
+
"dst_color", "one_minus_dst_color",
|
|
19
|
+
"src_alpha", "one_minus_src_alpha",
|
|
20
|
+
"dst_alpha", "one_minus_dst_alpha"};
|
|
20
21
|
|
|
21
|
-
static const char
|
|
22
|
-
"add", "subtract", "reverse_subtract", "min", "max"
|
|
23
|
-
};
|
|
22
|
+
static const char* equation_names[] = {"add", "subtract", "reverse_subtract", "min", "max"};
|
|
24
23
|
|
|
25
|
-
static void BlendMode_free(void
|
|
24
|
+
static void BlendMode_free(void* ptr) {
|
|
26
25
|
free(ptr);
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
static const rb_data_type_t BlendMode_data_type = {
|
|
30
29
|
.wrap_struct_name = "SFML::BlendMode",
|
|
31
30
|
.function = {.dmark = NULL, .dfree = BlendMode_free, .dsize = NULL},
|
|
32
|
-
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
33
|
-
};
|
|
31
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
34
32
|
|
|
35
33
|
static VALUE BlendMode_wrap(sfBlendMode mode) {
|
|
36
|
-
BlendMode
|
|
34
|
+
BlendMode* ptr = malloc(sizeof(BlendMode));
|
|
37
35
|
|
|
38
36
|
ptr->mode = mode;
|
|
39
37
|
|
|
@@ -44,15 +42,15 @@ static sfBlendFactor factor_from_rb(VALUE rb_factor) {
|
|
|
44
42
|
size_t i;
|
|
45
43
|
|
|
46
44
|
if (RB_INTEGER_TYPE_P(rb_factor)) {
|
|
47
|
-
return (sfBlendFactor)
|
|
45
|
+
return (sfBlendFactor)NUM2INT(rb_factor);
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
if (SYMBOL_P(rb_factor)) {
|
|
51
|
-
const char
|
|
49
|
+
const char* name = rb_id2name(SYM2ID(rb_factor));
|
|
52
50
|
|
|
53
51
|
for (i = 0; i < sizeof(factor_names) / sizeof(factor_names[0]); i++) {
|
|
54
52
|
if (strcmp(name, factor_names[i]) == 0) {
|
|
55
|
-
return (sfBlendFactor)
|
|
53
|
+
return (sfBlendFactor)i;
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
56
|
}
|
|
@@ -65,15 +63,15 @@ static sfBlendEquation equation_from_rb(VALUE rb_equation) {
|
|
|
65
63
|
size_t i;
|
|
66
64
|
|
|
67
65
|
if (RB_INTEGER_TYPE_P(rb_equation)) {
|
|
68
|
-
return (sfBlendEquation)
|
|
66
|
+
return (sfBlendEquation)NUM2INT(rb_equation);
|
|
69
67
|
}
|
|
70
68
|
|
|
71
69
|
if (SYMBOL_P(rb_equation)) {
|
|
72
|
-
const char
|
|
70
|
+
const char* name = rb_id2name(SYM2ID(rb_equation));
|
|
73
71
|
|
|
74
72
|
for (i = 0; i < sizeof(equation_names) / sizeof(equation_names[0]); i++) {
|
|
75
73
|
if (strcmp(name, equation_names[i]) == 0) {
|
|
76
|
-
return (sfBlendEquation)
|
|
74
|
+
return (sfBlendEquation)i;
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
77
|
}
|
|
@@ -82,105 +80,245 @@ static sfBlendEquation equation_from_rb(VALUE rb_equation) {
|
|
|
82
80
|
return sfBlendEquationAdd;
|
|
83
81
|
}
|
|
84
82
|
|
|
85
|
-
static VALUE
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
static VALUE BlendMode_alloc(VALUE klass) {
|
|
84
|
+
BlendMode* ptr = malloc(sizeof(BlendMode));
|
|
85
|
+
|
|
86
|
+
if (ptr == NULL) {
|
|
87
|
+
rb_raise(rb_eNoMemError, "failed to allocate blend mode");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
ptr->mode = sfBlendAlpha;
|
|
91
|
+
|
|
92
|
+
return TypedData_Wrap_Struct(klass, &BlendMode_data_type, ptr);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* call-seq:
|
|
96
|
+
* BlendMode.new -> BlendMode(ALPHA)
|
|
97
|
+
* BlendMode.new(color_src_factor, color_dst_factor, color_equation, alpha_src_factor,
|
|
98
|
+
* alpha_dst_factor, alpha_equation) -> BlendMode
|
|
99
|
+
*
|
|
100
|
+
* Each factor argument is a Symbol (one of +:zero+, +:one+, +:src_color+,
|
|
101
|
+
* +:one_minus_src_color+, +:dst_color+, +:one_minus_dst_color+,
|
|
102
|
+
* +:src_alpha+, +:one_minus_src_alpha+, +:dst_alpha+,
|
|
103
|
+
* +:one_minus_dst_alpha+) or the equivalent Integer. Each equation argument
|
|
104
|
+
* is a Symbol (+:add+, +:subtract+, +:reverse_subtract+, +:min+, +:max+) or
|
|
105
|
+
* the equivalent Integer.
|
|
106
|
+
*
|
|
107
|
+
* @return [BlendMode]
|
|
108
|
+
* @raise [ArgumentError] if given an argument count other than 0 or 6
|
|
109
|
+
*/
|
|
110
|
+
static VALUE BlendMode_initialize(int argc, VALUE* argv, VALUE self) {
|
|
88
111
|
sfBlendMode mode = sfBlendAlpha;
|
|
89
112
|
|
|
90
113
|
if (argc == 6) {
|
|
91
|
-
mode = (sfBlendMode)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
};
|
|
114
|
+
mode = (sfBlendMode){factor_from_rb(argv[0]), factor_from_rb(argv[1]),
|
|
115
|
+
equation_from_rb(argv[2]), factor_from_rb(argv[3]),
|
|
116
|
+
factor_from_rb(argv[4]), equation_from_rb(argv[5])};
|
|
95
117
|
} else if (argc != 0) {
|
|
96
118
|
raise_invalid_arguments_excepted(6, argc);
|
|
97
119
|
}
|
|
98
120
|
|
|
99
|
-
|
|
100
|
-
ptr->mode = mode;
|
|
101
|
-
|
|
102
|
-
self = TypedData_Wrap_Struct(klass, &BlendMode_data_type, ptr);
|
|
121
|
+
((BlendMode*)Get_BlendMode_Struct(self))->mode = mode;
|
|
103
122
|
|
|
104
123
|
return self;
|
|
105
124
|
}
|
|
106
125
|
|
|
126
|
+
/* call-seq: color_src_factor -> Symbol
|
|
127
|
+
*
|
|
128
|
+
* Returns the source blend factor for color components.
|
|
129
|
+
*
|
|
130
|
+
* @return [Symbol] the source blending factor for the color/RGB channels
|
|
131
|
+
*/
|
|
107
132
|
static VALUE BlendMode_get_color_src_factor(VALUE self) {
|
|
108
|
-
return ID2SYM(
|
|
133
|
+
return ID2SYM(
|
|
134
|
+
rb_intern(factor_names[((BlendMode*)Get_BlendMode_Struct(self))->mode.colorSrcFactor]));
|
|
109
135
|
}
|
|
110
136
|
|
|
137
|
+
/* call-seq: color_dst_factor -> Symbol
|
|
138
|
+
*
|
|
139
|
+
* Returns the destination blend factor for color components.
|
|
140
|
+
*
|
|
141
|
+
* @return [Symbol] the destination blending factor for the color/RGB channels
|
|
142
|
+
*/
|
|
111
143
|
static VALUE BlendMode_get_color_dst_factor(VALUE self) {
|
|
112
|
-
return ID2SYM(
|
|
144
|
+
return ID2SYM(
|
|
145
|
+
rb_intern(factor_names[((BlendMode*)Get_BlendMode_Struct(self))->mode.colorDstFactor]));
|
|
113
146
|
}
|
|
114
147
|
|
|
148
|
+
/* call-seq: color_equation -> Symbol
|
|
149
|
+
*
|
|
150
|
+
* Returns the blend equation for color components.
|
|
151
|
+
*
|
|
152
|
+
* @return [Symbol] the blending equation for the color/RGB channels
|
|
153
|
+
*/
|
|
115
154
|
static VALUE BlendMode_get_color_equation(VALUE self) {
|
|
116
|
-
return ID2SYM(
|
|
155
|
+
return ID2SYM(
|
|
156
|
+
rb_intern(equation_names[((BlendMode*)Get_BlendMode_Struct(self))->mode.colorEquation]));
|
|
117
157
|
}
|
|
118
158
|
|
|
159
|
+
/* call-seq: alpha_src_factor -> Symbol
|
|
160
|
+
*
|
|
161
|
+
* Returns the source blend factor for alpha.
|
|
162
|
+
*
|
|
163
|
+
* @return [Symbol] the source blending factor for the alpha channel
|
|
164
|
+
*/
|
|
119
165
|
static VALUE BlendMode_get_alpha_src_factor(VALUE self) {
|
|
120
|
-
return ID2SYM(
|
|
166
|
+
return ID2SYM(
|
|
167
|
+
rb_intern(factor_names[((BlendMode*)Get_BlendMode_Struct(self))->mode.alphaSrcFactor]));
|
|
121
168
|
}
|
|
122
169
|
|
|
170
|
+
/* call-seq: alpha_dst_factor -> Symbol
|
|
171
|
+
*
|
|
172
|
+
* Returns the destination blend factor for alpha.
|
|
173
|
+
*
|
|
174
|
+
* @return [Symbol] the destination blending factor for the alpha channel
|
|
175
|
+
*/
|
|
123
176
|
static VALUE BlendMode_get_alpha_dst_factor(VALUE self) {
|
|
124
|
-
return ID2SYM(
|
|
177
|
+
return ID2SYM(
|
|
178
|
+
rb_intern(factor_names[((BlendMode*)Get_BlendMode_Struct(self))->mode.alphaDstFactor]));
|
|
125
179
|
}
|
|
126
180
|
|
|
181
|
+
/* call-seq: alpha_equation -> Symbol
|
|
182
|
+
*
|
|
183
|
+
* Returns the blend equation for alpha.
|
|
184
|
+
*
|
|
185
|
+
* @return [Symbol] the blending equation for the alpha channel
|
|
186
|
+
*/
|
|
127
187
|
static VALUE BlendMode_get_alpha_equation(VALUE self) {
|
|
128
|
-
return ID2SYM(
|
|
188
|
+
return ID2SYM(
|
|
189
|
+
rb_intern(equation_names[((BlendMode*)Get_BlendMode_Struct(self))->mode.alphaEquation]));
|
|
129
190
|
}
|
|
130
191
|
|
|
192
|
+
/* call-seq:
|
|
193
|
+
* color_src_factor=(value) -> Symbol
|
|
194
|
+
*
|
|
195
|
+
* Sets the source blend factor for color components.
|
|
196
|
+
*
|
|
197
|
+
* @return [Symbol] +value+
|
|
198
|
+
*/
|
|
131
199
|
static VALUE BlendMode_set_color_src_factor(VALUE self, VALUE rb_value) {
|
|
132
|
-
(
|
|
200
|
+
rb_check_frozen(self);
|
|
201
|
+
((BlendMode*)Get_BlendMode_Struct(self))->mode.colorSrcFactor = factor_from_rb(rb_value);
|
|
133
202
|
return rb_value;
|
|
134
203
|
}
|
|
135
204
|
|
|
205
|
+
/* call-seq:
|
|
206
|
+
* color_dst_factor=(value) -> Symbol
|
|
207
|
+
*
|
|
208
|
+
* Sets the destination blend factor for color components.
|
|
209
|
+
*
|
|
210
|
+
* @return [Symbol] +value+
|
|
211
|
+
*/
|
|
136
212
|
static VALUE BlendMode_set_color_dst_factor(VALUE self, VALUE rb_value) {
|
|
137
|
-
(
|
|
213
|
+
rb_check_frozen(self);
|
|
214
|
+
((BlendMode*)Get_BlendMode_Struct(self))->mode.colorDstFactor = factor_from_rb(rb_value);
|
|
138
215
|
return rb_value;
|
|
139
216
|
}
|
|
140
217
|
|
|
218
|
+
/* call-seq:
|
|
219
|
+
* color_equation=(value) -> Symbol
|
|
220
|
+
*
|
|
221
|
+
* Sets the blend equation for color components.
|
|
222
|
+
*
|
|
223
|
+
* @return [Symbol] +value+
|
|
224
|
+
*/
|
|
141
225
|
static VALUE BlendMode_set_color_equation(VALUE self, VALUE rb_value) {
|
|
142
|
-
(
|
|
226
|
+
rb_check_frozen(self);
|
|
227
|
+
((BlendMode*)Get_BlendMode_Struct(self))->mode.colorEquation = equation_from_rb(rb_value);
|
|
143
228
|
return rb_value;
|
|
144
229
|
}
|
|
145
230
|
|
|
231
|
+
/* call-seq:
|
|
232
|
+
* alpha_src_factor=(value) -> Symbol
|
|
233
|
+
*
|
|
234
|
+
* Sets the source blend factor for alpha.
|
|
235
|
+
*
|
|
236
|
+
* @return [Symbol] +value+
|
|
237
|
+
*/
|
|
146
238
|
static VALUE BlendMode_set_alpha_src_factor(VALUE self, VALUE rb_value) {
|
|
147
|
-
(
|
|
239
|
+
rb_check_frozen(self);
|
|
240
|
+
((BlendMode*)Get_BlendMode_Struct(self))->mode.alphaSrcFactor = factor_from_rb(rb_value);
|
|
148
241
|
return rb_value;
|
|
149
242
|
}
|
|
150
243
|
|
|
244
|
+
/* call-seq:
|
|
245
|
+
* alpha_dst_factor=(value) -> Symbol
|
|
246
|
+
*
|
|
247
|
+
* Sets the destination blend factor for alpha.
|
|
248
|
+
*
|
|
249
|
+
* @return [Symbol] +value+
|
|
250
|
+
*/
|
|
151
251
|
static VALUE BlendMode_set_alpha_dst_factor(VALUE self, VALUE rb_value) {
|
|
152
|
-
(
|
|
252
|
+
rb_check_frozen(self);
|
|
253
|
+
((BlendMode*)Get_BlendMode_Struct(self))->mode.alphaDstFactor = factor_from_rb(rb_value);
|
|
153
254
|
return rb_value;
|
|
154
255
|
}
|
|
155
256
|
|
|
257
|
+
/* call-seq:
|
|
258
|
+
* alpha_equation=(value) -> Symbol
|
|
259
|
+
*
|
|
260
|
+
* Sets the blend equation for alpha.
|
|
261
|
+
*
|
|
262
|
+
* @return [Symbol] +value+
|
|
263
|
+
*/
|
|
156
264
|
static VALUE BlendMode_set_alpha_equation(VALUE self, VALUE rb_value) {
|
|
157
|
-
(
|
|
265
|
+
rb_check_frozen(self);
|
|
266
|
+
((BlendMode*)Get_BlendMode_Struct(self))->mode.alphaEquation = equation_from_rb(rb_value);
|
|
158
267
|
return rb_value;
|
|
159
268
|
}
|
|
160
269
|
|
|
270
|
+
/* call-seq:
|
|
271
|
+
* self == other -> true or false
|
|
272
|
+
*
|
|
273
|
+
* Returns +true+ if the two objects are equal.
|
|
274
|
+
*
|
|
275
|
+
* @return [Boolean]
|
|
276
|
+
*/
|
|
161
277
|
static VALUE BlendMode_eql(VALUE self, VALUE rb_other) {
|
|
162
|
-
sfBlendMode a = ((BlendMode
|
|
278
|
+
sfBlendMode a = ((BlendMode*)Get_BlendMode_Struct(self))->mode;
|
|
163
279
|
sfBlendMode b;
|
|
164
280
|
|
|
165
281
|
if (!rb_obj_is_kind_of(rb_other, rb_cBlendMode)) {
|
|
166
282
|
return Qfalse;
|
|
167
283
|
}
|
|
168
284
|
|
|
169
|
-
b = ((BlendMode
|
|
285
|
+
b = ((BlendMode*)Get_BlendMode_Struct(rb_other))->mode;
|
|
170
286
|
|
|
171
287
|
return BOOL2RB(a.colorSrcFactor == b.colorSrcFactor && a.colorDstFactor == b.colorDstFactor &&
|
|
172
288
|
a.colorEquation == b.colorEquation && a.alphaSrcFactor == b.alphaSrcFactor &&
|
|
173
289
|
a.alphaDstFactor == b.alphaDstFactor && a.alphaEquation == b.alphaEquation);
|
|
174
290
|
}
|
|
175
291
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
292
|
+
/* Document-class: SFML::BlendMode
|
|
293
|
+
* Describes how the colors of a drawn object are combined with the colors
|
|
294
|
+
* already in the render target, via two triples of (source factor,
|
|
295
|
+
* destination factor, equation) -- one for the color/RGB channels, one for
|
|
296
|
+
* the alpha channel.
|
|
297
|
+
*
|
|
298
|
+
* @!attribute color_src_factor
|
|
299
|
+
* The source blend factor for color components.
|
|
300
|
+
* @return [Symbol] the source blending factor for the color channels
|
|
301
|
+
* @!attribute color_dst_factor
|
|
302
|
+
* The destination blend factor for color components.
|
|
303
|
+
* @return [Symbol] the destination blending factor for the color channels
|
|
304
|
+
* @!attribute color_equation
|
|
305
|
+
* The blend equation for color components.
|
|
306
|
+
* @return [Symbol] the blending equation for the color channels
|
|
307
|
+
* @!attribute alpha_src_factor
|
|
308
|
+
* The source blend factor for alpha.
|
|
309
|
+
* @return [Symbol] the source blending factor for the alpha channel
|
|
310
|
+
* @!attribute alpha_dst_factor
|
|
311
|
+
* The destination blend factor for alpha.
|
|
312
|
+
* @return [Symbol] the destination blending factor for the alpha channel
|
|
313
|
+
* @!attribute alpha_equation
|
|
314
|
+
* The blend equation for alpha.
|
|
315
|
+
* @return [Symbol] the blending equation for the alpha channel
|
|
316
|
+
*/
|
|
317
|
+
void Init_BlendMode(VALUE rb_mSFML) {
|
|
318
|
+
rb_cBlendMode = rb_define_class_under(rb_mSFML, "BlendMode", rb_cObject);
|
|
319
|
+
|
|
320
|
+
rb_define_alloc_func(rb_cBlendMode, BlendMode_alloc);
|
|
321
|
+
rb_define_method(rb_cBlendMode, "initialize", BlendMode_initialize, -1);
|
|
184
322
|
|
|
185
323
|
rb_define_method(rb_cBlendMode, "color_src_factor", BlendMode_get_color_src_factor, 0);
|
|
186
324
|
rb_define_method(rb_cBlendMode, "color_dst_factor", BlendMode_get_color_dst_factor, 0);
|
|
@@ -198,27 +336,47 @@ void Init_BlendMode(VALUE rb_module) {
|
|
|
198
336
|
|
|
199
337
|
rb_define_method(rb_cBlendMode, "==", BlendMode_eql, 1);
|
|
200
338
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
339
|
+
/* No blending: source pixels overwrite destination pixels unchanged
|
|
340
|
+
* (One, Zero, Add for both the color and alpha channels). */
|
|
341
|
+
rb_define_const(rb_cBlendMode, "NONE", rb_obj_freeze(BlendMode_wrap(sfBlendNone)));
|
|
342
|
+
|
|
343
|
+
/* Standard alpha blending: the source is blended over the destination
|
|
344
|
+
* using the source alpha (SrcAlpha, OneMinusSrcAlpha, Add for color;
|
|
345
|
+
* One, OneMinusSrcAlpha, Add for alpha). The default blend mode. */
|
|
346
|
+
rb_define_const(rb_cBlendMode, "ALPHA", rb_obj_freeze(BlendMode_wrap(sfBlendAlpha)));
|
|
347
|
+
|
|
348
|
+
/* Additive blending: the source color, scaled by its alpha, is added to
|
|
349
|
+
* the destination (SrcAlpha, One, Add for color; One, One, Add for
|
|
350
|
+
* alpha). */
|
|
351
|
+
rb_define_const(rb_cBlendMode, "ADD", rb_obj_freeze(BlendMode_wrap(sfBlendAdd)));
|
|
352
|
+
|
|
353
|
+
/* Multiplicative blending: source and destination colors are multiplied
|
|
354
|
+
* together (DstColor, Zero, Add for both the color and alpha
|
|
355
|
+
* channels). */
|
|
356
|
+
rb_define_const(rb_cBlendMode, "MULTIPLY", rb_obj_freeze(BlendMode_wrap(sfBlendMultiply)));
|
|
357
|
+
|
|
358
|
+
/* Component-wise minimum of the source and destination colors (One,
|
|
359
|
+
* One, Min for both the color and alpha channels). */
|
|
360
|
+
rb_define_const(rb_cBlendMode, "MIN", rb_obj_freeze(BlendMode_wrap(sfBlendMin)));
|
|
361
|
+
|
|
362
|
+
/* Component-wise maximum of the source and destination colors (One,
|
|
363
|
+
* One, Max for both the color and alpha channels). */
|
|
364
|
+
rb_define_const(rb_cBlendMode, "MAX", rb_obj_freeze(BlendMode_wrap(sfBlendMax)));
|
|
207
365
|
}
|
|
208
366
|
|
|
209
367
|
VALUE Get_Klass_BlendMode(void) {
|
|
210
368
|
return rb_cBlendMode;
|
|
211
369
|
}
|
|
212
370
|
|
|
213
|
-
void
|
|
214
|
-
BlendMode
|
|
371
|
+
void* Get_BlendMode_Struct(VALUE self) {
|
|
372
|
+
BlendMode* ptr;
|
|
215
373
|
TypedData_Get_Struct(self, BlendMode, &BlendMode_data_type, ptr);
|
|
216
374
|
return ptr;
|
|
217
375
|
}
|
|
218
376
|
|
|
219
377
|
sfBlendMode blend_mode_from_rb(VALUE rb_mode) {
|
|
220
378
|
if (rb_obj_is_kind_of(rb_mode, rb_cBlendMode)) {
|
|
221
|
-
return ((BlendMode
|
|
379
|
+
return ((BlendMode*)Get_BlendMode_Struct(rb_mode))->mode;
|
|
222
380
|
}
|
|
223
381
|
|
|
224
382
|
if (RB_INTEGER_TYPE_P(rb_mode) == 0 && !SYMBOL_P(rb_mode)) {
|
|
@@ -226,7 +384,7 @@ sfBlendMode blend_mode_from_rb(VALUE rb_mode) {
|
|
|
226
384
|
}
|
|
227
385
|
|
|
228
386
|
if (SYMBOL_P(rb_mode)) {
|
|
229
|
-
const char
|
|
387
|
+
const char* name = rb_id2name(SYM2ID(rb_mode));
|
|
230
388
|
|
|
231
389
|
if (strcmp(name, "none") == 0) {
|
|
232
390
|
return sfBlendNone;
|