sfml3-rb 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/CHANGELOG.md +67 -16
  4. data/README.md +123 -32
  5. data/TODO.md +18 -11
  6. data/ext/audio/audio_enums.c +58 -20
  7. data/ext/audio/listener.c +89 -6
  8. data/ext/audio/music.c +212 -5
  9. data/ext/audio/sound.c +218 -9
  10. data/ext/audio/sound_buffer.c +197 -47
  11. data/ext/audio/sound_buffer_recorder.c +90 -18
  12. data/ext/audio/sound_recorder.c +188 -58
  13. data/ext/audio/sound_source_cone.c +127 -33
  14. data/ext/audio/sound_stream.c +204 -21
  15. data/ext/core/exceptions.c +10 -8
  16. data/ext/core/unicode.c +12 -2
  17. data/ext/ext.c +8 -0
  18. data/ext/graphics/blend_mode.c +218 -60
  19. data/ext/graphics/circle.c +300 -16
  20. data/ext/graphics/color.c +253 -94
  21. data/ext/graphics/drawable.c +16 -4
  22. data/ext/graphics/font.c +144 -25
  23. data/ext/graphics/glyph.c +38 -8
  24. data/ext/graphics/image.c +205 -41
  25. data/ext/graphics/polygon.c +317 -30
  26. data/ext/graphics/rect.c +225 -60
  27. data/ext/graphics/rectangle.c +307 -35
  28. data/ext/graphics/render_state.c +124 -12
  29. data/ext/graphics/render_texture.c +191 -14
  30. data/ext/graphics/render_window.c +55 -0
  31. data/ext/graphics/render_window.h +10 -0
  32. data/ext/graphics/shader.c +289 -17
  33. data/ext/graphics/shape.c +265 -32
  34. data/ext/graphics/sprite.c +245 -30
  35. data/ext/graphics/stencil_mode.c +163 -46
  36. data/ext/graphics/target.c +121 -43
  37. data/ext/graphics/target.h +31 -17
  38. data/ext/graphics/text.c +339 -19
  39. data/ext/graphics/texture.c +291 -6
  40. data/ext/graphics/transform.c +178 -5
  41. data/ext/graphics/transformable.c +127 -12
  42. data/ext/graphics/vertex.c +98 -6
  43. data/ext/graphics/vertex_array.c +142 -21
  44. data/ext/graphics/vertex_buffer.c +154 -12
  45. data/ext/graphics/view.c +140 -6
  46. data/ext/network/ftp.c +278 -12
  47. data/ext/network/http.c +179 -44
  48. data/ext/network/ip_address.c +127 -35
  49. data/ext/network/network_enums.c +248 -141
  50. data/ext/network/packet.c +280 -41
  51. data/ext/network/socket_selector.c +98 -21
  52. data/ext/network/tcp_listener.c +82 -18
  53. data/ext/network/tcp_socket.c +135 -27
  54. data/ext/network/udp_socket.c +129 -28
  55. data/ext/ports.rb +7 -0
  56. data/ext/system/buffer.c +47 -16
  57. data/ext/system/clock.c +77 -12
  58. data/ext/system/input_stream.c +113 -51
  59. data/ext/system/sleep.c +10 -2
  60. data/ext/system/time.c +182 -40
  61. data/ext/system/vec2.c +166 -39
  62. data/ext/system/vec3.c +177 -39
  63. data/ext/window/clipboard.c +47 -17
  64. data/ext/window/context.c +66 -13
  65. data/ext/window/context_settings.c +132 -42
  66. data/ext/window/cursor.c +45 -9
  67. data/ext/window/event.c +164 -53
  68. data/ext/window/joystick.c +69 -3
  69. data/ext/window/keyboard.c +168 -116
  70. data/ext/window/mouse.c +64 -13
  71. data/ext/window/sensor.c +28 -2
  72. data/ext/window/touch.c +32 -12
  73. data/ext/window/video_mode.c +93 -31
  74. data/ext/window/vulkan.c +34 -6
  75. data/ext/window/window.c +228 -229
  76. data/ext/window/window.h +4 -4
  77. data/ext/window/window_base.c +251 -0
  78. data/ext/window/window_base.h +43 -0
  79. data/ext/window/window_base.inc +236 -0
  80. data/lib/sfml/version.rb +1 -1
  81. data/sig/audio/audio_enums.rbs +30 -0
  82. data/sig/audio/listener.rbs +16 -0
  83. data/sig/audio/music.rbs +56 -0
  84. data/sig/audio/sound.rbs +51 -0
  85. data/sig/audio/sound_buffer.rbs +17 -0
  86. data/sig/audio/sound_buffer_recorder.rbs +14 -0
  87. data/sig/audio/sound_recorder.rbs +17 -0
  88. data/sig/audio/sound_source_cone.rbs +14 -0
  89. data/sig/audio/sound_stream.rbs +51 -0
  90. data/sig/graphics/blend_mode.rbs +29 -0
  91. data/sig/graphics/circle.rbs +44 -0
  92. data/sig/graphics/color.rbs +39 -0
  93. data/sig/graphics/drawable.rbs +5 -0
  94. data/sig/graphics/font.rbs +20 -0
  95. data/sig/graphics/glyph.rbs +7 -0
  96. data/sig/graphics/image.rbs +22 -0
  97. data/sig/graphics/polygon.rbs +42 -0
  98. data/sig/graphics/rect.rbs +33 -0
  99. data/sig/graphics/rectangle.rbs +42 -0
  100. data/sig/graphics/render_state.rbs +21 -0
  101. data/sig/graphics/render_target.rbs +18 -0
  102. data/sig/graphics/render_texture.rbs +39 -0
  103. data/sig/graphics/render_window.rbs +7 -0
  104. data/sig/graphics/shader.rbs +39 -0
  105. data/sig/graphics/shape.rbs +38 -0
  106. data/sig/graphics/sprite.rbs +34 -0
  107. data/sig/graphics/stencil_mode.rbs +18 -0
  108. data/sig/graphics/target.rbs +8 -0
  109. data/sig/graphics/text.rbs +48 -0
  110. data/sig/graphics/texture.rbs +34 -0
  111. data/sig/graphics/transform.rbs +37 -0
  112. data/sig/graphics/transformable.rbs +25 -0
  113. data/sig/graphics/vertex.rbs +17 -0
  114. data/sig/graphics/vertex_array.rbs +17 -0
  115. data/sig/graphics/vertex_buffer.rbs +22 -0
  116. data/sig/graphics/view.rbs +23 -0
  117. data/sig/network/ftp.rbs +46 -0
  118. data/sig/network/http.rbs +27 -0
  119. data/sig/network/ip_address.rbs +22 -0
  120. data/sig/network/network_enums.rbs +95 -0
  121. data/sig/network/packet.rbs +40 -0
  122. data/sig/network/socket_selector.rbs +14 -0
  123. data/sig/network/tcp_listener.rbs +13 -0
  124. data/sig/network/tcp_socket.rbs +18 -0
  125. data/sig/network/udp_socket.rbs +17 -0
  126. data/sig/sfml/version.rbs +3 -0
  127. data/sig/system/buffer.rbs +11 -0
  128. data/sig/system/clock.rbs +13 -0
  129. data/sig/system/input_stream.rbs +7 -0
  130. data/sig/system/sleep.rbs +3 -0
  131. data/sig/system/time.rbs +28 -0
  132. data/sig/system/vec2.rbs +26 -0
  133. data/sig/system/vec3.rbs +27 -0
  134. data/sig/window/clipboard.rbs +8 -0
  135. data/sig/window/context.rbs +11 -0
  136. data/sig/window/context_settings.rbs +20 -0
  137. data/sig/window/cursor.rbs +6 -0
  138. data/sig/window/event.rbs +20 -0
  139. data/sig/window/joystick.rbs +15 -0
  140. data/sig/window/keyboard.rbs +10 -0
  141. data/sig/window/mouse.rbs +9 -0
  142. data/sig/window/sensor.rbs +8 -0
  143. data/sig/window/touch.rbs +6 -0
  144. data/sig/window/video_mode.rbs +16 -0
  145. data/sig/window/vulkan.rbs +7 -0
  146. data/sig/window/window.rbs +34 -0
  147. data/sig/window/window_base.rbs +33 -0
  148. metadata +76 -3
data/ext/window/event.c CHANGED
@@ -14,52 +14,84 @@
14
14
 
15
15
  static VALUE rb_cEvent;
16
16
 
17
- static sfEvent *Event_create() {
18
- return malloc(sizeof(sfEvent));
19
- }
20
-
21
- static void Event_free(void *ptr) {
17
+ static void Event_free(void* ptr) {
22
18
  free(ptr);
23
19
  }
24
20
 
25
21
  static const rb_data_type_t Event_data_type = {
26
22
  .wrap_struct_name = "SFML::Event",
27
23
  .function = {.dmark = NULL, .dfree = Event_free, .dsize = NULL},
28
- .flags = RUBY_TYPED_FREE_IMMEDIATELY
29
- };
24
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY};
30
25
 
31
- static VALUE Event_new(VALUE klass) {
32
- VALUE self;
33
- sfEvent *event;
26
+ static VALUE Event_alloc(VALUE klass) {
27
+ sfEvent* event = malloc(sizeof(sfEvent));
34
28
 
35
- event = Event_create();
36
- self = TypedData_Wrap_Struct(klass, &Event_data_type, event);
29
+ if (event == NULL) {
30
+ rb_raise(rb_eNoMemError, "failed to allocate event");
31
+ }
37
32
 
38
- rb_obj_call_init(self, 0, NULL);
33
+ *event = (sfEvent){0};
39
34
 
40
- return self;
35
+ return TypedData_Wrap_Struct(klass, &Event_data_type, event);
41
36
  }
42
37
 
43
- static VALUE Event_init(VALUE self) {
38
+ /* call-seq:
39
+ * Event.new -> Event
40
+ *
41
+ * Creates an empty, uninitialized event.
42
+ *
43
+ * @return [Event]
44
+ */
45
+
46
+ /* call-seq: initialize -> self
47
+ *
48
+ * Does nothing; instances are built internally by the event-polling methods.
49
+ *
50
+ * @private No-op; objects of this class are only ever constructed
51
+ * internally (e.g. by #poll_event!).
52
+ * @return [self]
53
+ */
54
+ static VALUE Event_initialize(VALUE self) {
44
55
  return self;
45
56
  }
46
57
 
58
+ /* call-seq: type -> String
59
+ *
60
+ * Returns the event's kind as a String, such as +"closed"+ or +"key-pressed"+.
61
+ *
62
+ * @return [String] the event's kind, e.g. +"closed"+, +"key-pressed"+,
63
+ * +"mouse-moved"+ (see SFML::Window#poll_event!)
64
+ */
47
65
  static VALUE Event_type(VALUE self) {
48
66
  return rb_str_new2(get_event_name(Get_Event_Struct(self)->type));
49
67
  }
50
68
 
69
+ /* call-seq: size -> Vector2
70
+ *
71
+ * Returns the new size carried by a +"resized"+ event.
72
+ *
73
+ * @return [Vector2] the new size, for a +"resized"+ event
74
+ */
51
75
  static VALUE Event_get_size(VALUE self) {
52
76
  sfVector2u size = Get_Event_Struct(self)->size.size;
53
77
 
54
- return vec2f_to_rb((sfVector2f) {(float) size.x, (float) size.y});
78
+ return vec2f_to_rb((sfVector2f){(float)size.x, (float)size.y});
55
79
  }
56
80
 
81
+ /* call-seq: key -> Hash
82
+ *
83
+ * Returns the key descriptor Hash for a key press or release event.
84
+ *
85
+ * @return [Hash] +:code+, +:scancode+, +:alt+, +:control+, +:shift+,
86
+ * +:system+, for a +"key-pressed"+/+"key-released"+ event
87
+ */
57
88
  static VALUE Event_get_key(VALUE self) {
58
- sfKeyEvent *event = &Get_Event_Struct(self)->key;
89
+ sfKeyEvent* event = &Get_Event_Struct(self)->key;
59
90
  VALUE hash = rb_hash_new();
60
91
 
61
92
  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)));
93
+ rb_hash_aset(hash, ID2SYM(rb_intern("scancode")),
94
+ rb_str_new2(sfKeyboard_getDescription(event->scancode)));
63
95
  rb_hash_aset(hash, ID2SYM(rb_intern("alt")), BOOL2RB(event->alt));
64
96
  rb_hash_aset(hash, ID2SYM(rb_intern("control")), BOOL2RB(event->control));
65
97
  rb_hash_aset(hash, ID2SYM(rb_intern("shift")), BOOL2RB(event->shift));
@@ -73,76 +105,127 @@ static VALUE unicode_to_utf8(uint32_t code) {
73
105
  int length = 0;
74
106
 
75
107
  if (code < 0x80) {
76
- buffer[length++] = (char) code;
108
+ buffer[length++] = (char)code;
77
109
  } else if (code < 0x800) {
78
- buffer[length++] = (char) (0xC0 | (code >> 6));
79
- buffer[length++] = (char) (0x80 | (code & 0x3F));
110
+ buffer[length++] = (char)(0xC0 | (code >> 6));
111
+ buffer[length++] = (char)(0x80 | (code & 0x3F));
80
112
  } 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));
113
+ buffer[length++] = (char)(0xE0 | (code >> 12));
114
+ buffer[length++] = (char)(0x80 | ((code >> 6) & 0x3F));
115
+ buffer[length++] = (char)(0x80 | (code & 0x3F));
84
116
  } 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));
117
+ buffer[length++] = (char)(0xF0 | (code >> 18));
118
+ buffer[length++] = (char)(0x80 | ((code >> 12) & 0x3F));
119
+ buffer[length++] = (char)(0x80 | ((code >> 6) & 0x3F));
120
+ buffer[length++] = (char)(0x80 | (code & 0x3F));
89
121
  }
90
122
 
91
123
  return rb_utf8_str_new(buffer, length);
92
124
  }
93
125
 
126
+ /* call-seq: text -> String
127
+ *
128
+ * Returns the entered character for a +"text-entered"+ event.
129
+ *
130
+ * @return [String] the entered character, decoded from Unicode, for a
131
+ * +"text-entered"+ event
132
+ */
94
133
  static VALUE Event_get_text(VALUE self) {
95
134
  return unicode_to_utf8(Get_Event_Struct(self)->text.unicode);
96
135
  }
97
136
 
137
+ /* call-seq: mouse_move -> Vector2
138
+ *
139
+ * Returns the new cursor position for a +"mouse-moved"+ event.
140
+ *
141
+ * @return [Vector2] the new cursor position, for a +"mouse-moved"+ event
142
+ */
98
143
  static VALUE Event_get_mouse_move(VALUE self) {
99
144
  sfVector2i position = Get_Event_Struct(self)->mouseMove.position;
100
145
 
101
- return vec2f_to_rb((sfVector2f) {(float) position.x, (float) position.y});
146
+ return vec2f_to_rb((sfVector2f){(float)position.x, (float)position.y});
102
147
  }
103
148
 
149
+ /* call-seq: mouse_move_raw -> Vector2
150
+ *
151
+ * Returns the unfiltered relative motion for a +"mouse-moved-raw"+ event.
152
+ *
153
+ * @return [Vector2] unfiltered relative motion, for a +"mouse-moved-raw"+
154
+ * event
155
+ */
104
156
  static VALUE Event_get_mouse_move_raw(VALUE self) {
105
157
  sfVector2i delta = Get_Event_Struct(self)->mouseMoveRaw.delta;
106
158
 
107
- return vec2f_to_rb((sfVector2f) {(float) delta.x, (float) delta.y});
159
+ return vec2f_to_rb((sfVector2f){(float)delta.x, (float)delta.y});
108
160
  }
109
161
 
162
+ /* call-seq: mouse_button -> Hash
163
+ *
164
+ * Returns the button descriptor Hash for a mouse press or release event.
165
+ *
166
+ * @return [Hash] +:button+, +:position+, for a
167
+ * +"mouse-button-pressed"+/+"mouse-button-released"+ event
168
+ */
110
169
  static VALUE Event_get_mouse_button(VALUE self) {
111
- sfMouseButtonEvent *event = &Get_Event_Struct(self)->mouseButton;
170
+ sfMouseButtonEvent* event = &Get_Event_Struct(self)->mouseButton;
112
171
  VALUE hash = rb_hash_new();
113
172
 
114
- rb_hash_aset(hash, ID2SYM(rb_intern("button")), ID2SYM(rb_intern(mouse_button_name(event->button))));
173
+ rb_hash_aset(hash, ID2SYM(rb_intern("button")),
174
+ ID2SYM(rb_intern(mouse_button_name(event->button))));
115
175
  rb_hash_aset(hash, ID2SYM(rb_intern("position")),
116
- vec2f_to_rb((sfVector2f) {(float) event->position.x, (float) event->position.y}));
176
+ vec2f_to_rb((sfVector2f){(float)event->position.x, (float)event->position.y}));
117
177
 
118
178
  return hash;
119
179
  }
120
180
 
181
+ /* call-seq: mouse_wheel_scroll -> Hash
182
+ *
183
+ * Returns the wheel descriptor Hash for a +"mouse-wheel-scrolled"+ event.
184
+ *
185
+ * @return [Hash] +:wheel+, +:delta+, +:position+, for a
186
+ * +"mouse-wheel-scrolled"+ event
187
+ */
121
188
  static VALUE Event_get_mouse_wheel_scroll(VALUE self) {
122
- sfMouseWheelScrollEvent *event = &Get_Event_Struct(self)->mouseWheelScroll;
189
+ sfMouseWheelScrollEvent* event = &Get_Event_Struct(self)->mouseWheelScroll;
123
190
  VALUE hash = rb_hash_new();
124
191
 
125
- rb_hash_aset(hash, ID2SYM(rb_intern("wheel")), ID2SYM(rb_intern(mouse_wheel_name(event->wheel))));
192
+ rb_hash_aset(hash, ID2SYM(rb_intern("wheel")),
193
+ ID2SYM(rb_intern(mouse_wheel_name(event->wheel))));
126
194
  rb_hash_aset(hash, ID2SYM(rb_intern("delta")), DBL2NUM(event->delta));
127
195
  rb_hash_aset(hash, ID2SYM(rb_intern("position")),
128
- vec2f_to_rb((sfVector2f) {(float) event->position.x, (float) event->position.y}));
196
+ vec2f_to_rb((sfVector2f){(float)event->position.x, (float)event->position.y}));
129
197
 
130
198
  return hash;
131
199
  }
132
200
 
201
+ /* call-seq: joystick_move -> Hash
202
+ *
203
+ * Returns the descriptor Hash for a +"joystick-moved"+ event.
204
+ *
205
+ * @return [Hash] +:joystick_id+, +:axis+, +:position+, for a
206
+ * +"joystick-moved"+ event
207
+ */
133
208
  static VALUE Event_get_joystick_move(VALUE self) {
134
- sfJoystickMoveEvent *event = &Get_Event_Struct(self)->joystickMove;
209
+ sfJoystickMoveEvent* event = &Get_Event_Struct(self)->joystickMove;
135
210
  VALUE hash = rb_hash_new();
136
211
 
137
212
  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))));
213
+ rb_hash_aset(hash, ID2SYM(rb_intern("axis")),
214
+ ID2SYM(rb_intern(joystick_axis_name(event->axis))));
139
215
  rb_hash_aset(hash, ID2SYM(rb_intern("position")), DBL2NUM(event->position));
140
216
 
141
217
  return hash;
142
218
  }
143
219
 
220
+ /* call-seq: joystick_button -> Hash
221
+ *
222
+ * Returns the descriptor Hash for a joystick button press or release event.
223
+ *
224
+ * @return [Hash] +:joystick_id+, +:button+, for a
225
+ * +"joystick-button-pressed"+/+"joystick-button-released"+ event
226
+ */
144
227
  static VALUE Event_get_joystick_button(VALUE self) {
145
- sfJoystickButtonEvent *event = &Get_Event_Struct(self)->joystickButton;
228
+ sfJoystickButtonEvent* event = &Get_Event_Struct(self)->joystickButton;
146
229
  VALUE hash = rb_hash_new();
147
230
 
148
231
  rb_hash_aset(hash, ID2SYM(rb_intern("joystick_id")), UINT2NUM(event->joystickId));
@@ -151,43 +234,71 @@ static VALUE Event_get_joystick_button(VALUE self) {
151
234
  return hash;
152
235
  }
153
236
 
237
+ /* call-seq: joystick_connect -> Hash
238
+ *
239
+ * Returns the descriptor Hash for a joystick connect or disconnect event.
240
+ *
241
+ * @return [Hash] +:joystick_id+, +:connected+, for a
242
+ * +"joystick-connected"+/+"joystick-disconnected"+ event
243
+ */
154
244
  static VALUE Event_get_joystick_connect(VALUE self) {
155
- sfEvent *event = Get_Event_Struct(self);
245
+ sfEvent* event = Get_Event_Struct(self);
156
246
  VALUE hash = rb_hash_new();
157
247
 
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));
248
+ rb_hash_aset(hash, ID2SYM(rb_intern("joystick_id")),
249
+ UINT2NUM(event->joystickConnect.joystickId));
250
+ rb_hash_aset(hash, ID2SYM(rb_intern("connected")),
251
+ BOOL2RB(event->type == sfEvtJoystickConnected));
160
252
 
161
253
  return hash;
162
254
  }
163
255
 
256
+ /* call-seq: touch -> Hash
257
+ *
258
+ * Returns the descriptor Hash for a touch begin, move or end event.
259
+ *
260
+ * @return [Hash] +:finger+, +:position+, for a
261
+ * +"touch-began"+/+"touch-moved"+/+"touch-ended"+ event
262
+ */
164
263
  static VALUE Event_get_touch(VALUE self) {
165
- sfTouchEvent *event = &Get_Event_Struct(self)->touch;
264
+ sfTouchEvent* event = &Get_Event_Struct(self)->touch;
166
265
  VALUE hash = rb_hash_new();
167
266
 
168
267
  rb_hash_aset(hash, ID2SYM(rb_intern("finger")), UINT2NUM(event->finger));
169
268
  rb_hash_aset(hash, ID2SYM(rb_intern("position")),
170
- vec2f_to_rb((sfVector2f) {(float) event->position.x, (float) event->position.y}));
269
+ vec2f_to_rb((sfVector2f){(float)event->position.x, (float)event->position.y}));
171
270
 
172
271
  return hash;
173
272
  }
174
273
 
274
+ /* call-seq: sensor -> Hash
275
+ *
276
+ * Returns the descriptor Hash for a +"sensor-changed"+ event.
277
+ *
278
+ * @return [Hash] +:type+, +:value+, for a +"sensor-changed"+ event
279
+ */
175
280
  static VALUE Event_get_sensor(VALUE self) {
176
- sfSensorEvent *event = &Get_Event_Struct(self)->sensor;
281
+ sfSensorEvent* event = &Get_Event_Struct(self)->sensor;
177
282
  VALUE hash = rb_hash_new();
178
283
 
179
- rb_hash_aset(hash, ID2SYM(rb_intern("type")), ID2SYM(rb_intern(sensor_type_name(event->sensorType))));
284
+ rb_hash_aset(hash, ID2SYM(rb_intern("type")),
285
+ ID2SYM(rb_intern(sensor_type_name(event->sensorType))));
180
286
  rb_hash_aset(hash, ID2SYM(rb_intern("value")), vec3f_to_rb(event->value));
181
287
 
182
288
  return hash;
183
289
  }
184
290
 
185
- void Init_Event(VALUE rb_module) {
186
- rb_cEvent = rb_define_class_under(rb_module, "Event", rb_cObject);
187
-
188
- rb_define_singleton_method(rb_cEvent, "new", Event_new, 0);
291
+ /* Document-class: SFML::Event
292
+ * A window or input event, polled from Window#poll_event!/#wait_event!.
293
+ *
294
+ * #type tells which of the accessors below is meaningful for this
295
+ * particular event; the others return stale or default data.
296
+ */
297
+ void Init_Event(VALUE rb_mSFML) {
298
+ rb_cEvent = rb_define_class_under(rb_mSFML, "Event", rb_cObject);
189
299
 
190
- rb_define_method(rb_cEvent, "initialize", Event_init, 0);
300
+ rb_define_alloc_func(rb_cEvent, Event_alloc);
301
+ rb_define_method(rb_cEvent, "initialize", Event_initialize, 0);
191
302
 
192
303
  rb_define_method(rb_cEvent, "type", Event_type, 0);
193
304
  rb_define_method(rb_cEvent, "size", Event_get_size, 0);
@@ -205,8 +316,8 @@ void Init_Event(VALUE rb_module) {
205
316
  rb_define_method(rb_cEvent, "sensor", Event_get_sensor, 0);
206
317
  }
207
318
 
208
- sfEvent *Get_Event_Struct(VALUE self) {
209
- sfEvent *ptr;
319
+ sfEvent* Get_Event_Struct(VALUE self) {
320
+ sfEvent* ptr;
210
321
  TypedData_Get_Struct(self, sfEvent, &Event_data_type, ptr);
211
322
  return ptr;
212
323
  }
@@ -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);