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.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/CHANGELOG.md +67 -16
  4. data/README.md +123 -32
  5. data/TODO.md +18 -11
  6. data/ext/audio/audio_enums.c +58 -20
  7. data/ext/audio/listener.c +89 -6
  8. data/ext/audio/music.c +212 -5
  9. data/ext/audio/sound.c +218 -9
  10. data/ext/audio/sound_buffer.c +197 -47
  11. data/ext/audio/sound_buffer_recorder.c +90 -18
  12. data/ext/audio/sound_recorder.c +188 -58
  13. data/ext/audio/sound_source_cone.c +127 -33
  14. data/ext/audio/sound_stream.c +204 -21
  15. data/ext/core/exceptions.c +10 -8
  16. data/ext/core/unicode.c +12 -2
  17. data/ext/ext.c +8 -0
  18. data/ext/graphics/blend_mode.c +218 -60
  19. data/ext/graphics/circle.c +300 -16
  20. data/ext/graphics/color.c +253 -94
  21. data/ext/graphics/drawable.c +16 -4
  22. data/ext/graphics/font.c +144 -25
  23. data/ext/graphics/glyph.c +38 -8
  24. data/ext/graphics/image.c +205 -41
  25. data/ext/graphics/polygon.c +317 -30
  26. data/ext/graphics/rect.c +225 -60
  27. data/ext/graphics/rectangle.c +307 -35
  28. data/ext/graphics/render_state.c +124 -12
  29. data/ext/graphics/render_texture.c +191 -14
  30. data/ext/graphics/render_window.c +55 -0
  31. data/ext/graphics/render_window.h +10 -0
  32. data/ext/graphics/shader.c +289 -17
  33. data/ext/graphics/shape.c +265 -32
  34. data/ext/graphics/sprite.c +245 -30
  35. data/ext/graphics/stencil_mode.c +163 -46
  36. data/ext/graphics/target.c +121 -43
  37. data/ext/graphics/target.h +31 -17
  38. data/ext/graphics/text.c +339 -19
  39. data/ext/graphics/texture.c +291 -6
  40. data/ext/graphics/transform.c +178 -5
  41. data/ext/graphics/transformable.c +127 -12
  42. data/ext/graphics/vertex.c +98 -6
  43. data/ext/graphics/vertex_array.c +142 -21
  44. data/ext/graphics/vertex_buffer.c +154 -12
  45. data/ext/graphics/view.c +140 -6
  46. data/ext/network/ftp.c +278 -12
  47. data/ext/network/http.c +179 -44
  48. data/ext/network/ip_address.c +127 -35
  49. data/ext/network/network_enums.c +248 -141
  50. data/ext/network/packet.c +280 -41
  51. data/ext/network/socket_selector.c +98 -21
  52. data/ext/network/tcp_listener.c +82 -18
  53. data/ext/network/tcp_socket.c +135 -27
  54. data/ext/network/udp_socket.c +129 -28
  55. data/ext/ports.rb +7 -0
  56. data/ext/system/buffer.c +47 -16
  57. data/ext/system/clock.c +77 -12
  58. data/ext/system/input_stream.c +113 -51
  59. data/ext/system/sleep.c +10 -2
  60. data/ext/system/time.c +182 -40
  61. data/ext/system/vec2.c +166 -39
  62. data/ext/system/vec3.c +177 -39
  63. data/ext/window/clipboard.c +47 -17
  64. data/ext/window/context.c +66 -13
  65. data/ext/window/context_settings.c +132 -42
  66. data/ext/window/cursor.c +45 -9
  67. data/ext/window/event.c +164 -53
  68. data/ext/window/joystick.c +69 -3
  69. data/ext/window/keyboard.c +168 -116
  70. data/ext/window/mouse.c +64 -13
  71. data/ext/window/sensor.c +28 -2
  72. data/ext/window/touch.c +32 -12
  73. data/ext/window/video_mode.c +93 -31
  74. data/ext/window/vulkan.c +34 -6
  75. data/ext/window/window.c +228 -229
  76. data/ext/window/window.h +4 -4
  77. data/ext/window/window_base.c +251 -0
  78. data/ext/window/window_base.h +43 -0
  79. data/ext/window/window_base.inc +236 -0
  80. data/lib/sfml/version.rb +1 -1
  81. data/sig/audio/audio_enums.rbs +30 -0
  82. data/sig/audio/listener.rbs +16 -0
  83. data/sig/audio/music.rbs +56 -0
  84. data/sig/audio/sound.rbs +51 -0
  85. data/sig/audio/sound_buffer.rbs +17 -0
  86. data/sig/audio/sound_buffer_recorder.rbs +14 -0
  87. data/sig/audio/sound_recorder.rbs +17 -0
  88. data/sig/audio/sound_source_cone.rbs +14 -0
  89. data/sig/audio/sound_stream.rbs +51 -0
  90. data/sig/graphics/blend_mode.rbs +29 -0
  91. data/sig/graphics/circle.rbs +44 -0
  92. data/sig/graphics/color.rbs +39 -0
  93. data/sig/graphics/drawable.rbs +5 -0
  94. data/sig/graphics/font.rbs +20 -0
  95. data/sig/graphics/glyph.rbs +7 -0
  96. data/sig/graphics/image.rbs +22 -0
  97. data/sig/graphics/polygon.rbs +42 -0
  98. data/sig/graphics/rect.rbs +33 -0
  99. data/sig/graphics/rectangle.rbs +42 -0
  100. data/sig/graphics/render_state.rbs +21 -0
  101. data/sig/graphics/render_target.rbs +18 -0
  102. data/sig/graphics/render_texture.rbs +39 -0
  103. data/sig/graphics/render_window.rbs +7 -0
  104. data/sig/graphics/shader.rbs +39 -0
  105. data/sig/graphics/shape.rbs +38 -0
  106. data/sig/graphics/sprite.rbs +34 -0
  107. data/sig/graphics/stencil_mode.rbs +18 -0
  108. data/sig/graphics/target.rbs +8 -0
  109. data/sig/graphics/text.rbs +48 -0
  110. data/sig/graphics/texture.rbs +34 -0
  111. data/sig/graphics/transform.rbs +37 -0
  112. data/sig/graphics/transformable.rbs +25 -0
  113. data/sig/graphics/vertex.rbs +17 -0
  114. data/sig/graphics/vertex_array.rbs +17 -0
  115. data/sig/graphics/vertex_buffer.rbs +22 -0
  116. data/sig/graphics/view.rbs +23 -0
  117. data/sig/network/ftp.rbs +46 -0
  118. data/sig/network/http.rbs +27 -0
  119. data/sig/network/ip_address.rbs +22 -0
  120. data/sig/network/network_enums.rbs +95 -0
  121. data/sig/network/packet.rbs +40 -0
  122. data/sig/network/socket_selector.rbs +14 -0
  123. data/sig/network/tcp_listener.rbs +13 -0
  124. data/sig/network/tcp_socket.rbs +18 -0
  125. data/sig/network/udp_socket.rbs +17 -0
  126. data/sig/sfml/version.rbs +3 -0
  127. data/sig/system/buffer.rbs +11 -0
  128. data/sig/system/clock.rbs +13 -0
  129. data/sig/system/input_stream.rbs +7 -0
  130. data/sig/system/sleep.rbs +3 -0
  131. data/sig/system/time.rbs +28 -0
  132. data/sig/system/vec2.rbs +26 -0
  133. data/sig/system/vec3.rbs +27 -0
  134. data/sig/window/clipboard.rbs +8 -0
  135. data/sig/window/context.rbs +11 -0
  136. data/sig/window/context_settings.rbs +20 -0
  137. data/sig/window/cursor.rbs +6 -0
  138. data/sig/window/event.rbs +20 -0
  139. data/sig/window/joystick.rbs +15 -0
  140. data/sig/window/keyboard.rbs +10 -0
  141. data/sig/window/mouse.rbs +9 -0
  142. data/sig/window/sensor.rbs +8 -0
  143. data/sig/window/touch.rbs +6 -0
  144. data/sig/window/video_mode.rbs +16 -0
  145. data/sig/window/vulkan.rbs +7 -0
  146. data/sig/window/window.rbs +34 -0
  147. data/sig/window/window_base.rbs +33 -0
  148. 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 *ptr) {
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) value;
34
+ return (unsigned char)value;
36
35
  }
37
36
 
38
37
  static VALUE Color_wrap(sfColor color) {
39
- Color *ptr = malloc(sizeof(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) NUM2UINT(rb_integer);
46
+ unsigned int value = (unsigned int)NUM2UINT(rb_integer);
48
47
 
49
48
  if (value <= 0xFFFFFF) {
50
- return (sfColor) {
51
- (unsigned char) ((value >> 16) & 0xFF),
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
- (unsigned char) ((value >> 24) & 0xFF),
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 Color_new(int argc, VALUE *argv, VALUE klass) {
67
- VALUE self;
68
- Color *ptr;
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 *) Get_Color_Struct(argv[0]))->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
- ptr = malloc(sizeof(Color));
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
- (unsigned char) ((NUM2UINT(rb_integer) >> 16) & 0xFF),
97
- (unsigned char) ((NUM2UINT(rb_integer) >> 8) & 0xFF),
98
- (unsigned char) (NUM2UINT(rb_integer) & 0xFF),
99
- 255
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 *) Get_Color_Struct(self))->color.r);
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 *) Get_Color_Struct(self))->color.g);
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 *) Get_Color_Struct(self))->color.b);
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 *) Get_Color_Struct(self))->color.a);
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
- ((Color *) Get_Color_Struct(self))->color.r = clamp_channel(NUM2INT(rb_value));
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
- ((Color *) Get_Color_Struct(self))->color.g = clamp_channel(NUM2INT(rb_value));
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
- ((Color *) Get_Color_Struct(self))->color.b = clamp_channel(NUM2INT(rb_value));
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
- ((Color *) Get_Color_Struct(self))->color.a = clamp_channel(NUM2INT(rb_value));
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 *) Get_Color_Struct(self))->color;
232
+ sfColor color = ((Color*)Get_Color_Struct(self))->color;
145
233
 
146
- return UINT2NUM(((unsigned int) color.r << 24) | ((unsigned int) color.g << 16) |
147
- ((unsigned int) color.b << 8) | (unsigned int) color.a);
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 *) Get_Color_Struct(self))->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), INT2NUM(color.a));
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 *) Get_Color_Struct(self))->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 *) Get_Color_Struct(rb_other))->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 *) Get_Color_Struct(self))->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
- clamp_channel(a.r + b.r), clamp_channel(a.g + b.g),
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 *) Get_Color_Struct(self))->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
- clamp_channel(a.r - b.r), clamp_channel(a.g - b.g),
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 *) Get_Color_Struct(self))->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((sfColor) {
194
- (unsigned char) ((a.r * b.r) / 255), (unsigned char) ((a.g * b.g) / 255),
195
- (unsigned char) ((a.b * b.b) / 255), (unsigned char) ((a.a * b.a) / 255)
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 *) Get_Color_Struct(self))->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
- static void Color_define_predefined(VALUE klass, const char *name, sfColor color) {
209
- rb_define_const(klass, name, Color_wrap(color));
210
- }
211
-
212
- void Init_Color(VALUE rb_module) {
213
- rb_cColor = rb_define_class_under(rb_module, "Color", rb_cObject);
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
- Color_define_predefined(rb_cColor, "BLACK", sfBlack);
239
- Color_define_predefined(rb_cColor, "WHITE", sfWhite);
240
- Color_define_predefined(rb_cColor, "RED", sfRed);
241
- Color_define_predefined(rb_cColor, "GREEN", sfGreen);
242
- Color_define_predefined(rb_cColor, "BLUE", sfBlue);
243
- Color_define_predefined(rb_cColor, "YELLOW", sfYellow);
244
- Color_define_predefined(rb_cColor, "MAGENTA", sfMagenta);
245
- Color_define_predefined(rb_cColor, "CYAN", sfCyan);
246
- Color_define_predefined(rb_cColor, "TRANSPARENT", sfTransparent);
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 *Get_Color_Struct(VALUE self) {
254
- Color *ptr;
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 *) Get_Color_Struct(rb_color))->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
- clamp_channel(NUM2INT(rb_ary_entry(rb_color, 0))),
273
- clamp_channel(NUM2INT(rb_ary_entry(rb_color, 1))),
274
- clamp_channel(NUM2INT(rb_ary_entry(rb_color, 2))),
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) {0, 0, 0, 255};
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((sfColor) {clamp_channel(r), clamp_channel(g), clamp_channel(b), clamp_channel(a)});
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) || RB_INTEGER_TYPE_P(rb_color)) {
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 *color_a, sfColor *color_b) {
463
+ void color_swap(sfColor* color_a, sfColor* color_b) {
305
464
  sfColor c;
306
465
 
307
466
  c = *color_b;
@@ -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
- void Init_Drawable(VALUE rb_module) {
32
- rb_mDrawable = rb_define_module_under(rb_module, "Drawable");
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
  }