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/rect.c CHANGED
@@ -13,121 +13,223 @@ typedef struct {
13
13
 
14
14
  static VALUE rb_cRect;
15
15
 
16
- static void Rect_free(void *ptr) {
16
+ static void Rect_free(void* ptr) {
17
17
  free(ptr);
18
18
  }
19
19
 
20
20
  static const rb_data_type_t Rect_data_type = {
21
21
  .wrap_struct_name = "SFML::Rect",
22
22
  .function = {.dmark = NULL, .dfree = Rect_free, .dsize = NULL},
23
- .flags = RUBY_TYPED_FREE_IMMEDIATELY
24
- };
23
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY};
25
24
 
26
25
  static VALUE Rect_wrap(sfFloatRect rect) {
27
- Rect *ptr = malloc(sizeof(Rect));
26
+ Rect* ptr = malloc(sizeof(Rect));
28
27
 
29
28
  ptr->rect = rect;
30
29
 
31
30
  return TypedData_Wrap_Struct(rb_cRect, &Rect_data_type, ptr);
32
31
  }
33
32
 
34
- static VALUE Rect_new(int argc, VALUE *argv, VALUE klass) {
35
- VALUE self;
36
- Rect *ptr;
33
+ static VALUE Rect_alloc(VALUE klass) {
34
+ Rect* ptr = malloc(sizeof(Rect));
35
+
36
+ if (ptr == NULL) {
37
+ rb_raise(rb_eNoMemError, "failed to allocate rect");
38
+ }
39
+
40
+ ptr->rect = (sfFloatRect){{0, 0}, {0, 0}};
41
+
42
+ return TypedData_Wrap_Struct(klass, &Rect_data_type, ptr);
43
+ }
44
+
45
+ /* call-seq:
46
+ * Rect.new -> Rect(0, 0, 0, 0)
47
+ * Rect.new(left, top) -> Rect(left, top, 0, 0)
48
+ * Rect.new(left, top, width, height) -> Rect(left, top, width, height)
49
+ * Rect.new([left, top, width, height]) -> Rect(left, top, width, height)
50
+ * Rect.new(other_rect) -> copy of +other_rect+
51
+ *
52
+ * Used for both float rects (positions/sizes) and int rects (pixel
53
+ * sub-regions of a texture); the underlying storage is always Float.
54
+ *
55
+ * @return [Rect]
56
+ * @raise [ArgumentError] if given an Array shorter than 4 elements, or an
57
+ * argument count other than 0, 1, 2 or 4
58
+ */
59
+ static VALUE Rect_initialize(int argc, VALUE* argv, VALUE self) {
37
60
  sfFloatRect rect = {{0, 0}, {0, 0}};
38
61
 
39
62
  if (argc == 1 && rb_obj_is_kind_of(argv[0], rb_cRect)) {
40
- rect = ((Rect *) Get_Rect_Struct(argv[0]))->rect;
63
+ rect = ((Rect*)Get_Rect_Struct(argv[0]))->rect;
41
64
  } else if (argc == 1 && RB_TYPE_P(argv[0], T_ARRAY)) {
42
65
  rect = rect_from_rb(argv[0]);
43
66
  } else if (argc == 2) {
44
- rect = (sfFloatRect) {
45
- {(float) NUM2DBL(argv[0]), (float) NUM2DBL(argv[1])},
46
- {0, 0}
47
- };
67
+ rect = (sfFloatRect){{(float)NUM2DBL(argv[0]), (float)NUM2DBL(argv[1])}, {0, 0}};
48
68
  } else if (argc == 4) {
49
- rect = (sfFloatRect) {
50
- {(float) NUM2DBL(argv[0]), (float) NUM2DBL(argv[1])},
51
- {(float) NUM2DBL(argv[2]), (float) NUM2DBL(argv[3])}
52
- };
69
+ rect = (sfFloatRect){{(float)NUM2DBL(argv[0]), (float)NUM2DBL(argv[1])},
70
+ {(float)NUM2DBL(argv[2]), (float)NUM2DBL(argv[3])}};
53
71
  } else if (argc != 0) {
54
72
  raise_invalid_arguments_excepted(4, argc);
55
73
  }
56
74
 
57
- ptr = malloc(sizeof(Rect));
58
- ptr->rect = rect;
59
-
60
- self = TypedData_Wrap_Struct(klass, &Rect_data_type, ptr);
75
+ ((Rect*)Get_Rect_Struct(self))->rect = rect;
61
76
 
62
77
  return self;
63
78
  }
64
79
 
80
+ /* call-seq: left -> Float
81
+ *
82
+ * Returns the X coordinate of the left edge.
83
+ *
84
+ * @return [Float]
85
+ */
65
86
  static VALUE Rect_get_left(VALUE self) {
66
- return DBL2NUM(((Rect *) Get_Rect_Struct(self))->rect.position.x);
87
+ return DBL2NUM(((Rect*)Get_Rect_Struct(self))->rect.position.x);
67
88
  }
68
89
 
90
+ /* call-seq: top -> Float
91
+ *
92
+ * Returns the Y coordinate of the top edge.
93
+ *
94
+ * @return [Float]
95
+ */
69
96
  static VALUE Rect_get_top(VALUE self) {
70
- return DBL2NUM(((Rect *) Get_Rect_Struct(self))->rect.position.y);
97
+ return DBL2NUM(((Rect*)Get_Rect_Struct(self))->rect.position.y);
71
98
  }
72
99
 
100
+ /* call-seq: width -> Float
101
+ *
102
+ * Returns the width.
103
+ *
104
+ * @return [Float]
105
+ */
73
106
  static VALUE Rect_get_width(VALUE self) {
74
- return DBL2NUM(((Rect *) Get_Rect_Struct(self))->rect.size.x);
107
+ return DBL2NUM(((Rect*)Get_Rect_Struct(self))->rect.size.x);
75
108
  }
76
109
 
110
+ /* call-seq: height -> Float
111
+ *
112
+ * Returns the height.
113
+ *
114
+ * @return [Float]
115
+ */
77
116
  static VALUE Rect_get_height(VALUE self) {
78
- return DBL2NUM(((Rect *) Get_Rect_Struct(self))->rect.size.y);
117
+ return DBL2NUM(((Rect*)Get_Rect_Struct(self))->rect.size.y);
79
118
  }
80
119
 
120
+ /* call-seq:
121
+ * left=(value) -> Float
122
+ *
123
+ * Sets the X coordinate of the left edge.
124
+ *
125
+ * @return [Float] +value+
126
+ */
81
127
  static VALUE Rect_set_left(VALUE self, VALUE rb_value) {
82
- ((Rect *) Get_Rect_Struct(self))->rect.position.x = NUM2DBL(rb_value);
128
+ ((Rect*)Get_Rect_Struct(self))->rect.position.x = NUM2DBL(rb_value);
83
129
  return rb_value;
84
130
  }
85
131
 
132
+ /* call-seq:
133
+ * top=(value) -> Float
134
+ *
135
+ * Sets the Y coordinate of the top edge.
136
+ *
137
+ * @return [Float] +value+
138
+ */
86
139
  static VALUE Rect_set_top(VALUE self, VALUE rb_value) {
87
- ((Rect *) Get_Rect_Struct(self))->rect.position.y = NUM2DBL(rb_value);
140
+ ((Rect*)Get_Rect_Struct(self))->rect.position.y = NUM2DBL(rb_value);
88
141
  return rb_value;
89
142
  }
90
143
 
144
+ /* call-seq:
145
+ * width=(value) -> Float
146
+ *
147
+ * Sets the width.
148
+ *
149
+ * @return [Float] +value+
150
+ */
91
151
  static VALUE Rect_set_width(VALUE self, VALUE rb_value) {
92
- ((Rect *) Get_Rect_Struct(self))->rect.size.x = NUM2DBL(rb_value);
152
+ ((Rect*)Get_Rect_Struct(self))->rect.size.x = NUM2DBL(rb_value);
93
153
  return rb_value;
94
154
  }
95
155
 
156
+ /* call-seq:
157
+ * height=(value) -> Float
158
+ *
159
+ * Sets the height.
160
+ *
161
+ * @return [Float] +value+
162
+ */
96
163
  static VALUE Rect_set_height(VALUE self, VALUE rb_value) {
97
- ((Rect *) Get_Rect_Struct(self))->rect.size.y = NUM2DBL(rb_value);
164
+ ((Rect*)Get_Rect_Struct(self))->rect.size.y = NUM2DBL(rb_value);
98
165
  return rb_value;
99
166
  }
100
167
 
168
+ /* call-seq: position -> Vector2
169
+ *
170
+ * Returns the object's position.
171
+ *
172
+ * @return [Vector2] the +(left, top)+ corner
173
+ */
101
174
  static VALUE Rect_get_position(VALUE self) {
102
- sfFloatRect rect = ((Rect *) Get_Rect_Struct(self))->rect;
175
+ sfFloatRect rect = ((Rect*)Get_Rect_Struct(self))->rect;
103
176
 
104
177
  return vec2f_to_rb(rect.position);
105
178
  }
106
179
 
180
+ /* call-seq: size -> Vector2
181
+ *
182
+ * Returns the object's size.
183
+ *
184
+ * @return [Vector2] the +(width, height)+ dimensions
185
+ */
107
186
  static VALUE Rect_get_size(VALUE self) {
108
- sfFloatRect rect = ((Rect *) Get_Rect_Struct(self))->rect;
187
+ sfFloatRect rect = ((Rect*)Get_Rect_Struct(self))->rect;
109
188
 
110
189
  return vec2f_to_rb(rect.size);
111
190
  }
112
191
 
192
+ /* call-seq:
193
+ * position=(value) -> Vector2
194
+ *
195
+ * Sets the object's position.
196
+ *
197
+ * @return [Vector2] +value+
198
+ */
113
199
  static VALUE Rect_set_position(VALUE self, VALUE rb_position) {
114
- ((Rect *) Get_Rect_Struct(self))->rect.position = vec2f_from_rb(rb_position);
200
+ ((Rect*)Get_Rect_Struct(self))->rect.position = vec2f_from_rb(rb_position);
115
201
  return rb_position;
116
202
  }
117
203
 
204
+ /* call-seq:
205
+ * size=(value) -> Vector2
206
+ *
207
+ * Sets the object's size.
208
+ *
209
+ * @return [Vector2] +value+
210
+ */
118
211
  static VALUE Rect_set_size(VALUE self, VALUE rb_size) {
119
- ((Rect *) Get_Rect_Struct(self))->rect.size = vec2f_from_rb(rb_size);
212
+ ((Rect*)Get_Rect_Struct(self))->rect.size = vec2f_from_rb(rb_size);
120
213
  return rb_size;
121
214
  }
122
215
 
123
- static VALUE Rect_contains(int argc, VALUE *argv, VALUE self) {
124
- sfFloatRect rect = ((Rect *) Get_Rect_Struct(self))->rect;
216
+ /* call-seq:
217
+ * contains?(point) -> true or false
218
+ * contains?(x, y) -> true or false
219
+ *
220
+ * Returns +true+ if the rectangle contains the given point.
221
+ *
222
+ * @return [Boolean]
223
+ * @raise [ArgumentError] if given an argument count other than 1 or 2
224
+ */
225
+ static VALUE Rect_contains(int argc, VALUE* argv, VALUE self) {
226
+ sfFloatRect rect = ((Rect*)Get_Rect_Struct(self))->rect;
125
227
  sfVector2f point;
126
228
 
127
229
  if (argc == 1) {
128
230
  point = vec2f_from_rb(argv[0]);
129
231
  } else if (argc == 2) {
130
- point = (sfVector2f) {(float) NUM2DBL(argv[0]), (float) NUM2DBL(argv[1])};
232
+ point = (sfVector2f){(float)NUM2DBL(argv[0]), (float)NUM2DBL(argv[1])};
131
233
  } else {
132
234
  raise_invalid_arguments_excepted(2, argc);
133
235
  return Qfalse;
@@ -136,8 +238,16 @@ static VALUE Rect_contains(int argc, VALUE *argv, VALUE self) {
136
238
  return BOOL2RB(sfFloatRect_contains(&rect, point));
137
239
  }
138
240
 
241
+ /* call-seq:
242
+ * intersection(other) -> Rect or nil
243
+ *
244
+ * Returns the overlapping region of two rectangles.
245
+ *
246
+ * @return [Rect, nil] the overlapping region, or +nil+ if the rects don't
247
+ * intersect
248
+ */
139
249
  static VALUE Rect_intersection(VALUE self, VALUE rb_other) {
140
- sfFloatRect a = ((Rect *) Get_Rect_Struct(self))->rect;
250
+ sfFloatRect a = ((Rect*)Get_Rect_Struct(self))->rect;
141
251
  sfFloatRect b = rect_from_rb(rb_other);
142
252
  sfFloatRect intersection;
143
253
 
@@ -148,17 +258,36 @@ static VALUE Rect_intersection(VALUE self, VALUE rb_other) {
148
258
  return Qnil;
149
259
  }
150
260
 
261
+ /* call-seq:
262
+ * intersects?(other) -> true or false
263
+ *
264
+ * Returns +true+ if the two rectangles overlap.
265
+ *
266
+ * @return [Boolean]
267
+ */
151
268
  static VALUE Rect_intersects(VALUE self, VALUE rb_other) {
152
269
  return BOOL2RB(Rect_intersection(self, rb_other) != Qnil);
153
270
  }
154
271
 
272
+ /* call-seq: to_a -> [Float, Float, Float, Float]
273
+ *
274
+ * Returns the object as an Array.
275
+ *
276
+ * @return [Array<Float>] +[left, top, width, height]+
277
+ */
155
278
  static VALUE Rect_to_a(VALUE self) {
156
- sfFloatRect rect = ((Rect *) Get_Rect_Struct(self))->rect;
279
+ sfFloatRect rect = ((Rect*)Get_Rect_Struct(self))->rect;
157
280
 
158
281
  return rb_ary_new_from_args(4, DBL2NUM(rect.position.x), DBL2NUM(rect.position.y),
159
282
  DBL2NUM(rect.size.x), DBL2NUM(rect.size.y));
160
283
  }
161
284
 
285
+ /* call-seq: each { |component| ... } -> self
286
+ *
287
+ * Yields +left+, +top+, +width+, +height+ in that order.
288
+ *
289
+ * @return [self]
290
+ */
162
291
  static VALUE Rect_each(VALUE self) {
163
292
  VALUE array = Rect_to_a(self);
164
293
  long i;
@@ -170,12 +299,19 @@ static VALUE Rect_each(VALUE self) {
170
299
  return self;
171
300
  }
172
301
 
302
+ /* call-seq:
303
+ * self == other -> true or false
304
+ *
305
+ * +other+ may be a Rect or a 4-element Array.
306
+ *
307
+ * @return [Boolean]
308
+ */
173
309
  static VALUE Rect_eql(VALUE self, VALUE rb_other) {
174
- sfFloatRect a = ((Rect *) Get_Rect_Struct(self))->rect;
310
+ sfFloatRect a = ((Rect*)Get_Rect_Struct(self))->rect;
175
311
  sfFloatRect b;
176
312
 
177
313
  if (rb_obj_is_kind_of(rb_other, rb_cRect)) {
178
- b = ((Rect *) Get_Rect_Struct(rb_other))->rect;
314
+ b = ((Rect*)Get_Rect_Struct(rb_other))->rect;
179
315
  } else if (RB_TYPE_P(rb_other, T_ARRAY) && RARRAY_LEN(rb_other) >= 4) {
180
316
  b = rect_from_rb(rb_other);
181
317
  } else {
@@ -186,21 +322,55 @@ static VALUE Rect_eql(VALUE self, VALUE rb_other) {
186
322
  a.size.x == b.size.x && a.size.y == b.size.y);
187
323
  }
188
324
 
325
+ /* call-seq: to_s -> String
326
+ *
327
+ * Returns a human-readable representation of the object.
328
+ *
329
+ * @return [String] +"(left, top, width, height)"+
330
+ */
189
331
  static VALUE Rect_to_s(VALUE self) {
190
- sfFloatRect rect = ((Rect *) Get_Rect_Struct(self))->rect;
332
+ sfFloatRect rect = ((Rect*)Get_Rect_Struct(self))->rect;
191
333
  char buffer[96];
192
334
 
193
- snprintf(buffer, sizeof(buffer), "(%g, %g, %g, %g)", rect.position.x, rect.position.y, rect.size.x, rect.size.y);
335
+ snprintf(buffer, sizeof(buffer), "(%g, %g, %g, %g)", rect.position.x, rect.position.y,
336
+ rect.size.x, rect.size.y);
194
337
 
195
338
  return rb_str_new2(buffer);
196
339
  }
197
340
 
198
- void Init_Rect(VALUE rb_module) {
199
- rb_cRect = rb_define_class_under(rb_module, "Rect", rb_cObject);
341
+ /* Document-class: SFML::Rect
342
+ * An axis-aligned rectangle, stored as a position +(left, top)+ and a size
343
+ * +(width, height)+. Used both for float rects (bounds, viewports) and int
344
+ * rects (texture sub-regions) -- the underlying storage is always Float.
345
+ *
346
+ * Includes +Enumerable+ and behaves like a 4-element sequence.
347
+ *
348
+ * @!attribute left
349
+ * The X coordinate of the left edge.
350
+ * @return [Float] the X coordinate of the top-left corner
351
+ * @!attribute top
352
+ * The Y coordinate of the top edge.
353
+ * @return [Float] the Y coordinate of the top-left corner
354
+ * @!attribute width
355
+ * The width.
356
+ * @return [Float] the width
357
+ * @!attribute height
358
+ * The height.
359
+ * @return [Float] the height
360
+ * @!attribute position
361
+ * The object's position.
362
+ * @return [Vector2] the +(left, top)+ corner
363
+ * @!attribute size
364
+ * The object's size.
365
+ * @return [Vector2] the +(width, height)+ dimensions
366
+ */
367
+ void Init_Rect(VALUE rb_mSFML) {
368
+ rb_cRect = rb_define_class_under(rb_mSFML, "Rect", rb_cObject);
200
369
 
201
370
  rb_include_module(rb_cRect, rb_mEnumerable);
202
371
 
203
- rb_define_singleton_method(rb_cRect, "new", Rect_new, -1);
372
+ rb_define_alloc_func(rb_cRect, Rect_alloc);
373
+ rb_define_method(rb_cRect, "initialize", Rect_initialize, -1);
204
374
 
205
375
  rb_define_method(rb_cRect, "left", Rect_get_left, 0);
206
376
  rb_define_method(rb_cRect, "top", Rect_get_top, 0);
@@ -231,15 +401,15 @@ VALUE Get_Klass_Rect(void) {
231
401
  return rb_cRect;
232
402
  }
233
403
 
234
- void *Get_Rect_Struct(VALUE self) {
235
- Rect *ptr;
404
+ void* Get_Rect_Struct(VALUE self) {
405
+ Rect* ptr;
236
406
  TypedData_Get_Struct(self, Rect, &Rect_data_type, ptr);
237
407
  return ptr;
238
408
  }
239
409
 
240
410
  sfFloatRect rect_from_rb(VALUE rb_rect) {
241
411
  if (rb_obj_is_kind_of(rb_rect, rb_cRect)) {
242
- return ((Rect *) Get_Rect_Struct(rb_rect))->rect;
412
+ return ((Rect*)Get_Rect_Struct(rb_rect))->rect;
243
413
  }
244
414
 
245
415
  if (RB_TYPE_P(rb_rect, T_ARRAY)) {
@@ -247,15 +417,14 @@ sfFloatRect rect_from_rb(VALUE rb_rect) {
247
417
  raise_invalid_array_length(4);
248
418
  }
249
419
 
250
- return (sfFloatRect) {
251
- {(float) NUM2DBL(rb_ary_entry(rb_rect, 0)), (float) NUM2DBL(rb_ary_entry(rb_rect, 1))},
252
- {(float) NUM2DBL(rb_ary_entry(rb_rect, 2)), (float) NUM2DBL(rb_ary_entry(rb_rect, 3))}
253
- };
420
+ return (sfFloatRect){
421
+ {(float)NUM2DBL(rb_ary_entry(rb_rect, 0)), (float)NUM2DBL(rb_ary_entry(rb_rect, 1))},
422
+ {(float)NUM2DBL(rb_ary_entry(rb_rect, 2)), (float)NUM2DBL(rb_ary_entry(rb_rect, 3))}};
254
423
  }
255
424
 
256
425
  raise_invalid_argument_class(rb_cRect);
257
426
 
258
- return (sfFloatRect) {{0, 0}, {0, 0}};
427
+ return (sfFloatRect){{0, 0}, {0, 0}};
259
428
  }
260
429
 
261
430
  VALUE rect_to_rb(sfFloatRect c_rect) {
@@ -265,17 +434,13 @@ VALUE rect_to_rb(sfFloatRect c_rect) {
265
434
  sfIntRect int_rect_from_rb(VALUE rb_rect) {
266
435
  sfFloatRect rect = rect_from_rb(rb_rect);
267
436
 
268
- return (sfIntRect) {
269
- {(int) rect.position.x, (int) rect.position.y},
270
- {(int) rect.size.x, (int) rect.size.y}
271
- };
437
+ return (sfIntRect){{(int)rect.position.x, (int)rect.position.y},
438
+ {(int)rect.size.x, (int)rect.size.y}};
272
439
  }
273
440
 
274
441
  VALUE int_rect_to_rb(sfIntRect c_rect) {
275
- return Rect_wrap((sfFloatRect) {
276
- {(float) c_rect.position.x, (float) c_rect.position.y},
277
- {(float) c_rect.size.x, (float) c_rect.size.y}
278
- });
442
+ return Rect_wrap((sfFloatRect){{(float)c_rect.position.x, (float)c_rect.position.y},
443
+ {(float)c_rect.size.x, (float)c_rect.size.y}});
279
444
  }
280
445
 
281
446
  void Rect_check(VALUE rb_rect) {