@kmamal/sdl 0.11.5 → 0.11.7
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.
- package/README.md +46 -7
- package/binding.gyp +1 -0
- package/package.json +1 -1
- package/src/javascript/audio/audio-instance.js +2 -3
- package/src/javascript/audio/device.js +1 -10
- package/src/javascript/audio/index.js +5 -7
- package/src/javascript/controller/controller-instance.js +2 -0
- package/src/javascript/controller/device.js +14 -3
- package/src/javascript/controller/index.js +5 -11
- package/src/javascript/events/index.js +56 -126
- package/src/javascript/events/reconcile-audio-devices.js +15 -0
- package/src/javascript/events/reconcile-displays.js +16 -0
- package/src/javascript/events/reconcile-joystick-and-controller-devices.js +37 -0
- package/src/javascript/events/reconcile.js +61 -0
- package/src/javascript/joystick/device.js +9 -3
- package/src/javascript/joystick/index.js +13 -5
- package/src/javascript/joystick/joystick-instance.js +2 -0
- package/src/javascript/sensor/sensor-instance.js +2 -0
- package/src/javascript/video/display.js +4 -0
- package/src/javascript/video/index.js +1 -0
- package/src/native/audio.cpp +10 -12
- package/src/native/audio.h +4 -0
- package/src/native/controller.cpp +72 -56
- package/src/native/controller.h +3 -0
- package/src/native/enums.cpp +315 -315
- package/src/native/events.cpp +156 -80
- package/src/native/events.h +1 -0
- package/src/native/global.cpp +46 -20
- package/src/native/joystick.cpp +87 -48
- package/src/native/joystick.h +3 -2
- package/src/native/keyboard.cpp +1 -1
- package/src/native/mouse.cpp +2 -2
- package/src/native/power.cpp +9 -3
- package/src/native/sensor.cpp +24 -13
- package/src/native/video.cpp +21 -13
- package/src/native/video.h +1 -0
- package/src/native/window.cpp +28 -22
- package/src/types/index.d.ts +57 -17
package/src/native/events.cpp
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#include "events.h"
|
|
2
2
|
#include "enums.h"
|
|
3
3
|
#include "global.h"
|
|
4
|
+
#include "video.h"
|
|
4
5
|
#include "joystick.h"
|
|
5
6
|
#include "controller.h"
|
|
6
7
|
#include "audio.h"
|
|
@@ -27,6 +28,7 @@ std::string events::types::QUIT;
|
|
|
27
28
|
std::string events::types::DISPLAY_ADD;
|
|
28
29
|
std::string events::types::DISPLAY_REMOVE;
|
|
29
30
|
std::string events::types::DISPLAY_ORIENT;
|
|
31
|
+
std::string events::types::DISPLAY_MOVE;
|
|
30
32
|
std::string events::types::DISPLAY_CHANGE;
|
|
31
33
|
std::string events::types::SHOW;
|
|
32
34
|
std::string events::types::HIDE;
|
|
@@ -83,19 +85,50 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
83
85
|
|
|
84
86
|
case SDL_DISPLAYEVENT: {
|
|
85
87
|
packed.Set("family", events::families::DISPLAY);
|
|
86
|
-
|
|
88
|
+
|
|
89
|
+
int display_index = event.display.display;
|
|
90
|
+
packed.Set("displayIndex", display_index);
|
|
87
91
|
|
|
88
92
|
switch (event.display.event) {
|
|
89
93
|
case SDL_DISPLAYEVENT_CONNECTED: { packed.Set("type", events::types::DISPLAY_ADD); break; }
|
|
90
94
|
case SDL_DISPLAYEVENT_DISCONNECTED: { packed.Set("type", events::types::DISPLAY_REMOVE); break; }
|
|
91
|
-
case SDL_DISPLAYEVENT_ORIENTATION: {
|
|
95
|
+
case SDL_DISPLAYEVENT_ORIENTATION: {
|
|
96
|
+
packed.Set("type", events::types::DISPLAY_ORIENT);
|
|
97
|
+
packed.Set("orientation", video::orientations[(SDL_DisplayOrientation) event.display.data1]);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case SDL_DISPLAYEVENT_MOVED: {
|
|
101
|
+
packed.Set("type", events::types::DISPLAY_MOVE);
|
|
102
|
+
|
|
103
|
+
SDL_Rect rect;
|
|
104
|
+
|
|
105
|
+
if(SDL_GetDisplayBounds(display_index, &rect) < 0) {
|
|
106
|
+
std::ostringstream message;
|
|
107
|
+
message << "SDL_GetDisplayBounds(" << display_index << ") error: " << SDL_GetError();
|
|
108
|
+
SDL_ClearError();
|
|
109
|
+
throw Napi::Error::New(env, message.str());
|
|
110
|
+
}
|
|
111
|
+
packed.Set("geometryX", rect.x);
|
|
112
|
+
packed.Set("geometryY", rect.y);
|
|
113
|
+
|
|
114
|
+
if(SDL_GetDisplayUsableBounds(display_index, &rect) < 0) {
|
|
115
|
+
std::ostringstream message;
|
|
116
|
+
message << "SDL_GetDisplayUsableBounds(" << display_index << ") error: " << SDL_GetError();
|
|
117
|
+
SDL_ClearError();
|
|
118
|
+
throw Napi::Error::New(env, message.str());
|
|
119
|
+
}
|
|
120
|
+
packed.Set("usableX", rect.x);
|
|
121
|
+
packed.Set("usableY", rect.y);
|
|
122
|
+
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
92
125
|
}
|
|
93
126
|
break;
|
|
94
127
|
}
|
|
95
128
|
|
|
96
129
|
case SDL_WINDOWEVENT: {
|
|
97
130
|
packed.Set("family", events::families::WINDOW);
|
|
98
|
-
packed.Set("windowId",
|
|
131
|
+
packed.Set("windowId", event.window.windowID);
|
|
99
132
|
|
|
100
133
|
switch (event.window.event) {
|
|
101
134
|
case SDL_WINDOWEVENT_SHOWN: { packed.Set("type", events::types::SHOW); break; }
|
|
@@ -103,8 +136,8 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
103
136
|
case SDL_WINDOWEVENT_EXPOSED: { packed.Set("type", events::types::EXPOSE); break; }
|
|
104
137
|
case SDL_WINDOWEVENT_MOVED: {
|
|
105
138
|
packed.Set("type", events::types::MOVE);
|
|
106
|
-
packed.Set("x",
|
|
107
|
-
packed.Set("y",
|
|
139
|
+
packed.Set("x", event.window.data1);
|
|
140
|
+
packed.Set("y", event.window.data2);
|
|
108
141
|
break;
|
|
109
142
|
}
|
|
110
143
|
case SDL_WINDOWEVENT_SIZE_CHANGED: {
|
|
@@ -123,15 +156,15 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
123
156
|
SDL_GetWindowSizeInPixels(window, &pixel_width, &pixel_height);
|
|
124
157
|
|
|
125
158
|
packed.Set("type", events::types::RESIZE);
|
|
126
|
-
packed.Set("width",
|
|
127
|
-
packed.Set("height",
|
|
128
|
-
packed.Set("pixelWidth",
|
|
129
|
-
packed.Set("pixelHeight",
|
|
159
|
+
packed.Set("width", event.window.data1);
|
|
160
|
+
packed.Set("height", event.window.data2);
|
|
161
|
+
packed.Set("pixelWidth", pixel_width);
|
|
162
|
+
packed.Set("pixelHeight", pixel_height);
|
|
130
163
|
break;
|
|
131
164
|
}
|
|
132
165
|
case SDL_WINDOWEVENT_DISPLAY_CHANGED: {
|
|
133
166
|
packed.Set("type", events::types::DISPLAY_CHANGE);
|
|
134
|
-
packed.Set("displayIndex",
|
|
167
|
+
packed.Set("displayIndex", event.window.data1);
|
|
135
168
|
break;
|
|
136
169
|
}
|
|
137
170
|
case SDL_WINDOWEVENT_MINIMIZED: { packed.Set("type", events::types::MINIMIZE); break; }
|
|
@@ -150,7 +183,7 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
150
183
|
case SDL_DROPCOMPLETE: {
|
|
151
184
|
packed.Set("family", events::families::DROP);
|
|
152
185
|
packed.Set("type", event.type == SDL_DROPBEGIN ? events::types::DROP_BEGIN : events::types::DROP_COMPLETE);
|
|
153
|
-
packed.Set("windowId",
|
|
186
|
+
packed.Set("windowId", event.drop.windowID);
|
|
154
187
|
break;
|
|
155
188
|
}
|
|
156
189
|
case SDL_DROPFILE:
|
|
@@ -158,84 +191,94 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
158
191
|
packed.Set("family", events::families::DROP);
|
|
159
192
|
bool is_file = event.type == SDL_DROPFILE;
|
|
160
193
|
packed.Set("type", is_file ? events::types::DROP_FILE : events::types::DROP_TEXT);
|
|
161
|
-
packed.Set("windowId",
|
|
162
|
-
packed.Set(is_file ? "file" : "text",
|
|
194
|
+
packed.Set("windowId", event.drop.windowID);
|
|
195
|
+
packed.Set(is_file ? "file" : "text", event.drop.file);
|
|
163
196
|
break;
|
|
164
197
|
}
|
|
165
198
|
|
|
166
199
|
case SDL_KEYDOWN:
|
|
167
200
|
case SDL_KEYUP: {
|
|
168
201
|
packed.Set("family", events::families::KEYBOARD);
|
|
169
|
-
packed.Set(
|
|
170
|
-
|
|
202
|
+
packed.Set(
|
|
203
|
+
"type",
|
|
204
|
+
event.type == SDL_KEYDOWN
|
|
205
|
+
? events::types::KEY_DOWN
|
|
206
|
+
: events::types::KEY_UP
|
|
207
|
+
);
|
|
208
|
+
packed.Set("windowId", event.key.windowID);
|
|
171
209
|
|
|
172
210
|
SDL_Keysym symbol = event.key.keysym;
|
|
173
|
-
packed.Set("scancode",
|
|
211
|
+
packed.Set("scancode", (int) symbol.scancode);
|
|
174
212
|
|
|
175
213
|
const char *name = SDL_GetKeyName(symbol.sym);
|
|
176
214
|
if (name[0] != '\0') {
|
|
177
|
-
packed.Set("key",
|
|
215
|
+
packed.Set("key", name);
|
|
178
216
|
}
|
|
179
217
|
else {
|
|
180
218
|
packed.Set("key", env.Null());
|
|
181
219
|
}
|
|
182
220
|
|
|
183
221
|
if (event.type == SDL_KEYDOWN) {
|
|
184
|
-
packed.Set("repeat",
|
|
222
|
+
packed.Set("repeat", !!event.key.repeat);
|
|
185
223
|
}
|
|
186
224
|
|
|
187
|
-
packed.Set("alt",
|
|
188
|
-
packed.Set("ctrl",
|
|
189
|
-
packed.Set("shift",
|
|
190
|
-
packed.Set("super",
|
|
191
|
-
packed.Set("altgr",
|
|
192
|
-
packed.Set("numlock",
|
|
193
|
-
packed.Set("capslock",
|
|
225
|
+
packed.Set("alt", !!(symbol.mod & KMOD_ALT));
|
|
226
|
+
packed.Set("ctrl", !!(symbol.mod & KMOD_CTRL));
|
|
227
|
+
packed.Set("shift", !!(symbol.mod & KMOD_SHIFT));
|
|
228
|
+
packed.Set("super", !!(symbol.mod & KMOD_GUI));
|
|
229
|
+
packed.Set("altgr", !!(symbol.mod & KMOD_MODE));
|
|
230
|
+
packed.Set("numlock", !!(symbol.mod & KMOD_NUM));
|
|
231
|
+
packed.Set("capslock", !!(symbol.mod & KMOD_CAPS));
|
|
194
232
|
break;
|
|
195
233
|
}
|
|
196
234
|
|
|
197
235
|
case SDL_TEXTINPUT: {
|
|
198
236
|
packed.Set("family", events::families::TEXT);
|
|
199
237
|
packed.Set("type", events::types::TEXT_INPUT);
|
|
200
|
-
packed.Set("windowId",
|
|
201
|
-
packed.Set("text",
|
|
238
|
+
packed.Set("windowId", event.text.windowID);
|
|
239
|
+
packed.Set("text", event.text.text);
|
|
202
240
|
break ;
|
|
203
241
|
}
|
|
204
242
|
|
|
205
243
|
case SDL_MOUSEMOTION: {
|
|
206
244
|
packed.Set("family", events::families::MOUSE);
|
|
207
245
|
packed.Set("type", events::types::MOUSE_MOVE);
|
|
208
|
-
packed.Set("windowId",
|
|
209
|
-
packed.Set("touch",
|
|
210
|
-
packed.Set("x",
|
|
211
|
-
packed.Set("y",
|
|
246
|
+
packed.Set("windowId", event.motion.windowID);
|
|
247
|
+
packed.Set("touch", event.motion.which == SDL_TOUCH_MOUSEID);
|
|
248
|
+
packed.Set("x", event.motion.x);
|
|
249
|
+
packed.Set("y", event.motion.y);
|
|
212
250
|
break;
|
|
213
251
|
}
|
|
214
252
|
case SDL_MOUSEBUTTONDOWN:
|
|
215
253
|
case SDL_MOUSEBUTTONUP: {
|
|
216
254
|
packed.Set("family", events::families::MOUSE);
|
|
217
|
-
packed.Set(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
255
|
+
packed.Set(
|
|
256
|
+
"type",
|
|
257
|
+
event.type == SDL_MOUSEBUTTONDOWN
|
|
258
|
+
? events::types::MOUSE_BUTTON_DOWN
|
|
259
|
+
: events::types::MOUSE_BUTTON_UP
|
|
260
|
+
);
|
|
261
|
+
packed.Set("windowId", event.button.windowID);
|
|
262
|
+
packed.Set("touch", event.button.which == SDL_TOUCH_MOUSEID);
|
|
263
|
+
packed.Set("button", event.button.button);
|
|
264
|
+
packed.Set("x", event.button.x);
|
|
265
|
+
packed.Set("y", event.button.y);
|
|
223
266
|
break;
|
|
224
267
|
}
|
|
225
268
|
case SDL_MOUSEWHEEL: {
|
|
226
269
|
packed.Set("family", events::families::MOUSE);
|
|
227
270
|
packed.Set("type", events::types::MOUSE_WHEEL);
|
|
228
|
-
packed.Set("windowId",
|
|
229
|
-
packed.Set("touch",
|
|
271
|
+
packed.Set("windowId", event.wheel.windowID);
|
|
272
|
+
packed.Set("touch", event.wheel.which == SDL_TOUCH_MOUSEID);
|
|
230
273
|
|
|
231
274
|
int x, y;
|
|
232
275
|
SDL_GetMouseState(&x, &y);
|
|
233
|
-
packed.Set("x",
|
|
234
|
-
packed.Set("y",
|
|
276
|
+
packed.Set("x", x);
|
|
277
|
+
packed.Set("y", y);
|
|
235
278
|
|
|
236
|
-
packed.Set("dx",
|
|
237
|
-
packed.Set("dy",
|
|
238
|
-
packed.Set("flipped",
|
|
279
|
+
packed.Set("dx", event.wheel.x);
|
|
280
|
+
packed.Set("dy", event.wheel.y);
|
|
281
|
+
packed.Set("flipped", event.wheel.direction);
|
|
239
282
|
break;
|
|
240
283
|
}
|
|
241
284
|
|
|
@@ -248,7 +291,7 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
248
291
|
case SDL_JOYDEVICEREMOVED: {
|
|
249
292
|
packed.Set("family", events::families::JOYSTICK_DEVICE);
|
|
250
293
|
packed.Set("type", events::types::DEVICE_REMOVE);
|
|
251
|
-
packed.Set("joystickId",
|
|
294
|
+
packed.Set("joystickId", event.jdevice.which);
|
|
252
295
|
packed.Set("devices", joystick::_getDevices(env));
|
|
253
296
|
break;
|
|
254
297
|
}
|
|
@@ -256,33 +299,48 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
256
299
|
case SDL_JOYAXISMOTION: {
|
|
257
300
|
packed.Set("family", events::families::JOYSTICK);
|
|
258
301
|
packed.Set("type", events::types::AXIS_MOTION);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
302
|
+
|
|
303
|
+
int joystick_id = event.jaxis.which;
|
|
304
|
+
SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystick_id);
|
|
305
|
+
if (joystick == nullptr) {
|
|
306
|
+
std::ostringstream message;
|
|
307
|
+
message << "SDL_JoystickFromInstanceID(" << joystick_id << ") error: " << SDL_GetError();
|
|
308
|
+
SDL_ClearError();
|
|
309
|
+
throw Napi::Error::New(env, message.str());
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
packed.Set("joystickId", joystick_id);
|
|
313
|
+
packed.Set("axis", event.jaxis.axis);
|
|
314
|
+
packed.Set("value", joystick::mapAxisValue(joystick, event.jaxis.axis, event.jaxis.value));
|
|
262
315
|
break ;
|
|
263
316
|
}
|
|
264
317
|
case SDL_JOYBALLMOTION: {
|
|
265
318
|
packed.Set("family", events::families::JOYSTICK);
|
|
266
319
|
packed.Set("type", events::types::BALL_MOTION);
|
|
267
|
-
packed.Set("joystickId",
|
|
268
|
-
packed.Set("ball",
|
|
269
|
-
packed.Set("x",
|
|
270
|
-
packed.Set("y",
|
|
320
|
+
packed.Set("joystickId", event.jball.which);
|
|
321
|
+
packed.Set("ball", event.jball.ball);
|
|
322
|
+
packed.Set("x", event.jball.xrel);
|
|
323
|
+
packed.Set("y", event.jball.yrel);
|
|
271
324
|
break ;
|
|
272
325
|
}
|
|
273
326
|
case SDL_JOYBUTTONDOWN:
|
|
274
327
|
case SDL_JOYBUTTONUP: {
|
|
275
328
|
packed.Set("family", events::families::JOYSTICK);
|
|
276
|
-
packed.Set(
|
|
277
|
-
|
|
278
|
-
|
|
329
|
+
packed.Set(
|
|
330
|
+
"type",
|
|
331
|
+
event.type == SDL_JOYBUTTONDOWN
|
|
332
|
+
? events::types::BUTTON_DOWN
|
|
333
|
+
: events::types::BUTTON_UP
|
|
334
|
+
);
|
|
335
|
+
packed.Set("joystickId", event.jbutton.which);
|
|
336
|
+
packed.Set("button", event.jbutton.button);
|
|
279
337
|
break ;
|
|
280
338
|
}
|
|
281
339
|
case SDL_JOYHATMOTION: {
|
|
282
340
|
packed.Set("family", events::families::JOYSTICK);
|
|
283
341
|
packed.Set("type", events::types::HAT_MOTION);
|
|
284
|
-
packed.Set("joystickId",
|
|
285
|
-
packed.Set("hat",
|
|
342
|
+
packed.Set("joystickId", event.jhat.which);
|
|
343
|
+
packed.Set("hat", event.jhat.hat);
|
|
286
344
|
packed.Set("value", joystick::hat_positions[event.jhat.value]);
|
|
287
345
|
break ;
|
|
288
346
|
}
|
|
@@ -290,9 +348,8 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
290
348
|
case SDL_CONTROLLERDEVICEREMAPPED: {
|
|
291
349
|
packed.Set("family", events::families::CONTROLLER);
|
|
292
350
|
packed.Set("type", events::types::REMAP);
|
|
293
|
-
SDL_JoystickID controller_id = event.cdevice.which;
|
|
294
|
-
packed.Set("controllerId", Napi::Number::New(env, controller_id));
|
|
295
351
|
|
|
352
|
+
SDL_JoystickID controller_id = event.cdevice.which;
|
|
296
353
|
SDL_GameController *controller = SDL_GameControllerFromInstanceID(controller_id);
|
|
297
354
|
if (controller == nullptr) {
|
|
298
355
|
std::ostringstream message;
|
|
@@ -301,6 +358,7 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
301
358
|
throw Napi::Error::New(env, message.str());
|
|
302
359
|
}
|
|
303
360
|
|
|
361
|
+
packed.Set("controllerId", controller_id);
|
|
304
362
|
controller::getState(env, controller, packed);
|
|
305
363
|
break;
|
|
306
364
|
}
|
|
@@ -308,16 +366,32 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
308
366
|
case SDL_CONTROLLERAXISMOTION: {
|
|
309
367
|
packed.Set("family", events::families::CONTROLLER);
|
|
310
368
|
packed.Set("type", events::types::AXIS_MOTION);
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
369
|
+
|
|
370
|
+
int controller_id = event.caxis.which;
|
|
371
|
+
SDL_GameController *controller = SDL_GameControllerFromInstanceID(controller_id);
|
|
372
|
+
if (controller == nullptr) {
|
|
373
|
+
std::ostringstream message;
|
|
374
|
+
message << "SDL_GameControllerFromInstanceID(" << controller_id << ") error: " << SDL_GetError();
|
|
375
|
+
SDL_ClearError();
|
|
376
|
+
throw Napi::Error::New(env, message.str());
|
|
377
|
+
}
|
|
378
|
+
SDL_GameControllerAxis axis = (SDL_GameControllerAxis) event.caxis.axis;
|
|
379
|
+
|
|
380
|
+
packed.Set("controllerId", controller_id);
|
|
381
|
+
packed.Set("axis", controller::axes[axis]);
|
|
382
|
+
packed.Set("value", controller::mapAxisValue(controller, axis, event.caxis.value));
|
|
314
383
|
break;
|
|
315
384
|
}
|
|
316
385
|
case SDL_CONTROLLERBUTTONDOWN:
|
|
317
386
|
case SDL_CONTROLLERBUTTONUP: {
|
|
318
387
|
packed.Set("family", events::families::CONTROLLER);
|
|
319
|
-
packed.Set(
|
|
320
|
-
|
|
388
|
+
packed.Set(
|
|
389
|
+
"type",
|
|
390
|
+
event.type == SDL_CONTROLLERBUTTONDOWN
|
|
391
|
+
? events::types::BUTTON_DOWN
|
|
392
|
+
: events::types::BUTTON_UP
|
|
393
|
+
);
|
|
394
|
+
packed.Set("controllerId", event.cbutton.which);
|
|
321
395
|
packed.Set("button", controller::buttons[(SDL_GameControllerButton) event.cbutton.button]);
|
|
322
396
|
break;
|
|
323
397
|
}
|
|
@@ -325,7 +399,7 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
325
399
|
case SDL_SENSORUPDATE: {
|
|
326
400
|
packed.Set("family", events::families::SENSOR);
|
|
327
401
|
packed.Set("type", events::types::UPDATE);
|
|
328
|
-
packed.Set("sensorId",
|
|
402
|
+
packed.Set("sensorId", event.sensor.which);
|
|
329
403
|
break;
|
|
330
404
|
}
|
|
331
405
|
|
|
@@ -333,16 +407,18 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
333
407
|
packed.Set("family", events::families::AUDIO_DEVICE);
|
|
334
408
|
packed.Set("type", events::types::DEVICE_ADD);
|
|
335
409
|
bool is_capture = event.adevice.iscapture;
|
|
336
|
-
packed.Set("
|
|
410
|
+
packed.Set("audioDeviceType", audio::device_types[is_capture]);
|
|
337
411
|
packed.Set("devices", audio::_getDevices(env, is_capture));
|
|
338
412
|
break;
|
|
339
413
|
}
|
|
340
414
|
case SDL_AUDIODEVICEREMOVED: {
|
|
341
415
|
packed.Set("family", events::families::AUDIO_DEVICE);
|
|
342
416
|
packed.Set("type", events::types::DEVICE_REMOVE);
|
|
343
|
-
|
|
417
|
+
|
|
344
418
|
bool is_capture = event.adevice.iscapture;
|
|
345
|
-
|
|
419
|
+
|
|
420
|
+
packed.Set("audioId", event.adevice.which);
|
|
421
|
+
packed.Set("audioDeviceType", audio::device_types[is_capture]);
|
|
346
422
|
packed.Set("devices", audio::_getDevices(env, is_capture));
|
|
347
423
|
break;
|
|
348
424
|
}
|
|
@@ -358,22 +434,22 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
358
434
|
// SET_STRING(object, "type", event.type == SDL_FINGERUP
|
|
359
435
|
// ? "fingerUp"
|
|
360
436
|
// : "fingerDown");
|
|
361
|
-
// packed.Set("touch_id",
|
|
362
|
-
// packed.Set("finger_id",
|
|
363
|
-
// packed.Set("pressure",
|
|
364
|
-
// packed.Set("x",
|
|
365
|
-
// packed.Set("y",
|
|
437
|
+
// packed.Set("touch_id", event.tfinger.touchId);
|
|
438
|
+
// packed.Set("finger_id", event.tfinger.fingerId);
|
|
439
|
+
// packed.Set("pressure", event.tfinger.pressure);
|
|
440
|
+
// packed.Set("x", event.tfinger.x);
|
|
441
|
+
// packed.Set("y", event.tfinger.y);
|
|
366
442
|
// break;
|
|
367
443
|
// }
|
|
368
444
|
// case SDL_FINGERMOTION: {
|
|
369
445
|
// SET_STRING(object, "type", "fingerMotion");
|
|
370
|
-
// packed.Set("touch_id",
|
|
371
|
-
// packed.Set("finger_id",
|
|
372
|
-
// packed.Set("pressure",
|
|
373
|
-
// packed.Set("x",
|
|
374
|
-
// packed.Set("y",
|
|
375
|
-
// packed.Set("dx",
|
|
376
|
-
// packed.Set("dy",
|
|
446
|
+
// packed.Set("touch_id", event.tfinger.touchId);
|
|
447
|
+
// packed.Set("finger_id", event.tfinger.fingerId);
|
|
448
|
+
// packed.Set("pressure", event.tfinger.pressure);
|
|
449
|
+
// packed.Set("x", event.tfinger.x);
|
|
450
|
+
// packed.Set("y", event.tfinger.y);
|
|
451
|
+
// packed.Set("dx", event.tfinger.dx);
|
|
452
|
+
// packed.Set("dy", event.tfinger.dy);
|
|
377
453
|
// break;
|
|
378
454
|
// }
|
|
379
455
|
}
|
package/src/native/events.h
CHANGED
package/src/native/global.cpp
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#include "joystick.h"
|
|
6
6
|
#include "controller.h"
|
|
7
7
|
#include "sensor.h"
|
|
8
|
+
#include "audio.h"
|
|
8
9
|
#include "power.h"
|
|
9
10
|
#include <SDL.h>
|
|
10
11
|
#include <string>
|
|
@@ -58,6 +59,7 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
58
59
|
events::types::DISPLAY_ADD = "displayAdd";
|
|
59
60
|
events::types::DISPLAY_REMOVE = "displayRemove";
|
|
60
61
|
events::types::DISPLAY_ORIENT = "displayOrient";
|
|
62
|
+
events::types::DISPLAY_MOVE = "displayMove";
|
|
61
63
|
events::types::DISPLAY_CHANGE = "displayChange";
|
|
62
64
|
events::types::SHOW = "show";
|
|
63
65
|
events::types::HIDE = "hide";
|
|
@@ -93,6 +95,12 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
93
95
|
events::types::REMAP = "remap";
|
|
94
96
|
events::types::UPDATE = "update";
|
|
95
97
|
|
|
98
|
+
// video::orientations[SDL_ORIENTATION_UNKNOWN] = nullptr;
|
|
99
|
+
video::orientations[SDL_ORIENTATION_LANDSCAPE] = "landscape";
|
|
100
|
+
video::orientations[SDL_ORIENTATION_LANDSCAPE_FLIPPED] = "landscapeFlipped";
|
|
101
|
+
video::orientations[SDL_ORIENTATION_PORTRAIT] = "portrait";
|
|
102
|
+
video::orientations[SDL_ORIENTATION_PORTRAIT_FLIPPED] = "portraitFlipped";
|
|
103
|
+
|
|
96
104
|
video::formats[SDL_PIXELFORMAT_RGB332] = "rgb332";
|
|
97
105
|
video::formats[SDL_PIXELFORMAT_RGB444] = "rgb444";
|
|
98
106
|
video::formats[SDL_PIXELFORMAT_RGB555] = "rgb555";
|
|
@@ -130,6 +138,17 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
130
138
|
video::formats[SDL_PIXELFORMAT_NV12] = "nv12";
|
|
131
139
|
video::formats[SDL_PIXELFORMAT_NV21] = "nv21";
|
|
132
140
|
|
|
141
|
+
// joystick::types[SDL_JOYSTICK_TYPE_UNKNOWN] = nullptr;
|
|
142
|
+
joystick::types[SDL_JOYSTICK_TYPE_GAMECONTROLLER] = "gamecontroller";
|
|
143
|
+
joystick::types[SDL_JOYSTICK_TYPE_WHEEL] = "wheel";
|
|
144
|
+
joystick::types[SDL_JOYSTICK_TYPE_ARCADE_STICK] = "arcadestick";
|
|
145
|
+
joystick::types[SDL_JOYSTICK_TYPE_FLIGHT_STICK] = "flightstick";
|
|
146
|
+
joystick::types[SDL_JOYSTICK_TYPE_DANCE_PAD] = "dancepad";
|
|
147
|
+
joystick::types[SDL_JOYSTICK_TYPE_GUITAR] = "guitar";
|
|
148
|
+
joystick::types[SDL_JOYSTICK_TYPE_DRUM_KIT] = "drumkit";
|
|
149
|
+
joystick::types[SDL_JOYSTICK_TYPE_ARCADE_PAD] = "arcadepad";
|
|
150
|
+
joystick::types[SDL_JOYSTICK_TYPE_THROTTLE] = "throttle";
|
|
151
|
+
|
|
133
152
|
// joystick::power_levels[SDL_JOYSTICK_POWER_UNKNOWN] = nullptr;
|
|
134
153
|
joystick::power_levels[SDL_JOYSTICK_POWER_EMPTY] = "empty";
|
|
135
154
|
joystick::power_levels[SDL_JOYSTICK_POWER_LOW] = "low";
|
|
@@ -138,17 +157,6 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
138
157
|
joystick::power_levels[SDL_JOYSTICK_POWER_WIRED] = "wired";
|
|
139
158
|
joystick::power_levels[SDL_JOYSTICK_POWER_MAX] = "max";
|
|
140
159
|
|
|
141
|
-
// joystick::joystick_types[SDL_JOYSTICK_TYPE_UNKNOWN] = nullptr; // Only possible on error
|
|
142
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_GAMECONTROLLER] = "gamecontroller";
|
|
143
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_WHEEL] = "wheel";
|
|
144
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_ARCADE_STICK] = "arcadestick";
|
|
145
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_FLIGHT_STICK] = "flightstick";
|
|
146
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_DANCE_PAD] = "dancepad";
|
|
147
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_GUITAR] = "guitar";
|
|
148
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_DRUM_KIT] = "drumkit";
|
|
149
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_ARCADE_PAD] = "arcadepad";
|
|
150
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_THROTTLE] = "throttle";
|
|
151
|
-
|
|
152
160
|
joystick::hat_positions[SDL_HAT_CENTERED] = "centered";
|
|
153
161
|
joystick::hat_positions[SDL_HAT_UP] = "up";
|
|
154
162
|
joystick::hat_positions[SDL_HAT_RIGHT] = "right";
|
|
@@ -159,6 +167,21 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
159
167
|
joystick::hat_positions[SDL_HAT_LEFTUP] = "leftup";
|
|
160
168
|
joystick::hat_positions[SDL_HAT_LEFTDOWN] = "leftdown";
|
|
161
169
|
|
|
170
|
+
// controller::types[SDL_CONTROLLER_TYPE_UNKNOWN] = nullptr;
|
|
171
|
+
controller::types[SDL_CONTROLLER_TYPE_XBOX360] = "xbox360";
|
|
172
|
+
controller::types[SDL_CONTROLLER_TYPE_XBOXONE] = "xboxOne";
|
|
173
|
+
controller::types[SDL_CONTROLLER_TYPE_PS3] = "ps3";
|
|
174
|
+
controller::types[SDL_CONTROLLER_TYPE_PS4] = "ps4";
|
|
175
|
+
controller::types[SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO] = "nintendoSwitchPro";
|
|
176
|
+
controller::types[SDL_CONTROLLER_TYPE_VIRTUAL] = "virtual";
|
|
177
|
+
controller::types[SDL_CONTROLLER_TYPE_PS5] = "ps5";
|
|
178
|
+
controller::types[SDL_CONTROLLER_TYPE_AMAZON_LUNA] = "amazonLuna";
|
|
179
|
+
controller::types[SDL_CONTROLLER_TYPE_GOOGLE_STADIA] = "googleStadia";
|
|
180
|
+
controller::types[SDL_CONTROLLER_TYPE_NVIDIA_SHIELD] = "nvidiaShield";
|
|
181
|
+
controller::types[SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT] = "nintendoSwitchJoyconLeft";
|
|
182
|
+
controller::types[SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT] = "nintendoSwitchJoyconRight";
|
|
183
|
+
controller::types[SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR] = "nintendoSwitchJoyconPair";
|
|
184
|
+
|
|
162
185
|
controller::axes[SDL_CONTROLLER_AXIS_LEFTX] = "leftStickX";
|
|
163
186
|
controller::axes[SDL_CONTROLLER_AXIS_LEFTY] = "leftStickY";
|
|
164
187
|
controller::axes[SDL_CONTROLLER_AXIS_RIGHTX] = "rightStickX";
|
|
@@ -202,6 +225,9 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
202
225
|
sensor::sides[SDL_SENSOR_ACCEL_R] = "right";
|
|
203
226
|
sensor::sides[SDL_SENSOR_GYRO_R] = "right";
|
|
204
227
|
|
|
228
|
+
audio::device_types[true] = "recording";
|
|
229
|
+
audio::device_types[false] = "playback";
|
|
230
|
+
|
|
205
231
|
// power::states[SDL_POWERSTATE_UNKNOWN] = nullptr;
|
|
206
232
|
power::states[SDL_POWERSTATE_NO_BATTERY] = "noBattery";
|
|
207
233
|
power::states[SDL_POWERSTATE_ON_BATTERY] = "battery";
|
|
@@ -228,17 +254,17 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
228
254
|
SDL_VERSION(&sdl_compile_version);
|
|
229
255
|
|
|
230
256
|
Napi::Object compile_version = Napi::Object::New(env);
|
|
231
|
-
compile_version.Set("major",
|
|
232
|
-
compile_version.Set("minor",
|
|
233
|
-
compile_version.Set("patch",
|
|
257
|
+
compile_version.Set("major", sdl_compile_version.major);
|
|
258
|
+
compile_version.Set("minor", sdl_compile_version.minor);
|
|
259
|
+
compile_version.Set("patch", sdl_compile_version.patch);
|
|
234
260
|
|
|
235
261
|
SDL_version sdl_runtime_version;
|
|
236
262
|
SDL_GetVersion(&sdl_runtime_version);
|
|
237
263
|
|
|
238
264
|
Napi::Object runtime_version = Napi::Object::New(env);
|
|
239
|
-
runtime_version.Set("major",
|
|
240
|
-
runtime_version.Set("minor",
|
|
241
|
-
runtime_version.Set("patch",
|
|
265
|
+
runtime_version.Set("major", sdl_runtime_version.major);
|
|
266
|
+
runtime_version.Set("minor", sdl_runtime_version.minor);
|
|
267
|
+
runtime_version.Set("patch", sdl_runtime_version.patch);
|
|
242
268
|
|
|
243
269
|
Napi::Object versions = Napi::Object::New(env);
|
|
244
270
|
versions.Set("compile", compile_version);
|
|
@@ -263,7 +289,7 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
263
289
|
SDL_ClearError();
|
|
264
290
|
throw Napi::Error::New(env, message.str());
|
|
265
291
|
}
|
|
266
|
-
all_video_drivers.Set(all_video_drivers.Length(),
|
|
292
|
+
all_video_drivers.Set(all_video_drivers.Length(), name);
|
|
267
293
|
}
|
|
268
294
|
|
|
269
295
|
Napi::Value current_video_driver;
|
|
@@ -302,7 +328,7 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
302
328
|
SDL_ClearError();
|
|
303
329
|
throw Napi::Error::New(env, message.str());
|
|
304
330
|
}
|
|
305
|
-
all_audio_drivers.Set(all_audio_drivers.Length(),
|
|
331
|
+
all_audio_drivers.Set(all_audio_drivers.Length(), name);
|
|
306
332
|
}
|
|
307
333
|
|
|
308
334
|
Napi::Value current_audio_driver;
|
|
@@ -342,7 +368,7 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
342
368
|
|
|
343
369
|
Napi::Object result = Napi::Object::New(env);
|
|
344
370
|
result.Set("version", versions);
|
|
345
|
-
result.Set("platform",
|
|
371
|
+
result.Set("platform", platform_name);
|
|
346
372
|
result.Set("drivers", drivers);
|
|
347
373
|
|
|
348
374
|
return result;
|