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/color.c
CHANGED
|
@@ -13,15 +13,14 @@ typedef struct {
|
|
|
13
13
|
|
|
14
14
|
static VALUE rb_cColor;
|
|
15
15
|
|
|
16
|
-
static void Color_free(void
|
|
16
|
+
static void Color_free(void* ptr) {
|
|
17
17
|
free(ptr);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
static const rb_data_type_t Color_data_type = {
|
|
21
21
|
.wrap_struct_name = "SFML::Color",
|
|
22
22
|
.function = {.dmark = NULL, .dfree = Color_free, .dsize = NULL},
|
|
23
|
-
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
24
|
-
};
|
|
23
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
25
24
|
|
|
26
25
|
static unsigned char clamp_channel(int value) {
|
|
27
26
|
if (value < 0) {
|
|
@@ -32,11 +31,11 @@ static unsigned char clamp_channel(int value) {
|
|
|
32
31
|
return 255;
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
return (unsigned char)
|
|
34
|
+
return (unsigned char)value;
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
static VALUE Color_wrap(sfColor color) {
|
|
39
|
-
Color
|
|
38
|
+
Color* ptr = malloc(sizeof(Color));
|
|
40
39
|
|
|
41
40
|
ptr->color = color;
|
|
42
41
|
|
|
@@ -44,32 +43,40 @@ static VALUE Color_wrap(sfColor color) {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
static sfColor Color_from_integer(VALUE rb_integer) {
|
|
47
|
-
unsigned int value = (unsigned int)
|
|
46
|
+
unsigned int value = (unsigned int)NUM2UINT(rb_integer);
|
|
48
47
|
|
|
49
48
|
if (value <= 0xFFFFFF) {
|
|
50
|
-
return (sfColor)
|
|
51
|
-
|
|
52
|
-
(unsigned char) ((value >> 8) & 0xFF),
|
|
53
|
-
(unsigned char) (value & 0xFF),
|
|
54
|
-
255
|
|
55
|
-
};
|
|
49
|
+
return (sfColor){(unsigned char)((value >> 16) & 0xFF),
|
|
50
|
+
(unsigned char)((value >> 8) & 0xFF), (unsigned char)(value & 0xFF), 255};
|
|
56
51
|
}
|
|
57
52
|
|
|
58
|
-
return (sfColor)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
return (sfColor){(unsigned char)((value >> 24) & 0xFF), (unsigned char)((value >> 16) & 0xFF),
|
|
54
|
+
(unsigned char)((value >> 8) & 0xFF), (unsigned char)(value & 0xFF)};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* call-seq:
|
|
58
|
+
* Color.new -> Color(0, 0, 0, 255)
|
|
59
|
+
* Color.new(r, g, b, a=255) -> Color(r, g, b, a)
|
|
60
|
+
* Color.new([r, g, b]) -> Color(r, g, b, 255)
|
|
61
|
+
* Color.new([r, g, b, a]) -> Color(r, g, b, a)
|
|
62
|
+
* Color.new(packed_integer) -> Color
|
|
63
|
+
* Color.new(other_color) -> copy of +other_color+
|
|
64
|
+
*
|
|
65
|
+
* Each channel argument is clamped to 0..255. A single Integer argument is
|
|
66
|
+
* interpreted as #from_rgb (0xRRGGBB) if it fits in 24 bits, or #from_rgba
|
|
67
|
+
* (0xRRGGBBAA) otherwise.
|
|
68
|
+
*
|
|
69
|
+
* @return [Color]
|
|
70
|
+
* @raise [ArgumentError] if given an Array shorter than 3 elements, or an
|
|
71
|
+
* argument count other than 0, 1, 3 or 4
|
|
72
|
+
*/
|
|
73
|
+
static VALUE Color_new(int argc, VALUE* argv, VALUE klass) {
|
|
67
74
|
VALUE self;
|
|
68
|
-
Color
|
|
75
|
+
Color* ptr;
|
|
69
76
|
sfColor color = {0, 0, 0, 255};
|
|
70
77
|
|
|
71
78
|
if (argc == 1 && rb_obj_is_kind_of(argv[0], rb_cColor)) {
|
|
72
|
-
color = ((Color
|
|
79
|
+
color = ((Color*)Get_Color_Struct(argv[0]))->color;
|
|
73
80
|
} else if (argc == 1 && RB_TYPE_P(argv[0], T_ARRAY)) {
|
|
74
81
|
color = color_from_rb(argv[0]);
|
|
75
82
|
} else if (argc == 1 && RB_INTEGER_TYPE_P(argv[0])) {
|
|
@@ -91,113 +98,226 @@ static VALUE Color_new(int argc, VALUE *argv, VALUE klass) {
|
|
|
91
98
|
return self;
|
|
92
99
|
}
|
|
93
100
|
|
|
101
|
+
/* call-seq:
|
|
102
|
+
* Color.from_rgb(value) -> Color
|
|
103
|
+
*
|
|
104
|
+
* Creates a color from 8-bit red, green and blue components.
|
|
105
|
+
*
|
|
106
|
+
* @return [Color] the fully-opaque color packed as 0xRRGGBB
|
|
107
|
+
*/
|
|
94
108
|
static VALUE Color_from_rgb(VALUE klass, VALUE rb_integer) {
|
|
95
|
-
return Color_wrap((sfColor)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
109
|
+
return Color_wrap((sfColor){(unsigned char)((NUM2UINT(rb_integer) >> 16) & 0xFF),
|
|
110
|
+
(unsigned char)((NUM2UINT(rb_integer) >> 8) & 0xFF),
|
|
111
|
+
(unsigned char)(NUM2UINT(rb_integer) & 0xFF), 255});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* call-seq:
|
|
115
|
+
* Color.from_rgba(value) -> Color
|
|
116
|
+
*
|
|
117
|
+
* Also available as .from_integer.
|
|
118
|
+
*
|
|
119
|
+
* @return [Color] the color packed as 0xRRGGBBAA (or 0xRRGGBB, treated as
|
|
120
|
+
* fully opaque, if it fits in 24 bits)
|
|
121
|
+
*/
|
|
103
122
|
static VALUE Color_from_rgba(VALUE klass, VALUE rb_integer) {
|
|
104
123
|
return Color_wrap(Color_from_integer(rb_integer));
|
|
105
124
|
}
|
|
106
125
|
|
|
126
|
+
/* call-seq: r -> Integer
|
|
127
|
+
*
|
|
128
|
+
* Returns the red component.
|
|
129
|
+
*
|
|
130
|
+
* @return [Integer] the red channel, 0..255
|
|
131
|
+
*/
|
|
107
132
|
static VALUE Color_get_r(VALUE self) {
|
|
108
|
-
return INT2NUM(((Color
|
|
133
|
+
return INT2NUM(((Color*)Get_Color_Struct(self))->color.r);
|
|
109
134
|
}
|
|
110
135
|
|
|
136
|
+
/* call-seq: g -> Integer
|
|
137
|
+
*
|
|
138
|
+
* Returns the green component.
|
|
139
|
+
*
|
|
140
|
+
* @return [Integer] the green channel, 0..255
|
|
141
|
+
*/
|
|
111
142
|
static VALUE Color_get_g(VALUE self) {
|
|
112
|
-
return INT2NUM(((Color
|
|
143
|
+
return INT2NUM(((Color*)Get_Color_Struct(self))->color.g);
|
|
113
144
|
}
|
|
114
145
|
|
|
146
|
+
/* call-seq: b -> Integer
|
|
147
|
+
*
|
|
148
|
+
* Returns the blue component.
|
|
149
|
+
*
|
|
150
|
+
* @return [Integer] the blue channel, 0..255
|
|
151
|
+
*/
|
|
115
152
|
static VALUE Color_get_b(VALUE self) {
|
|
116
|
-
return INT2NUM(((Color
|
|
153
|
+
return INT2NUM(((Color*)Get_Color_Struct(self))->color.b);
|
|
117
154
|
}
|
|
118
155
|
|
|
156
|
+
/* call-seq: a -> Integer
|
|
157
|
+
*
|
|
158
|
+
* Returns the alpha component.
|
|
159
|
+
*
|
|
160
|
+
* @return [Integer] the alpha channel, 0..255
|
|
161
|
+
*/
|
|
119
162
|
static VALUE Color_get_a(VALUE self) {
|
|
120
|
-
return INT2NUM(((Color
|
|
163
|
+
return INT2NUM(((Color*)Get_Color_Struct(self))->color.a);
|
|
121
164
|
}
|
|
122
165
|
|
|
166
|
+
/* call-seq:
|
|
167
|
+
* r=(value) -> Integer
|
|
168
|
+
*
|
|
169
|
+
* Sets the red channel. +value+ is clamped to 0..255.
|
|
170
|
+
*
|
|
171
|
+
* @return [Integer] +value+
|
|
172
|
+
*/
|
|
123
173
|
static VALUE Color_set_r(VALUE self, VALUE rb_value) {
|
|
124
|
-
(
|
|
174
|
+
rb_check_frozen(self);
|
|
175
|
+
((Color*)Get_Color_Struct(self))->color.r = clamp_channel(NUM2INT(rb_value));
|
|
125
176
|
return rb_value;
|
|
126
177
|
}
|
|
127
178
|
|
|
179
|
+
/* call-seq:
|
|
180
|
+
* g=(value) -> Integer
|
|
181
|
+
*
|
|
182
|
+
* Sets the green channel. +value+ is clamped to 0..255.
|
|
183
|
+
*
|
|
184
|
+
* @return [Integer] +value+
|
|
185
|
+
*/
|
|
128
186
|
static VALUE Color_set_g(VALUE self, VALUE rb_value) {
|
|
129
|
-
(
|
|
187
|
+
rb_check_frozen(self);
|
|
188
|
+
((Color*)Get_Color_Struct(self))->color.g = clamp_channel(NUM2INT(rb_value));
|
|
130
189
|
return rb_value;
|
|
131
190
|
}
|
|
132
191
|
|
|
192
|
+
/* call-seq:
|
|
193
|
+
* b=(value) -> Integer
|
|
194
|
+
*
|
|
195
|
+
* Sets the blue channel. +value+ is clamped to 0..255.
|
|
196
|
+
*
|
|
197
|
+
* @return [Integer] +value+
|
|
198
|
+
*/
|
|
133
199
|
static VALUE Color_set_b(VALUE self, VALUE rb_value) {
|
|
134
|
-
(
|
|
200
|
+
rb_check_frozen(self);
|
|
201
|
+
((Color*)Get_Color_Struct(self))->color.b = clamp_channel(NUM2INT(rb_value));
|
|
135
202
|
return rb_value;
|
|
136
203
|
}
|
|
137
204
|
|
|
205
|
+
/* call-seq:
|
|
206
|
+
* a=(value) -> Integer
|
|
207
|
+
*
|
|
208
|
+
* Sets the alpha channel. +value+ is clamped to 0..255.
|
|
209
|
+
*
|
|
210
|
+
* @return [Integer] +value+
|
|
211
|
+
*/
|
|
138
212
|
static VALUE Color_set_a(VALUE self, VALUE rb_value) {
|
|
139
|
-
(
|
|
213
|
+
rb_check_frozen(self);
|
|
214
|
+
((Color*)Get_Color_Struct(self))->color.a = clamp_channel(NUM2INT(rb_value));
|
|
140
215
|
return rb_value;
|
|
141
216
|
}
|
|
142
217
|
|
|
218
|
+
/* call-seq: to_i -> Integer
|
|
219
|
+
*
|
|
220
|
+
* Returns the color encoded as a 32-bit integer.
|
|
221
|
+
*
|
|
222
|
+
* @return [Integer] the color packed as 0xRRGGBBAA
|
|
223
|
+
*/
|
|
143
224
|
static VALUE Color_to_i(VALUE self) {
|
|
144
|
-
sfColor color = ((Color
|
|
225
|
+
sfColor color = ((Color*)Get_Color_Struct(self))->color;
|
|
145
226
|
|
|
146
|
-
return UINT2NUM(((unsigned int)
|
|
147
|
-
((unsigned int)
|
|
227
|
+
return UINT2NUM(((unsigned int)color.r << 24) | ((unsigned int)color.g << 16) |
|
|
228
|
+
((unsigned int)color.b << 8) | (unsigned int)color.a);
|
|
148
229
|
}
|
|
149
230
|
|
|
231
|
+
/* call-seq: to_a -> [Integer, Integer, Integer, Integer]
|
|
232
|
+
*
|
|
233
|
+
* Returns the object as an Array.
|
|
234
|
+
*
|
|
235
|
+
* @return [Array<Integer>] +[r, g, b, a]+
|
|
236
|
+
*/
|
|
150
237
|
static VALUE Color_to_a(VALUE self) {
|
|
151
|
-
sfColor color = ((Color
|
|
238
|
+
sfColor color = ((Color*)Get_Color_Struct(self))->color;
|
|
152
239
|
|
|
153
|
-
return rb_ary_new_from_args(4, INT2NUM(color.r), INT2NUM(color.g), INT2NUM(color.b),
|
|
240
|
+
return rb_ary_new_from_args(4, INT2NUM(color.r), INT2NUM(color.g), INT2NUM(color.b),
|
|
241
|
+
INT2NUM(color.a));
|
|
154
242
|
}
|
|
155
243
|
|
|
244
|
+
/* call-seq:
|
|
245
|
+
* self == other -> true or false
|
|
246
|
+
*
|
|
247
|
+
* Returns +true+ if the two objects are equal.
|
|
248
|
+
*
|
|
249
|
+
* @return [Boolean]
|
|
250
|
+
*/
|
|
156
251
|
static VALUE Color_eql(VALUE self, VALUE rb_other) {
|
|
157
|
-
sfColor a = ((Color
|
|
252
|
+
sfColor a = ((Color*)Get_Color_Struct(self))->color;
|
|
158
253
|
sfColor b;
|
|
159
254
|
|
|
160
255
|
if (!rb_obj_is_kind_of(rb_other, rb_cColor)) {
|
|
161
256
|
return Qfalse;
|
|
162
257
|
}
|
|
163
258
|
|
|
164
|
-
b = ((Color
|
|
259
|
+
b = ((Color*)Get_Color_Struct(rb_other))->color;
|
|
165
260
|
|
|
166
261
|
return BOOL2RB(a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a);
|
|
167
262
|
}
|
|
168
263
|
|
|
264
|
+
/* call-seq:
|
|
265
|
+
* self + other -> Color
|
|
266
|
+
*
|
|
267
|
+
* +other+ may be a Color, a 3/4-element Array, or a packed Integer.
|
|
268
|
+
* Channels are summed and clamped to 0..255.
|
|
269
|
+
*
|
|
270
|
+
* @return [Color]
|
|
271
|
+
*/
|
|
169
272
|
static VALUE Color_add(VALUE self, VALUE rb_other) {
|
|
170
|
-
sfColor a = ((Color
|
|
273
|
+
sfColor a = ((Color*)Get_Color_Struct(self))->color;
|
|
171
274
|
sfColor b = color_from_rb(rb_other);
|
|
172
275
|
|
|
173
|
-
return Color_wrap((sfColor)
|
|
174
|
-
|
|
175
|
-
clamp_channel(a.b + b.b), clamp_channel(a.a + b.a)
|
|
176
|
-
});
|
|
276
|
+
return Color_wrap((sfColor){clamp_channel(a.r + b.r), clamp_channel(a.g + b.g),
|
|
277
|
+
clamp_channel(a.b + b.b), clamp_channel(a.a + b.a)});
|
|
177
278
|
}
|
|
178
279
|
|
|
280
|
+
/* call-seq:
|
|
281
|
+
* self - other -> Color
|
|
282
|
+
*
|
|
283
|
+
* +other+ may be a Color, a 3/4-element Array, or a packed Integer.
|
|
284
|
+
* Channels are subtracted and clamped to 0..255.
|
|
285
|
+
*
|
|
286
|
+
* @return [Color]
|
|
287
|
+
*/
|
|
179
288
|
static VALUE Color_sub(VALUE self, VALUE rb_other) {
|
|
180
|
-
sfColor a = ((Color
|
|
289
|
+
sfColor a = ((Color*)Get_Color_Struct(self))->color;
|
|
181
290
|
sfColor b = color_from_rb(rb_other);
|
|
182
291
|
|
|
183
|
-
return Color_wrap((sfColor)
|
|
184
|
-
|
|
185
|
-
clamp_channel(a.b - b.b), clamp_channel(a.a - b.a)
|
|
186
|
-
});
|
|
292
|
+
return Color_wrap((sfColor){clamp_channel(a.r - b.r), clamp_channel(a.g - b.g),
|
|
293
|
+
clamp_channel(a.b - b.b), clamp_channel(a.a - b.a)});
|
|
187
294
|
}
|
|
188
295
|
|
|
296
|
+
/* call-seq:
|
|
297
|
+
* self * other -> Color
|
|
298
|
+
*
|
|
299
|
+
* Componentwise modulation: each channel is +(self_channel * other_channel)
|
|
300
|
+
* / 255+. +other+ may be a Color, a 3/4-element Array, or a packed Integer.
|
|
301
|
+
*
|
|
302
|
+
* @return [Color]
|
|
303
|
+
*/
|
|
189
304
|
static VALUE Color_mul(VALUE self, VALUE rb_other) {
|
|
190
|
-
sfColor a = ((Color
|
|
305
|
+
sfColor a = ((Color*)Get_Color_Struct(self))->color;
|
|
191
306
|
sfColor b = color_from_rb(rb_other);
|
|
192
307
|
|
|
193
|
-
return Color_wrap(
|
|
194
|
-
(unsigned char)
|
|
195
|
-
|
|
196
|
-
});
|
|
308
|
+
return Color_wrap(
|
|
309
|
+
(sfColor){(unsigned char)((a.r * b.r) / 255), (unsigned char)((a.g * b.g) / 255),
|
|
310
|
+
(unsigned char)((a.b * b.b) / 255), (unsigned char)((a.a * b.a) / 255)});
|
|
197
311
|
}
|
|
198
312
|
|
|
313
|
+
/* call-seq: to_s -> String
|
|
314
|
+
*
|
|
315
|
+
* Returns a human-readable representation of the object.
|
|
316
|
+
*
|
|
317
|
+
* @return [String] +"(r, g, b, a)"+
|
|
318
|
+
*/
|
|
199
319
|
static VALUE Color_to_s(VALUE self) {
|
|
200
|
-
sfColor c = ((Color
|
|
320
|
+
sfColor c = ((Color*)Get_Color_Struct(self))->color;
|
|
201
321
|
char buffer[64];
|
|
202
322
|
|
|
203
323
|
snprintf(buffer, sizeof(buffer), "(%u, %u, %u, %u)", c.r, c.g, c.b, c.a);
|
|
@@ -205,16 +325,29 @@ static VALUE Color_to_s(VALUE self) {
|
|
|
205
325
|
return rb_str_new2(buffer);
|
|
206
326
|
}
|
|
207
327
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
328
|
+
/* Document-class: SFML::Color
|
|
329
|
+
* An RGBA color, each channel an Integer 0..255.
|
|
330
|
+
*
|
|
331
|
+
* @!attribute r
|
|
332
|
+
* The red component.
|
|
333
|
+
* @return [Integer] the red channel, 0..255
|
|
334
|
+
* @!attribute g
|
|
335
|
+
* The green component.
|
|
336
|
+
* @return [Integer] the green channel, 0..255
|
|
337
|
+
* @!attribute b
|
|
338
|
+
* The blue component.
|
|
339
|
+
* @return [Integer] the blue channel, 0..255
|
|
340
|
+
* @!attribute a
|
|
341
|
+
* The alpha component.
|
|
342
|
+
* @return [Integer] the alpha channel, 0..255
|
|
343
|
+
*/
|
|
344
|
+
void Init_Color(VALUE rb_mSFML) {
|
|
345
|
+
rb_cColor = rb_define_class_under(rb_mSFML, "Color", rb_cObject);
|
|
214
346
|
|
|
215
347
|
rb_define_singleton_method(rb_cColor, "new", Color_new, -1);
|
|
216
348
|
rb_define_singleton_method(rb_cColor, "from_rgb", Color_from_rgb, 1);
|
|
217
349
|
rb_define_singleton_method(rb_cColor, "from_rgba", Color_from_rgba, 1);
|
|
350
|
+
|
|
218
351
|
rb_define_singleton_method(rb_cColor, "from_integer", Color_from_rgba, 1);
|
|
219
352
|
|
|
220
353
|
rb_define_method(rb_cColor, "r", Color_get_r, 0);
|
|
@@ -235,30 +368,47 @@ void Init_Color(VALUE rb_module) {
|
|
|
235
368
|
rb_define_method(rb_cColor, "*", Color_mul, 1);
|
|
236
369
|
rb_define_method(rb_cColor, "to_s", Color_to_s, 0);
|
|
237
370
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
371
|
+
/* Opaque black, RGBA(0, 0, 0, 255). */
|
|
372
|
+
rb_define_const(rb_cColor, "BLACK", rb_obj_freeze(Color_wrap(sfBlack)));
|
|
373
|
+
|
|
374
|
+
/* Opaque white, RGBA(255, 255, 255, 255). */
|
|
375
|
+
rb_define_const(rb_cColor, "WHITE", rb_obj_freeze(Color_wrap(sfWhite)));
|
|
376
|
+
|
|
377
|
+
/* Opaque red, RGBA(255, 0, 0, 255). */
|
|
378
|
+
rb_define_const(rb_cColor, "RED", rb_obj_freeze(Color_wrap(sfRed)));
|
|
379
|
+
|
|
380
|
+
/* Opaque green, RGBA(0, 255, 0, 255). */
|
|
381
|
+
rb_define_const(rb_cColor, "GREEN", rb_obj_freeze(Color_wrap(sfGreen)));
|
|
382
|
+
|
|
383
|
+
/* Opaque blue, RGBA(0, 0, 255, 255). */
|
|
384
|
+
rb_define_const(rb_cColor, "BLUE", rb_obj_freeze(Color_wrap(sfBlue)));
|
|
385
|
+
|
|
386
|
+
/* Opaque yellow, RGBA(255, 255, 0, 255). */
|
|
387
|
+
rb_define_const(rb_cColor, "YELLOW", rb_obj_freeze(Color_wrap(sfYellow)));
|
|
388
|
+
|
|
389
|
+
/* Opaque magenta, RGBA(255, 0, 255, 255). */
|
|
390
|
+
rb_define_const(rb_cColor, "MAGENTA", rb_obj_freeze(Color_wrap(sfMagenta)));
|
|
391
|
+
|
|
392
|
+
/* Opaque cyan, RGBA(0, 255, 255, 255). */
|
|
393
|
+
rb_define_const(rb_cColor, "CYAN", rb_obj_freeze(Color_wrap(sfCyan)));
|
|
394
|
+
|
|
395
|
+
/* Fully transparent black, RGBA(0, 0, 0, 0). */
|
|
396
|
+
rb_define_const(rb_cColor, "TRANSPARENT", rb_obj_freeze(Color_wrap(sfTransparent)));
|
|
247
397
|
}
|
|
248
398
|
|
|
249
399
|
VALUE Get_Klass_Color(void) {
|
|
250
400
|
return rb_cColor;
|
|
251
401
|
}
|
|
252
402
|
|
|
253
|
-
void
|
|
254
|
-
Color
|
|
403
|
+
void* Get_Color_Struct(VALUE self) {
|
|
404
|
+
Color* ptr;
|
|
255
405
|
TypedData_Get_Struct(self, Color, &Color_data_type, ptr);
|
|
256
406
|
return ptr;
|
|
257
407
|
}
|
|
258
408
|
|
|
259
409
|
sfColor color_from_rb(VALUE rb_color) {
|
|
260
410
|
if (rb_obj_is_kind_of(rb_color, rb_cColor)) {
|
|
261
|
-
return ((Color
|
|
411
|
+
return ((Color*)Get_Color_Struct(rb_color))->color;
|
|
262
412
|
}
|
|
263
413
|
|
|
264
414
|
if (RB_TYPE_P(rb_color, T_ARRAY)) {
|
|
@@ -268,12 +418,10 @@ sfColor color_from_rb(VALUE rb_color) {
|
|
|
268
418
|
raise_invalid_array_length(VALID_LENGTH_COLOR);
|
|
269
419
|
}
|
|
270
420
|
|
|
271
|
-
return (sfColor)
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
(length == 4) ? clamp_channel(NUM2INT(rb_ary_entry(rb_color, 3))) : 255
|
|
276
|
-
};
|
|
421
|
+
return (sfColor){clamp_channel(NUM2INT(rb_ary_entry(rb_color, 0))),
|
|
422
|
+
clamp_channel(NUM2INT(rb_ary_entry(rb_color, 1))),
|
|
423
|
+
clamp_channel(NUM2INT(rb_ary_entry(rb_color, 2))),
|
|
424
|
+
(length == 4) ? clamp_channel(NUM2INT(rb_ary_entry(rb_color, 3))) : 255};
|
|
277
425
|
}
|
|
278
426
|
|
|
279
427
|
if (RB_INTEGER_TYPE_P(rb_color)) {
|
|
@@ -282,7 +430,7 @@ sfColor color_from_rb(VALUE rb_color) {
|
|
|
282
430
|
|
|
283
431
|
raise_invalid_argument_class(rb_cColor);
|
|
284
432
|
|
|
285
|
-
return (sfColor)
|
|
433
|
+
return (sfColor){0, 0, 0, 255};
|
|
286
434
|
}
|
|
287
435
|
|
|
288
436
|
VALUE color_to_rb(sfColor color) {
|
|
@@ -290,18 +438,20 @@ VALUE color_to_rb(sfColor color) {
|
|
|
290
438
|
}
|
|
291
439
|
|
|
292
440
|
VALUE color_new(int r, int g, int b, int a) {
|
|
293
|
-
return Color_wrap(
|
|
441
|
+
return Color_wrap(
|
|
442
|
+
(sfColor){clamp_channel(r), clamp_channel(g), clamp_channel(b), clamp_channel(a)});
|
|
294
443
|
}
|
|
295
444
|
|
|
296
445
|
void color_check(VALUE rb_color) {
|
|
297
|
-
if (rb_obj_is_kind_of(rb_color, rb_cColor) || RB_TYPE_P(rb_color, T_ARRAY) ||
|
|
446
|
+
if (rb_obj_is_kind_of(rb_color, rb_cColor) || RB_TYPE_P(rb_color, T_ARRAY) ||
|
|
447
|
+
RB_INTEGER_TYPE_P(rb_color)) {
|
|
298
448
|
return;
|
|
299
449
|
}
|
|
300
450
|
|
|
301
451
|
raise_invalid_argument_class(rb_cColor);
|
|
302
452
|
}
|
|
303
453
|
|
|
304
|
-
void color_swap(sfColor
|
|
454
|
+
void color_swap(sfColor* color_a, sfColor* color_b) {
|
|
305
455
|
sfColor c;
|
|
306
456
|
|
|
307
457
|
c = *color_b;
|
data/ext/graphics/drawable.c
CHANGED
|
@@ -16,20 +16,31 @@
|
|
|
16
16
|
|
|
17
17
|
static VALUE rb_mDrawable;
|
|
18
18
|
|
|
19
|
+
/* call-seq:
|
|
20
|
+
* draw(target, state) -> nil
|
|
21
|
+
*
|
|
22
|
+
* Default no-op implementation; classes that include Drawable (Circle,
|
|
23
|
+
* RectangleShape, ConvexShape, Shape, Sprite, Text, VertexArray,
|
|
24
|
+
* VertexBuffer, ...) override this with the actual drawing call.
|
|
25
|
+
*
|
|
26
|
+
* @return [nil]
|
|
27
|
+
*/
|
|
19
28
|
static VALUE Drawable_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
|
|
20
29
|
if (!rb_obj_is_kind_of(rb_target, Get_Klass_Target())) {
|
|
21
|
-
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
|
|
25
|
-
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
return Qnil;
|
|
29
36
|
}
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
/* Document-module: SFML::Drawable
|
|
39
|
+
* A mixin for anything that can be drawn to a render target (Window,
|
|
40
|
+
* RenderTexture) via #draw(target, state).
|
|
41
|
+
*/
|
|
42
|
+
void Init_Drawable(VALUE rb_mSFML) {
|
|
43
|
+
rb_mDrawable = rb_define_module_under(rb_mSFML, "Drawable");
|
|
33
44
|
|
|
34
45
|
rb_define_method(rb_mDrawable, "draw", Drawable_draw, 2);
|
|
35
46
|
}
|