@kmamal/sdl 0.11.4 → 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 +70 -16
- 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 +61 -123
- 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/javascript/video/window.js +6 -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 +161 -79
- package/src/native/events.h +2 -0
- package/src/native/global.cpp +47 -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 +41 -29
- package/src/types/index.d.ts +65 -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,8 @@ 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;
|
|
32
|
+
std::string events::types::DISPLAY_CHANGE;
|
|
30
33
|
std::string events::types::SHOW;
|
|
31
34
|
std::string events::types::HIDE;
|
|
32
35
|
std::string events::types::EXPOSE;
|
|
@@ -82,19 +85,50 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
82
85
|
|
|
83
86
|
case SDL_DISPLAYEVENT: {
|
|
84
87
|
packed.Set("family", events::families::DISPLAY);
|
|
85
|
-
|
|
88
|
+
|
|
89
|
+
int display_index = event.display.display;
|
|
90
|
+
packed.Set("displayIndex", display_index);
|
|
86
91
|
|
|
87
92
|
switch (event.display.event) {
|
|
88
93
|
case SDL_DISPLAYEVENT_CONNECTED: { packed.Set("type", events::types::DISPLAY_ADD); break; }
|
|
89
94
|
case SDL_DISPLAYEVENT_DISCONNECTED: { packed.Set("type", events::types::DISPLAY_REMOVE); break; }
|
|
90
|
-
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
|
+
}
|
|
91
125
|
}
|
|
92
126
|
break;
|
|
93
127
|
}
|
|
94
128
|
|
|
95
129
|
case SDL_WINDOWEVENT: {
|
|
96
130
|
packed.Set("family", events::families::WINDOW);
|
|
97
|
-
packed.Set("windowId",
|
|
131
|
+
packed.Set("windowId", event.window.windowID);
|
|
98
132
|
|
|
99
133
|
switch (event.window.event) {
|
|
100
134
|
case SDL_WINDOWEVENT_SHOWN: { packed.Set("type", events::types::SHOW); break; }
|
|
@@ -102,8 +136,8 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
102
136
|
case SDL_WINDOWEVENT_EXPOSED: { packed.Set("type", events::types::EXPOSE); break; }
|
|
103
137
|
case SDL_WINDOWEVENT_MOVED: {
|
|
104
138
|
packed.Set("type", events::types::MOVE);
|
|
105
|
-
packed.Set("x",
|
|
106
|
-
packed.Set("y",
|
|
139
|
+
packed.Set("x", event.window.data1);
|
|
140
|
+
packed.Set("y", event.window.data2);
|
|
107
141
|
break;
|
|
108
142
|
}
|
|
109
143
|
case SDL_WINDOWEVENT_SIZE_CHANGED: {
|
|
@@ -122,10 +156,15 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
122
156
|
SDL_GetWindowSizeInPixels(window, &pixel_width, &pixel_height);
|
|
123
157
|
|
|
124
158
|
packed.Set("type", events::types::RESIZE);
|
|
125
|
-
packed.Set("width",
|
|
126
|
-
packed.Set("height",
|
|
127
|
-
packed.Set("pixelWidth",
|
|
128
|
-
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);
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
case SDL_WINDOWEVENT_DISPLAY_CHANGED: {
|
|
166
|
+
packed.Set("type", events::types::DISPLAY_CHANGE);
|
|
167
|
+
packed.Set("displayIndex", event.window.data1);
|
|
129
168
|
break;
|
|
130
169
|
}
|
|
131
170
|
case SDL_WINDOWEVENT_MINIMIZED: { packed.Set("type", events::types::MINIMIZE); break; }
|
|
@@ -144,7 +183,7 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
144
183
|
case SDL_DROPCOMPLETE: {
|
|
145
184
|
packed.Set("family", events::families::DROP);
|
|
146
185
|
packed.Set("type", event.type == SDL_DROPBEGIN ? events::types::DROP_BEGIN : events::types::DROP_COMPLETE);
|
|
147
|
-
packed.Set("windowId",
|
|
186
|
+
packed.Set("windowId", event.drop.windowID);
|
|
148
187
|
break;
|
|
149
188
|
}
|
|
150
189
|
case SDL_DROPFILE:
|
|
@@ -152,84 +191,94 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
152
191
|
packed.Set("family", events::families::DROP);
|
|
153
192
|
bool is_file = event.type == SDL_DROPFILE;
|
|
154
193
|
packed.Set("type", is_file ? events::types::DROP_FILE : events::types::DROP_TEXT);
|
|
155
|
-
packed.Set("windowId",
|
|
156
|
-
packed.Set(is_file ? "file" : "text",
|
|
194
|
+
packed.Set("windowId", event.drop.windowID);
|
|
195
|
+
packed.Set(is_file ? "file" : "text", event.drop.file);
|
|
157
196
|
break;
|
|
158
197
|
}
|
|
159
198
|
|
|
160
199
|
case SDL_KEYDOWN:
|
|
161
200
|
case SDL_KEYUP: {
|
|
162
201
|
packed.Set("family", events::families::KEYBOARD);
|
|
163
|
-
packed.Set(
|
|
164
|
-
|
|
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);
|
|
165
209
|
|
|
166
210
|
SDL_Keysym symbol = event.key.keysym;
|
|
167
|
-
packed.Set("scancode",
|
|
211
|
+
packed.Set("scancode", (int) symbol.scancode);
|
|
168
212
|
|
|
169
213
|
const char *name = SDL_GetKeyName(symbol.sym);
|
|
170
214
|
if (name[0] != '\0') {
|
|
171
|
-
packed.Set("key",
|
|
215
|
+
packed.Set("key", name);
|
|
172
216
|
}
|
|
173
217
|
else {
|
|
174
218
|
packed.Set("key", env.Null());
|
|
175
219
|
}
|
|
176
220
|
|
|
177
221
|
if (event.type == SDL_KEYDOWN) {
|
|
178
|
-
packed.Set("repeat",
|
|
222
|
+
packed.Set("repeat", !!event.key.repeat);
|
|
179
223
|
}
|
|
180
224
|
|
|
181
|
-
packed.Set("alt",
|
|
182
|
-
packed.Set("ctrl",
|
|
183
|
-
packed.Set("shift",
|
|
184
|
-
packed.Set("super",
|
|
185
|
-
packed.Set("altgr",
|
|
186
|
-
packed.Set("numlock",
|
|
187
|
-
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));
|
|
188
232
|
break;
|
|
189
233
|
}
|
|
190
234
|
|
|
191
235
|
case SDL_TEXTINPUT: {
|
|
192
236
|
packed.Set("family", events::families::TEXT);
|
|
193
237
|
packed.Set("type", events::types::TEXT_INPUT);
|
|
194
|
-
packed.Set("windowId",
|
|
195
|
-
packed.Set("text",
|
|
238
|
+
packed.Set("windowId", event.text.windowID);
|
|
239
|
+
packed.Set("text", event.text.text);
|
|
196
240
|
break ;
|
|
197
241
|
}
|
|
198
242
|
|
|
199
243
|
case SDL_MOUSEMOTION: {
|
|
200
244
|
packed.Set("family", events::families::MOUSE);
|
|
201
245
|
packed.Set("type", events::types::MOUSE_MOVE);
|
|
202
|
-
packed.Set("windowId",
|
|
203
|
-
packed.Set("touch",
|
|
204
|
-
packed.Set("x",
|
|
205
|
-
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);
|
|
206
250
|
break;
|
|
207
251
|
}
|
|
208
252
|
case SDL_MOUSEBUTTONDOWN:
|
|
209
253
|
case SDL_MOUSEBUTTONUP: {
|
|
210
254
|
packed.Set("family", events::families::MOUSE);
|
|
211
|
-
packed.Set(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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);
|
|
217
266
|
break;
|
|
218
267
|
}
|
|
219
268
|
case SDL_MOUSEWHEEL: {
|
|
220
269
|
packed.Set("family", events::families::MOUSE);
|
|
221
270
|
packed.Set("type", events::types::MOUSE_WHEEL);
|
|
222
|
-
packed.Set("windowId",
|
|
223
|
-
packed.Set("touch",
|
|
271
|
+
packed.Set("windowId", event.wheel.windowID);
|
|
272
|
+
packed.Set("touch", event.wheel.which == SDL_TOUCH_MOUSEID);
|
|
224
273
|
|
|
225
274
|
int x, y;
|
|
226
275
|
SDL_GetMouseState(&x, &y);
|
|
227
|
-
packed.Set("x",
|
|
228
|
-
packed.Set("y",
|
|
276
|
+
packed.Set("x", x);
|
|
277
|
+
packed.Set("y", y);
|
|
229
278
|
|
|
230
|
-
packed.Set("dx",
|
|
231
|
-
packed.Set("dy",
|
|
232
|
-
packed.Set("flipped",
|
|
279
|
+
packed.Set("dx", event.wheel.x);
|
|
280
|
+
packed.Set("dy", event.wheel.y);
|
|
281
|
+
packed.Set("flipped", event.wheel.direction);
|
|
233
282
|
break;
|
|
234
283
|
}
|
|
235
284
|
|
|
@@ -242,7 +291,7 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
242
291
|
case SDL_JOYDEVICEREMOVED: {
|
|
243
292
|
packed.Set("family", events::families::JOYSTICK_DEVICE);
|
|
244
293
|
packed.Set("type", events::types::DEVICE_REMOVE);
|
|
245
|
-
packed.Set("joystickId",
|
|
294
|
+
packed.Set("joystickId", event.jdevice.which);
|
|
246
295
|
packed.Set("devices", joystick::_getDevices(env));
|
|
247
296
|
break;
|
|
248
297
|
}
|
|
@@ -250,33 +299,48 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
250
299
|
case SDL_JOYAXISMOTION: {
|
|
251
300
|
packed.Set("family", events::families::JOYSTICK);
|
|
252
301
|
packed.Set("type", events::types::AXIS_MOTION);
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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));
|
|
256
315
|
break ;
|
|
257
316
|
}
|
|
258
317
|
case SDL_JOYBALLMOTION: {
|
|
259
318
|
packed.Set("family", events::families::JOYSTICK);
|
|
260
319
|
packed.Set("type", events::types::BALL_MOTION);
|
|
261
|
-
packed.Set("joystickId",
|
|
262
|
-
packed.Set("ball",
|
|
263
|
-
packed.Set("x",
|
|
264
|
-
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);
|
|
265
324
|
break ;
|
|
266
325
|
}
|
|
267
326
|
case SDL_JOYBUTTONDOWN:
|
|
268
327
|
case SDL_JOYBUTTONUP: {
|
|
269
328
|
packed.Set("family", events::families::JOYSTICK);
|
|
270
|
-
packed.Set(
|
|
271
|
-
|
|
272
|
-
|
|
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);
|
|
273
337
|
break ;
|
|
274
338
|
}
|
|
275
339
|
case SDL_JOYHATMOTION: {
|
|
276
340
|
packed.Set("family", events::families::JOYSTICK);
|
|
277
341
|
packed.Set("type", events::types::HAT_MOTION);
|
|
278
|
-
packed.Set("joystickId",
|
|
279
|
-
packed.Set("hat",
|
|
342
|
+
packed.Set("joystickId", event.jhat.which);
|
|
343
|
+
packed.Set("hat", event.jhat.hat);
|
|
280
344
|
packed.Set("value", joystick::hat_positions[event.jhat.value]);
|
|
281
345
|
break ;
|
|
282
346
|
}
|
|
@@ -284,9 +348,8 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
284
348
|
case SDL_CONTROLLERDEVICEREMAPPED: {
|
|
285
349
|
packed.Set("family", events::families::CONTROLLER);
|
|
286
350
|
packed.Set("type", events::types::REMAP);
|
|
287
|
-
SDL_JoystickID controller_id = event.cdevice.which;
|
|
288
|
-
packed.Set("controllerId", Napi::Number::New(env, controller_id));
|
|
289
351
|
|
|
352
|
+
SDL_JoystickID controller_id = event.cdevice.which;
|
|
290
353
|
SDL_GameController *controller = SDL_GameControllerFromInstanceID(controller_id);
|
|
291
354
|
if (controller == nullptr) {
|
|
292
355
|
std::ostringstream message;
|
|
@@ -295,6 +358,7 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
295
358
|
throw Napi::Error::New(env, message.str());
|
|
296
359
|
}
|
|
297
360
|
|
|
361
|
+
packed.Set("controllerId", controller_id);
|
|
298
362
|
controller::getState(env, controller, packed);
|
|
299
363
|
break;
|
|
300
364
|
}
|
|
@@ -302,16 +366,32 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
302
366
|
case SDL_CONTROLLERAXISMOTION: {
|
|
303
367
|
packed.Set("family", events::families::CONTROLLER);
|
|
304
368
|
packed.Set("type", events::types::AXIS_MOTION);
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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));
|
|
308
383
|
break;
|
|
309
384
|
}
|
|
310
385
|
case SDL_CONTROLLERBUTTONDOWN:
|
|
311
386
|
case SDL_CONTROLLERBUTTONUP: {
|
|
312
387
|
packed.Set("family", events::families::CONTROLLER);
|
|
313
|
-
packed.Set(
|
|
314
|
-
|
|
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);
|
|
315
395
|
packed.Set("button", controller::buttons[(SDL_GameControllerButton) event.cbutton.button]);
|
|
316
396
|
break;
|
|
317
397
|
}
|
|
@@ -319,7 +399,7 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
319
399
|
case SDL_SENSORUPDATE: {
|
|
320
400
|
packed.Set("family", events::families::SENSOR);
|
|
321
401
|
packed.Set("type", events::types::UPDATE);
|
|
322
|
-
packed.Set("sensorId",
|
|
402
|
+
packed.Set("sensorId", event.sensor.which);
|
|
323
403
|
break;
|
|
324
404
|
}
|
|
325
405
|
|
|
@@ -327,16 +407,18 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
327
407
|
packed.Set("family", events::families::AUDIO_DEVICE);
|
|
328
408
|
packed.Set("type", events::types::DEVICE_ADD);
|
|
329
409
|
bool is_capture = event.adevice.iscapture;
|
|
330
|
-
packed.Set("
|
|
410
|
+
packed.Set("audioDeviceType", audio::device_types[is_capture]);
|
|
331
411
|
packed.Set("devices", audio::_getDevices(env, is_capture));
|
|
332
412
|
break;
|
|
333
413
|
}
|
|
334
414
|
case SDL_AUDIODEVICEREMOVED: {
|
|
335
415
|
packed.Set("family", events::families::AUDIO_DEVICE);
|
|
336
416
|
packed.Set("type", events::types::DEVICE_REMOVE);
|
|
337
|
-
|
|
417
|
+
|
|
338
418
|
bool is_capture = event.adevice.iscapture;
|
|
339
|
-
|
|
419
|
+
|
|
420
|
+
packed.Set("audioId", event.adevice.which);
|
|
421
|
+
packed.Set("audioDeviceType", audio::device_types[is_capture]);
|
|
340
422
|
packed.Set("devices", audio::_getDevices(env, is_capture));
|
|
341
423
|
break;
|
|
342
424
|
}
|
|
@@ -352,22 +434,22 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
352
434
|
// SET_STRING(object, "type", event.type == SDL_FINGERUP
|
|
353
435
|
// ? "fingerUp"
|
|
354
436
|
// : "fingerDown");
|
|
355
|
-
// packed.Set("touch_id",
|
|
356
|
-
// packed.Set("finger_id",
|
|
357
|
-
// packed.Set("pressure",
|
|
358
|
-
// packed.Set("x",
|
|
359
|
-
// 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);
|
|
360
442
|
// break;
|
|
361
443
|
// }
|
|
362
444
|
// case SDL_FINGERMOTION: {
|
|
363
445
|
// SET_STRING(object, "type", "fingerMotion");
|
|
364
|
-
// packed.Set("touch_id",
|
|
365
|
-
// packed.Set("finger_id",
|
|
366
|
-
// packed.Set("pressure",
|
|
367
|
-
// packed.Set("x",
|
|
368
|
-
// packed.Set("y",
|
|
369
|
-
// packed.Set("dx",
|
|
370
|
-
// 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);
|
|
371
453
|
// break;
|
|
372
454
|
// }
|
|
373
455
|
}
|
package/src/native/events.h
CHANGED
|
@@ -28,6 +28,8 @@ namespace events {
|
|
|
28
28
|
extern std::string DISPLAY_ADD;
|
|
29
29
|
extern std::string DISPLAY_REMOVE;
|
|
30
30
|
extern std::string DISPLAY_ORIENT;
|
|
31
|
+
extern std::string DISPLAY_MOVE;
|
|
32
|
+
extern std::string DISPLAY_CHANGE;
|
|
31
33
|
extern std::string SHOW;
|
|
32
34
|
extern std::string HIDE;
|
|
33
35
|
extern std::string EXPOSE;
|
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,8 @@ 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";
|
|
63
|
+
events::types::DISPLAY_CHANGE = "displayChange";
|
|
61
64
|
events::types::SHOW = "show";
|
|
62
65
|
events::types::HIDE = "hide";
|
|
63
66
|
events::types::EXPOSE = "expose";
|
|
@@ -92,6 +95,12 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
92
95
|
events::types::REMAP = "remap";
|
|
93
96
|
events::types::UPDATE = "update";
|
|
94
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
|
+
|
|
95
104
|
video::formats[SDL_PIXELFORMAT_RGB332] = "rgb332";
|
|
96
105
|
video::formats[SDL_PIXELFORMAT_RGB444] = "rgb444";
|
|
97
106
|
video::formats[SDL_PIXELFORMAT_RGB555] = "rgb555";
|
|
@@ -129,6 +138,17 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
129
138
|
video::formats[SDL_PIXELFORMAT_NV12] = "nv12";
|
|
130
139
|
video::formats[SDL_PIXELFORMAT_NV21] = "nv21";
|
|
131
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
|
+
|
|
132
152
|
// joystick::power_levels[SDL_JOYSTICK_POWER_UNKNOWN] = nullptr;
|
|
133
153
|
joystick::power_levels[SDL_JOYSTICK_POWER_EMPTY] = "empty";
|
|
134
154
|
joystick::power_levels[SDL_JOYSTICK_POWER_LOW] = "low";
|
|
@@ -137,17 +157,6 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
137
157
|
joystick::power_levels[SDL_JOYSTICK_POWER_WIRED] = "wired";
|
|
138
158
|
joystick::power_levels[SDL_JOYSTICK_POWER_MAX] = "max";
|
|
139
159
|
|
|
140
|
-
// joystick::joystick_types[SDL_JOYSTICK_TYPE_UNKNOWN] = nullptr; // Only possible on error
|
|
141
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_GAMECONTROLLER] = "gamecontroller";
|
|
142
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_WHEEL] = "wheel";
|
|
143
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_ARCADE_STICK] = "arcadestick";
|
|
144
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_FLIGHT_STICK] = "flightstick";
|
|
145
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_DANCE_PAD] = "dancepad";
|
|
146
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_GUITAR] = "guitar";
|
|
147
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_DRUM_KIT] = "drumkit";
|
|
148
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_ARCADE_PAD] = "arcadepad";
|
|
149
|
-
joystick::joystick_types[SDL_JOYSTICK_TYPE_THROTTLE] = "throttle";
|
|
150
|
-
|
|
151
160
|
joystick::hat_positions[SDL_HAT_CENTERED] = "centered";
|
|
152
161
|
joystick::hat_positions[SDL_HAT_UP] = "up";
|
|
153
162
|
joystick::hat_positions[SDL_HAT_RIGHT] = "right";
|
|
@@ -158,6 +167,21 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
158
167
|
joystick::hat_positions[SDL_HAT_LEFTUP] = "leftup";
|
|
159
168
|
joystick::hat_positions[SDL_HAT_LEFTDOWN] = "leftdown";
|
|
160
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
|
+
|
|
161
185
|
controller::axes[SDL_CONTROLLER_AXIS_LEFTX] = "leftStickX";
|
|
162
186
|
controller::axes[SDL_CONTROLLER_AXIS_LEFTY] = "leftStickY";
|
|
163
187
|
controller::axes[SDL_CONTROLLER_AXIS_RIGHTX] = "rightStickX";
|
|
@@ -201,6 +225,9 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
201
225
|
sensor::sides[SDL_SENSOR_ACCEL_R] = "right";
|
|
202
226
|
sensor::sides[SDL_SENSOR_GYRO_R] = "right";
|
|
203
227
|
|
|
228
|
+
audio::device_types[true] = "recording";
|
|
229
|
+
audio::device_types[false] = "playback";
|
|
230
|
+
|
|
204
231
|
// power::states[SDL_POWERSTATE_UNKNOWN] = nullptr;
|
|
205
232
|
power::states[SDL_POWERSTATE_NO_BATTERY] = "noBattery";
|
|
206
233
|
power::states[SDL_POWERSTATE_ON_BATTERY] = "battery";
|
|
@@ -227,17 +254,17 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
227
254
|
SDL_VERSION(&sdl_compile_version);
|
|
228
255
|
|
|
229
256
|
Napi::Object compile_version = Napi::Object::New(env);
|
|
230
|
-
compile_version.Set("major",
|
|
231
|
-
compile_version.Set("minor",
|
|
232
|
-
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);
|
|
233
260
|
|
|
234
261
|
SDL_version sdl_runtime_version;
|
|
235
262
|
SDL_GetVersion(&sdl_runtime_version);
|
|
236
263
|
|
|
237
264
|
Napi::Object runtime_version = Napi::Object::New(env);
|
|
238
|
-
runtime_version.Set("major",
|
|
239
|
-
runtime_version.Set("minor",
|
|
240
|
-
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);
|
|
241
268
|
|
|
242
269
|
Napi::Object versions = Napi::Object::New(env);
|
|
243
270
|
versions.Set("compile", compile_version);
|
|
@@ -262,7 +289,7 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
262
289
|
SDL_ClearError();
|
|
263
290
|
throw Napi::Error::New(env, message.str());
|
|
264
291
|
}
|
|
265
|
-
all_video_drivers.Set(all_video_drivers.Length(),
|
|
292
|
+
all_video_drivers.Set(all_video_drivers.Length(), name);
|
|
266
293
|
}
|
|
267
294
|
|
|
268
295
|
Napi::Value current_video_driver;
|
|
@@ -301,7 +328,7 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
301
328
|
SDL_ClearError();
|
|
302
329
|
throw Napi::Error::New(env, message.str());
|
|
303
330
|
}
|
|
304
|
-
all_audio_drivers.Set(all_audio_drivers.Length(),
|
|
331
|
+
all_audio_drivers.Set(all_audio_drivers.Length(), name);
|
|
305
332
|
}
|
|
306
333
|
|
|
307
334
|
Napi::Value current_audio_driver;
|
|
@@ -341,7 +368,7 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
341
368
|
|
|
342
369
|
Napi::Object result = Napi::Object::New(env);
|
|
343
370
|
result.Set("version", versions);
|
|
344
|
-
result.Set("platform",
|
|
371
|
+
result.Set("platform", platform_name);
|
|
345
372
|
result.Set("drivers", drivers);
|
|
346
373
|
|
|
347
374
|
return result;
|