sfml3-rb 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/CHANGELOG.md +43 -17
  4. data/README.md +97 -29
  5. data/ext/audio/audio_enums.c +58 -20
  6. data/ext/audio/listener.c +89 -6
  7. data/ext/audio/music.c +206 -5
  8. data/ext/audio/sound.c +175 -5
  9. data/ext/audio/sound_buffer.c +189 -47
  10. data/ext/audio/sound_buffer_recorder.c +83 -16
  11. data/ext/audio/sound_recorder.c +172 -52
  12. data/ext/audio/sound_source_cone.c +108 -29
  13. data/ext/audio/sound_stream.c +178 -5
  14. data/ext/core/exceptions.c +10 -8
  15. data/ext/core/unicode.c +12 -2
  16. data/ext/ext.c +4 -0
  17. data/ext/graphics/blend_mode.c +203 -53
  18. data/ext/graphics/circle.c +271 -4
  19. data/ext/graphics/color.c +240 -90
  20. data/ext/graphics/drawable.c +15 -4
  21. data/ext/graphics/font.c +138 -25
  22. data/ext/graphics/glyph.c +31 -8
  23. data/ext/graphics/image.c +180 -37
  24. data/ext/graphics/polygon.c +293 -26
  25. data/ext/graphics/rect.c +211 -54
  26. data/ext/graphics/rectangle.c +279 -26
  27. data/ext/graphics/render_state.c +116 -2
  28. data/ext/graphics/render_texture.c +163 -2
  29. data/ext/graphics/shader.c +283 -17
  30. data/ext/graphics/shape.c +252 -26
  31. data/ext/graphics/sprite.c +216 -25
  32. data/ext/graphics/stencil_mode.c +148 -39
  33. data/ext/graphics/target.c +67 -22
  34. data/ext/graphics/target.h +15 -15
  35. data/ext/graphics/text.c +306 -6
  36. data/ext/graphics/texture.c +257 -3
  37. data/ext/graphics/transform.c +178 -5
  38. data/ext/graphics/transformable.c +126 -2
  39. data/ext/graphics/vertex.c +79 -2
  40. data/ext/graphics/vertex_array.c +128 -16
  41. data/ext/graphics/vertex_buffer.c +124 -2
  42. data/ext/graphics/view.c +130 -2
  43. data/ext/network/ftp.c +249 -10
  44. data/ext/network/http.c +156 -38
  45. data/ext/network/ip_address.c +107 -26
  46. data/ext/network/network_enums.c +248 -141
  47. data/ext/network/packet.c +273 -39
  48. data/ext/network/socket_selector.c +91 -19
  49. data/ext/network/tcp_listener.c +75 -16
  50. data/ext/network/tcp_socket.c +128 -25
  51. data/ext/network/udp_socket.c +122 -26
  52. data/ext/ports.rb +7 -0
  53. data/ext/system/buffer.c +41 -12
  54. data/ext/system/clock.c +68 -9
  55. data/ext/system/input_stream.c +94 -42
  56. data/ext/system/sleep.c +10 -2
  57. data/ext/system/time.c +172 -34
  58. data/ext/system/vec2.c +156 -35
  59. data/ext/system/vec3.c +166 -35
  60. data/ext/window/clipboard.c +47 -17
  61. data/ext/window/context.c +59 -9
  62. data/ext/window/context_settings.c +116 -38
  63. data/ext/window/cursor.c +39 -9
  64. data/ext/window/event.c +163 -42
  65. data/ext/window/joystick.c +69 -3
  66. data/ext/window/keyboard.c +168 -116
  67. data/ext/window/mouse.c +36 -2
  68. data/ext/window/sensor.c +28 -2
  69. data/ext/window/touch.c +20 -2
  70. data/ext/window/video_mode.c +90 -19
  71. data/ext/window/vulkan.c +34 -6
  72. data/ext/window/window.c +340 -16
  73. data/lib/sfml/version.rb +1 -1
  74. data/sig/audio/audio_enums.rbs +30 -0
  75. data/sig/audio/listener.rbs +16 -0
  76. data/sig/audio/music.rbs +56 -0
  77. data/sig/audio/sound.rbs +51 -0
  78. data/sig/audio/sound_buffer.rbs +17 -0
  79. data/sig/audio/sound_buffer_recorder.rbs +14 -0
  80. data/sig/audio/sound_recorder.rbs +17 -0
  81. data/sig/audio/sound_source_cone.rbs +14 -0
  82. data/sig/audio/sound_stream.rbs +51 -0
  83. data/sig/graphics/blend_mode.rbs +29 -0
  84. data/sig/graphics/circle.rbs +44 -0
  85. data/sig/graphics/color.rbs +39 -0
  86. data/sig/graphics/drawable.rbs +5 -0
  87. data/sig/graphics/font.rbs +20 -0
  88. data/sig/graphics/glyph.rbs +7 -0
  89. data/sig/graphics/image.rbs +22 -0
  90. data/sig/graphics/polygon.rbs +42 -0
  91. data/sig/graphics/rect.rbs +33 -0
  92. data/sig/graphics/rectangle.rbs +42 -0
  93. data/sig/graphics/render_state.rbs +21 -0
  94. data/sig/graphics/render_texture.rbs +37 -0
  95. data/sig/graphics/shader.rbs +39 -0
  96. data/sig/graphics/shape.rbs +38 -0
  97. data/sig/graphics/sprite.rbs +34 -0
  98. data/sig/graphics/stencil_mode.rbs +18 -0
  99. data/sig/graphics/target.rbs +10 -0
  100. data/sig/graphics/text.rbs +48 -0
  101. data/sig/graphics/texture.rbs +34 -0
  102. data/sig/graphics/transform.rbs +37 -0
  103. data/sig/graphics/transformable.rbs +25 -0
  104. data/sig/graphics/vertex.rbs +17 -0
  105. data/sig/graphics/vertex_array.rbs +17 -0
  106. data/sig/graphics/vertex_buffer.rbs +22 -0
  107. data/sig/graphics/view.rbs +24 -0
  108. data/sig/network/ftp.rbs +46 -0
  109. data/sig/network/http.rbs +27 -0
  110. data/sig/network/ip_address.rbs +22 -0
  111. data/sig/network/network_enums.rbs +95 -0
  112. data/sig/network/packet.rbs +40 -0
  113. data/sig/network/socket_selector.rbs +14 -0
  114. data/sig/network/tcp_listener.rbs +13 -0
  115. data/sig/network/tcp_socket.rbs +18 -0
  116. data/sig/network/udp_socket.rbs +17 -0
  117. data/sig/system/buffer.rbs +11 -0
  118. data/sig/system/clock.rbs +13 -0
  119. data/sig/system/input_stream.rbs +7 -0
  120. data/sig/system/sleep.rbs +3 -0
  121. data/sig/system/time.rbs +28 -0
  122. data/sig/system/vec2.rbs +26 -0
  123. data/sig/system/vec3.rbs +27 -0
  124. data/sig/window/clipboard.rbs +8 -0
  125. data/sig/window/context.rbs +11 -0
  126. data/sig/window/context_settings.rbs +20 -0
  127. data/sig/window/cursor.rbs +6 -0
  128. data/sig/window/event.rbs +20 -0
  129. data/sig/window/joystick.rbs +15 -0
  130. data/sig/window/keyboard.rbs +10 -0
  131. data/sig/window/mouse.rbs +9 -0
  132. data/sig/window/sensor.rbs +8 -0
  133. data/sig/window/touch.rbs +6 -0
  134. data/sig/window/video_mode.rbs +16 -0
  135. data/sig/window/vulkan.rbs +7 -0
  136. data/sig/window/window.rbs +57 -0
  137. metadata +66 -2
@@ -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,6 +24,13 @@ 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
+ /* call-seq:
28
+ * Transformable.new -> Transformable
29
+ *
30
+ * Creates a transformable object with a default position, rotation and scale.
31
+ *
32
+ * @return [Transformable]
33
+ */
27
34
  static VALUE Transformable_new(VALUE klass) {
28
35
  VALUE self;
29
36
  sfTransformable* transformable;
@@ -36,10 +43,24 @@ static VALUE Transformable_new(VALUE klass) {
36
43
  return self;
37
44
  }
38
45
 
46
+ /* call-seq: initialize -> self
47
+ *
48
+ * Initializes the transformable state, including position, rotation and scale.
49
+ *
50
+ * @private No-op; called internally by .new.
51
+ * @return [self]
52
+ */
39
53
  static VALUE Transformable_init(VALUE self) {
40
54
  return self;
41
55
  }
42
56
 
57
+ /* call-seq:
58
+ * position=(value) -> self
59
+ *
60
+ * Sets the object's position.
61
+ *
62
+ * @return [self]
63
+ */
43
64
  static VALUE Transformable_set_position(VALUE self, VALUE rb_position) {
44
65
  sfVector2f position = VEC2_RB2C(rb_position);
45
66
  sfTransformable_setPosition(Get_Transformable_Struct(self), position);
@@ -47,12 +68,26 @@ static VALUE Transformable_set_position(VALUE self, VALUE rb_position) {
47
68
  return self;
48
69
  }
49
70
 
71
+ /* call-seq:
72
+ * rotation=(value) -> self
73
+ *
74
+ * Sets the object's rotation, in degrees.
75
+ *
76
+ * @return [self]
77
+ */
50
78
  static VALUE Transformable_set_rotation(VALUE self, VALUE rb_angle) {
51
79
  sfTransformable_setRotation(Get_Transformable_Struct(self), NUM2DBL(rb_angle));
52
80
 
53
81
  return self;
54
82
  }
55
83
 
84
+ /* call-seq:
85
+ * scale=(value) -> self
86
+ *
87
+ * Sets the object's scale factors.
88
+ *
89
+ * @return [self]
90
+ */
56
91
  static VALUE Transformable_set_scale(VALUE self, VALUE rb_scale) {
57
92
  sfVector2f scale = VEC2_RB2C(rb_scale);
58
93
  sfTransformable_setScale(Get_Transformable_Struct(self), scale);
@@ -60,6 +95,13 @@ static VALUE Transformable_set_scale(VALUE self, VALUE rb_scale) {
60
95
  return self;
61
96
  }
62
97
 
98
+ /* call-seq:
99
+ * origin=(value) -> self
100
+ *
101
+ * Sets the object's origin.
102
+ *
103
+ * @return [self]
104
+ */
63
105
  static VALUE Transformable_set_origin(VALUE self, VALUE rb_origin) {
64
106
  sfVector2f origin = VEC2_RB2C(rb_origin);
65
107
  sfTransformable_setOrigin(Get_Transformable_Struct(self), origin);
@@ -67,28 +109,59 @@ static VALUE Transformable_set_origin(VALUE self, VALUE rb_origin) {
67
109
  return self;
68
110
  }
69
111
 
112
+ /* call-seq: position -> Vector2
113
+ *
114
+ * Returns the object's position.
115
+ *
116
+ * @return [Vector2]
117
+ */
70
118
  static VALUE Transformable_get_position(VALUE self) {
71
119
  sfVector2f position = sfTransformable_getPosition(Get_Transformable_Struct(self));
72
120
 
73
121
  return VEC2_C2RB(position);
74
122
  }
75
123
 
124
+ /* call-seq: rotation -> Float
125
+ *
126
+ * Returns the object's rotation, in degrees.
127
+ *
128
+ * @return [Float] the current rotation, in degrees
129
+ */
76
130
  static VALUE Transformable_get_rotation(VALUE self) {
77
131
  return DBL2NUM(sfTransformable_getRotation(Get_Transformable_Struct(self)));
78
132
  }
79
133
 
134
+ /* call-seq: scale -> Vector2
135
+ *
136
+ * Returns the object's scale factors.
137
+ *
138
+ * @return [Vector2]
139
+ */
80
140
  static VALUE Transformable_get_scale(VALUE self) {
81
141
  sfVector2f scale = sfTransformable_getScale(Get_Transformable_Struct(self));
82
142
 
83
143
  return VEC2_C2RB(scale);
84
144
  }
85
145
 
146
+ /* call-seq: origin -> Vector2
147
+ *
148
+ * Returns the object's origin.
149
+ *
150
+ * @return [Vector2]
151
+ */
86
152
  static VALUE Transformable_get_origin(VALUE self) {
87
153
  sfVector2f origin = sfTransformable_getOrigin(Get_Transformable_Struct(self));
88
154
 
89
155
  return VEC2_C2RB(origin);
90
156
  }
91
157
 
158
+ /* call-seq:
159
+ * move(offset) -> self
160
+ *
161
+ * Adds +offset+ to the current position.
162
+ *
163
+ * @return [self]
164
+ */
92
165
  static VALUE Transformable_move(VALUE self, VALUE rb_move) {
93
166
  sfVector2f move = VEC2_RB2C(rb_move);
94
167
  sfTransformable_move(Get_Transformable_Struct(self), move);
@@ -96,12 +169,26 @@ static VALUE Transformable_move(VALUE self, VALUE rb_move) {
96
169
  return self;
97
170
  }
98
171
 
172
+ /* call-seq:
173
+ * rotate(angle) -> self
174
+ *
175
+ * Adds +angle+ degrees to the current rotation.
176
+ *
177
+ * @return [self]
178
+ */
99
179
  static VALUE Transformable_rotate(VALUE self, VALUE rb_angle) {
100
180
  sfTransformable_rotate(Get_Transformable_Struct(self), NUM2DBL(rb_angle));
101
181
 
102
182
  return self;
103
183
  }
104
184
 
185
+ /* call-seq:
186
+ * scale!(factors) -> self
187
+ *
188
+ * Multiplies the current scale componentwise by +factors+.
189
+ *
190
+ * @return [self]
191
+ */
105
192
  static VALUE Transformable_scale(VALUE self, VALUE rb_scale) {
106
193
  sfVector2f scale = VEC2_RB2C(rb_scale);
107
194
  sfTransformable_scale(Get_Transformable_Struct(self), scale);
@@ -109,6 +196,13 @@ static VALUE Transformable_scale(VALUE self, VALUE rb_scale) {
109
196
  return self;
110
197
  }
111
198
 
199
+ /* call-seq: transform -> Array<Float>
200
+ *
201
+ * Returns the object's 3x3 row-major transform matrix.
202
+ *
203
+ * @return [Array<Float>] the 9-element matrix (also available as #matrix)
204
+ * combining this object's position, rotation, scale and origin
205
+ */
112
206
  static VALUE Transformable_get_matrix(VALUE self) {
113
207
  sfTransformable* transformable = Get_Transformable_Struct(self);
114
208
  sfTransform transform = sfTransformable_getTransform(transformable);
@@ -116,12 +210,24 @@ static VALUE Transformable_get_matrix(VALUE self) {
116
210
  return Transform_MatrixToArray(transform.matrix);
117
211
  }
118
212
 
213
+ /* call-seq: inverse_transform -> Array<Float>
214
+ *
215
+ * Returns the 3x3 row-major inverse of the object's transform matrix.
216
+ *
217
+ * @return [Array<Float>] the inverse of #transform
218
+ */
119
219
  static VALUE Transformable_get_inverse_matrix(VALUE self) {
120
220
  sfTransform transform = sfTransformable_getInverseTransform(Get_Transformable_Struct(self));
121
221
 
122
222
  return Transform_MatrixToArray(transform.matrix);
123
223
  }
124
224
 
225
+ /* call-seq: copy -> Transformable
226
+ *
227
+ * Returns a deep copy of the object.
228
+ *
229
+ * @return [Transformable] an independent copy
230
+ */
125
231
  static VALUE Transformable_copy(VALUE self) {
126
232
  sfTransformable* copy = sfTransformable_copy(Get_Transformable_Struct(self));
127
233
  VALUE other = TypedData_Wrap_Struct(rb_cTransformable, &Transformable_data_type, copy);
@@ -131,8 +237,26 @@ static VALUE Transformable_copy(VALUE self) {
131
237
  return other;
132
238
  }
133
239
 
134
- void Init_Transformable(VALUE rb_module) {
135
- rb_cTransformable = rb_define_class_under(rb_module, "Transformable", rb_cObject);
240
+ /* Document-class: SFML::Transformable
241
+ * A standalone position/rotation/scale/origin, decoupled from any drawable
242
+ * object -- the same transform state that Sprite, Text and Shape each carry
243
+ * internally, usable on its own (e.g. as a scene-graph node).
244
+ *
245
+ * @!attribute position
246
+ * The object's position.
247
+ * @return [Vector2]
248
+ * @!attribute rotation
249
+ * The object's rotation, in degrees.
250
+ * @return [Float] degrees
251
+ * @!attribute scale
252
+ * The object's scale factors.
253
+ * @return [Vector2]
254
+ * @!attribute origin
255
+ * The object's origin.
256
+ * @return [Vector2]
257
+ */
258
+ void Init_Transformable(VALUE rb_mSFML) {
259
+ rb_cTransformable = rb_define_class_under(rb_mSFML, "Transformable", rb_cObject);
136
260
 
137
261
  rb_define_singleton_method(rb_cTransformable, "new", Transformable_new, 0);
138
262
  rb_define_method(rb_cTransformable, "initialize", Transformable_init, 0);
@@ -31,6 +31,17 @@ static VALUE Vertex_wrap(sfVertex vertex) {
31
31
  return TypedData_Wrap_Struct(rb_cVertex, &Vertex_data_type, ptr);
32
32
  }
33
33
 
34
+ /* call-seq:
35
+ * Vertex.new -> Vertex
36
+ * Vertex.new(position) -> Vertex
37
+ * Vertex.new(position, color) -> Vertex
38
+ * Vertex.new(position, color, tex_coords) -> Vertex
39
+ *
40
+ * Any omitted argument defaults to position +(0, 0)+, color white, and
41
+ * tex_coords +(0, 0)+.
42
+ *
43
+ * @return [Vertex]
44
+ */
34
45
  static VALUE Vertex_new(int argc, VALUE* argv, VALUE klass) {
35
46
  VALUE rb_position, rb_color, rb_tex_coords;
36
47
  sfVertex vertex = {{0, 0}, {255, 255, 255, 255}, {0, 0}};
@@ -52,39 +63,91 @@ static VALUE Vertex_new(int argc, VALUE* argv, VALUE klass) {
52
63
  return Vertex_wrap(vertex);
53
64
  }
54
65
 
66
+ /* call-seq: position -> Vector2
67
+ *
68
+ * Returns the object's position.
69
+ *
70
+ * @return [Vector2]
71
+ */
55
72
  static VALUE Vertex_get_position(VALUE self) {
56
73
  return vec2f_to_rb(((Vertex*)Get_Vertex_Struct(self))->vertex.position);
57
74
  }
58
75
 
76
+ /* call-seq:
77
+ * position=(value) -> Vector2
78
+ *
79
+ * Sets the object's position.
80
+ *
81
+ * @return [Vector2] +value+
82
+ */
59
83
  static VALUE Vertex_set_position(VALUE self, VALUE rb_position) {
60
84
  ((Vertex*)Get_Vertex_Struct(self))->vertex.position = vec2f_from_rb(rb_position);
61
85
  return rb_position;
62
86
  }
63
87
 
88
+ /* call-seq: color -> Color
89
+ *
90
+ * Returns the object's color.
91
+ *
92
+ * @return [Color]
93
+ */
64
94
  static VALUE Vertex_get_color(VALUE self) {
65
95
  return color_to_rb(((Vertex*)Get_Vertex_Struct(self))->vertex.color);
66
96
  }
67
97
 
98
+ /* call-seq:
99
+ * color=(value) -> Color
100
+ *
101
+ * Sets the object's color.
102
+ *
103
+ * @return [Color] +value+
104
+ */
68
105
  static VALUE Vertex_set_color(VALUE self, VALUE rb_color) {
69
106
  ((Vertex*)Get_Vertex_Struct(self))->vertex.color = color_from_rb(rb_color);
70
107
  return rb_color;
71
108
  }
72
109
 
110
+ /* call-seq: tex_coords -> Vector2
111
+ *
112
+ * Returns the vertex's texture coordinates.
113
+ *
114
+ * @return [Vector2]
115
+ */
73
116
  static VALUE Vertex_get_tex_coords(VALUE self) {
74
117
  return vec2f_to_rb(((Vertex*)Get_Vertex_Struct(self))->vertex.texCoords);
75
118
  }
76
119
 
120
+ /* call-seq:
121
+ * tex_coords=(value) -> Vector2
122
+ *
123
+ * Sets the vertex's texture coordinates.
124
+ *
125
+ * @return [Vector2] +value+
126
+ */
77
127
  static VALUE Vertex_set_tex_coords(VALUE self, VALUE rb_tex_coords) {
78
128
  ((Vertex*)Get_Vertex_Struct(self))->vertex.texCoords = vec2f_from_rb(rb_tex_coords);
79
129
  return rb_tex_coords;
80
130
  }
81
131
 
132
+ /* call-seq: to_a -> [Vector2, Color]
133
+ *
134
+ * Returns the object as an Array.
135
+ *
136
+ * @return [Array] +[position, color]+
137
+ */
82
138
  static VALUE Vertex_to_a(VALUE self) {
83
139
  Vertex* v = Get_Vertex_Struct(self);
84
140
 
85
141
  return rb_ary_new_from_args(2, vec2f_to_rb(v->vertex.position), color_to_rb(v->vertex.color));
86
142
  }
87
143
 
144
+ /* call-seq:
145
+ * self == other -> true or false
146
+ *
147
+ * Returns +true+ if the two objects are equal.
148
+ *
149
+ * @return [Boolean]
150
+ */
88
151
  static VALUE Vertex_eql(VALUE self, VALUE rb_other) {
89
152
  sfVertex a = ((Vertex*)Get_Vertex_Struct(self))->vertex;
90
153
  sfVertex b;
@@ -101,8 +164,22 @@ static VALUE Vertex_eql(VALUE self, VALUE rb_other) {
101
164
  a.texCoords.y == b.texCoords.y);
102
165
  }
103
166
 
104
- void Init_Vertex(VALUE rb_module) {
105
- rb_cVertex = rb_define_class_under(rb_module, "Vertex", rb_cObject);
167
+ /* Document-class: SFML::Vertex
168
+ * A single point used to build up VertexArray and VertexBuffer primitives:
169
+ * a position, a color, and texture coordinates.
170
+ *
171
+ * @!attribute position
172
+ * The object's position.
173
+ * @return [Vector2]
174
+ * @!attribute color
175
+ * The object's color.
176
+ * @return [Color]
177
+ * @!attribute tex_coords
178
+ * The vertex's texture coordinates.
179
+ * @return [Vector2]
180
+ */
181
+ void Init_Vertex(VALUE rb_mSFML) {
182
+ rb_cVertex = rb_define_class_under(rb_mSFML, "Vertex", rb_cObject);
106
183
 
107
184
  rb_define_singleton_method(rb_cVertex, "new", Vertex_new, -1);
108
185