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
data/ext/system/vec3.c CHANGED
@@ -12,19 +12,31 @@ typedef struct {
12
12
 
13
13
  static VALUE rb_cVector3;
14
14
 
15
- static void Vector3_free(void *ptr) {
15
+ static void Vector3_free(void* ptr) {
16
16
  free(ptr);
17
17
  }
18
18
 
19
19
  static const rb_data_type_t Vector3_data_type = {
20
20
  .wrap_struct_name = "SFML::Vector3",
21
21
  .function = {.dmark = NULL, .dfree = Vector3_free, .dsize = NULL},
22
- .flags = RUBY_TYPED_FREE_IMMEDIATELY
23
- };
24
-
25
- static VALUE Vector3_new(int argc, VALUE *argv, VALUE klass) {
22
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY};
23
+
24
+ /* call-seq:
25
+ * Vector3.new -> Vector3(0, 0, 0)
26
+ * Vector3.new(x, y, z) -> Vector3(x, y, z)
27
+ * Vector3.new([x, y, z]) -> Vector3(x, y, z)
28
+ * Vector3.new(other_vector3) -> copy of +other_vector3+
29
+ *
30
+ * Creates a new 3D vector from three coordinates, a 3-element Array, or
31
+ * another Vector3.
32
+ *
33
+ * @return [Vector3]
34
+ * @raise [ArgumentError] if given an Array shorter than 3 elements, or an
35
+ * argument count other than 0, 1 or 3
36
+ */
37
+ static VALUE Vector3_new(int argc, VALUE* argv, VALUE klass) {
26
38
  VALUE self;
27
- Vector3 *ptr;
39
+ Vector3* ptr;
28
40
  float x = 0;
29
41
  float y = 0;
30
42
  float z = 0;
@@ -51,6 +63,11 @@ static VALUE Vector3_new(int argc, VALUE *argv, VALUE klass) {
51
63
  }
52
64
 
53
65
  ptr = malloc(sizeof(Vector3));
66
+
67
+ if (ptr == NULL) {
68
+ rb_raise(rb_eNoMemError, "failed to allocate vector");
69
+ }
70
+
54
71
  ptr->vec.x = x;
55
72
  ptr->vec.y = y;
56
73
  ptr->vec.z = z;
@@ -60,41 +77,92 @@ static VALUE Vector3_new(int argc, VALUE *argv, VALUE klass) {
60
77
  return self;
61
78
  }
62
79
 
80
+ /* call-seq: x -> Float
81
+ *
82
+ * Returns the X component of the vector.
83
+ *
84
+ * @return [Float] the X component
85
+ */
63
86
  static VALUE Vector3_get_x(VALUE self) {
64
- return DBL2NUM(((Vector3 *) Get_Vector3_Struct(self))->vec.x);
87
+ return DBL2NUM(((Vector3*)Get_Vector3_Struct(self))->vec.x);
65
88
  }
66
89
 
90
+ /* call-seq: y -> Float
91
+ *
92
+ * Returns the Y component of the vector.
93
+ *
94
+ * @return [Float] the Y component
95
+ */
67
96
  static VALUE Vector3_get_y(VALUE self) {
68
- return DBL2NUM(((Vector3 *) Get_Vector3_Struct(self))->vec.y);
97
+ return DBL2NUM(((Vector3*)Get_Vector3_Struct(self))->vec.y);
69
98
  }
70
99
 
100
+ /* call-seq: z -> Float
101
+ *
102
+ * Returns the Z component of the vector.
103
+ *
104
+ * @return [Float] the Z component
105
+ */
71
106
  static VALUE Vector3_get_z(VALUE self) {
72
- return DBL2NUM(((Vector3 *) Get_Vector3_Struct(self))->vec.z);
107
+ return DBL2NUM(((Vector3*)Get_Vector3_Struct(self))->vec.z);
73
108
  }
74
109
 
110
+ /* call-seq:
111
+ * x=(value) -> Float
112
+ *
113
+ * Sets the X component. +value+ is any Float-convertible number.
114
+ *
115
+ * @return [Float] +value+
116
+ */
75
117
  static VALUE Vector3_set_x(VALUE self, VALUE rb_x) {
76
- ((Vector3 *) Get_Vector3_Struct(self))->vec.x = NUM2DBL(rb_x);
118
+ ((Vector3*)Get_Vector3_Struct(self))->vec.x = NUM2DBL(rb_x);
77
119
  return rb_x;
78
120
  }
79
121
 
122
+ /* call-seq:
123
+ * y=(value) -> Float
124
+ *
125
+ * Sets the Y component. +value+ is any Float-convertible number.
126
+ *
127
+ * @return [Float] +value+
128
+ */
80
129
  static VALUE Vector3_set_y(VALUE self, VALUE rb_y) {
81
- ((Vector3 *) Get_Vector3_Struct(self))->vec.y = NUM2DBL(rb_y);
130
+ ((Vector3*)Get_Vector3_Struct(self))->vec.y = NUM2DBL(rb_y);
82
131
  return rb_y;
83
132
  }
84
133
 
134
+ /* call-seq:
135
+ * z=(value) -> Float
136
+ *
137
+ * Sets the Z component. +value+ is any Float-convertible number.
138
+ *
139
+ * @return [Float] +value+
140
+ */
85
141
  static VALUE Vector3_set_z(VALUE self, VALUE rb_z) {
86
- ((Vector3 *) Get_Vector3_Struct(self))->vec.z = NUM2DBL(rb_z);
142
+ ((Vector3*)Get_Vector3_Struct(self))->vec.z = NUM2DBL(rb_z);
87
143
  return rb_z;
88
144
  }
89
145
 
146
+ /* call-seq: to_a -> Array
147
+ *
148
+ * Returns the vector's components as a three-element Array.
149
+ *
150
+ * @return [Array<Float>] +[x, y, z]+
151
+ */
90
152
  static VALUE Vector3_to_a(VALUE self) {
91
- Vector3 *vec = Get_Vector3_Struct(self);
153
+ Vector3* vec = Get_Vector3_Struct(self);
92
154
 
93
155
  return rb_ary_new_from_args(3, DBL2NUM(vec->vec.x), DBL2NUM(vec->vec.y), DBL2NUM(vec->vec.z));
94
156
  }
95
157
 
158
+ /* call-seq: each { |component| ... } -> self
159
+ *
160
+ * Yields +x+, +y+, then +z+.
161
+ *
162
+ * @return [self]
163
+ */
96
164
  static VALUE Vector3_each(VALUE self) {
97
- Vector3 *vec = Get_Vector3_Struct(self);
165
+ Vector3* vec = Get_Vector3_Struct(self);
98
166
 
99
167
  rb_yield(DBL2NUM(vec->vec.x));
100
168
  rb_yield(DBL2NUM(vec->vec.y));
@@ -103,16 +171,29 @@ static VALUE Vector3_each(VALUE self) {
103
171
  return self;
104
172
  }
105
173
 
174
+ /* call-seq: size -> Integer
175
+ *
176
+ * Returns the number of components, always 3.
177
+ *
178
+ * @return [Integer] always 3
179
+ */
106
180
  static VALUE Vector3_size(VALUE self) {
107
181
  return INT2NUM(3);
108
182
  }
109
183
 
184
+ /* call-seq:
185
+ * self == other -> true or false
186
+ *
187
+ * +other+ may be a Vector3 or a 3-element Array.
188
+ *
189
+ * @return [Boolean]
190
+ */
110
191
  static VALUE Vector3_eql(VALUE self, VALUE rb_other) {
111
- Vector3 *a = Get_Vector3_Struct(self);
192
+ Vector3* a = Get_Vector3_Struct(self);
112
193
  sfVector3f b;
113
194
 
114
195
  if (rb_obj_is_kind_of(rb_other, rb_cVector3)) {
115
- b = ((Vector3 *) Get_Vector3_Struct(rb_other))->vec;
196
+ b = ((Vector3*)Get_Vector3_Struct(rb_other))->vec;
116
197
  } else if (RB_TYPE_P(rb_other, T_ARRAY) && RARRAY_LEN(rb_other) >= 3) {
117
198
  b = vec3f_from_rb(rb_other);
118
199
  } else {
@@ -122,29 +203,56 @@ static VALUE Vector3_eql(VALUE self, VALUE rb_other) {
122
203
  return BOOL2RB(a->vec.x == b.x && a->vec.y == b.y && a->vec.z == b.z);
123
204
  }
124
205
 
206
+ /* call-seq:
207
+ * self + other -> Vector3
208
+ *
209
+ * +other+ may be a Vector3 or a 3-element Array.
210
+ *
211
+ * @return [Vector3] componentwise sum
212
+ */
125
213
  static VALUE Vector3_add(VALUE self, VALUE rb_other) {
126
- Vector3 *a = Get_Vector3_Struct(self);
214
+ Vector3* a = Get_Vector3_Struct(self);
127
215
  sfVector3f b = vec3f_from_rb(rb_other);
128
216
 
129
- return vec3f_to_rb((sfVector3f) {a->vec.x + b.x, a->vec.y + b.y, a->vec.z + b.z});
217
+ return vec3f_to_rb((sfVector3f){a->vec.x + b.x, a->vec.y + b.y, a->vec.z + b.z});
130
218
  }
131
219
 
220
+ /* call-seq:
221
+ * self - other -> Vector3
222
+ *
223
+ * +other+ may be a Vector3 or a 3-element Array.
224
+ *
225
+ * @return [Vector3] componentwise difference
226
+ */
132
227
  static VALUE Vector3_sub(VALUE self, VALUE rb_other) {
133
- Vector3 *a = Get_Vector3_Struct(self);
228
+ Vector3* a = Get_Vector3_Struct(self);
134
229
  sfVector3f b = vec3f_from_rb(rb_other);
135
230
 
136
- return vec3f_to_rb((sfVector3f) {a->vec.x - b.x, a->vec.y - b.y, a->vec.z - b.z});
231
+ return vec3f_to_rb((sfVector3f){a->vec.x - b.x, a->vec.y - b.y, a->vec.z - b.z});
137
232
  }
138
233
 
234
+ /* call-seq:
235
+ * self * scalar -> Vector3
236
+ *
237
+ * Multiplies all three components by +scalar+.
238
+ *
239
+ * @return [Vector3]
240
+ */
139
241
  static VALUE Vector3_mul(VALUE self, VALUE rb_scalar) {
140
- Vector3 *a = Get_Vector3_Struct(self);
242
+ Vector3* a = Get_Vector3_Struct(self);
141
243
  float scalar = NUM2DBL(rb_scalar);
142
244
 
143
- return vec3f_to_rb((sfVector3f) {a->vec.x * scalar, a->vec.y * scalar, a->vec.z * scalar});
245
+ return vec3f_to_rb((sfVector3f){a->vec.x * scalar, a->vec.y * scalar, a->vec.z * scalar});
144
246
  }
145
247
 
248
+ /* call-seq: to_s -> String
249
+ *
250
+ * Returns a human-readable +"(x, y, z)"+ representation.
251
+ *
252
+ * @return [String] +"(x, y, z)"+
253
+ */
146
254
  static VALUE Vector3_to_s(VALUE self) {
147
- Vector3 *a = Get_Vector3_Struct(self);
255
+ Vector3* a = Get_Vector3_Struct(self);
148
256
  char buffer[96];
149
257
 
150
258
  snprintf(buffer, sizeof(buffer), "(%g, %g, %g)", a->vec.x, a->vec.y, a->vec.z);
@@ -152,8 +260,29 @@ static VALUE Vector3_to_s(VALUE self) {
152
260
  return rb_str_new2(buffer);
153
261
  }
154
262
 
155
- void Init_Vector3(VALUE rb_module) {
156
- rb_cVector3 = rb_define_class_under(rb_module, "Vector3", rb_cObject);
263
+ /* Document-class: SFML::Vector3
264
+ * A 3D vector of floats, used for positions, sizes and directions in 3D
265
+ * space (e.g. Listener and SoundSource position/direction/velocity).
266
+ *
267
+ * Includes +Enumerable+ and behaves like a 3-element sequence: it responds to
268
+ * #each and #to_a, and can be compared or combined with a plain
269
+ * +[x, y, z]+ Array anywhere a Vector3 is accepted.
270
+ *
271
+ * @!attribute x
272
+ * Returns the X component.
273
+ *
274
+ * @return [Float] the X component
275
+ * @!attribute y
276
+ * Returns the Y component.
277
+ *
278
+ * @return [Float] the Y component
279
+ * @!attribute z
280
+ * Returns the Z component.
281
+ *
282
+ * @return [Float] the Z component
283
+ */
284
+ void Init_Vector3(VALUE rb_mSFML) {
285
+ rb_cVector3 = rb_define_class_under(rb_mSFML, "Vector3", rb_cObject);
157
286
 
158
287
  rb_include_module(rb_cVector3, rb_mEnumerable);
159
288
 
@@ -182,15 +311,15 @@ VALUE Get_Klass_Vector3(void) {
182
311
  return rb_cVector3;
183
312
  }
184
313
 
185
- void *Get_Vector3_Struct(VALUE self) {
186
- Vector3 *ptr;
314
+ void* Get_Vector3_Struct(VALUE self) {
315
+ Vector3* ptr;
187
316
  TypedData_Get_Struct(self, Vector3, &Vector3_data_type, ptr);
188
317
  return ptr;
189
318
  }
190
319
 
191
320
  sfVector3f vec3f_from_rb(VALUE rb_vec) {
192
321
  if (rb_obj_is_kind_of(rb_vec, rb_cVector3)) {
193
- return ((Vector3 *) Get_Vector3_Struct(rb_vec))->vec;
322
+ return ((Vector3*)Get_Vector3_Struct(rb_vec))->vec;
194
323
  }
195
324
 
196
325
  if (RB_TYPE_P(rb_vec, T_ARRAY)) {
@@ -198,20 +327,22 @@ sfVector3f vec3f_from_rb(VALUE rb_vec) {
198
327
  raise_invalid_array_length(3);
199
328
  }
200
329
 
201
- return (sfVector3f) {
202
- (float) NUM2DBL(rb_ary_entry(rb_vec, 0)),
203
- (float) NUM2DBL(rb_ary_entry(rb_vec, 1)),
204
- (float) NUM2DBL(rb_ary_entry(rb_vec, 2))
205
- };
330
+ return (sfVector3f){(float)NUM2DBL(rb_ary_entry(rb_vec, 0)),
331
+ (float)NUM2DBL(rb_ary_entry(rb_vec, 1)),
332
+ (float)NUM2DBL(rb_ary_entry(rb_vec, 2))};
206
333
  }
207
334
 
208
335
  raise_invalid_argument_class(rb_cVector3);
209
336
 
210
- return (sfVector3f) {0, 0, 0};
337
+ return (sfVector3f){0, 0, 0};
211
338
  }
212
339
 
213
340
  VALUE vec3f_to_rb(sfVector3f c_vec) {
214
- Vector3 *ptr = malloc(sizeof(Vector3));
341
+ Vector3* ptr = malloc(sizeof(Vector3));
342
+
343
+ if (ptr == NULL) {
344
+ rb_raise(rb_eNoMemError, "failed to allocate vector");
345
+ }
215
346
 
216
347
  ptr->vec = c_vec;
217
348
 
@@ -5,41 +5,61 @@
5
5
 
6
6
  #include "core/sfml.h"
7
7
 
8
- static void unicode_char_to_utf8(sfChar32 code, char buffer[4], int *length) {
8
+ static void unicode_char_to_utf8(sfChar32 code, char buffer[4], int* length) {
9
9
  if (code < 0x80) {
10
- buffer[0] = (char) code;
10
+ buffer[0] = (char)code;
11
11
  *length = 1;
12
12
  } else if (code < 0x800) {
13
- buffer[0] = (char) (0xC0 | (code >> 6));
14
- buffer[1] = (char) (0x80 | (code & 0x3F));
13
+ buffer[0] = (char)(0xC0 | (code >> 6));
14
+ buffer[1] = (char)(0x80 | (code & 0x3F));
15
15
  *length = 2;
16
16
  } else if (code < 0x10000) {
17
- buffer[0] = (char) (0xE0 | (code >> 12));
18
- buffer[1] = (char) (0x80 | ((code >> 6) & 0x3F));
19
- buffer[2] = (char) (0x80 | (code & 0x3F));
17
+ buffer[0] = (char)(0xE0 | (code >> 12));
18
+ buffer[1] = (char)(0x80 | ((code >> 6) & 0x3F));
19
+ buffer[2] = (char)(0x80 | (code & 0x3F));
20
20
  *length = 3;
21
21
  } else {
22
- buffer[0] = (char) (0xF0 | (code >> 18));
23
- buffer[1] = (char) (0x80 | ((code >> 12) & 0x3F));
24
- buffer[2] = (char) (0x80 | ((code >> 6) & 0x3F));
25
- buffer[3] = (char) (0x80 | (code & 0x3F));
22
+ buffer[0] = (char)(0xF0 | (code >> 18));
23
+ buffer[1] = (char)(0x80 | ((code >> 12) & 0x3F));
24
+ buffer[2] = (char)(0x80 | ((code >> 6) & 0x3F));
25
+ buffer[3] = (char)(0x80 | (code & 0x3F));
26
26
  *length = 4;
27
27
  }
28
28
  }
29
29
 
30
+ /* call-seq: string -> String
31
+ *
32
+ * Returns the current system clipboard contents as a plain String.
33
+ *
34
+ * @return [String] the current system clipboard contents
35
+ */
30
36
  static VALUE Clipboard_get_string(VALUE module) {
31
- const char *string = sfClipboard_getString();
37
+ const char* string = sfClipboard_getString();
32
38
 
33
39
  return rb_utf8_str_new_cstr(string != NULL ? string : "");
34
40
  }
35
41
 
42
+ /* call-seq:
43
+ * string=(value) -> String
44
+ *
45
+ * Sets the system clipboard to +value+.
46
+ *
47
+ * @return [String] +value+
48
+ */
36
49
  static VALUE Clipboard_set_string(VALUE module, VALUE rb_text) {
37
50
  sfClipboard_setString(StringValueCStr(rb_text));
38
51
  return rb_text;
39
52
  }
40
53
 
54
+ /* call-seq: unicode_string -> String
55
+ *
56
+ * Returns the current system clipboard contents, decoding UTF-32 to UTF-8.
57
+ *
58
+ * @return [String] the current system clipboard contents, decoded from
59
+ * UTF-32 to a UTF-8 Ruby String
60
+ */
41
61
  static VALUE Clipboard_get_unicode_string(VALUE module) {
42
- const sfChar32 *chars = sfClipboard_getUnicodeString();
62
+ const sfChar32* chars = sfClipboard_getUnicodeString();
43
63
  VALUE string = rb_utf8_str_new("", 0);
44
64
 
45
65
  if (chars == NULL) {
@@ -57,10 +77,17 @@ static VALUE Clipboard_get_unicode_string(VALUE module) {
57
77
  return string;
58
78
  }
59
79
 
80
+ /* call-seq:
81
+ * unicode_string=(value) -> String
82
+ *
83
+ * Sets the system clipboard to +value+, encoding it to UTF-32 first.
84
+ *
85
+ * @return [String] +value+
86
+ */
60
87
  static VALUE Clipboard_set_unicode_string(VALUE module, VALUE rb_text) {
61
88
  VALUE codepoints;
62
89
  long count;
63
- sfChar32 *chars;
90
+ sfChar32* chars;
64
91
 
65
92
  StringValue(rb_text);
66
93
  codepoints = rb_funcall(rb_text, rb_intern("codepoints"), 0);
@@ -68,7 +95,7 @@ static VALUE Clipboard_set_unicode_string(VALUE module, VALUE rb_text) {
68
95
  chars = ALLOC_N(sfChar32, count + 1);
69
96
 
70
97
  for (long i = 0; i < count; i++) {
71
- chars[i] = (sfChar32) NUM2UINT(rb_ary_entry(codepoints, i));
98
+ chars[i] = (sfChar32)NUM2UINT(rb_ary_entry(codepoints, i));
72
99
  }
73
100
 
74
101
  chars[count] = 0;
@@ -79,8 +106,11 @@ static VALUE Clipboard_set_unicode_string(VALUE module, VALUE rb_text) {
79
106
  return rb_text;
80
107
  }
81
108
 
82
- void Init_Clipboard(VALUE rb_module) {
83
- VALUE rb_mClipboard = rb_define_module_under(rb_module, "Clipboard");
109
+ /* Document-module: SFML::Clipboard
110
+ * Access to the system clipboard, as plain text or Unicode text.
111
+ */
112
+ void Init_Clipboard(VALUE rb_mSFML) {
113
+ VALUE rb_mClipboard = rb_define_module_under(rb_mSFML, "Clipboard");
84
114
 
85
115
  rb_define_module_function(rb_mClipboard, "string", Clipboard_get_string, 0);
86
116
  rb_define_module_function(rb_mClipboard, "string=", Clipboard_set_string, 1);
data/ext/window/context.c CHANGED
@@ -8,24 +8,31 @@
8
8
 
9
9
  static VALUE rb_cContext;
10
10
 
11
- static void Context_free(void *ptr) {
11
+ static void Context_free(void* ptr) {
12
12
  sfContext_destroy(ptr);
13
13
  }
14
14
 
15
15
  static const rb_data_type_t Context_data_type = {
16
16
  .wrap_struct_name = "SFML::Context",
17
17
  .function = {.dmark = NULL, .dfree = Context_free, .dsize = NULL},
18
- .flags = RUBY_TYPED_FREE_IMMEDIATELY
19
- };
18
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY};
20
19
 
21
- static sfContext *Get_Context_Struct(VALUE self) {
22
- sfContext *ptr;
20
+ static sfContext* Get_Context_Struct(VALUE self) {
21
+ sfContext* ptr;
23
22
  TypedData_Get_Struct(self, sfContext, &Context_data_type, ptr);
24
23
  return ptr;
25
24
  }
26
25
 
26
+ /* call-seq:
27
+ * Context.new -> Context
28
+ *
29
+ * Creates and activates a new OpenGL context on the current thread.
30
+ *
31
+ * @return [Context]
32
+ * @raise [RuntimeError] if context creation fails
33
+ */
27
34
  static VALUE Context_new(VALUE klass) {
28
- sfContext *context = sfContext_create();
35
+ sfContext* context = sfContext_create();
29
36
  VALUE self;
30
37
 
31
38
  if (context == NULL) {
@@ -37,28 +44,71 @@ static VALUE Context_new(VALUE klass) {
37
44
  return self;
38
45
  }
39
46
 
47
+ /* call-seq:
48
+ * extension_available?(name) -> true or false
49
+ *
50
+ * Returns +true+ if the OpenGL extension +name+ is available in the currently
51
+ * active context.
52
+ *
53
+ * @return [Boolean] whether the OpenGL extension +name+ is available in the
54
+ * currently active context
55
+ */
40
56
  static VALUE Context_extension_available(VALUE klass, VALUE rb_name) {
41
57
  return BOOL2RB(sfContext_isExtensionAvailable(StringValueCStr(rb_name)));
42
58
  }
43
59
 
60
+ /* call-seq:
61
+ * active=(value) -> true or false
62
+ *
63
+ * Activates or deactivates this context as the current one on the calling
64
+ * thread.
65
+ *
66
+ * @return [Boolean] whether activation succeeded
67
+ */
44
68
  static VALUE Context_set_active(VALUE self, VALUE rb_active) {
45
69
  return BOOL2RB(sfContext_setActive(Get_Context_Struct(self), RTEST(rb_active)));
46
70
  }
47
71
 
72
+ /* call-seq:
73
+ * function(name) -> Integer
74
+ *
75
+ * Returns the address of the OpenGL function +name+ as an Integer, or 0 when
76
+ * it is not available.
77
+ *
78
+ * @return [Integer] the address of the OpenGL function +name+, as a raw
79
+ * pointer value, or 0 if it is not available
80
+ */
48
81
  static VALUE Context_get_function(VALUE klass, VALUE rb_name) {
49
- return ULL2NUM((unsigned long long) (uintptr_t) sfContext_getFunction(StringValueCStr(rb_name)));
82
+ return ULL2NUM((unsigned long long)(uintptr_t)sfContext_getFunction(StringValueCStr(rb_name)));
50
83
  }
51
84
 
85
+ /* call-seq: settings -> ContextSettings
86
+ *
87
+ * Returns the settings this context was created with.
88
+ *
89
+ * @return [ContextSettings] the settings this context was created with
90
+ */
52
91
  static VALUE Context_get_settings(VALUE self) {
53
92
  return context_settings_to_rb(sfContext_getSettings(Get_Context_Struct(self)));
54
93
  }
55
94
 
95
+ /* call-seq: active_context_id -> Integer
96
+ *
97
+ * Returns the unique identifier of the currently active context on the
98
+ * calling thread, or 0 if none is active.
99
+ *
100
+ * @return [Integer] the unique identifier of the currently active context on
101
+ * the calling thread, or 0 if none is active
102
+ */
56
103
  static VALUE Context_active_context_id(VALUE klass) {
57
104
  return ULL2NUM(sfContext_getActiveContextId());
58
105
  }
59
106
 
60
- void Init_Context(VALUE rb_module) {
61
- rb_cContext = rb_define_class_under(rb_module, "Context", rb_cObject);
107
+ /* Document-class: SFML::Context
108
+ * A raw OpenGL context, usable off-screen or on a thread without a Window.
109
+ */
110
+ void Init_Context(VALUE rb_mSFML) {
111
+ rb_cContext = rb_define_class_under(rb_mSFML, "Context", rb_cObject);
62
112
 
63
113
  rb_define_singleton_method(rb_cContext, "new", Context_new, 0);
64
114
  rb_define_singleton_method(rb_cContext, "extension_available?", Context_extension_available, 1);