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
@@ -15,39 +15,38 @@
15
15
  #include "core/macros.h"
16
16
 
17
17
  typedef struct {
18
- sfSprite *sprite;
18
+ sfSprite* sprite;
19
19
  VALUE rb_texture;
20
20
  } Sprite;
21
21
 
22
22
  static VALUE rb_cSprite;
23
23
 
24
- static void Sprite_mark(void *ptr) {
25
- rb_gc_mark(((Sprite *) ptr)->rb_texture);
24
+ static void Sprite_mark(void* ptr) {
25
+ rb_gc_mark(((Sprite*)ptr)->rb_texture);
26
26
  }
27
27
 
28
- static void Sprite_free(void *ptr) {
29
- sfSprite_destroy(((Sprite *) ptr)->sprite);
28
+ static void Sprite_free(void* ptr) {
29
+ sfSprite_destroy(((Sprite*)ptr)->sprite);
30
30
  free(ptr);
31
31
  }
32
32
 
33
33
  static const rb_data_type_t Sprite_data_type = {
34
34
  .wrap_struct_name = "SFML::Sprite",
35
35
  .function = {.dmark = Sprite_mark, .dfree = Sprite_free, .dsize = NULL},
36
- .flags = RUBY_TYPED_FREE_IMMEDIATELY
37
- };
36
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY};
38
37
 
39
- static Sprite *Get_Sprite(VALUE self) {
40
- Sprite *ptr;
38
+ static Sprite* Get_Sprite(VALUE self) {
39
+ Sprite* ptr;
41
40
  TypedData_Get_Struct(self, Sprite, &Sprite_data_type, ptr);
42
41
  return ptr;
43
42
  }
44
43
 
45
- static sfSprite *Get_Sprite_Struct(VALUE self) {
44
+ static sfSprite* Get_Sprite_Struct(VALUE self) {
46
45
  return Get_Sprite(self)->sprite;
47
46
  }
48
47
 
49
- static VALUE Sprite_wrap(VALUE klass, sfSprite *sprite) {
50
- Sprite *ptr;
48
+ static VALUE Sprite_wrap(VALUE klass, sfSprite* sprite) {
49
+ Sprite* ptr;
51
50
 
52
51
  if (sprite == NULL) {
53
52
  rb_raise(rb_eRuntimeError, "failed to create sprite");
@@ -60,33 +59,55 @@ static VALUE Sprite_wrap(VALUE klass, sfSprite *sprite) {
60
59
  return TypedData_Wrap_Struct(klass, &Sprite_data_type, ptr);
61
60
  }
62
61
 
63
- static VALUE Sprite_new(int argc, VALUE *argv, VALUE klass) {
64
- VALUE rb_texture, self;
65
- Sprite *ptr;
62
+ /* call-seq:
63
+ * Sprite.new(texture) -> Sprite
64
+ *
65
+ * CSFML requires a texture at creation time -- its C API unconditionally
66
+ * dereferences a NULL texture argument rather than tolerating one, so unlike
67
+ * most other constructors here, the texture is not optional.
68
+ *
69
+ * @return [Sprite]
70
+ * @raise [ArgumentError] if +texture+ is not a Texture
71
+ */
72
+ static VALUE Sprite_new(VALUE klass, VALUE rb_texture) {
73
+ VALUE self;
74
+ Sprite* ptr;
66
75
 
67
- rb_scan_args(argc, argv, "01", &rb_texture);
68
-
69
- if (!NIL_P(rb_texture) && !rb_obj_is_kind_of(rb_texture, Get_Klass_Texture())) {
76
+ if (!rb_obj_is_kind_of(rb_texture, Get_Klass_Texture())) {
70
77
  raise_invalid_argument_class(Get_Klass_Texture());
71
78
  }
72
79
 
73
80
  ptr = malloc(sizeof(Sprite));
74
- ptr->sprite = sfSprite_create(NIL_P(rb_texture) ? NULL : Get_Texture_Struct(rb_texture));
75
- ptr->rb_texture = NIL_P(rb_texture) ? Qnil : rb_texture;
81
+ ptr->sprite = sfSprite_create(Get_Texture_Struct(rb_texture));
82
+ ptr->rb_texture = rb_texture;
76
83
 
77
84
  self = TypedData_Wrap_Struct(klass, &Sprite_data_type, ptr);
78
85
 
79
86
  return self;
80
87
  }
81
88
 
89
+ /* call-seq: copy -> Sprite
90
+ *
91
+ * Returns a deep copy of the object.
92
+ *
93
+ * @return [Sprite] an independent copy
94
+ */
82
95
  static VALUE Sprite_copy(VALUE self) {
83
- Sprite *ptr = Get_Sprite(self);
96
+ Sprite* ptr = Get_Sprite(self);
84
97
 
85
98
  return Sprite_wrap(Get_Klass_Sprite(), sfSprite_copy(ptr->sprite));
86
99
  }
87
100
 
101
+ /* call-seq:
102
+ * texture=(value) -> Texture or nil
103
+ *
104
+ * Sets the object's texture.
105
+ *
106
+ * @return [Texture, nil] +value+
107
+ * @raise [TypeError] if +value+ is neither nil nor a Texture
108
+ */
88
109
  static VALUE Sprite_set_texture(VALUE self, VALUE rb_texture) {
89
- Sprite *ptr = Get_Sprite(self);
110
+ Sprite* ptr = Get_Sprite(self);
90
111
 
91
112
  if (NIL_P(rb_texture)) {
92
113
  ptr->rb_texture = Qnil;
@@ -104,95 +125,236 @@ static VALUE Sprite_set_texture(VALUE self, VALUE rb_texture) {
104
125
  return rb_texture;
105
126
  }
106
127
 
128
+ /* call-seq: texture -> Texture or nil
129
+ *
130
+ * Returns the object's texture, or +nil+ if it has none.
131
+ *
132
+ * @return [Texture, nil]
133
+ */
107
134
  static VALUE Sprite_get_texture(VALUE self) {
108
135
  return Get_Sprite(self)->rb_texture;
109
136
  }
110
137
 
138
+ /* call-seq: texture_rect -> Rect
139
+ *
140
+ * Returns the sub-rectangle of the texture displayed on the object.
141
+ *
142
+ * @return [Rect] the sub-rectangle of the texture that gets displayed
143
+ */
111
144
  static VALUE Sprite_get_texture_rect(VALUE self) {
112
145
  return int_rect_to_rb(sfSprite_getTextureRect(Get_Sprite_Struct(self)));
113
146
  }
114
147
 
148
+ /* call-seq:
149
+ * texture_rect=(value) -> Rect
150
+ *
151
+ * Sets the sub-rectangle of the texture displayed on the object.
152
+ *
153
+ * @return [Rect] +value+
154
+ */
115
155
  static VALUE Sprite_set_texture_rect(VALUE self, VALUE rb_rect) {
116
156
  sfSprite_setTextureRect(Get_Sprite_Struct(self), int_rect_from_rb(rb_rect));
117
157
  return rb_rect;
118
158
  }
119
159
 
160
+ /* call-seq: color -> Color
161
+ *
162
+ * Returns the object's color.
163
+ *
164
+ * @return [Color] the tint color multiplied with the texture's pixels
165
+ */
120
166
  static VALUE Sprite_get_color(VALUE self) {
121
167
  return color_to_rb(sfSprite_getColor(Get_Sprite_Struct(self)));
122
168
  }
123
169
 
170
+ /* call-seq:
171
+ * color=(value) -> Color
172
+ *
173
+ * Sets the object's color.
174
+ *
175
+ * @return [Color] +value+
176
+ */
124
177
  static VALUE Sprite_set_color(VALUE self, VALUE rb_color) {
125
178
  sfSprite_setColor(Get_Sprite_Struct(self), color_from_rb(rb_color));
126
179
  return rb_color;
127
180
  }
128
181
 
182
+ /* call-seq: position -> Vector2
183
+ *
184
+ * Returns the object's position.
185
+ *
186
+ * @return [Vector2]
187
+ */
129
188
  static VALUE Sprite_get_position(VALUE self) {
130
189
  return vec2f_to_rb(sfSprite_getPosition(Get_Sprite_Struct(self)));
131
190
  }
132
191
 
192
+ /* call-seq:
193
+ * position=(value) -> Vector2
194
+ *
195
+ * Sets the object's position.
196
+ *
197
+ * @return [Vector2] +value+
198
+ */
133
199
  static VALUE Sprite_set_position(VALUE self, VALUE rb_position) {
134
200
  sfSprite_setPosition(Get_Sprite_Struct(self), vec2f_from_rb(rb_position));
135
201
  return rb_position;
136
202
  }
137
203
 
204
+ /* call-seq: rotation -> Float
205
+ *
206
+ * Returns the object's rotation, in degrees.
207
+ *
208
+ * @return [Float] degrees
209
+ */
138
210
  static VALUE Sprite_get_rotation(VALUE self) {
139
211
  return DBL2NUM(sfSprite_getRotation(Get_Sprite_Struct(self)));
140
212
  }
141
213
 
214
+ /* call-seq:
215
+ * rotation=(value) -> Float
216
+ *
217
+ * Sets the object's rotation, in degrees.
218
+ *
219
+ * @return [Float] +value+
220
+ */
142
221
  static VALUE Sprite_set_rotation(VALUE self, VALUE rb_rotation) {
143
222
  sfSprite_setRotation(Get_Sprite_Struct(self), NUM2DBL(rb_rotation));
144
223
  return rb_rotation;
145
224
  }
146
225
 
226
+ /* call-seq: scale -> Vector2
227
+ *
228
+ * Returns the object's scale factors.
229
+ *
230
+ * @return [Vector2]
231
+ */
147
232
  static VALUE Sprite_get_scale(VALUE self) {
148
233
  return vec2f_to_rb(sfSprite_getScale(Get_Sprite_Struct(self)));
149
234
  }
150
235
 
236
+ /* call-seq:
237
+ * scale=(value) -> Vector2
238
+ *
239
+ * Sets the object's scale factors.
240
+ *
241
+ * @return [Vector2] +value+
242
+ */
151
243
  static VALUE Sprite_set_scale(VALUE self, VALUE rb_scale) {
152
244
  sfSprite_setScale(Get_Sprite_Struct(self), vec2f_from_rb(rb_scale));
153
245
  return rb_scale;
154
246
  }
155
247
 
248
+ /* call-seq: origin -> Vector2
249
+ *
250
+ * Returns the object's origin.
251
+ *
252
+ * @return [Vector2]
253
+ */
156
254
  static VALUE Sprite_get_origin(VALUE self) {
157
255
  return vec2f_to_rb(sfSprite_getOrigin(Get_Sprite_Struct(self)));
158
256
  }
159
257
 
258
+ /* call-seq:
259
+ * origin=(value) -> Vector2
260
+ *
261
+ * Sets the object's origin.
262
+ *
263
+ * @return [Vector2] +value+
264
+ */
160
265
  static VALUE Sprite_set_origin(VALUE self, VALUE rb_origin) {
161
266
  sfSprite_setOrigin(Get_Sprite_Struct(self), vec2f_from_rb(rb_origin));
162
267
  return rb_origin;
163
268
  }
164
269
 
270
+ /* call-seq:
271
+ * move(offset) -> self
272
+ *
273
+ * Moves the object by +offset+.
274
+ *
275
+ * @return [self]
276
+ */
165
277
  static VALUE Sprite_move(VALUE self, VALUE rb_offset) {
166
278
  sfSprite_move(Get_Sprite_Struct(self), vec2f_from_rb(rb_offset));
167
279
  return self;
168
280
  }
169
281
 
282
+ /* call-seq:
283
+ * rotate(angle) -> self
284
+ *
285
+ * Rotates the object by +angle+ degrees.
286
+ *
287
+ * @return [self]
288
+ */
170
289
  static VALUE Sprite_rotate(VALUE self, VALUE rb_angle) {
171
290
  sfSprite_rotate(Get_Sprite_Struct(self), NUM2DBL(rb_angle));
172
291
  return self;
173
292
  }
174
293
 
294
+ /* call-seq:
295
+ * scale!(factors) -> self
296
+ *
297
+ * Scales the object by +factors+ relative to its current scale.
298
+ *
299
+ * @return [self]
300
+ */
175
301
  static VALUE Sprite_scale(VALUE self, VALUE rb_factors) {
176
302
  sfSprite_scale(Get_Sprite_Struct(self), vec2f_from_rb(rb_factors));
177
303
  return self;
178
304
  }
179
305
 
306
+ /* call-seq: transform -> Array<Float>
307
+ *
308
+ * Returns the object's 3x3 row-major transform matrix.
309
+ *
310
+ * @return [Array<Float>] the 9-element matrix (also available as #matrix)
311
+ */
180
312
  static VALUE Sprite_get_transform(VALUE self) {
181
313
  return Transform_MatrixToArray(sfSprite_getTransform(Get_Sprite_Struct(self)).matrix);
182
314
  }
183
315
 
316
+ /* call-seq: inverse_transform -> Array<Float>
317
+ *
318
+ * Returns the 3x3 row-major inverse of the object's transform matrix.
319
+ *
320
+ * @return [Array<Float>] the inverse of #transform
321
+ */
184
322
  static VALUE Sprite_get_inverse_transform(VALUE self) {
185
323
  return Transform_MatrixToArray(sfSprite_getInverseTransform(Get_Sprite_Struct(self)).matrix);
186
324
  }
187
325
 
326
+ /* call-seq: local_bounds -> Rect
327
+ *
328
+ * Returns the bounding box in local (untransformed) coordinates.
329
+ *
330
+ * @return [Rect] the bounding box in local coordinates, before any
331
+ * transform is applied
332
+ */
188
333
  static VALUE Sprite_get_local_bounds(VALUE self) {
189
334
  return rect_to_rb(sfSprite_getLocalBounds(Get_Sprite_Struct(self)));
190
335
  }
191
336
 
337
+ /* call-seq: global_bounds -> Rect
338
+ *
339
+ * Returns the bounding box after the transform is applied.
340
+ *
341
+ * @return [Rect] the bounding box in the parent's coordinate system, after
342
+ * the current transform is applied
343
+ */
192
344
  static VALUE Sprite_get_global_bounds(VALUE self) {
193
345
  return rect_to_rb(sfSprite_getGlobalBounds(Get_Sprite_Struct(self)));
194
346
  }
195
347
 
348
+ /* call-seq:
349
+ * draw(target, state) -> nil
350
+ *
351
+ * Part of the Drawable interface; call Target#draw instead of this
352
+ * directly.
353
+ *
354
+ * @return [nil]
355
+ * @raise [TypeError] if +target+ is not a Target or +state+ is not a
356
+ * RenderState
357
+ */
196
358
  static VALUE Sprite_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
197
359
  if (!rb_obj_is_kind_of(rb_target, Get_Klass_Target())) {
198
360
  raise_invalid_argument_class(Get_Klass_Target());
@@ -208,12 +370,41 @@ static VALUE Sprite_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
208
370
  return Qnil;
209
371
  }
210
372
 
211
- void Init_Sprite(VALUE rb_module) {
212
- rb_cSprite = rb_define_class_under(rb_module, "Sprite", rb_cObject);
373
+ /* Document-class: SFML::Sprite
374
+ * A drawable representation of a Texture (or a sub-rectangle of one),
375
+ * positioned, rotated, scaled and tinted like any other Transformable
376
+ * object.
377
+ *
378
+ * Includes +Drawable+.
379
+ *
380
+ * @!attribute texture
381
+ * The object's texture, or +nil+ if it has none.
382
+ * @return [Texture, nil]
383
+ * @!attribute texture_rect
384
+ * The sub-rectangle of the texture displayed on the object.
385
+ * @return [Rect]
386
+ * @!attribute color
387
+ * The object's color.
388
+ * @return [Color]
389
+ * @!attribute position
390
+ * The object's position.
391
+ * @return [Vector2]
392
+ * @!attribute rotation
393
+ * The object's rotation, in degrees.
394
+ * @return [Float] degrees
395
+ * @!attribute scale
396
+ * The object's scale factors.
397
+ * @return [Vector2]
398
+ * @!attribute origin
399
+ * The object's origin.
400
+ * @return [Vector2]
401
+ */
402
+ void Init_Sprite(VALUE rb_mSFML) {
403
+ rb_cSprite = rb_define_class_under(rb_mSFML, "Sprite", rb_cObject);
213
404
 
214
405
  rb_include_module(rb_cSprite, Get_Module_Drawable());
215
406
 
216
- rb_define_singleton_method(rb_cSprite, "new", Sprite_new, -1);
407
+ rb_define_singleton_method(rb_cSprite, "new", Sprite_new, 1);
217
408
 
218
409
  rb_define_method(rb_cSprite, "copy", Sprite_copy, 0);
219
410