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