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
@@ -62,9 +62,18 @@ static VALUE Transform_alloc(VALUE klass) {
62
62
  return TypedData_Wrap_Struct(klass, &Transform_data_type, transform);
63
63
  }
64
64
 
65
- /* new -> identity
66
- new(array_of_9) -> from that matrix
67
- new(a00, a01, ... a22) -> from those nine elements */
65
+ /* call-seq:
66
+ * Transform.new -> identity Transform
67
+ * Transform.new(array_of_9) -> Transform
68
+ * Transform.new(a00, a01, ... a22) -> Transform
69
+ *
70
+ * A Transform wraps a 3x3 matrix (9 floats, row-major). With no arguments it
71
+ * is the identity transform; with a single 9-element Array or nine
72
+ * individual numbers, it is built from those matrix elements directly.
73
+ *
74
+ * @return [Transform]
75
+ * @raise [ArgumentError] if given an argument count other than 0, 1 or 9
76
+ */
68
77
  static VALUE Transform_init(int argc, VALUE* argv, VALUE self) {
69
78
  sfTransform* transform = Get_Transform_Struct(self);
70
79
  float matrix[MATRIX_LENGTH];
@@ -93,11 +102,26 @@ static VALUE Transform_init(int argc, VALUE* argv, VALUE self) {
93
102
  return self;
94
103
  }
95
104
 
105
+ /* call-seq:
106
+ * Transform.identity -> Transform
107
+ *
108
+ * Returns the identity transform.
109
+ *
110
+ * @return [Transform] a fresh identity transform
111
+ */
96
112
  static VALUE Transform_s_identity(VALUE klass) {
97
113
  (void)klass;
98
114
  return Transform_wrap(sfTransform_Identity);
99
115
  }
100
116
 
117
+ /* call-seq:
118
+ * Transform.from_a(array_of_9) -> Transform
119
+ *
120
+ * Creates a transform from a nine-element array.
121
+ *
122
+ * @return [Transform]
123
+ * @raise [ArgumentError] if the Array has fewer than 9 elements
124
+ */
101
125
  static VALUE Transform_s_from_a(VALUE klass, VALUE rb_matrix) {
102
126
  (void)klass;
103
127
  return Transform_wrap(Transform_ArrayToTransform(rb_matrix));
@@ -107,6 +131,12 @@ static VALUE Transform_s_from_a(VALUE klass, VALUE rb_matrix) {
107
131
  /* Matrix access */
108
132
  /* -------------------------------------------------------------------------- */
109
133
 
134
+ /* call-seq: to_a -> Array<Float>
135
+ *
136
+ * Returns the object as an Array.
137
+ *
138
+ * @return [Array<Float>] the 9 matrix elements, row-major
139
+ */
110
140
  static VALUE Transform_to_a(VALUE self) {
111
141
  return Transform_MatrixToArray(Get_Transform_Struct(self)->matrix);
112
142
  }
@@ -114,6 +144,13 @@ static VALUE Transform_to_a(VALUE self) {
114
144
  /* The 16-float 4x4 that sfTransform_getMatrix() fills, ready for glLoadMatrixf.
115
145
  Deliberately not called #matrix: that name already means the 3x3 everywhere
116
146
  else in this binding (Sprite#matrix, Text#matrix, RenderState#matrix). */
147
+ /* call-seq: gl_matrix -> Array<Float>
148
+ *
149
+ * Returns the transform as a 4x4 OpenGL matrix.
150
+ *
151
+ * @return [Array<Float>] the equivalent 16-element 4x4 matrix, ready for
152
+ * +glLoadMatrixf+
153
+ */
117
154
  static VALUE Transform_gl_matrix(VALUE self) {
118
155
  float matrix[GL_MATRIX_LENGTH];
119
156
  VALUE rb_arr;
@@ -130,6 +167,13 @@ static VALUE Transform_gl_matrix(VALUE self) {
130
167
  return rb_arr;
131
168
  }
132
169
 
170
+ /* call-seq:
171
+ * self == other -> true or false
172
+ *
173
+ * +other+ may be a Transform or a 9-element Array.
174
+ *
175
+ * @return [Boolean]
176
+ */
133
177
  static VALUE Transform_eql(VALUE self, VALUE rb_other) {
134
178
  sfTransform other;
135
179
 
@@ -142,6 +186,12 @@ static VALUE Transform_eql(VALUE self, VALUE rb_other) {
142
186
  return BOOL2RB(sfTransform_equal(Get_Transform_Struct(self), &other));
143
187
  }
144
188
 
189
+ /* call-seq: to_s -> String
190
+ *
191
+ * Returns a human-readable representation of the object.
192
+ *
193
+ * @return [String]
194
+ */
145
195
  static VALUE Transform_to_s(VALUE self) {
146
196
  const float* m = Get_Transform_Struct(self)->matrix;
147
197
 
@@ -153,6 +203,13 @@ static VALUE Transform_to_s(VALUE self) {
153
203
  /* Application */
154
204
  /* -------------------------------------------------------------------------- */
155
205
 
206
+ /* call-seq:
207
+ * transform_point(point) -> Vector2
208
+ *
209
+ * Applies the transform to a point and returns the result.
210
+ *
211
+ * @return [Vector2] +point+ transformed by this matrix
212
+ */
156
213
  static VALUE Transform_transform_point(VALUE self, VALUE rb_point) {
157
214
  sfVector2f point =
158
215
  sfTransform_transformPoint(Get_Transform_Struct(self), vec2f_from_rb(rb_point));
@@ -160,16 +217,37 @@ static VALUE Transform_transform_point(VALUE self, VALUE rb_point) {
160
217
  return vec2f_to_rb(point);
161
218
  }
162
219
 
220
+ /* call-seq:
221
+ * transform_rect(rect) -> Rect
222
+ *
223
+ * Applies the transform to a rectangle and returns the result.
224
+ *
225
+ * @return [Rect] the axis-aligned bounding box of +rect+ transformed by
226
+ * this matrix
227
+ */
163
228
  static VALUE Transform_transform_rect(VALUE self, VALUE rb_rect) {
164
229
  sfFloatRect rect = sfTransform_transformRect(Get_Transform_Struct(self), rect_from_rb(rb_rect));
165
230
 
166
231
  return rect_to_rb(rect);
167
232
  }
168
233
 
234
+ /* call-seq: inverse -> Transform
235
+ *
236
+ * Returns the inverse of the transform.
237
+ *
238
+ * @return [Transform] the inverse of this transform, or the identity if it
239
+ * is not invertible
240
+ */
169
241
  static VALUE Transform_get_inverse(VALUE self) {
170
242
  return Transform_wrap(sfTransform_getInverse(Get_Transform_Struct(self)));
171
243
  }
172
244
 
245
+ /* call-seq: copy -> Transform
246
+ *
247
+ * Returns a deep copy of the object.
248
+ *
249
+ * @return [Transform] an independent copy
250
+ */
173
251
  static VALUE Transform_copy(VALUE self) {
174
252
  return Transform_wrap(*Get_Transform_Struct(self));
175
253
  }
@@ -178,6 +256,14 @@ static VALUE Transform_copy(VALUE self) {
178
256
  /* Mutators -- each returns self so they chain */
179
257
  /* -------------------------------------------------------------------------- */
180
258
 
259
+ /* call-seq:
260
+ * combine!(other) -> self
261
+ *
262
+ * Combines this transform with +other+ (a Transform or 9-element Array) in
263
+ * place, equivalent to matrix multiplication (+self+ * +other+).
264
+ *
265
+ * @return [self]
266
+ */
181
267
  static VALUE Transform_combine_bang(VALUE self, VALUE rb_other) {
182
268
  sfTransform other = Transform_ArrayToTransform(rb_other);
183
269
 
@@ -186,6 +272,16 @@ static VALUE Transform_combine_bang(VALUE self, VALUE rb_other) {
186
272
  return self;
187
273
  }
188
274
 
275
+ /* call-seq:
276
+ * self * other -> Transform
277
+ * combine(other) -> Transform
278
+ *
279
+ * Non-mutating combination: returns a new Transform equal to +self+
280
+ * combined with +other+ (a Transform or 9-element Array), leaving both
281
+ * operands untouched.
282
+ *
283
+ * @return [Transform]
284
+ */
189
285
  static VALUE Transform_mul(VALUE self, VALUE rb_other) {
190
286
  sfTransform combined = *Get_Transform_Struct(self);
191
287
  sfTransform other = Transform_ArrayToTransform(rb_other);
@@ -195,11 +291,27 @@ static VALUE Transform_mul(VALUE self, VALUE rb_other) {
195
291
  return Transform_wrap(combined);
196
292
  }
197
293
 
294
+ /* call-seq:
295
+ * translate!(offset) -> self
296
+ *
297
+ * Applies a translation to the transform in place.
298
+ *
299
+ * @return [self]
300
+ */
198
301
  static VALUE Transform_translate_bang(VALUE self, VALUE rb_offset) {
199
302
  sfTransform_translate(Transform_writable(self), vec2f_from_rb(rb_offset));
200
303
  return self;
201
304
  }
202
305
 
306
+ /* call-seq:
307
+ * rotate!(angle) -> self
308
+ * rotate!(angle, center) -> self
309
+ *
310
+ * Rotates by +angle+ degrees in place, around +center+ if given, otherwise
311
+ * around the origin.
312
+ *
313
+ * @return [self]
314
+ */
203
315
  static VALUE Transform_rotate_bang(int argc, VALUE* argv, VALUE self) {
204
316
  VALUE rb_angle, rb_center;
205
317
  sfTransform* transform;
@@ -216,6 +328,15 @@ static VALUE Transform_rotate_bang(int argc, VALUE* argv, VALUE self) {
216
328
  return self;
217
329
  }
218
330
 
331
+ /* call-seq:
332
+ * scale!(factors) -> self
333
+ * scale!(factors, center) -> self
334
+ *
335
+ * Scales by +factors+ (a Vector2 or 2-element Array) in place, around
336
+ * +center+ if given, otherwise around the origin.
337
+ *
338
+ * @return [self]
339
+ */
219
340
  static VALUE Transform_scale_bang(int argc, VALUE* argv, VALUE self) {
220
341
  VALUE rb_factors, rb_center;
221
342
  sfTransform* transform;
@@ -233,14 +354,39 @@ static VALUE Transform_scale_bang(int argc, VALUE* argv, VALUE self) {
233
354
  }
234
355
 
235
356
  /* Non-mutating forms: copy, then apply. */
357
+ /* call-seq:
358
+ * translate(offset) -> Transform
359
+ *
360
+ * Returns a copy translated by the given offsets.
361
+ *
362
+ * @return [Transform] a new transform, translated by +offset+
363
+ */
236
364
  static VALUE Transform_translate(VALUE self, VALUE rb_offset) {
237
365
  return Transform_translate_bang(Transform_copy(self), rb_offset);
238
366
  }
239
367
 
368
+ /* call-seq:
369
+ * rotate(angle) -> Transform
370
+ * rotate(angle, center) -> Transform
371
+ *
372
+ * Returns a copy rotated by +angle+ degrees, around +center+ if given.
373
+ *
374
+ * @return [Transform] a new transform, rotated by +angle+ degrees around
375
+ * +center+ if given, otherwise around the origin
376
+ */
240
377
  static VALUE Transform_rotate(int argc, VALUE* argv, VALUE self) {
241
378
  return Transform_rotate_bang(argc, argv, Transform_copy(self));
242
379
  }
243
380
 
381
+ /* call-seq:
382
+ * scale(factors) -> Transform
383
+ * scale(factors, center) -> Transform
384
+ *
385
+ * Returns a copy scaled by +factors+, around +center+ if given.
386
+ *
387
+ * @return [Transform] a new transform, scaled by +factors+ around +center+
388
+ * if given, otherwise around the origin
389
+ */
244
390
  static VALUE Transform_scale(int argc, VALUE* argv, VALUE self) {
245
391
  return Transform_scale_bang(argc, argv, Transform_copy(self));
246
392
  }
@@ -252,6 +398,15 @@ static VALUE Transform_scale(int argc, VALUE* argv, VALUE self) {
252
398
  /* Transform used to be a module whose two functions took and returned plain
253
399
  9-element Arrays. Both are kept, Array-in/Array-out, so existing callers are
254
400
  unaffected by the promotion to a class. */
401
+ /* call-seq:
402
+ * Transform.combine(array_a, array_b) -> Array<Float>
403
+ *
404
+ * Returns the transform that combines +array_a+ and +array_b+.
405
+ *
406
+ * @deprecated Use #combine on a Transform instead.
407
+ * @return [Array<Float>] the 9-element matrix of +array_a+ combined with
408
+ * +array_b+
409
+ */
255
410
  static VALUE Transform_s_combine(VALUE klass, VALUE rb_arr_a, VALUE rb_arr_b) {
256
411
  sfTransform transform_a = Transform_ArrayToTransform(rb_arr_a);
257
412
  sfTransform transform_b = Transform_ArrayToTransform(rb_arr_b);
@@ -263,6 +418,14 @@ static VALUE Transform_s_combine(VALUE klass, VALUE rb_arr_a, VALUE rb_arr_b) {
263
418
  return Transform_MatrixToArray(transform_a.matrix);
264
419
  }
265
420
 
421
+ /* call-seq:
422
+ * Transform.inverse(array) -> Array<Float>
423
+ *
424
+ * Returns the inverse of the given transform.
425
+ *
426
+ * @deprecated Use #inverse on a Transform instead.
427
+ * @return [Array<Float>] the 9-element inverse matrix of +array+
428
+ */
266
429
  static VALUE Transform_s_inverse(VALUE klass, VALUE rb_matrix) {
267
430
  sfTransform transform = Transform_ArrayToTransform(rb_matrix);
268
431
 
@@ -271,8 +434,17 @@ static VALUE Transform_s_inverse(VALUE klass, VALUE rb_matrix) {
271
434
  return Transform_MatrixToArray(sfTransform_getInverse(&transform).matrix);
272
435
  }
273
436
 
274
- void Init_Transform(VALUE rb_module) {
275
- rb_cTransform = rb_define_class_under(rb_module, "Transform", rb_cObject);
437
+ /* Document-class: SFML::Transform
438
+ * A 3x3 matrix describing a 2D transformation (translation, rotation,
439
+ * scaling, or any combination). Used to build up and query the
440
+ * transformations applied by Sprite, Text and Transformable.
441
+ *
442
+ * @!attribute [r] matrix
443
+ * The object's 3x3 transform matrix.
444
+ * @return [Array<Float>] the 9 matrix elements, row-major (alias for #to_a)
445
+ */
446
+ void Init_Transform(VALUE rb_mSFML) {
447
+ rb_cTransform = rb_define_class_under(rb_mSFML, "Transform", rb_cObject);
276
448
 
277
449
  rb_define_alloc_func(rb_cTransform, Transform_alloc);
278
450
  rb_define_method(rb_cTransform, "initialize", Transform_init, -1);
@@ -305,6 +477,7 @@ void Init_Transform(VALUE rb_module) {
305
477
  rb_define_method(rb_cTransform, "scale", Transform_scale, -1);
306
478
  rb_define_method(rb_cTransform, "scale!", Transform_scale_bang, -1);
307
479
 
480
+ /* The identity transform, frozen. */
308
481
  rb_define_const(rb_cTransform, "IDENTITY", rb_obj_freeze(Transform_wrap(sfTransform_Identity)));
309
482
  }
310
483
 
@@ -24,22 +24,34 @@ static const rb_data_type_t Transformable_data_type = {
24
24
  .function = {.dmark = NULL, .dfree = Transformable_free, .dsize = NULL},
25
25
  .flags = RUBY_TYPED_FREE_IMMEDIATELY};
26
26
 
27
- static VALUE Transformable_new(VALUE klass) {
28
- VALUE self;
29
- sfTransformable* transformable;
27
+ static VALUE Transformable_alloc(VALUE klass) {
28
+ sfTransformable* transformable = Transformable_create();
30
29
 
31
- transformable = Transformable_create();
32
- self = TypedData_Wrap_Struct(klass, &Transformable_data_type, transformable);
30
+ if (transformable == NULL) {
31
+ rb_raise(rb_eRuntimeError, "failed to create transformable");
32
+ }
33
33
 
34
- rb_obj_call_init(self, 0, NULL);
35
-
36
- return self;
34
+ return TypedData_Wrap_Struct(klass, &Transformable_data_type, transformable);
37
35
  }
38
36
 
37
+ /* call-seq:
38
+ * Transformable.new -> Transformable
39
+ *
40
+ * Creates a transformable object with a default position, rotation and scale.
41
+ *
42
+ * @return [Transformable]
43
+ */
39
44
  static VALUE Transformable_init(VALUE self) {
40
45
  return self;
41
46
  }
42
47
 
48
+ /* call-seq:
49
+ * position=(value) -> self
50
+ *
51
+ * Sets the object's position.
52
+ *
53
+ * @return [self]
54
+ */
43
55
  static VALUE Transformable_set_position(VALUE self, VALUE rb_position) {
44
56
  sfVector2f position = VEC2_RB2C(rb_position);
45
57
  sfTransformable_setPosition(Get_Transformable_Struct(self), position);
@@ -47,12 +59,26 @@ static VALUE Transformable_set_position(VALUE self, VALUE rb_position) {
47
59
  return self;
48
60
  }
49
61
 
62
+ /* call-seq:
63
+ * rotation=(value) -> self
64
+ *
65
+ * Sets the object's rotation, in degrees.
66
+ *
67
+ * @return [self]
68
+ */
50
69
  static VALUE Transformable_set_rotation(VALUE self, VALUE rb_angle) {
51
70
  sfTransformable_setRotation(Get_Transformable_Struct(self), NUM2DBL(rb_angle));
52
71
 
53
72
  return self;
54
73
  }
55
74
 
75
+ /* call-seq:
76
+ * scale=(value) -> self
77
+ *
78
+ * Sets the object's scale factors.
79
+ *
80
+ * @return [self]
81
+ */
56
82
  static VALUE Transformable_set_scale(VALUE self, VALUE rb_scale) {
57
83
  sfVector2f scale = VEC2_RB2C(rb_scale);
58
84
  sfTransformable_setScale(Get_Transformable_Struct(self), scale);
@@ -60,6 +86,13 @@ static VALUE Transformable_set_scale(VALUE self, VALUE rb_scale) {
60
86
  return self;
61
87
  }
62
88
 
89
+ /* call-seq:
90
+ * origin=(value) -> self
91
+ *
92
+ * Sets the object's origin.
93
+ *
94
+ * @return [self]
95
+ */
63
96
  static VALUE Transformable_set_origin(VALUE self, VALUE rb_origin) {
64
97
  sfVector2f origin = VEC2_RB2C(rb_origin);
65
98
  sfTransformable_setOrigin(Get_Transformable_Struct(self), origin);
@@ -67,28 +100,59 @@ static VALUE Transformable_set_origin(VALUE self, VALUE rb_origin) {
67
100
  return self;
68
101
  }
69
102
 
103
+ /* call-seq: position -> Vector2
104
+ *
105
+ * Returns the object's position.
106
+ *
107
+ * @return [Vector2]
108
+ */
70
109
  static VALUE Transformable_get_position(VALUE self) {
71
110
  sfVector2f position = sfTransformable_getPosition(Get_Transformable_Struct(self));
72
111
 
73
112
  return VEC2_C2RB(position);
74
113
  }
75
114
 
115
+ /* call-seq: rotation -> Float
116
+ *
117
+ * Returns the object's rotation, in degrees.
118
+ *
119
+ * @return [Float] the current rotation, in degrees
120
+ */
76
121
  static VALUE Transformable_get_rotation(VALUE self) {
77
122
  return DBL2NUM(sfTransformable_getRotation(Get_Transformable_Struct(self)));
78
123
  }
79
124
 
125
+ /* call-seq: scale -> Vector2
126
+ *
127
+ * Returns the object's scale factors.
128
+ *
129
+ * @return [Vector2]
130
+ */
80
131
  static VALUE Transformable_get_scale(VALUE self) {
81
132
  sfVector2f scale = sfTransformable_getScale(Get_Transformable_Struct(self));
82
133
 
83
134
  return VEC2_C2RB(scale);
84
135
  }
85
136
 
137
+ /* call-seq: origin -> Vector2
138
+ *
139
+ * Returns the object's origin.
140
+ *
141
+ * @return [Vector2]
142
+ */
86
143
  static VALUE Transformable_get_origin(VALUE self) {
87
144
  sfVector2f origin = sfTransformable_getOrigin(Get_Transformable_Struct(self));
88
145
 
89
146
  return VEC2_C2RB(origin);
90
147
  }
91
148
 
149
+ /* call-seq:
150
+ * move(offset) -> self
151
+ *
152
+ * Adds +offset+ to the current position.
153
+ *
154
+ * @return [self]
155
+ */
92
156
  static VALUE Transformable_move(VALUE self, VALUE rb_move) {
93
157
  sfVector2f move = VEC2_RB2C(rb_move);
94
158
  sfTransformable_move(Get_Transformable_Struct(self), move);
@@ -96,12 +160,26 @@ static VALUE Transformable_move(VALUE self, VALUE rb_move) {
96
160
  return self;
97
161
  }
98
162
 
163
+ /* call-seq:
164
+ * rotate(angle) -> self
165
+ *
166
+ * Adds +angle+ degrees to the current rotation.
167
+ *
168
+ * @return [self]
169
+ */
99
170
  static VALUE Transformable_rotate(VALUE self, VALUE rb_angle) {
100
171
  sfTransformable_rotate(Get_Transformable_Struct(self), NUM2DBL(rb_angle));
101
172
 
102
173
  return self;
103
174
  }
104
175
 
176
+ /* call-seq:
177
+ * scale!(factors) -> self
178
+ *
179
+ * Multiplies the current scale componentwise by +factors+.
180
+ *
181
+ * @return [self]
182
+ */
105
183
  static VALUE Transformable_scale(VALUE self, VALUE rb_scale) {
106
184
  sfVector2f scale = VEC2_RB2C(rb_scale);
107
185
  sfTransformable_scale(Get_Transformable_Struct(self), scale);
@@ -109,6 +187,13 @@ static VALUE Transformable_scale(VALUE self, VALUE rb_scale) {
109
187
  return self;
110
188
  }
111
189
 
190
+ /* call-seq: transform -> Array<Float>
191
+ *
192
+ * Returns the object's 3x3 row-major transform matrix.
193
+ *
194
+ * @return [Array<Float>] the 9-element matrix (also available as #matrix)
195
+ * combining this object's position, rotation, scale and origin
196
+ */
112
197
  static VALUE Transformable_get_matrix(VALUE self) {
113
198
  sfTransformable* transformable = Get_Transformable_Struct(self);
114
199
  sfTransform transform = sfTransformable_getTransform(transformable);
@@ -116,12 +201,24 @@ static VALUE Transformable_get_matrix(VALUE self) {
116
201
  return Transform_MatrixToArray(transform.matrix);
117
202
  }
118
203
 
204
+ /* call-seq: inverse_transform -> Array<Float>
205
+ *
206
+ * Returns the 3x3 row-major inverse of the object's transform matrix.
207
+ *
208
+ * @return [Array<Float>] the inverse of #transform
209
+ */
119
210
  static VALUE Transformable_get_inverse_matrix(VALUE self) {
120
211
  sfTransform transform = sfTransformable_getInverseTransform(Get_Transformable_Struct(self));
121
212
 
122
213
  return Transform_MatrixToArray(transform.matrix);
123
214
  }
124
215
 
216
+ /* call-seq: copy -> Transformable
217
+ *
218
+ * Returns a deep copy of the object.
219
+ *
220
+ * @return [Transformable] an independent copy
221
+ */
125
222
  static VALUE Transformable_copy(VALUE self) {
126
223
  sfTransformable* copy = sfTransformable_copy(Get_Transformable_Struct(self));
127
224
  VALUE other = TypedData_Wrap_Struct(rb_cTransformable, &Transformable_data_type, copy);
@@ -131,10 +228,28 @@ static VALUE Transformable_copy(VALUE self) {
131
228
  return other;
132
229
  }
133
230
 
134
- void Init_Transformable(VALUE rb_module) {
135
- rb_cTransformable = rb_define_class_under(rb_module, "Transformable", rb_cObject);
136
-
137
- rb_define_singleton_method(rb_cTransformable, "new", Transformable_new, 0);
231
+ /* Document-class: SFML::Transformable
232
+ * A standalone position/rotation/scale/origin, decoupled from any drawable
233
+ * object -- the same transform state that Sprite, Text and Shape each carry
234
+ * internally, usable on its own (e.g. as a scene-graph node).
235
+ *
236
+ * @!attribute position
237
+ * The object's position.
238
+ * @return [Vector2]
239
+ * @!attribute rotation
240
+ * The object's rotation, in degrees.
241
+ * @return [Float] degrees
242
+ * @!attribute scale
243
+ * The object's scale factors.
244
+ * @return [Vector2]
245
+ * @!attribute origin
246
+ * The object's origin.
247
+ * @return [Vector2]
248
+ */
249
+ void Init_Transformable(VALUE rb_mSFML) {
250
+ rb_cTransformable = rb_define_class_under(rb_mSFML, "Transformable", rb_cObject);
251
+
252
+ rb_define_alloc_func(rb_cTransformable, Transformable_alloc);
138
253
  rb_define_method(rb_cTransformable, "initialize", Transformable_init, 0);
139
254
 
140
255
  rb_define_method(rb_cTransformable, "position=", Transformable_set_position, 1);