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/window/event.c CHANGED
@@ -14,23 +14,35 @@
14
14
 
15
15
  static VALUE rb_cEvent;
16
16
 
17
- static sfEvent *Event_create() {
18
- return malloc(sizeof(sfEvent));
17
+ static sfEvent* Event_create() {
18
+ sfEvent* event = malloc(sizeof(sfEvent));
19
+
20
+ if (event == NULL) {
21
+ rb_raise(rb_eNoMemError, "failed to allocate event");
22
+ }
23
+
24
+ return event;
19
25
  }
20
26
 
21
- static void Event_free(void *ptr) {
27
+ static void Event_free(void* ptr) {
22
28
  free(ptr);
23
29
  }
24
30
 
25
31
  static const rb_data_type_t Event_data_type = {
26
32
  .wrap_struct_name = "SFML::Event",
27
33
  .function = {.dmark = NULL, .dfree = Event_free, .dsize = NULL},
28
- .flags = RUBY_TYPED_FREE_IMMEDIATELY
29
- };
30
-
34
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY};
35
+
36
+ /* call-seq:
37
+ * Event.new -> Event
38
+ *
39
+ * Creates an empty, uninitialized event.
40
+ *
41
+ * @return [Event]
42
+ */
31
43
  static VALUE Event_new(VALUE klass) {
32
44
  VALUE self;
33
- sfEvent *event;
45
+ sfEvent* event;
34
46
 
35
47
  event = Event_create();
36
48
  self = TypedData_Wrap_Struct(klass, &Event_data_type, event);
@@ -40,26 +52,55 @@ static VALUE Event_new(VALUE klass) {
40
52
  return self;
41
53
  }
42
54
 
55
+ /* call-seq: initialize -> self
56
+ *
57
+ * Does nothing; instances are built internally by the event-polling methods.
58
+ *
59
+ * @private No-op; objects of this class are only ever constructed
60
+ * internally (e.g. by #poll_event!).
61
+ * @return [self]
62
+ */
43
63
  static VALUE Event_init(VALUE self) {
44
64
  return self;
45
65
  }
46
66
 
67
+ /* call-seq: type -> String
68
+ *
69
+ * Returns the event's kind as a String, such as +"closed"+ or +"key-pressed"+.
70
+ *
71
+ * @return [String] the event's kind, e.g. +"closed"+, +"key-pressed"+,
72
+ * +"mouse-moved"+ (see SFML::Window#poll_event!)
73
+ */
47
74
  static VALUE Event_type(VALUE self) {
48
75
  return rb_str_new2(get_event_name(Get_Event_Struct(self)->type));
49
76
  }
50
77
 
78
+ /* call-seq: size -> Vector2
79
+ *
80
+ * Returns the new size carried by a +"resized"+ event.
81
+ *
82
+ * @return [Vector2] the new size, for a +"resized"+ event
83
+ */
51
84
  static VALUE Event_get_size(VALUE self) {
52
85
  sfVector2u size = Get_Event_Struct(self)->size.size;
53
86
 
54
- return vec2f_to_rb((sfVector2f) {(float) size.x, (float) size.y});
87
+ return vec2f_to_rb((sfVector2f){(float)size.x, (float)size.y});
55
88
  }
56
89
 
90
+ /* call-seq: key -> Hash
91
+ *
92
+ * Returns the key descriptor Hash for a key press or release event.
93
+ *
94
+ * @return [Hash] +:code+, +:scancode+, +:alt+, +:control+, +:shift+,
95
+ * +:system+, for a +"key-pressed"+/+"key-released"+ event
96
+ */
57
97
  static VALUE Event_get_key(VALUE self) {
58
- sfKeyEvent *event = &Get_Event_Struct(self)->key;
98
+ sfKeyEvent* event = &Get_Event_Struct(self)->key;
59
99
  VALUE hash = rb_hash_new();
60
100
 
61
101
  rb_hash_aset(hash, ID2SYM(rb_intern("code")), ID2SYM(rb_intern(get_key_event(event->code))));
62
- rb_hash_aset(hash, ID2SYM(rb_intern("scancode")), rb_str_new2(sfKeyboard_getDescription(event->scancode)));
102
+ rb_hash_aset(hash, ID2SYM(rb_intern("scancode")),
103
+ rb_str_new2(sfKeyboard_getDescription(event->scancode)));
63
104
  rb_hash_aset(hash, ID2SYM(rb_intern("alt")), BOOL2RB(event->alt));
64
105
  rb_hash_aset(hash, ID2SYM(rb_intern("control")), BOOL2RB(event->control));
65
106
  rb_hash_aset(hash, ID2SYM(rb_intern("shift")), BOOL2RB(event->shift));
@@ -73,76 +114,127 @@ static VALUE unicode_to_utf8(uint32_t code) {
73
114
  int length = 0;
74
115
 
75
116
  if (code < 0x80) {
76
- buffer[length++] = (char) code;
117
+ buffer[length++] = (char)code;
77
118
  } else if (code < 0x800) {
78
- buffer[length++] = (char) (0xC0 | (code >> 6));
79
- buffer[length++] = (char) (0x80 | (code & 0x3F));
119
+ buffer[length++] = (char)(0xC0 | (code >> 6));
120
+ buffer[length++] = (char)(0x80 | (code & 0x3F));
80
121
  } else if (code < 0x10000) {
81
- buffer[length++] = (char) (0xE0 | (code >> 12));
82
- buffer[length++] = (char) (0x80 | ((code >> 6) & 0x3F));
83
- buffer[length++] = (char) (0x80 | (code & 0x3F));
122
+ buffer[length++] = (char)(0xE0 | (code >> 12));
123
+ buffer[length++] = (char)(0x80 | ((code >> 6) & 0x3F));
124
+ buffer[length++] = (char)(0x80 | (code & 0x3F));
84
125
  } else {
85
- buffer[length++] = (char) (0xF0 | (code >> 18));
86
- buffer[length++] = (char) (0x80 | ((code >> 12) & 0x3F));
87
- buffer[length++] = (char) (0x80 | ((code >> 6) & 0x3F));
88
- buffer[length++] = (char) (0x80 | (code & 0x3F));
126
+ buffer[length++] = (char)(0xF0 | (code >> 18));
127
+ buffer[length++] = (char)(0x80 | ((code >> 12) & 0x3F));
128
+ buffer[length++] = (char)(0x80 | ((code >> 6) & 0x3F));
129
+ buffer[length++] = (char)(0x80 | (code & 0x3F));
89
130
  }
90
131
 
91
132
  return rb_utf8_str_new(buffer, length);
92
133
  }
93
134
 
135
+ /* call-seq: text -> String
136
+ *
137
+ * Returns the entered character for a +"text-entered"+ event.
138
+ *
139
+ * @return [String] the entered character, decoded from Unicode, for a
140
+ * +"text-entered"+ event
141
+ */
94
142
  static VALUE Event_get_text(VALUE self) {
95
143
  return unicode_to_utf8(Get_Event_Struct(self)->text.unicode);
96
144
  }
97
145
 
146
+ /* call-seq: mouse_move -> Vector2
147
+ *
148
+ * Returns the new cursor position for a +"mouse-moved"+ event.
149
+ *
150
+ * @return [Vector2] the new cursor position, for a +"mouse-moved"+ event
151
+ */
98
152
  static VALUE Event_get_mouse_move(VALUE self) {
99
153
  sfVector2i position = Get_Event_Struct(self)->mouseMove.position;
100
154
 
101
- return vec2f_to_rb((sfVector2f) {(float) position.x, (float) position.y});
155
+ return vec2f_to_rb((sfVector2f){(float)position.x, (float)position.y});
102
156
  }
103
157
 
158
+ /* call-seq: mouse_move_raw -> Vector2
159
+ *
160
+ * Returns the unfiltered relative motion for a +"mouse-moved-raw"+ event.
161
+ *
162
+ * @return [Vector2] unfiltered relative motion, for a +"mouse-moved-raw"+
163
+ * event
164
+ */
104
165
  static VALUE Event_get_mouse_move_raw(VALUE self) {
105
166
  sfVector2i delta = Get_Event_Struct(self)->mouseMoveRaw.delta;
106
167
 
107
- return vec2f_to_rb((sfVector2f) {(float) delta.x, (float) delta.y});
168
+ return vec2f_to_rb((sfVector2f){(float)delta.x, (float)delta.y});
108
169
  }
109
170
 
171
+ /* call-seq: mouse_button -> Hash
172
+ *
173
+ * Returns the button descriptor Hash for a mouse press or release event.
174
+ *
175
+ * @return [Hash] +:button+, +:position+, for a
176
+ * +"mouse-button-pressed"+/+"mouse-button-released"+ event
177
+ */
110
178
  static VALUE Event_get_mouse_button(VALUE self) {
111
- sfMouseButtonEvent *event = &Get_Event_Struct(self)->mouseButton;
179
+ sfMouseButtonEvent* event = &Get_Event_Struct(self)->mouseButton;
112
180
  VALUE hash = rb_hash_new();
113
181
 
114
- rb_hash_aset(hash, ID2SYM(rb_intern("button")), ID2SYM(rb_intern(mouse_button_name(event->button))));
182
+ rb_hash_aset(hash, ID2SYM(rb_intern("button")),
183
+ ID2SYM(rb_intern(mouse_button_name(event->button))));
115
184
  rb_hash_aset(hash, ID2SYM(rb_intern("position")),
116
- vec2f_to_rb((sfVector2f) {(float) event->position.x, (float) event->position.y}));
185
+ vec2f_to_rb((sfVector2f){(float)event->position.x, (float)event->position.y}));
117
186
 
118
187
  return hash;
119
188
  }
120
189
 
190
+ /* call-seq: mouse_wheel_scroll -> Hash
191
+ *
192
+ * Returns the wheel descriptor Hash for a +"mouse-wheel-scrolled"+ event.
193
+ *
194
+ * @return [Hash] +:wheel+, +:delta+, +:position+, for a
195
+ * +"mouse-wheel-scrolled"+ event
196
+ */
121
197
  static VALUE Event_get_mouse_wheel_scroll(VALUE self) {
122
- sfMouseWheelScrollEvent *event = &Get_Event_Struct(self)->mouseWheelScroll;
198
+ sfMouseWheelScrollEvent* event = &Get_Event_Struct(self)->mouseWheelScroll;
123
199
  VALUE hash = rb_hash_new();
124
200
 
125
- rb_hash_aset(hash, ID2SYM(rb_intern("wheel")), ID2SYM(rb_intern(mouse_wheel_name(event->wheel))));
201
+ rb_hash_aset(hash, ID2SYM(rb_intern("wheel")),
202
+ ID2SYM(rb_intern(mouse_wheel_name(event->wheel))));
126
203
  rb_hash_aset(hash, ID2SYM(rb_intern("delta")), DBL2NUM(event->delta));
127
204
  rb_hash_aset(hash, ID2SYM(rb_intern("position")),
128
- vec2f_to_rb((sfVector2f) {(float) event->position.x, (float) event->position.y}));
205
+ vec2f_to_rb((sfVector2f){(float)event->position.x, (float)event->position.y}));
129
206
 
130
207
  return hash;
131
208
  }
132
209
 
210
+ /* call-seq: joystick_move -> Hash
211
+ *
212
+ * Returns the descriptor Hash for a +"joystick-moved"+ event.
213
+ *
214
+ * @return [Hash] +:joystick_id+, +:axis+, +:position+, for a
215
+ * +"joystick-moved"+ event
216
+ */
133
217
  static VALUE Event_get_joystick_move(VALUE self) {
134
- sfJoystickMoveEvent *event = &Get_Event_Struct(self)->joystickMove;
218
+ sfJoystickMoveEvent* event = &Get_Event_Struct(self)->joystickMove;
135
219
  VALUE hash = rb_hash_new();
136
220
 
137
221
  rb_hash_aset(hash, ID2SYM(rb_intern("joystick_id")), UINT2NUM(event->joystickId));
138
- rb_hash_aset(hash, ID2SYM(rb_intern("axis")), ID2SYM(rb_intern(joystick_axis_name(event->axis))));
222
+ rb_hash_aset(hash, ID2SYM(rb_intern("axis")),
223
+ ID2SYM(rb_intern(joystick_axis_name(event->axis))));
139
224
  rb_hash_aset(hash, ID2SYM(rb_intern("position")), DBL2NUM(event->position));
140
225
 
141
226
  return hash;
142
227
  }
143
228
 
229
+ /* call-seq: joystick_button -> Hash
230
+ *
231
+ * Returns the descriptor Hash for a joystick button press or release event.
232
+ *
233
+ * @return [Hash] +:joystick_id+, +:button+, for a
234
+ * +"joystick-button-pressed"+/+"joystick-button-released"+ event
235
+ */
144
236
  static VALUE Event_get_joystick_button(VALUE self) {
145
- sfJoystickButtonEvent *event = &Get_Event_Struct(self)->joystickButton;
237
+ sfJoystickButtonEvent* event = &Get_Event_Struct(self)->joystickButton;
146
238
  VALUE hash = rb_hash_new();
147
239
 
148
240
  rb_hash_aset(hash, ID2SYM(rb_intern("joystick_id")), UINT2NUM(event->joystickId));
@@ -151,39 +243,68 @@ static VALUE Event_get_joystick_button(VALUE self) {
151
243
  return hash;
152
244
  }
153
245
 
246
+ /* call-seq: joystick_connect -> Hash
247
+ *
248
+ * Returns the descriptor Hash for a joystick connect or disconnect event.
249
+ *
250
+ * @return [Hash] +:joystick_id+, +:connected+, for a
251
+ * +"joystick-connected"+/+"joystick-disconnected"+ event
252
+ */
154
253
  static VALUE Event_get_joystick_connect(VALUE self) {
155
- sfEvent *event = Get_Event_Struct(self);
254
+ sfEvent* event = Get_Event_Struct(self);
156
255
  VALUE hash = rb_hash_new();
157
256
 
158
- rb_hash_aset(hash, ID2SYM(rb_intern("joystick_id")), UINT2NUM(event->joystickConnect.joystickId));
159
- rb_hash_aset(hash, ID2SYM(rb_intern("connected")), BOOL2RB(event->type == sfEvtJoystickConnected));
257
+ rb_hash_aset(hash, ID2SYM(rb_intern("joystick_id")),
258
+ UINT2NUM(event->joystickConnect.joystickId));
259
+ rb_hash_aset(hash, ID2SYM(rb_intern("connected")),
260
+ BOOL2RB(event->type == sfEvtJoystickConnected));
160
261
 
161
262
  return hash;
162
263
  }
163
264
 
265
+ /* call-seq: touch -> Hash
266
+ *
267
+ * Returns the descriptor Hash for a touch begin, move or end event.
268
+ *
269
+ * @return [Hash] +:finger+, +:position+, for a
270
+ * +"touch-began"+/+"touch-moved"+/+"touch-ended"+ event
271
+ */
164
272
  static VALUE Event_get_touch(VALUE self) {
165
- sfTouchEvent *event = &Get_Event_Struct(self)->touch;
273
+ sfTouchEvent* event = &Get_Event_Struct(self)->touch;
166
274
  VALUE hash = rb_hash_new();
167
275
 
168
276
  rb_hash_aset(hash, ID2SYM(rb_intern("finger")), UINT2NUM(event->finger));
169
277
  rb_hash_aset(hash, ID2SYM(rb_intern("position")),
170
- vec2f_to_rb((sfVector2f) {(float) event->position.x, (float) event->position.y}));
278
+ vec2f_to_rb((sfVector2f){(float)event->position.x, (float)event->position.y}));
171
279
 
172
280
  return hash;
173
281
  }
174
282
 
283
+ /* call-seq: sensor -> Hash
284
+ *
285
+ * Returns the descriptor Hash for a +"sensor-changed"+ event.
286
+ *
287
+ * @return [Hash] +:type+, +:value+, for a +"sensor-changed"+ event
288
+ */
175
289
  static VALUE Event_get_sensor(VALUE self) {
176
- sfSensorEvent *event = &Get_Event_Struct(self)->sensor;
290
+ sfSensorEvent* event = &Get_Event_Struct(self)->sensor;
177
291
  VALUE hash = rb_hash_new();
178
292
 
179
- rb_hash_aset(hash, ID2SYM(rb_intern("type")), ID2SYM(rb_intern(sensor_type_name(event->sensorType))));
293
+ rb_hash_aset(hash, ID2SYM(rb_intern("type")),
294
+ ID2SYM(rb_intern(sensor_type_name(event->sensorType))));
180
295
  rb_hash_aset(hash, ID2SYM(rb_intern("value")), vec3f_to_rb(event->value));
181
296
 
182
297
  return hash;
183
298
  }
184
299
 
185
- void Init_Event(VALUE rb_module) {
186
- rb_cEvent = rb_define_class_under(rb_module, "Event", rb_cObject);
300
+ /* Document-class: SFML::Event
301
+ * A window or input event, polled from Window#poll_event!/#wait_event!.
302
+ *
303
+ * #type tells which of the accessors below is meaningful for this
304
+ * particular event; the others return stale or default data.
305
+ */
306
+ void Init_Event(VALUE rb_mSFML) {
307
+ rb_cEvent = rb_define_class_under(rb_mSFML, "Event", rb_cObject);
187
308
 
188
309
  rb_define_singleton_method(rb_cEvent, "new", Event_new, 0);
189
310
 
@@ -205,8 +326,8 @@ void Init_Event(VALUE rb_module) {
205
326
  rb_define_method(rb_cEvent, "sensor", Event_get_sensor, 0);
206
327
  }
207
328
 
208
- sfEvent *Get_Event_Struct(VALUE self) {
209
- sfEvent *ptr;
329
+ sfEvent* Get_Event_Struct(VALUE self) {
330
+ sfEvent* ptr;
210
331
  TypedData_Get_Struct(self, sfEvent, &Event_data_type, ptr);
211
332
  return ptr;
212
333
  }
@@ -6,26 +6,77 @@
6
6
  #include "core/macros.h"
7
7
  #include "core/sfml.h"
8
8
 
9
+ /* call-seq:
10
+ * connected?(joystick) -> true or false
11
+ *
12
+ * Returns +true+ if joystick number +joystick+ is currently connected.
13
+ *
14
+ * @return [Boolean] whether joystick number +joystick+ is currently
15
+ * connected
16
+ */
9
17
  static VALUE Joystick_is_connected(VALUE module, VALUE rb_joystick) {
10
18
  return BOOL2RB(sfJoystick_isConnected(NUM2UINT(rb_joystick)));
11
19
  }
12
20
 
21
+ /* call-seq:
22
+ * button_count(joystick) -> Integer
23
+ *
24
+ * Returns the number of buttons on joystick number +joystick+.
25
+ *
26
+ * @return [Integer] number of buttons on joystick number +joystick+
27
+ */
13
28
  static VALUE Joystick_get_button_count(VALUE module, VALUE rb_joystick) {
14
29
  return UINT2NUM(sfJoystick_getButtonCount(NUM2UINT(rb_joystick)));
15
30
  }
16
31
 
32
+ /* call-seq:
33
+ * has_axis?(joystick, axis) -> true or false
34
+ *
35
+ * Returns +true+ if joystick number +joystick+ has +axis+.
36
+ *
37
+ * @return [Boolean] whether joystick number +joystick+ has +axis+ (a Symbol
38
+ * like +:x+, +:y+, +:pov_x+, or an Integer)
39
+ */
17
40
  static VALUE Joystick_has_axis(VALUE module, VALUE rb_joystick, VALUE rb_axis) {
18
41
  return BOOL2RB(sfJoystick_hasAxis(NUM2UINT(rb_joystick), joystick_axis_from_rb(rb_axis)));
19
42
  }
20
43
 
44
+ /* call-seq:
45
+ * button_pressed?(joystick, button) -> true or false
46
+ *
47
+ * Returns +true+ if +button+ is currently pressed on joystick number
48
+ * +joystick+.
49
+ *
50
+ * @return [Boolean] whether +button+ is currently pressed on joystick number
51
+ * +joystick+
52
+ */
21
53
  static VALUE Joystick_is_button_pressed(VALUE module, VALUE rb_joystick, VALUE rb_button) {
22
54
  return BOOL2RB(sfJoystick_isButtonPressed(NUM2UINT(rb_joystick), NUM2UINT(rb_button)));
23
55
  }
24
56
 
57
+ /* call-seq:
58
+ * axis_position(joystick, axis) -> Float
59
+ *
60
+ * Returns the current position of +axis+ on joystick number +joystick+,
61
+ * between -100 and 100.
62
+ *
63
+ * @return [Float] the current position of +axis+ on joystick number
64
+ * +joystick+, between -100 and 100
65
+ */
25
66
  static VALUE Joystick_get_axis_position(VALUE module, VALUE rb_joystick, VALUE rb_axis) {
26
- return DBL2NUM(sfJoystick_getAxisPosition(NUM2UINT(rb_joystick), joystick_axis_from_rb(rb_axis)));
67
+ return DBL2NUM(
68
+ sfJoystick_getAxisPosition(NUM2UINT(rb_joystick), joystick_axis_from_rb(rb_axis)));
27
69
  }
28
70
 
71
+ /* call-seq:
72
+ * identification(joystick) -> Hash
73
+ *
74
+ * Returns the +:name+, +:vendor_id+ and +:product_id+ of joystick number
75
+ * +joystick+.
76
+ *
77
+ * @return [Hash] +:name+, +:vendor_id+, +:product_id+, for joystick number
78
+ * +joystick+
79
+ */
29
80
  static VALUE Joystick_get_identification(VALUE module, VALUE rb_joystick) {
30
81
  sfJoystickIdentification identification = sfJoystick_getIdentification(NUM2UINT(rb_joystick));
31
82
  VALUE hash = rb_hash_new();
@@ -38,16 +89,31 @@ static VALUE Joystick_get_identification(VALUE module, VALUE rb_joystick) {
38
89
  return hash;
39
90
  }
40
91
 
92
+ /* call-seq: update! -> nil
93
+ *
94
+ * Refreshes the connection state of all joysticks. Called implicitly by
95
+ * event polling; only needed if you query joystick state without polling
96
+ * events.
97
+ *
98
+ * @return [nil]
99
+ */
41
100
  static VALUE Joystick_update(VALUE module) {
42
101
  sfJoystick_update();
43
102
  return Qnil;
44
103
  }
45
104
 
46
- void Init_Joystick(VALUE rb_module) {
47
- VALUE rb_mJoystick = rb_define_module_under(rb_module, "Joystick");
105
+ /* Document-module: SFML::Joystick
106
+ * Access to raw joystick/gamepad state, addressed by joystick number
107
+ * (0 up to Joystick::COUNT - 1).
108
+ */
109
+ void Init_Joystick(VALUE rb_mSFML) {
110
+ VALUE rb_mJoystick = rb_define_module_under(rb_mSFML, "Joystick");
48
111
 
112
+ /* Maximum number of joysticks supported. */
49
113
  rb_define_const(rb_mJoystick, "COUNT", INT2NUM(sfJoystickCount));
114
+ /* Maximum number of buttons supported on a single joystick. */
50
115
  rb_define_const(rb_mJoystick, "BUTTON_COUNT", INT2NUM(sfJoystickButtonCount));
116
+ /* Maximum number of axes supported on a single joystick. */
51
117
  rb_define_const(rb_mJoystick, "AXIS_COUNT", INT2NUM(sfJoystickAxisCount));
52
118
 
53
119
  rb_define_module_function(rb_mJoystick, "connected?", Joystick_is_connected, 1);