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
@@ -11,125 +11,125 @@
11
11
  /* Indexed by sfKeyCode rather than by position: if upstream reorders or
12
12
  removes a key, this fails to compile instead of silently renaming every
13
13
  key after the change. sfKeyUnknown is -1 and so has no entry. */
14
- static const char *keys[] = {
15
- [sfKeyA] = "a",
16
- [sfKeyB] = "b",
17
- [sfKeyC] = "c",
18
- [sfKeyD] = "d",
19
- [sfKeyE] = "e",
20
- [sfKeyF] = "f",
21
- [sfKeyG] = "g",
22
- [sfKeyH] = "h",
23
- [sfKeyI] = "i",
24
- [sfKeyJ] = "j",
25
- [sfKeyK] = "k",
26
- [sfKeyL] = "l",
27
- [sfKeyM] = "m",
28
- [sfKeyN] = "n",
29
- [sfKeyO] = "o",
30
- [sfKeyP] = "p",
31
- [sfKeyQ] = "q",
32
- [sfKeyR] = "r",
33
- [sfKeyS] = "s",
34
- [sfKeyT] = "t",
35
- [sfKeyU] = "u",
36
- [sfKeyV] = "v",
37
- [sfKeyW] = "w",
38
- [sfKeyX] = "x",
39
- [sfKeyY] = "y",
40
- [sfKeyZ] = "z",
41
- [sfKeyNum0] = "num0",
42
- [sfKeyNum1] = "num1",
43
- [sfKeyNum2] = "num2",
44
- [sfKeyNum3] = "num3",
45
- [sfKeyNum4] = "num4",
46
- [sfKeyNum5] = "num5",
47
- [sfKeyNum6] = "num6",
48
- [sfKeyNum7] = "num7",
49
- [sfKeyNum8] = "num8",
50
- [sfKeyNum9] = "num9",
51
- [sfKeyEscape] = "escape",
52
- [sfKeyLControl] = "LControl",
53
- [sfKeyLShift] = "LShift",
54
- [sfKeyLAlt] = "LAlt",
55
- [sfKeyLSystem] = "LSystem",
56
- [sfKeyRControl] = "RControl",
57
- [sfKeyRShift] = "RShift",
58
- [sfKeyRAlt] = "RAlt",
59
- [sfKeyRSystem] = "RSystem",
60
- [sfKeyMenu] = "Menu",
61
- [sfKeyLBracket] = "LBracket",
62
- [sfKeyRBracket] = "RBracket",
63
- [sfKeySemicolon] = "Semicolon",
64
- [sfKeyComma] = "Comma",
65
- [sfKeyPeriod] = "Period",
66
- [sfKeyApostrophe] = "Quote",
67
- [sfKeySlash] = "Slash",
68
- [sfKeyBackslash] = "Backslash",
69
- [sfKeyGrave] = "Tilde",
70
- [sfKeyEqual] = "Equal",
71
- [sfKeyHyphen] = "Hyphen",
72
- [sfKeySpace] = "Space",
73
- [sfKeyEnter] = "Enter",
74
- [sfKeyBackspace] = "Backspace",
75
- [sfKeyTab] = "Tab",
76
- [sfKeyPageUp] = "PageUp",
77
- [sfKeyPageDown] = "PageDown",
78
- [sfKeyEnd] = "End",
79
- [sfKeyHome] = "Home",
80
- [sfKeyInsert] = "Insert",
81
- [sfKeyDelete] = "Delete",
82
- [sfKeyAdd] = "Add",
83
- [sfKeySubtract] = "Subtract",
84
- [sfKeyMultiply] = "Multiply",
85
- [sfKeyDivide] = "Divide",
86
- [sfKeyLeft] = "Left",
87
- [sfKeyRight] = "Right",
88
- [sfKeyUp] = "Up",
89
- [sfKeyDown] = "Down",
90
- [sfKeyNumpad0] = "Numpad0",
91
- [sfKeyNumpad1] = "Numpad1",
92
- [sfKeyNumpad2] = "Numpad2",
93
- [sfKeyNumpad3] = "Numpad3",
94
- [sfKeyNumpad4] = "Numpad4",
95
- [sfKeyNumpad5] = "Numpad5",
96
- [sfKeyNumpad6] = "Numpad6",
97
- [sfKeyNumpad7] = "Numpad7",
98
- [sfKeyNumpad8] = "Numpad8",
99
- [sfKeyNumpad9] = "Numpad9",
100
- [sfKeyF1] = "f1",
101
- [sfKeyF2] = "f2",
102
- [sfKeyF3] = "f3",
103
- [sfKeyF4] = "f4",
104
- [sfKeyF5] = "f5",
105
- [sfKeyF6] = "f6",
106
- [sfKeyF7] = "f7",
107
- [sfKeyF8] = "f8",
108
- [sfKeyF9] = "f9",
109
- [sfKeyF10] = "f10",
110
- [sfKeyF11] = "f11",
111
- [sfKeyF12] = "f12",
112
- [sfKeyF13] = "f13",
113
- [sfKeyF14] = "f14",
114
- [sfKeyF15] = "f15",
115
- [sfKeyPause] = "pause",
14
+ static const char* keys[] = {
15
+ [sfKeyA] = "a",
16
+ [sfKeyB] = "b",
17
+ [sfKeyC] = "c",
18
+ [sfKeyD] = "d",
19
+ [sfKeyE] = "e",
20
+ [sfKeyF] = "f",
21
+ [sfKeyG] = "g",
22
+ [sfKeyH] = "h",
23
+ [sfKeyI] = "i",
24
+ [sfKeyJ] = "j",
25
+ [sfKeyK] = "k",
26
+ [sfKeyL] = "l",
27
+ [sfKeyM] = "m",
28
+ [sfKeyN] = "n",
29
+ [sfKeyO] = "o",
30
+ [sfKeyP] = "p",
31
+ [sfKeyQ] = "q",
32
+ [sfKeyR] = "r",
33
+ [sfKeyS] = "s",
34
+ [sfKeyT] = "t",
35
+ [sfKeyU] = "u",
36
+ [sfKeyV] = "v",
37
+ [sfKeyW] = "w",
38
+ [sfKeyX] = "x",
39
+ [sfKeyY] = "y",
40
+ [sfKeyZ] = "z",
41
+ [sfKeyNum0] = "num0",
42
+ [sfKeyNum1] = "num1",
43
+ [sfKeyNum2] = "num2",
44
+ [sfKeyNum3] = "num3",
45
+ [sfKeyNum4] = "num4",
46
+ [sfKeyNum5] = "num5",
47
+ [sfKeyNum6] = "num6",
48
+ [sfKeyNum7] = "num7",
49
+ [sfKeyNum8] = "num8",
50
+ [sfKeyNum9] = "num9",
51
+ [sfKeyEscape] = "escape",
52
+ [sfKeyLControl] = "LControl",
53
+ [sfKeyLShift] = "LShift",
54
+ [sfKeyLAlt] = "LAlt",
55
+ [sfKeyLSystem] = "LSystem",
56
+ [sfKeyRControl] = "RControl",
57
+ [sfKeyRShift] = "RShift",
58
+ [sfKeyRAlt] = "RAlt",
59
+ [sfKeyRSystem] = "RSystem",
60
+ [sfKeyMenu] = "Menu",
61
+ [sfKeyLBracket] = "LBracket",
62
+ [sfKeyRBracket] = "RBracket",
63
+ [sfKeySemicolon] = "Semicolon",
64
+ [sfKeyComma] = "Comma",
65
+ [sfKeyPeriod] = "Period",
66
+ [sfKeyApostrophe] = "Quote",
67
+ [sfKeySlash] = "Slash",
68
+ [sfKeyBackslash] = "Backslash",
69
+ [sfKeyGrave] = "Tilde",
70
+ [sfKeyEqual] = "Equal",
71
+ [sfKeyHyphen] = "Hyphen",
72
+ [sfKeySpace] = "Space",
73
+ [sfKeyEnter] = "Enter",
74
+ [sfKeyBackspace] = "Backspace",
75
+ [sfKeyTab] = "Tab",
76
+ [sfKeyPageUp] = "PageUp",
77
+ [sfKeyPageDown] = "PageDown",
78
+ [sfKeyEnd] = "End",
79
+ [sfKeyHome] = "Home",
80
+ [sfKeyInsert] = "Insert",
81
+ [sfKeyDelete] = "Delete",
82
+ [sfKeyAdd] = "Add",
83
+ [sfKeySubtract] = "Subtract",
84
+ [sfKeyMultiply] = "Multiply",
85
+ [sfKeyDivide] = "Divide",
86
+ [sfKeyLeft] = "Left",
87
+ [sfKeyRight] = "Right",
88
+ [sfKeyUp] = "Up",
89
+ [sfKeyDown] = "Down",
90
+ [sfKeyNumpad0] = "Numpad0",
91
+ [sfKeyNumpad1] = "Numpad1",
92
+ [sfKeyNumpad2] = "Numpad2",
93
+ [sfKeyNumpad3] = "Numpad3",
94
+ [sfKeyNumpad4] = "Numpad4",
95
+ [sfKeyNumpad5] = "Numpad5",
96
+ [sfKeyNumpad6] = "Numpad6",
97
+ [sfKeyNumpad7] = "Numpad7",
98
+ [sfKeyNumpad8] = "Numpad8",
99
+ [sfKeyNumpad9] = "Numpad9",
100
+ [sfKeyF1] = "f1",
101
+ [sfKeyF2] = "f2",
102
+ [sfKeyF3] = "f3",
103
+ [sfKeyF4] = "f4",
104
+ [sfKeyF5] = "f5",
105
+ [sfKeyF6] = "f6",
106
+ [sfKeyF7] = "f7",
107
+ [sfKeyF8] = "f8",
108
+ [sfKeyF9] = "f9",
109
+ [sfKeyF10] = "f10",
110
+ [sfKeyF11] = "f11",
111
+ [sfKeyF12] = "f12",
112
+ [sfKeyF13] = "f13",
113
+ [sfKeyF14] = "f14",
114
+ [sfKeyF15] = "f15",
115
+ [sfKeyPause] = "pause",
116
116
  };
117
117
 
118
118
  #define LENGTH_KEYS (sizeof(keys) / sizeof(keys[0]))
119
119
 
120
- int find_key(const char *name) {
120
+ int find_key(const char* name) {
121
121
  size_t i;
122
122
 
123
123
  for (i = 0; i < LENGTH_KEYS; i++) {
124
124
  if (keys[i] != NULL && strcmp(keys[i], name) == 0) {
125
- return (int) i;
125
+ return (int)i;
126
126
  }
127
127
  }
128
128
 
129
129
  return -1;
130
130
  }
131
131
 
132
- const char *get_key_event(unsigned int key) {
132
+ const char* get_key_event(unsigned int key) {
133
133
  if (key < LENGTH_KEYS && keys[key] != NULL) {
134
134
  return keys[key];
135
135
  }
@@ -141,7 +141,7 @@ static int Keyboard_key_code(VALUE rb_key) {
141
141
  int code;
142
142
 
143
143
  if (SYMBOL_P(rb_key)) {
144
- const char *name = rb_id2name(SYM2ID(rb_key));
144
+ const char* name = rb_id2name(SYM2ID(rb_key));
145
145
 
146
146
  code = find_key(name);
147
147
 
@@ -153,7 +153,7 @@ static int Keyboard_key_code(VALUE rb_key) {
153
153
  }
154
154
 
155
155
  if (RB_TYPE_P(rb_key, T_STRING)) {
156
- const char *name = StringValueCStr(rb_key);
156
+ const char* name = StringValueCStr(rb_key);
157
157
 
158
158
  code = find_key(name);
159
159
 
@@ -167,41 +167,93 @@ static int Keyboard_key_code(VALUE rb_key) {
167
167
  return NUM2INT(rb_key);
168
168
  }
169
169
 
170
+ /* call-seq:
171
+ * pressed?(key) -> true or false
172
+ *
173
+ * +key+ may be a key Symbol (e.g. +:a+, +:Enter+, +:LShift+), a String key
174
+ * name, or an Integer key code.
175
+ *
176
+ * @return [Boolean]
177
+ * @raise [ArgumentError] if +key+ is a Symbol/String naming an unknown key
178
+ */
170
179
  static VALUE Keyboard_pressed_p(VALUE module, VALUE rb_key) {
171
- return BOOL2RB(sfKeyboard_isKeyPressed((sfKeyCode) Keyboard_key_code(rb_key)));
180
+ return BOOL2RB(sfKeyboard_isKeyPressed((sfKeyCode)Keyboard_key_code(rb_key)));
172
181
  }
173
182
 
183
+ /* call-seq:
184
+ * scancode_pressed?(scancode) -> true or false
185
+ *
186
+ * Unlike #pressed?, +scancode+ identifies a physical key position rather
187
+ * than the character it currently produces.
188
+ *
189
+ * @return [Boolean]
190
+ */
174
191
  static VALUE Keyboard_scancode_pressed_p(VALUE module, VALUE rb_scancode) {
175
- return BOOL2RB(sfKeyboard_isScancodePressed((sfScancode) NUM2INT(rb_scancode)));
192
+ return BOOL2RB(sfKeyboard_isScancodePressed((sfScancode)NUM2INT(rb_scancode)));
176
193
  }
177
194
 
195
+ /* call-seq:
196
+ * localize(scancode) -> Symbol
197
+ *
198
+ * Returns the key Symbol that +scancode+ produces on the current layout.
199
+ *
200
+ * @return [Symbol] the key that +scancode+ produces on the current keyboard
201
+ * layout
202
+ */
178
203
  static VALUE Keyboard_localize(VALUE module, VALUE rb_scancode) {
179
- return ID2SYM(rb_intern(get_key_event((unsigned int) sfKeyboard_localize((sfScancode) NUM2INT(rb_scancode)))));
204
+ return ID2SYM(rb_intern(
205
+ get_key_event((unsigned int)sfKeyboard_localize((sfScancode)NUM2INT(rb_scancode)))));
180
206
  }
181
207
 
208
+ /* call-seq:
209
+ * delocalize(key) -> Integer
210
+ *
211
+ * Returns the scancode that produces +key+ on the current keyboard layout.
212
+ *
213
+ * @return [Integer] the scancode that produces +key+ on the current keyboard
214
+ * layout
215
+ * @raise [ArgumentError] if +key+ is a Symbol/String naming an unknown key
216
+ */
182
217
  static VALUE Keyboard_delocalize(VALUE module, VALUE rb_key) {
183
- return INT2NUM(sfKeyboard_delocalize((sfKeyCode) Keyboard_key_code(rb_key)));
218
+ return INT2NUM(sfKeyboard_delocalize((sfKeyCode)Keyboard_key_code(rb_key)));
184
219
  }
185
220
 
221
+ /* call-seq:
222
+ * description(scancode) -> String
223
+ *
224
+ * Returns a human-readable, localized name for +scancode+.
225
+ *
226
+ * @return [String] a human-readable, localized name for +scancode+
227
+ */
186
228
  static VALUE Keyboard_description(VALUE module, VALUE rb_scancode) {
187
- const char *description = sfKeyboard_getDescription((sfScancode) NUM2INT(rb_scancode));
229
+ const char* description = sfKeyboard_getDescription((sfScancode)NUM2INT(rb_scancode));
188
230
 
189
231
  return rb_str_new_cstr(description != NULL ? description : "");
190
232
  }
191
233
 
234
+ /* call-seq:
235
+ * virtual_keyboard_visible=(value) -> true or false
236
+ *
237
+ * Shows or hides the on-screen keyboard, where the platform provides one.
238
+ *
239
+ * @return [Boolean] +value+
240
+ */
192
241
  static VALUE Keyboard_set_virtual_keyboard_visible(VALUE module, VALUE rb_visible) {
193
242
  sfKeyboard_setVirtualKeyboardVisible(RTEST(rb_visible));
194
243
  return rb_visible;
195
244
  }
196
245
 
197
- void Init_Keyboard(VALUE rb_module) {
198
- VALUE rb_mKeyboard = rb_define_module_under(rb_module, "Keyboard");
246
+ /* Document-module: SFML::Keyboard
247
+ * Real-time keyboard state and key/scancode lookups.
248
+ */
249
+ void Init_Keyboard(VALUE rb_mSFML) {
250
+ VALUE rb_mKeyboard = rb_define_module_under(rb_mSFML, "Keyboard");
199
251
 
200
252
  rb_define_module_function(rb_mKeyboard, "pressed?", Keyboard_pressed_p, 1);
201
253
  rb_define_module_function(rb_mKeyboard, "scancode_pressed?", Keyboard_scancode_pressed_p, 1);
202
254
  rb_define_module_function(rb_mKeyboard, "localize", Keyboard_localize, 1);
203
255
  rb_define_module_function(rb_mKeyboard, "delocalize", Keyboard_delocalize, 1);
204
256
  rb_define_module_function(rb_mKeyboard, "description", Keyboard_description, 1);
205
- rb_define_module_function(rb_mKeyboard, "virtual_keyboard_visible=",
206
- Keyboard_set_virtual_keyboard_visible, 1);
257
+ rb_define_module_function(
258
+ rb_mKeyboard, "virtual_keyboard_visible=", Keyboard_set_virtual_keyboard_visible, 1);
207
259
  }
data/ext/window/mouse.c CHANGED
@@ -4,29 +4,63 @@
4
4
 
5
5
  #include "window/input_enums.h"
6
6
  #include "window/window.h"
7
+ #include "window/window_base.h"
7
8
  #include "system/vec2.h"
8
9
  #include "core/exceptions.h"
9
10
  #include "core/macros.h"
10
11
  #include "core/sfml.h"
11
12
 
12
- /* nil means desktop-relative. CSFML gives sfRenderWindow its own entry points,
13
- so a window argument never has to be cast down to sfWindowBase. */
14
- static const sfRenderWindow* Mouse_relative_window(VALUE rb_window) {
15
- if (NIL_P(rb_window)) {
16
- return NULL;
13
+ /* A RenderWindow and a Window both wrap an sfRenderWindow; a WindowBase wraps
14
+ an sfWindowBase. CSFML ships a separate entry point for each, so pick the one
15
+ matching the handle -- casting an sfRenderWindow* down to sfWindowBase* would
16
+ rely on the base being at offset 0, which CSFML does not guarantee. */
17
+ static sfVector2i Mouse_get_relative_position(VALUE rb_window) {
18
+ if (rb_obj_is_kind_of(rb_window, Get_Klass_Window())) {
19
+ return sfMouse_getPositionRenderWindow(Get_Window_Struct(rb_window));
20
+ }
21
+
22
+ if (rb_obj_is_kind_of(rb_window, Get_Klass_WindowBase())) {
23
+ return sfMouse_getPositionWindowBase(Get_WindowBase_Struct(rb_window));
24
+ }
25
+
26
+ raise_invalid_argument_class(Get_Klass_WindowBase());
27
+ return (sfVector2i){0, 0};
28
+ }
29
+
30
+ static void Mouse_set_relative_position(VALUE rb_window, sfVector2i position) {
31
+ if (rb_obj_is_kind_of(rb_window, Get_Klass_Window())) {
32
+ sfMouse_setPositionRenderWindow(position, Get_Window_Struct(rb_window));
33
+ return;
17
34
  }
18
35
 
19
- if (!rb_obj_is_kind_of(rb_window, Get_Klass_Window())) {
20
- raise_invalid_argument_class(Get_Klass_Window());
36
+ if (rb_obj_is_kind_of(rb_window, Get_Klass_WindowBase())) {
37
+ sfMouse_setPositionWindowBase(position, Get_WindowBase_Struct(rb_window));
38
+ return;
21
39
  }
22
40
 
23
- return Get_Window_Struct(rb_window);
41
+ raise_invalid_argument_class(Get_Klass_WindowBase());
24
42
  }
25
43
 
44
+ /* call-seq:
45
+ * button_pressed?(button) -> true or false
46
+ *
47
+ * Returns +true+ if +button+ is currently pressed.
48
+ *
49
+ * @return [Boolean] whether +button+ (a Symbol like +:left+, +:right+,
50
+ * +:middle+, or an Integer) is currently pressed
51
+ */
26
52
  static VALUE Mouse_is_button_pressed(VALUE module, VALUE rb_button) {
27
53
  return BOOL2RB(sfMouse_isButtonPressed(mouse_button_from_rb(rb_button)));
28
54
  }
29
55
 
56
+ /* call-seq:
57
+ * position(window = nil) -> Vector2
58
+ *
59
+ * Returns the mouse position in desktop coordinates, or relative to +window+.
60
+ *
61
+ * @return [Vector2] the mouse position in desktop coordinates, or relative
62
+ * to +window+'s client area when given
63
+ */
30
64
  static VALUE Mouse_get_position(int argc, VALUE* argv, VALUE module) {
31
65
  VALUE rb_window;
32
66
  sfVector2i position;
@@ -35,12 +69,20 @@ static VALUE Mouse_get_position(int argc, VALUE* argv, VALUE module) {
35
69
  if (NIL_P(rb_window)) {
36
70
  position = sfMouse_getPosition(NULL);
37
71
  } else {
38
- position = sfMouse_getPositionRenderWindow(Mouse_relative_window(rb_window));
72
+ position = Mouse_get_relative_position(rb_window);
39
73
  }
40
74
 
41
75
  return vec2f_to_rb((sfVector2f){(float)position.x, (float)position.y});
42
76
  }
43
77
 
78
+ /* call-seq:
79
+ * set_position(position, window = nil) -> position
80
+ *
81
+ * Moves the mouse cursor to +position+, in desktop coordinates, or relative
82
+ * to +window+'s client area when given.
83
+ *
84
+ * @return [Vector2] +position+
85
+ */
44
86
  static VALUE Mouse_set_position(int argc, VALUE* argv, VALUE module) {
45
87
  VALUE rb_position, rb_window;
46
88
 
@@ -48,19 +90,28 @@ static VALUE Mouse_set_position(int argc, VALUE* argv, VALUE module) {
48
90
  if (NIL_P(rb_window)) {
49
91
  sfMouse_setPosition(vec2i_from_rb(rb_position), NULL);
50
92
  } else {
51
- sfMouse_setPositionRenderWindow(vec2i_from_rb(rb_position),
52
- Mouse_relative_window(rb_window));
93
+ Mouse_set_relative_position(rb_window, vec2i_from_rb(rb_position));
53
94
  }
54
95
 
55
96
  return rb_position;
56
97
  }
57
98
 
99
+ /* call-seq:
100
+ * position=(value) -> value
101
+ *
102
+ * Moves the mouse cursor to +value+, in desktop coordinates.
103
+ *
104
+ * @return [Vector2] +value+
105
+ */
58
106
  static VALUE Mouse_position_eq(VALUE module, VALUE rb_position) {
59
107
  return Mouse_set_position(1, &rb_position, module);
60
108
  }
61
109
 
62
- void Init_Mouse(VALUE rb_module) {
63
- VALUE rb_mMouse = rb_define_module_under(rb_module, "Mouse");
110
+ /* Document-module: SFML::Mouse
111
+ * Real-time mouse state and cursor positioning.
112
+ */
113
+ void Init_Mouse(VALUE rb_mSFML) {
114
+ VALUE rb_mMouse = rb_define_module_under(rb_mSFML, "Mouse");
64
115
 
65
116
  rb_define_module_function(rb_mMouse, "button_pressed?", Mouse_is_button_pressed, 1);
66
117
  rb_define_module_function(rb_mMouse, "pressed?", Mouse_is_button_pressed, 1);
data/ext/window/sensor.c CHANGED
@@ -7,21 +7,47 @@
7
7
  #include "core/macros.h"
8
8
  #include "core/sfml.h"
9
9
 
10
+ /* call-seq:
11
+ * available?(type) -> true or false
12
+ *
13
+ * Returns +true+ if sensor +type+ is available on this device.
14
+ *
15
+ * @return [Boolean] whether sensor +type+ (a Symbol like
16
+ * +:accelerometer+, +:gyroscope+) is available on this device
17
+ */
10
18
  static VALUE Sensor_is_available(VALUE module, VALUE rb_type) {
11
19
  return BOOL2RB(sfSensor_isAvailable(sensor_type_from_rb(rb_type)));
12
20
  }
13
21
 
22
+ /* call-seq:
23
+ * set_enabled(type, value) -> value
24
+ *
25
+ * Enables or disables sensor +type+. All sensors are disabled by default.
26
+ *
27
+ * @return [Boolean] +value+
28
+ */
14
29
  static VALUE Sensor_set_enabled(VALUE module, VALUE rb_type, VALUE rb_enabled) {
15
30
  sfSensor_setEnabled(sensor_type_from_rb(rb_type), RTEST(rb_enabled));
16
31
  return rb_enabled;
17
32
  }
18
33
 
34
+ /* call-seq:
35
+ * value(type) -> Vector3
36
+ *
37
+ * Returns the current value of sensor +type+.
38
+ *
39
+ * @return [Vector3] the current value of sensor +type+
40
+ */
19
41
  static VALUE Sensor_get_value(VALUE module, VALUE rb_type) {
20
42
  return vec3f_to_rb(sfSensor_getValue(sensor_type_from_rb(rb_type)));
21
43
  }
22
44
 
23
- void Init_Sensor(VALUE rb_module) {
24
- VALUE rb_mSensor = rb_define_module_under(rb_module, "Sensor");
45
+ /* Document-module: SFML::Sensor
46
+ * Access to hardware sensors (accelerometer, gyroscope, etc.), mainly
47
+ * relevant on mobile platforms.
48
+ */
49
+ void Init_Sensor(VALUE rb_mSFML) {
50
+ VALUE rb_mSensor = rb_define_module_under(rb_mSFML, "Sensor");
25
51
 
26
52
  rb_define_module_function(rb_mSensor, "available?", Sensor_is_available, 1);
27
53
  rb_define_module_function(rb_mSensor, "set_enabled", Sensor_set_enabled, 2);
data/ext/window/touch.c CHANGED
@@ -3,29 +3,47 @@
3
3
  #include <ruby.h>
4
4
 
5
5
  #include "window/window.h"
6
+ #include "window/window_base.h"
6
7
  #include "system/vec2.h"
7
8
  #include "core/exceptions.h"
8
9
  #include "core/macros.h"
9
10
  #include "core/sfml.h"
10
11
 
11
- /* nil means desktop-relative. CSFML gives sfRenderWindow its own entry point,
12
- so a window argument never has to be cast down to sfWindowBase. */
13
- static const sfRenderWindow* Touch_relative_window(VALUE rb_window) {
14
- if (NIL_P(rb_window)) {
15
- return NULL;
12
+ /* A RenderWindow and a Window both wrap an sfRenderWindow; a WindowBase wraps
13
+ an sfWindowBase. CSFML ships a separate entry point for each, so pick the one
14
+ matching the handle rather than casting between them. */
15
+ static sfVector2i Touch_relative_position(unsigned int finger, VALUE rb_window) {
16
+ if (rb_obj_is_kind_of(rb_window, Get_Klass_Window())) {
17
+ return sfTouch_getPositionRenderWindow(finger, Get_Window_Struct(rb_window));
16
18
  }
17
19
 
18
- if (!rb_obj_is_kind_of(rb_window, Get_Klass_Window())) {
19
- raise_invalid_argument_class(Get_Klass_Window());
20
+ if (rb_obj_is_kind_of(rb_window, Get_Klass_WindowBase())) {
21
+ return sfTouch_getPositionWindowBase(finger, Get_WindowBase_Struct(rb_window));
20
22
  }
21
23
 
22
- return Get_Window_Struct(rb_window);
24
+ raise_invalid_argument_class(Get_Klass_WindowBase());
25
+ return (sfVector2i){0, 0};
23
26
  }
24
27
 
28
+ /* call-seq:
29
+ * down?(finger) -> true or false
30
+ *
31
+ * Returns +true+ if touch point +finger+ is currently down.
32
+ *
33
+ * @return [Boolean] whether touch point +finger+ is currently down
34
+ */
25
35
  static VALUE Touch_is_down(VALUE module, VALUE rb_finger) {
26
36
  return BOOL2RB(sfTouch_isDown(NUM2UINT(rb_finger)));
27
37
  }
28
38
 
39
+ /* call-seq:
40
+ * position(finger, window = nil) -> Vector2
41
+ *
42
+ * Returns the position of touch point +finger+.
43
+ *
44
+ * @return [Vector2] the position of touch point +finger+, in desktop
45
+ * coordinates, or relative to +window+'s client area when given
46
+ */
29
47
  static VALUE Touch_get_position(int argc, VALUE* argv, VALUE module) {
30
48
  VALUE rb_finger, rb_window;
31
49
  sfVector2i position;
@@ -34,15 +52,17 @@ static VALUE Touch_get_position(int argc, VALUE* argv, VALUE module) {
34
52
  if (NIL_P(rb_window)) {
35
53
  position = sfTouch_getPosition(NUM2UINT(rb_finger), NULL);
36
54
  } else {
37
- position =
38
- sfTouch_getPositionRenderWindow(NUM2UINT(rb_finger), Touch_relative_window(rb_window));
55
+ position = Touch_relative_position(NUM2UINT(rb_finger), rb_window);
39
56
  }
40
57
 
41
58
  return vec2f_to_rb((sfVector2f){(float)position.x, (float)position.y});
42
59
  }
43
60
 
44
- void Init_Touch(VALUE rb_module) {
45
- VALUE rb_mTouch = rb_define_module_under(rb_module, "Touch");
61
+ /* Document-module: SFML::Touch
62
+ * Real-time touch-screen state.
63
+ */
64
+ void Init_Touch(VALUE rb_mSFML) {
65
+ VALUE rb_mTouch = rb_define_module_under(rb_mSFML, "Touch");
46
66
 
47
67
  rb_define_module_function(rb_mTouch, "down?", Touch_is_down, 1);
48
68
  rb_define_module_function(rb_mTouch, "position", Touch_get_position, -1);