@kmamal/sdl 0.9.5 → 0.9.6-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 (57) hide show
  1. package/README.md +111 -103
  2. package/binding.gyp +25 -5
  3. package/package.json +7 -4
  4. package/src/javascript/audio/audio-instance.js +9 -6
  5. package/src/javascript/cleanup.js +1 -1
  6. package/src/javascript/clipboard/index.js +2 -1
  7. package/src/javascript/controller/controller-instance.js +7 -4
  8. package/src/javascript/enums.js +1 -9
  9. package/src/javascript/events/index.js +293 -305
  10. package/src/javascript/index.js +1 -1
  11. package/src/javascript/joystick/device.js +0 -3
  12. package/src/javascript/joystick/joystick-instance.js +8 -6
  13. package/src/javascript/keyboard/index.js +3 -3
  14. package/src/javascript/keyboard/key-mapping.js +14 -6
  15. package/src/javascript/mouse/index.js +14 -13
  16. package/src/javascript/power/index.js +1 -8
  17. package/src/javascript/sensor/sensor-instance.js +1 -5
  18. package/src/javascript/video/index.js +0 -5
  19. package/src/javascript/video/window.js +17 -16
  20. package/src/native/audio.cpp +178 -0
  21. package/src/native/audio.h +21 -0
  22. package/src/native/clipboard.cpp +45 -0
  23. package/src/native/clipboard.h +13 -0
  24. package/src/native/cocoa-global.h +8 -0
  25. package/src/native/cocoa-global.mm +8 -0
  26. package/src/native/cocoa-window.h +9 -4
  27. package/src/native/cocoa-window.mm +6 -9
  28. package/src/native/controller.cpp +160 -0
  29. package/src/native/controller.h +22 -0
  30. package/src/native/enums.cpp +339 -0
  31. package/src/native/enums.h +12 -0
  32. package/src/native/events.cpp +391 -0
  33. package/src/native/events.h +70 -0
  34. package/src/native/global.cpp +361 -0
  35. package/src/native/global.h +15 -0
  36. package/src/native/joystick.cpp +394 -0
  37. package/src/native/joystick.h +29 -0
  38. package/src/native/keyboard.cpp +51 -0
  39. package/src/native/keyboard.h +18 -0
  40. package/src/native/module.cpp +98 -0
  41. package/src/native/mouse.cpp +186 -0
  42. package/src/native/mouse.h +21 -0
  43. package/src/native/power.cpp +23 -0
  44. package/src/native/power.h +17 -0
  45. package/src/native/sensor.cpp +124 -0
  46. package/src/native/sensor.h +21 -0
  47. package/src/native/video.cpp +95 -0
  48. package/src/native/video.h +16 -0
  49. package/src/native/window.cpp +755 -0
  50. package/src/native/window.h +29 -0
  51. package/src/types/index.d.ts +91 -49
  52. package/scripts/test.mjs +0 -12
  53. package/src/native/asprintf.c +0 -47
  54. package/src/native/asprintf.h +0 -37
  55. package/src/native/binding.cpp +0 -1680
  56. package/src/native/sdl-helpers.cpp +0 -2617
  57. package/src/native/sdl-helpers.h +0 -182
@@ -0,0 +1,394 @@
1
+ #include "joystick.h"
2
+ #include "global.h"
3
+ #include <SDL.h>
4
+ #include <string>
5
+ #include <sstream>
6
+ #include <map>
7
+
8
+
9
+ std::map<Uint8, std::string> joystick::hat_positions;
10
+ std::map<SDL_JoystickType, std::string> joystick::joystick_types;
11
+ std::map<SDL_JoystickPowerLevel, std::string> joystick::power_levels;
12
+
13
+
14
+ double
15
+ joystick::mapAxis (int value) {
16
+ const static int SDL_JOYSTICK_AXIS_RANGE = SDL_JOYSTICK_AXIS_MAX - SDL_JOYSTICK_AXIS_MIN;
17
+ return (value - SDL_JOYSTICK_AXIS_MIN) / (SDL_JOYSTICK_AXIS_RANGE / 2.0) - 1;
18
+ }
19
+
20
+ Napi::Array
21
+ joystick::_getDevices (Napi::Env &env)
22
+ {
23
+ int num_devices = SDL_NumJoysticks();
24
+ if (num_devices < 0) {
25
+ std::ostringstream message;
26
+ message << "SDL_NumJoysticks() error: " << SDL_GetError();
27
+ SDL_ClearError();
28
+ throw Napi::Error::New(env, message.str());
29
+ }
30
+
31
+ Napi::Array devices = Napi::Array::New(env, num_devices);
32
+
33
+ for (int i = 0; i < num_devices; i++) {
34
+ int id = SDL_JoystickGetDeviceInstanceID(i);
35
+ if (id == -1) {
36
+ std::ostringstream message;
37
+ message << "SDL_JoystickGetDeviceInstanceID(" << i << ") error: " << SDL_GetError();
38
+ SDL_ClearError();
39
+ throw Napi::Error::New(env, message.str());
40
+ }
41
+
42
+ SDL_JoystickType type = SDL_JoystickGetDeviceType(i);
43
+ // This function can only error if the index is invalid.
44
+
45
+ const char *name = SDL_JoystickNameForIndex(i);
46
+ if (name == nullptr) {
47
+ std::ostringstream message;
48
+ message << "SDL_JoystickNameForIndex(" << i << ") error: " << SDL_GetError();
49
+ SDL_ClearError();
50
+ throw Napi::Error::New(env, message.str());
51
+ }
52
+
53
+ const char *path = SDL_JoystickPathForIndex(i);
54
+ if (path == nullptr) {
55
+ std::ostringstream message;
56
+ message << "SDL_JoystickPathForIndex(" << i << ") error: " << SDL_GetError();
57
+ SDL_ClearError();
58
+ throw Napi::Error::New(env, message.str());
59
+ }
60
+
61
+ SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(i);
62
+ // This function can only error if the index is invalid.
63
+
64
+ char guid_string[33];
65
+ SDL_JoystickGetGUIDString(guid, guid_string, 33);
66
+
67
+ int vendor_number = SDL_JoystickGetDeviceVendor(i);
68
+ Napi::Value vendor = vendor_number == 0 ? env.Null() : Napi::Number::New(env, vendor_number);
69
+
70
+ int product_number = SDL_JoystickGetDeviceProduct(i);
71
+ Napi::Value product = product_number == 0 ? env.Null() : Napi::Number::New(env, product_number);
72
+
73
+ int version_number = SDL_JoystickGetDeviceProductVersion(i);
74
+ Napi::Value version = version_number == 0 ? env.Null() : Napi::Number::New(env, version_number);
75
+
76
+ int player_number = SDL_JoystickGetDevicePlayerIndex(i);
77
+ Napi::Value player = player_number == -1 ? env.Null() : Napi::Number::New(env, player_number);
78
+
79
+ bool is_controller = SDL_IsGameController(i);
80
+
81
+ Napi::Value mapping;
82
+ if (is_controller) {
83
+ const char *device_mapping = SDL_GameControllerMappingForDeviceIndex(i);
84
+ if (device_mapping == nullptr) {
85
+ std::ostringstream message;
86
+ message << "SDL_GameControllerMappingForDeviceIndex(" << i << ") error: " << SDL_GetError();
87
+ SDL_ClearError();
88
+ throw Napi::Error::New(env, message.str());
89
+ }
90
+ mapping = Napi::String::New(env, device_mapping);
91
+ } else {
92
+ mapping = env.Null();
93
+ }
94
+
95
+ Napi::Object device = Napi::Object::New(env);
96
+ device.Set("_index", Napi::Number::New(env, i));
97
+ device.Set("id", Napi::Number::New(env, id));
98
+ device.Set("type", joystick::joystick_types[type]);
99
+ device.Set("name", Napi::String::New(env, name));
100
+ device.Set("path", Napi::String::New(env, path));
101
+ device.Set("guid", Napi::String::New(env, guid_string));
102
+ device.Set("vendor", vendor);
103
+ device.Set("product", product);
104
+ device.Set("version", version);
105
+ device.Set("player", player);
106
+ device.Set("isController", Napi::Boolean::New(env, is_controller));
107
+ device.Set("mapping", mapping);
108
+
109
+ devices.Set(i, device);
110
+ }
111
+
112
+ return devices;
113
+ }
114
+
115
+
116
+ Napi::Value
117
+ joystick::getDevices(const Napi::CallbackInfo &info)
118
+ {
119
+ Napi::Env env = info.Env();
120
+
121
+ return joystick::_getDevices(env);
122
+ }
123
+
124
+ Napi::Value
125
+ joystick::open (const Napi::CallbackInfo &info)
126
+ {
127
+ Napi::Env env = info.Env();
128
+
129
+ int index = info[0].As<Napi::Number>().Int32Value();
130
+
131
+ SDL_Joystick *joystick = SDL_JoystickOpen(index);
132
+ if (joystick == nullptr) {
133
+ std::ostringstream message;
134
+ message << "SDL_JoystickOpen(" << index << ") error: " << SDL_GetError();
135
+ SDL_ClearError();
136
+ throw Napi::Error::New(env, message.str());
137
+ }
138
+
139
+ SDL_JoystickID joystick_id = SDL_JoystickInstanceID(joystick);
140
+ if (joystick_id < 0) {
141
+ std::ostringstream message;
142
+ message << "SDL_JoystickInstanceID(" << index << ") error: " << SDL_GetError();
143
+ SDL_ClearError();
144
+ throw Napi::Error::New(env, message.str());
145
+ }
146
+
147
+ int firmware = SDL_JoystickGetFirmwareVersion(joystick);
148
+ Napi::Value firmware_version = firmware == 0 ? env.Null() : Napi::Number::New(env, firmware);
149
+
150
+ const char *serial = SDL_JoystickGetSerial(joystick);
151
+ Napi::Value serial_number = serial == 0 ? env.Null() : Napi::String::New(env, serial);
152
+
153
+ SDL_bool has_led = SDL_JoystickHasLED(joystick);
154
+ SDL_bool has_rumble = SDL_JoystickHasRumble(joystick);
155
+ SDL_bool has_rumble_triggers = SDL_JoystickHasRumbleTriggers(joystick);
156
+
157
+ int num_axes = SDL_JoystickNumAxes(joystick);
158
+ if (num_axes < 0) {
159
+ std::ostringstream message;
160
+ message << "SDL_JoystickNumAxes(" << index << ") error: " << SDL_GetError();
161
+ SDL_ClearError();
162
+ throw Napi::Error::New(env, message.str());
163
+ }
164
+
165
+ Napi::Array axes = Napi::Array::New(env, num_axes);
166
+
167
+ for (int i = 0; i < num_axes; i++) {
168
+ double value = joystick::mapAxis(SDL_JoystickGetAxis(joystick, i));
169
+ const char *error = SDL_GetError();
170
+ if (error != global::no_error) {
171
+ std::ostringstream message;
172
+ message << "SDL_JoystickGetAxis(" << index << ", " << i << ") error: " << SDL_GetError();
173
+ SDL_ClearError();
174
+ throw Napi::Error::New(env, message.str());
175
+ }
176
+ axes.Set(i, Napi::Number::New(env, value));
177
+ }
178
+
179
+ int num_balls = SDL_JoystickNumBalls(joystick);
180
+ if (num_balls < 0) {
181
+ std::ostringstream message;
182
+ message << "SDL_JoystickNumBalls(" << index << ") error: " << SDL_GetError();
183
+ SDL_ClearError();
184
+ throw Napi::Error::New(env, message.str());
185
+ }
186
+
187
+ Napi::Array balls = Napi::Array::New(env, num_balls);
188
+
189
+ for (int i = 0; i < num_balls; i++) {
190
+ int dx, dy;
191
+ if (SDL_JoystickGetBall(joystick, i, &dx, &dy) == -1) {
192
+ std::ostringstream message;
193
+ message << "SDL_JoystickGetBall(" << index << ", " << i << ") error: " << SDL_GetError();
194
+ SDL_ClearError();
195
+ throw Napi::Error::New(env, message.str());
196
+ }
197
+
198
+ Napi::Object ball = Napi::Object::New(env);
199
+ ball.Set("x", Napi::Number::New(env, dx));
200
+ ball.Set("y", Napi::Number::New(env, dy));
201
+
202
+ balls.Set(i, ball);
203
+ }
204
+
205
+ int num_buttons = SDL_JoystickNumButtons(joystick);
206
+ if (num_buttons < 0) {
207
+ std::ostringstream message;
208
+ message << "SDL_JoystickNumButtons(" << index << ") error: " << SDL_GetError();
209
+ SDL_ClearError();
210
+ throw Napi::Error::New(env, message.str());
211
+ }
212
+
213
+ Napi::Array buttons = Napi::Array::New(env, num_buttons);
214
+
215
+ for (int i = 0; i < num_buttons; i++) {
216
+ int pressed = SDL_JoystickGetButton(joystick, i);
217
+ buttons.Set(i, Napi::Boolean::New(env, pressed));
218
+ }
219
+
220
+ int num_hats = SDL_JoystickNumHats(joystick);
221
+ if (num_hats < 0) {
222
+ std::ostringstream message;
223
+ message << "SDL_JoystickNumHats(" << index << ") error: " << SDL_GetError();
224
+ SDL_ClearError();
225
+ throw Napi::Error::New(env, message.str());
226
+ }
227
+
228
+ Napi::Array hats = Napi::Array::New(env, num_hats);
229
+
230
+ for (int i = 0; i < num_hats; i++) {
231
+ int hat_position = SDL_JoystickGetHat(joystick, i);
232
+ hats.Set(i, joystick::hat_positions[hat_position]);
233
+ }
234
+
235
+ Napi::Object result = Napi::Object::New(env);
236
+ // result.Set("id", Napi::Number::New(env, joystick_id)); // NOTE: Unused. Same as the device id
237
+ result.Set("firmwareVersion", firmware_version);
238
+ result.Set("serialNumber", serial_number);
239
+ result.Set("hasLed", Napi::Boolean::New(env, has_led));
240
+ result.Set("hasRumble", Napi::Boolean::New(env, has_rumble));
241
+ result.Set("hasRumbleTriggers", Napi::Boolean::New(env, has_rumble_triggers));
242
+ result.Set("axes", axes);
243
+ result.Set("balls", balls);
244
+ result.Set("buttons", buttons);
245
+ result.Set("hats", hats);
246
+
247
+ return result;
248
+ }
249
+
250
+ Napi::Value
251
+ joystick::getPower (const Napi::CallbackInfo &info)
252
+ {
253
+ Napi::Env env = info.Env();
254
+
255
+ int joystick_id = info[0].As<Napi::Number>().Int32Value();
256
+
257
+ SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystick_id);
258
+ if (joystick == nullptr) {
259
+ std::ostringstream message;
260
+ message << "SDL_JoystickFromInstanceID(" << joystick_id << ") error: " << SDL_GetError();
261
+ SDL_ClearError();
262
+ throw Napi::Error::New(env, message.str());
263
+ }
264
+
265
+ SDL_JoystickPowerLevel power_level = SDL_JoystickCurrentPowerLevel(joystick);
266
+ if (power_level == SDL_JOYSTICK_POWER_UNKNOWN) { return env.Null(); }
267
+
268
+ return Napi::String::New(env, joystick::power_levels[power_level]);
269
+ }
270
+
271
+ Napi::Value
272
+ joystick::rumble (const Napi::CallbackInfo &info)
273
+ {
274
+ Napi::Env env = info.Env();
275
+
276
+ int joystick_id = info[0].As<Napi::Number>().Int32Value();
277
+ double low_freq_rumble = info[1].As<Napi::Number>().DoubleValue();
278
+ double high_freq_rumble = info[2].As<Napi::Number>().DoubleValue();
279
+ int duration = info[3].As<Napi::Number>().Int32Value();
280
+
281
+ SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystick_id);
282
+ if (joystick == nullptr) {
283
+ std::ostringstream message;
284
+ message << "SDL_JoystickFromInstanceID(" << joystick_id << ") error: " << SDL_GetError();
285
+ SDL_ClearError();
286
+ throw Napi::Error::New(env, message.str());
287
+ }
288
+
289
+ if (SDL_JoystickRumble(joystick, low_freq_rumble * 0xFFFF, high_freq_rumble * 0xFFFF, duration) == -1) {
290
+ std::ostringstream message;
291
+ message << "SDL_JoystickRumble(" << joystick_id << ") error: " << SDL_GetError();
292
+ SDL_ClearError();
293
+ throw Napi::Error::New(env, message.str());
294
+ }
295
+
296
+ return env.Undefined();
297
+ }
298
+
299
+ Napi::Value
300
+ joystick::setLed (const Napi::CallbackInfo &info)
301
+ {
302
+ Napi::Env env = info.Env();
303
+
304
+ int joystick_id = info[0].As<Napi::Number>().Int32Value();
305
+ double red = info[1].As<Napi::Number>().DoubleValue();
306
+ double green = info[2].As<Napi::Number>().DoubleValue();
307
+ double blue = info[3].As<Napi::Number>().DoubleValue();
308
+
309
+ SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystick_id);
310
+ if (joystick == nullptr) {
311
+ std::ostringstream message;
312
+ message << "SDL_JoystickFromInstanceID(" << joystick_id << ") error: " << SDL_GetError();
313
+ SDL_ClearError();
314
+ throw Napi::Error::New(env, message.str());
315
+ }
316
+
317
+ if (SDL_JoystickSetLED(joystick, red * 0xFF, green * 0xFF, blue * 0xFF) == -1) {
318
+ std::ostringstream message;
319
+ message << "SDL_JoystickSetLED(" << joystick_id << ") error: " << SDL_GetError();
320
+ SDL_ClearError();
321
+ throw Napi::Error::New(env, message.str());
322
+ }
323
+
324
+ return env.Undefined();
325
+ }
326
+
327
+ Napi::Value
328
+ joystick::setPlayer (const Napi::CallbackInfo &info)
329
+ {
330
+ Napi::Env env = info.Env();
331
+
332
+ int joystick_id = info[0].As<Napi::Number>().Int32Value();
333
+ int player = info[1].As<Napi::Number>().Int32Value();
334
+
335
+ SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystick_id);
336
+ if (joystick == nullptr) {
337
+ std::ostringstream message;
338
+ message << "SDL_JoystickFromInstanceID(" << joystick_id << ") error: " << SDL_GetError();
339
+ SDL_ClearError();
340
+ throw Napi::Error::New(env, message.str());
341
+ }
342
+
343
+ SDL_JoystickSetPlayerIndex(joystick, player);
344
+
345
+ return env.Undefined();
346
+ }
347
+
348
+ Napi::Value
349
+ joystick::rumbleTriggers (const Napi::CallbackInfo &info)
350
+ {
351
+ Napi::Env env = info.Env();
352
+
353
+ int joystick_id = info[0].As<Napi::Number>().Int32Value();
354
+ double left_rumble = info[1].As<Napi::Number>().DoubleValue();
355
+ double right_rumble = info[2].As<Napi::Number>().DoubleValue();
356
+ int duration = info[3].As<Napi::Number>().Int32Value();
357
+
358
+ SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystick_id);
359
+ if (joystick == nullptr) {
360
+ std::ostringstream message;
361
+ message << "SDL_JoystickFromInstanceID(" << joystick_id << ") error: " << SDL_GetError();
362
+ SDL_ClearError();
363
+ throw Napi::Error::New(env, message.str());
364
+ }
365
+
366
+ if (SDL_JoystickRumbleTriggers(joystick, left_rumble * 0xFFFF, right_rumble * 0xFFFF, duration) == -1) {
367
+ std::ostringstream message;
368
+ message << "SDL_JoystickRumbleTriggers(" << joystick_id << ") error: " << SDL_GetError();
369
+ SDL_ClearError();
370
+ throw Napi::Error::New(env, message.str());
371
+ }
372
+
373
+ return env.Undefined();
374
+ }
375
+
376
+ Napi::Value
377
+ joystick::close (const Napi::CallbackInfo &info)
378
+ {
379
+ Napi::Env env = info.Env();
380
+
381
+ int joystick_id = info[0].As<Napi::Number>().Int32Value();
382
+
383
+ SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystick_id);
384
+ if (joystick == nullptr) {
385
+ std::ostringstream message;
386
+ message << "SDL_JoystickFromInstanceID(" << joystick_id << ") error: " << SDL_GetError();
387
+ SDL_ClearError();
388
+ throw Napi::Error::New(env, message.str());
389
+ }
390
+
391
+ SDL_JoystickClose(joystick);
392
+
393
+ return env.Undefined();
394
+ }
@@ -0,0 +1,29 @@
1
+ #ifndef _JOYSTICK_H_
2
+ #define _JOYSTICK_H_
3
+
4
+ #include <napi.h>
5
+ #include <SDL.h>
6
+ #include <map>
7
+ #include <string>
8
+
9
+ namespace joystick {
10
+
11
+ extern std::map<SDL_JoystickType, std::string> joystick_types;
12
+ extern std::map<Uint8, std::string> hat_positions;
13
+ extern std::map<SDL_JoystickPowerLevel, std::string> power_levels;
14
+
15
+ double mapAxis (int value);
16
+ Napi::Array _getDevices (Napi::Env &env);
17
+
18
+ Napi::Value getDevices(const Napi::CallbackInfo &info);
19
+ Napi::Value open(const Napi::CallbackInfo &info);
20
+ Napi::Value getPower(const Napi::CallbackInfo &info);
21
+ Napi::Value setLed(const Napi::CallbackInfo &info);
22
+ Napi::Value setPlayer(const Napi::CallbackInfo &info);
23
+ Napi::Value rumble(const Napi::CallbackInfo &info);
24
+ Napi::Value rumbleTriggers(const Napi::CallbackInfo &info);
25
+ Napi::Value close(const Napi::CallbackInfo &info);
26
+
27
+ }; // namespace joystick
28
+
29
+ #endif // _JOYSTICK_H_
@@ -0,0 +1,51 @@
1
+ #include "keyboard.h"
2
+ #include <SDL.h>
3
+ #include <string>
4
+ #include <sstream>
5
+
6
+ int keyboard::num_keys;
7
+ const Uint8 *keyboard::keys;
8
+
9
+
10
+ Napi::Value
11
+ keyboard::getKey(const Napi::CallbackInfo &info)
12
+ {
13
+ Napi::Env env = info.Env();
14
+
15
+ int scancode = info[0].As<Napi::Number>().Int32Value();
16
+
17
+ int keycode = SDL_GetKeyFromScancode((SDL_Scancode) scancode);
18
+ const char *keyname = SDL_GetKeyName(keycode);
19
+
20
+ return Napi::String::New(env, keyname);
21
+ }
22
+
23
+ Napi::Value
24
+ keyboard::getScancode(const Napi::CallbackInfo &info)
25
+ {
26
+ Napi::Env env = info.Env();
27
+
28
+ std::string keyname = info[0].As<Napi::String>().Utf8Value();
29
+
30
+ SDL_Keycode keycode = SDL_GetKeyFromName(keyname.c_str());
31
+ if (keycode == SDLK_UNKNOWN) { return env.Null(); }
32
+
33
+ int scancode = SDL_GetScancodeFromKey(keycode);
34
+ if (scancode == 0) { return env.Null(); }
35
+
36
+ return Napi::Number::New(env, scancode);
37
+ }
38
+
39
+ Napi::Value
40
+ keyboard::getState(const Napi::CallbackInfo &info)
41
+ {
42
+ Napi::Env env = info.Env();
43
+
44
+ Napi::Array result = Napi::Array::New(env, keyboard::num_keys);
45
+
46
+ for (int i = 0 ; i < keyboard::num_keys; i++) {
47
+ result.Set(i, Napi::Boolean::New(env, !!keyboard::keys[i]));
48
+ }
49
+
50
+ return result;
51
+ }
@@ -0,0 +1,18 @@
1
+ #ifndef _KEYBOARD_H_
2
+ #define _KEYBOARD_H_
3
+
4
+ #include <napi.h>
5
+ #include <SDL.h>
6
+
7
+ namespace keyboard {
8
+
9
+ extern int num_keys;
10
+ extern const Uint8 *keys;
11
+
12
+ Napi::Value getKey(const Napi::CallbackInfo &info);
13
+ Napi::Value getScancode(const Napi::CallbackInfo &info);
14
+ Napi::Value getState(const Napi::CallbackInfo &info);
15
+
16
+ }; // namespace keyboard
17
+
18
+ #endif // _KEYBOARD_H_
@@ -0,0 +1,98 @@
1
+ #include <napi.h>
2
+
3
+ #include "enums.h"
4
+ #include "global.h"
5
+ #include "events.h"
6
+ #include "video.h"
7
+ #include "window.h"
8
+ #include "keyboard.h"
9
+ #include "mouse.h"
10
+ #include "joystick.h"
11
+ #include "controller.h"
12
+ #include "sensor.h"
13
+ #include "audio.h"
14
+ #include "clipboard.h"
15
+ #include "power.h"
16
+
17
+
18
+ Napi::Object
19
+ init (Napi::Env env, Napi::Object exports)
20
+ {
21
+ exports.Set("enums_get", Napi::Function::New<enums::get>(env));
22
+
23
+ exports.Set("global_initialize", Napi::Function::New<global::initialize>(env));
24
+ exports.Set("global_cleanup", Napi::Function::New<global::cleanup>(env));
25
+
26
+ exports.Set("events_poll", Napi::Function::New<events::poll>(env));
27
+
28
+ exports.Set("video_getDisplays", Napi::Function::New<video::getDisplays>(env));
29
+
30
+ exports.Set("window_create", Napi::Function::New<window::create>(env));
31
+ exports.Set("window_setTitle", Napi::Function::New<window::setTitle>(env));
32
+ exports.Set("window_setPosition", Napi::Function::New<window::setPosition>(env));
33
+ exports.Set("window_setSize", Napi::Function::New<window::setSize>(env));
34
+ exports.Set("window_setFullscreen", Napi::Function::New<window::setFullscreen>(env));
35
+ exports.Set("window_setResizable", Napi::Function::New<window::setResizable>(env));
36
+ exports.Set("window_setBorderless", Napi::Function::New<window::setBorderless>(env));
37
+ exports.Set("window_setAcceleratedAndVsync", Napi::Function::New<window::setAcceleratedAndVsync>(env));
38
+ exports.Set("window_focus", Napi::Function::New<window::focus>(env));
39
+ exports.Set("window_show", Napi::Function::New<window::show>(env));
40
+ exports.Set("window_hide", Napi::Function::New<window::hide>(env));
41
+ exports.Set("window_maximize", Napi::Function::New<window::maximize>(env));
42
+ exports.Set("window_minimize", Napi::Function::New<window::minimize>(env));
43
+ exports.Set("window_restore", Napi::Function::New<window::restore>(env));
44
+ exports.Set("window_render", Napi::Function::New<window::render>(env));
45
+ exports.Set("window_setIcon", Napi::Function::New<window::setIcon>(env));
46
+ exports.Set("window_flash", Napi::Function::New<window::flash>(env));
47
+ exports.Set("window_destroy", Napi::Function::New<window::destroy>(env));
48
+
49
+ exports.Set("keyboard_getKey", Napi::Function::New<keyboard::getKey>(env));
50
+ exports.Set("keyboard_getScancode", Napi::Function::New<keyboard::getScancode>(env));
51
+ exports.Set("keyboard_getState", Napi::Function::New<keyboard::getState>(env));
52
+
53
+ exports.Set("mouse_getButton", Napi::Function::New<mouse::getButton>(env));
54
+ exports.Set("mouse_getPosition", Napi::Function::New<mouse::getPosition>(env));
55
+ exports.Set("mouse_setPosition", Napi::Function::New<mouse::setPosition>(env));
56
+ exports.Set("mouse_capture", Napi::Function::New<mouse::capture>(env));
57
+ exports.Set("mouse_setCursor", Napi::Function::New<mouse::setCursor>(env));
58
+ exports.Set("mouse_resetCursor", Napi::Function::New<mouse::resetCursor>(env));
59
+ exports.Set("mouse_setCursorImage", Napi::Function::New<mouse::setCursorImage>(env));
60
+ exports.Set("mouse_showCursor", Napi::Function::New<mouse::showCursor>(env));
61
+ exports.Set("mouse_redrawCursor", Napi::Function::New<mouse::redrawCursor>(env));
62
+
63
+ exports.Set("joystick_getDevices", Napi::Function::New<joystick::getDevices>(env));
64
+ exports.Set("joystick_open", Napi::Function::New<joystick::open>(env));
65
+ exports.Set("joystick_getPower", Napi::Function::New<joystick::getPower>(env));
66
+ exports.Set("joystick_setLed", Napi::Function::New<joystick::setLed>(env));
67
+ exports.Set("joystick_setPlayer", Napi::Function::New<joystick::setPlayer>(env));
68
+ exports.Set("joystick_rumble", Napi::Function::New<joystick::rumble>(env));
69
+ exports.Set("joystick_rumbleTriggers", Napi::Function::New<joystick::rumbleTriggers>(env));
70
+ exports.Set("joystick_close", Napi::Function::New<joystick::close>(env));
71
+
72
+ exports.Set("controller_addMappings", Napi::Function::New<controller::addMappings>(env));
73
+ exports.Set("controller_open", Napi::Function::New<controller::open>(env));
74
+ exports.Set("controller_close", Napi::Function::New<controller::close>(env));
75
+
76
+ exports.Set("sensor_getDevices", Napi::Function::New<sensor::getDevices>(env));
77
+ exports.Set("sensor_open", Napi::Function::New<sensor::open>(env));
78
+ exports.Set("sensor_getData", Napi::Function::New<sensor::getData>(env));
79
+ exports.Set("sensor_close", Napi::Function::New<sensor::close>(env));
80
+
81
+ exports.Set("audio_getDevices", Napi::Function::New<audio::getDevices>(env));
82
+ exports.Set("audio_open", Napi::Function::New<audio::open>(env));
83
+ exports.Set("audio_play", Napi::Function::New<audio::play>(env));
84
+ exports.Set("audio_getQueueSize", Napi::Function::New<audio::getQueueSize>(env));
85
+ exports.Set("audio_enqueue", Napi::Function::New<audio::enqueue>(env));
86
+ exports.Set("audio_dequeue", Napi::Function::New<audio::dequeue>(env));
87
+ exports.Set("audio_clearQueue", Napi::Function::New<audio::clearQueue>(env));
88
+ exports.Set("audio_close", Napi::Function::New<audio::close>(env));
89
+
90
+ exports.Set("clipboard_getText", Napi::Function::New<clipboard::getText>(env));
91
+ exports.Set("clipboard_setText", Napi::Function::New<clipboard::setText>(env));
92
+
93
+ exports.Set("power_getInfo", Napi::Function::New<power::getInfo>(env));
94
+
95
+ return exports;
96
+ }
97
+
98
+ NODE_API_MODULE(NODE_GYP_MODULE_NAME, init)