@kmamal/sdl 0.11.10 → 0.11.12
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/CHANGELOG.md +19 -1
- package/README.md +1105 -1031
- package/binding.gyp +1 -0
- package/package.json +14 -10
- package/src/javascript/controller/controller-instance.js +4 -1
- package/src/javascript/events/index.js +47 -0
- package/src/javascript/globals.js +1 -0
- package/src/javascript/index.js +2 -0
- package/src/javascript/joystick/joystick-instance.js +3 -1
- package/src/javascript/keyboard/index.js +11 -6
- package/src/javascript/touch/index.js +15 -0
- package/src/javascript/video/window.js +3 -0
- package/src/native/controller.cpp +15 -5
- package/src/native/controller.h +1 -0
- package/src/native/events.cpp +75 -29
- package/src/native/events.h +8 -0
- package/src/native/global.cpp +14 -0
- package/src/native/joystick.cpp +21 -24
- package/src/native/joystick.h +2 -1
- package/src/native/keyboard.cpp +1 -1
- package/src/native/module.cpp +3 -1
- package/src/native/touch.cpp +46 -0
- package/src/native/touch.h +16 -0
- package/src/types/index.d.ts +108 -20
package/src/native/joystick.h
CHANGED
|
@@ -16,10 +16,11 @@ namespace joystick {
|
|
|
16
16
|
double mapAxis (SDL_Joystick *joystick, int axis);
|
|
17
17
|
double mapAxisValue (SDL_Joystick *joystick, int axis, int value);
|
|
18
18
|
Napi::Array _getDevices (Napi::Env &env);
|
|
19
|
+
Napi::Value getPowerLevel(Napi::Env &env, SDL_Joystick *joystick);
|
|
20
|
+
Napi::Value mapPowerLevel(Napi::Env &env, SDL_JoystickPowerLevel power);
|
|
19
21
|
|
|
20
22
|
Napi::Value getDevices(const Napi::CallbackInfo &info);
|
|
21
23
|
Napi::Value open(const Napi::CallbackInfo &info);
|
|
22
|
-
Napi::Value getPower(const Napi::CallbackInfo &info);
|
|
23
24
|
Napi::Value setLed(const Napi::CallbackInfo &info);
|
|
24
25
|
Napi::Value setPlayer(const Napi::CallbackInfo &info);
|
|
25
26
|
Napi::Value rumble(const Napi::CallbackInfo &info);
|
package/src/native/keyboard.cpp
CHANGED
|
@@ -49,7 +49,7 @@ keyboard::getState(const Napi::CallbackInfo &info)
|
|
|
49
49
|
|
|
50
50
|
Napi::Array result = Napi::Array::New(env, keyboard::num_keys);
|
|
51
51
|
|
|
52
|
-
for (int i = 0
|
|
52
|
+
for (int i = 0; i < keyboard::num_keys; i++) {
|
|
53
53
|
result.Set(i, !!keyboard::keys[i]);
|
|
54
54
|
}
|
|
55
55
|
|
package/src/native/module.cpp
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
#include "window.h"
|
|
8
8
|
#include "keyboard.h"
|
|
9
9
|
#include "mouse.h"
|
|
10
|
+
#include "touch.h"
|
|
10
11
|
#include "joystick.h"
|
|
11
12
|
#include "controller.h"
|
|
12
13
|
#include "sensor.h"
|
|
@@ -60,9 +61,10 @@ init (Napi::Env env, Napi::Object exports)
|
|
|
60
61
|
exports.Set("mouse_showCursor", Napi::Function::New<mouse::showCursor>(env));
|
|
61
62
|
exports.Set("mouse_redrawCursor", Napi::Function::New<mouse::redrawCursor>(env));
|
|
62
63
|
|
|
64
|
+
exports.Set("touch_getDevices", Napi::Function::New<touch::getDevices>(env));
|
|
65
|
+
|
|
63
66
|
exports.Set("joystick_getDevices", Napi::Function::New<joystick::getDevices>(env));
|
|
64
67
|
exports.Set("joystick_open", Napi::Function::New<joystick::open>(env));
|
|
65
|
-
exports.Set("joystick_getPower", Napi::Function::New<joystick::getPower>(env));
|
|
66
68
|
exports.Set("joystick_setLed", Napi::Function::New<joystick::setLed>(env));
|
|
67
69
|
exports.Set("joystick_setPlayer", Napi::Function::New<joystick::setPlayer>(env));
|
|
68
70
|
exports.Set("joystick_rumble", Napi::Function::New<joystick::rumble>(env));
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#include "touch.h"
|
|
2
|
+
#include "global.h"
|
|
3
|
+
#include <SDL.h>
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <sstream>
|
|
6
|
+
|
|
7
|
+
std::map<SDL_TouchDeviceType, std::string> touch::device_types;
|
|
8
|
+
|
|
9
|
+
Napi::Value
|
|
10
|
+
touch::getDevices(const Napi::CallbackInfo &info)
|
|
11
|
+
{
|
|
12
|
+
Napi::Env env = info.Env();
|
|
13
|
+
|
|
14
|
+
int num_devices = SDL_GetNumTouchDevices();
|
|
15
|
+
|
|
16
|
+
Napi::Array devices = Napi::Array::New(env, num_devices);
|
|
17
|
+
|
|
18
|
+
for (int i = 0; i < num_devices; i++) {
|
|
19
|
+
SDL_TouchID id = SDL_GetTouchDevice(i);
|
|
20
|
+
if (id == 0) {
|
|
21
|
+
std::ostringstream message;
|
|
22
|
+
message << "SDL_GetTouchDevice(" << i << ") error: " << SDL_GetError();
|
|
23
|
+
SDL_ClearError();
|
|
24
|
+
throw Napi::Error::New(env, message.str());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const char *_name = SDL_GetTouchName(i);
|
|
28
|
+
Napi::Value name = _name != nullptr
|
|
29
|
+
? Napi::String::New(env, _name)
|
|
30
|
+
: env.Null();
|
|
31
|
+
|
|
32
|
+
SDL_TouchDeviceType _type = SDL_GetTouchDeviceType(id);
|
|
33
|
+
Napi::Value type = _type != SDL_TOUCH_DEVICE_INVALID
|
|
34
|
+
? Napi::String::New(env, device_types[_type])
|
|
35
|
+
: env.Null();
|
|
36
|
+
|
|
37
|
+
Napi::Object device = Napi::Object::New(env);
|
|
38
|
+
device.Set("id", id);
|
|
39
|
+
device.Set("name", name);
|
|
40
|
+
device.Set("type", type);
|
|
41
|
+
|
|
42
|
+
devices.Set(i, device);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return devices;
|
|
46
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#ifndef _TOUCH_H_
|
|
2
|
+
#define _TOUCH_H_
|
|
3
|
+
|
|
4
|
+
#include <napi.h>
|
|
5
|
+
#include <SDL.h>
|
|
6
|
+
#include <map>
|
|
7
|
+
|
|
8
|
+
namespace touch {
|
|
9
|
+
|
|
10
|
+
extern std::map<SDL_TouchDeviceType, std::string> device_types;
|
|
11
|
+
|
|
12
|
+
Napi::Value getDevices(const Napi::CallbackInfo &info);
|
|
13
|
+
|
|
14
|
+
}; // namespace touch
|
|
15
|
+
|
|
16
|
+
#endif // _TOUCH_H_
|
package/src/types/index.d.ts
CHANGED
|
@@ -82,6 +82,26 @@ export namespace Events {
|
|
|
82
82
|
readonly flipped: boolean
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
export interface MouseMove extends MouseEvent { readonly type: 'mouseMove' }
|
|
86
|
+
|
|
87
|
+
interface FingerEvent extends WindowEvent {
|
|
88
|
+
readonly device: Sdl.Touch.Device
|
|
89
|
+
readonly fingerId: number
|
|
90
|
+
readonly mouse: boolean
|
|
91
|
+
readonly x: number
|
|
92
|
+
readonly y: number
|
|
93
|
+
readonly pressure: number
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface FingerDown extends FingerEvent { readonly type: 'fingerDown' }
|
|
97
|
+
export interface FingerUp extends FingerEvent { readonly type: 'fingerUp' }
|
|
98
|
+
|
|
99
|
+
export interface FingerMove extends FingerEvent {
|
|
100
|
+
readonly type: 'fingerMove'
|
|
101
|
+
readonly dx: number
|
|
102
|
+
readonly dy: number
|
|
103
|
+
}
|
|
104
|
+
|
|
85
105
|
export interface Show extends WindowEvent { readonly type: 'show' }
|
|
86
106
|
export interface Hide extends WindowEvent { readonly type: 'hide' }
|
|
87
107
|
export interface Expose extends WindowEvent { readonly type: 'expose' }
|
|
@@ -133,6 +153,9 @@ export namespace Events {
|
|
|
133
153
|
| MouseButtonDown
|
|
134
154
|
| MouseButtonUp
|
|
135
155
|
| MouseWheel
|
|
156
|
+
| FingerDown
|
|
157
|
+
| FingerUp
|
|
158
|
+
| FingerMove
|
|
136
159
|
| Show
|
|
137
160
|
| Hide
|
|
138
161
|
| Expose
|
|
@@ -155,6 +178,17 @@ export namespace Events {
|
|
|
155
178
|
|
|
156
179
|
}
|
|
157
180
|
|
|
181
|
+
export namespace Keyboard {
|
|
182
|
+
|
|
183
|
+
interface KeyboardEvent extends BaseEvent {}
|
|
184
|
+
|
|
185
|
+
export interface KeymapChange extends KeyboardEvent { readonly type: 'keymapChange' }
|
|
186
|
+
|
|
187
|
+
export type Any
|
|
188
|
+
= KeymapChange
|
|
189
|
+
|
|
190
|
+
}
|
|
191
|
+
|
|
158
192
|
export namespace Joystick {
|
|
159
193
|
|
|
160
194
|
interface JoystickEvent extends BaseEvent {}
|
|
@@ -185,6 +219,11 @@ export namespace Events {
|
|
|
185
219
|
readonly value: Sdl.Joystick.HatPosition
|
|
186
220
|
}
|
|
187
221
|
|
|
222
|
+
export interface PowerUpdate extends JoystickEvent {
|
|
223
|
+
readonly type: 'powerUpdate'
|
|
224
|
+
readonly power: Sdl.Joystick.PowerLevel | null
|
|
225
|
+
}
|
|
226
|
+
|
|
188
227
|
export interface Close extends JoystickEvent { readonly type: 'close' }
|
|
189
228
|
|
|
190
229
|
export type Any
|
|
@@ -193,6 +232,7 @@ export namespace Events {
|
|
|
193
232
|
| ButtonDown
|
|
194
233
|
| ButtonUp
|
|
195
234
|
| HatMotion
|
|
235
|
+
| PowerUpdate
|
|
196
236
|
| Close
|
|
197
237
|
|
|
198
238
|
}
|
|
@@ -206,7 +246,9 @@ export namespace Events {
|
|
|
206
246
|
export interface Add extends DeviceEvent { readonly type: 'deviceAdd' }
|
|
207
247
|
export interface Remove extends DeviceEvent { readonly type: 'deviceRemove' }
|
|
208
248
|
|
|
209
|
-
export type Any
|
|
249
|
+
export type Any
|
|
250
|
+
= Add
|
|
251
|
+
| Remove
|
|
210
252
|
|
|
211
253
|
}
|
|
212
254
|
|
|
@@ -227,6 +269,16 @@ export namespace Events {
|
|
|
227
269
|
export interface ButtonDown extends ButtonEvent { readonly type: 'buttonDown' }
|
|
228
270
|
export interface ButtonUp extends ButtonEvent { readonly type: 'buttonUp' }
|
|
229
271
|
|
|
272
|
+
export interface PowerUpdate extends ControllerEvent {
|
|
273
|
+
readonly type: 'powerUpdate'
|
|
274
|
+
readonly power: Sdl.Joystick.PowerLevel | null
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export interface SteamHandleUpdate extends ControllerEvent {
|
|
278
|
+
readonly type: 'steamHandleUpdate'
|
|
279
|
+
readonly steamHandle: Buffer | null
|
|
280
|
+
}
|
|
281
|
+
|
|
230
282
|
export interface Remap extends ControllerEvent { readonly type: 'remap' }
|
|
231
283
|
|
|
232
284
|
export interface Close extends ControllerEvent { readonly type: 'close' }
|
|
@@ -235,6 +287,8 @@ export namespace Events {
|
|
|
235
287
|
= AxisMotion
|
|
236
288
|
| ButtonDown
|
|
237
289
|
| ButtonUp
|
|
290
|
+
| PowerUpdate
|
|
291
|
+
| SteamHandleUpdate
|
|
238
292
|
| Remap
|
|
239
293
|
| Close
|
|
240
294
|
|
|
@@ -265,7 +319,9 @@ export namespace Events {
|
|
|
265
319
|
export interface Add extends DeviceEvent { readonly type: 'deviceAdd' }
|
|
266
320
|
export interface Remove extends DeviceEvent { readonly type: 'deviceRemove' }
|
|
267
321
|
|
|
268
|
-
export type Any
|
|
322
|
+
export type Any
|
|
323
|
+
= Add
|
|
324
|
+
| Remove
|
|
269
325
|
|
|
270
326
|
}
|
|
271
327
|
|
|
@@ -275,7 +331,8 @@ export namespace Events {
|
|
|
275
331
|
|
|
276
332
|
export interface Close extends AudioEvent { readonly type: 'close' }
|
|
277
333
|
|
|
278
|
-
export type Any
|
|
334
|
+
export type Any
|
|
335
|
+
= Close
|
|
279
336
|
|
|
280
337
|
}
|
|
281
338
|
|
|
@@ -288,7 +345,9 @@ export namespace Events {
|
|
|
288
345
|
export interface Add extends DeviceEvent { readonly type: 'deviceAdd' }
|
|
289
346
|
export interface Remove extends DeviceEvent { readonly type: 'deviceRemove' }
|
|
290
347
|
|
|
291
|
-
export type Any
|
|
348
|
+
export type Any
|
|
349
|
+
= Add
|
|
350
|
+
| Remove
|
|
292
351
|
|
|
293
352
|
}
|
|
294
353
|
|
|
@@ -296,7 +355,8 @@ export namespace Events {
|
|
|
296
355
|
|
|
297
356
|
export interface Update extends BaseEvent { readonly type: 'update' }
|
|
298
357
|
|
|
299
|
-
export type Any
|
|
358
|
+
export type Any
|
|
359
|
+
= Update
|
|
300
360
|
|
|
301
361
|
}
|
|
302
362
|
|
|
@@ -329,12 +389,12 @@ export namespace Sdl {
|
|
|
329
389
|
}
|
|
330
390
|
}
|
|
331
391
|
readonly initialized: {
|
|
332
|
-
video: boolean
|
|
333
|
-
audio: boolean
|
|
334
|
-
joystick: boolean
|
|
335
|
-
controller: boolean
|
|
336
|
-
haptic: boolean
|
|
337
|
-
sensor: boolean
|
|
392
|
+
readonly video: boolean
|
|
393
|
+
readonly audio: boolean
|
|
394
|
+
readonly joystick: boolean
|
|
395
|
+
readonly controller: boolean
|
|
396
|
+
readonly haptic: boolean
|
|
397
|
+
readonly sensor: boolean
|
|
338
398
|
}
|
|
339
399
|
}
|
|
340
400
|
|
|
@@ -436,6 +496,9 @@ export namespace Sdl {
|
|
|
436
496
|
on (event: 'mouseButtonUp', listener: (event: Events.Window.MouseButtonUp) => void): this
|
|
437
497
|
on (event: 'mouseMove', listener: (event: Events.Window.MouseMove) => void): this
|
|
438
498
|
on (event: 'mouseWheel', listener: (event: Events.Window.MouseWheel) => void): this
|
|
499
|
+
on (event: 'fingerDown', listener: (event: Events.Window.FingerDown) => void): this
|
|
500
|
+
on (event: 'fingerUp', listener: (event: Events.Window.FingerUp) => void): this
|
|
501
|
+
on (event: 'fingerMove', listener: (event: Events.Window.FingerMove) => void): this
|
|
439
502
|
on (event: 'dropBegin', listener: (event: Events.Window.DropBegin) => void): this
|
|
440
503
|
on (event: 'dropText', listener: (event: Events.Window.DropText) => void): this
|
|
441
504
|
on (event: 'dropFile', listener: (event: Events.Window.DropFile) => void): this
|
|
@@ -814,6 +877,8 @@ export namespace Sdl {
|
|
|
814
877
|
interface Module {
|
|
815
878
|
readonly SCANCODE: { [name in ScancodeNames]: Scancode }
|
|
816
879
|
|
|
880
|
+
on (event: 'keymapChange', listener: (event: Events.Keyboard.KeymapChange) => void): this
|
|
881
|
+
|
|
817
882
|
getKey (scancode: Scancode): Key | null
|
|
818
883
|
getScancode (key: Key): Scancode | null
|
|
819
884
|
|
|
@@ -870,11 +935,30 @@ export namespace Sdl {
|
|
|
870
935
|
|
|
871
936
|
}
|
|
872
937
|
|
|
938
|
+
export namespace Touch {
|
|
939
|
+
|
|
940
|
+
export type DeviceType
|
|
941
|
+
= 'direct'
|
|
942
|
+
| 'indirectAbsolute'
|
|
943
|
+
| 'indirectRelative'
|
|
944
|
+
|
|
945
|
+
export interface Device {
|
|
946
|
+
readonly id: number
|
|
947
|
+
readonly name: string | null
|
|
948
|
+
readonly type: DeviceType | null
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
interface Module {
|
|
952
|
+
readonly devices: Device[]
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
}
|
|
956
|
+
|
|
873
957
|
export namespace Joystick {
|
|
874
958
|
|
|
875
959
|
export interface BallPosition {
|
|
876
|
-
x: number
|
|
877
|
-
y: number
|
|
960
|
+
readonly x: number
|
|
961
|
+
readonly y: number
|
|
878
962
|
}
|
|
879
963
|
|
|
880
964
|
export type JoystickType
|
|
@@ -926,6 +1010,7 @@ export namespace Sdl {
|
|
|
926
1010
|
on (event: 'buttonDown', listener: (event: Events.Joystick.ButtonDown) => void): this
|
|
927
1011
|
on (event: 'buttonUp', listener: (event: Events.Joystick.ButtonUp) => void): this
|
|
928
1012
|
on (event: 'hatMotion', listener: (event: Events.Joystick.HatMotion) => void): this
|
|
1013
|
+
on (event: 'powerUpdate', listener: (event: Events.Joystick.PowerUpdate) => void): this
|
|
929
1014
|
on (event: 'close', listener: (event: Events.Joystick.Close) => void): this
|
|
930
1015
|
on (event: '*', listener: (type: string, event: Events.Joystick.Any) => void): this
|
|
931
1016
|
|
|
@@ -1034,6 +1119,8 @@ export namespace Sdl {
|
|
|
1034
1119
|
on (event: 'axisMotion', listener: (event: Events.Controller.AxisMotion) => void): this
|
|
1035
1120
|
on (event: 'buttonDown', listener: (event: Events.Controller.ButtonDown) => void): this
|
|
1036
1121
|
on (event: 'buttonUp', listener: (event: Events.Controller.ButtonUp) => void): this
|
|
1122
|
+
on (event: 'powerUpdate', listener: (event: Events.Controller.PowerUpdate) => void): this
|
|
1123
|
+
on (event: 'steamHandleUpdate', listener: (event: Events.Controller.SteamHandleUpdate) => void): this
|
|
1037
1124
|
on (event: 'remap', listener: (event: Events.Controller.Remap) => void): this
|
|
1038
1125
|
on (event: 'close', listener: (event: Events.Controller.Close) => void): this
|
|
1039
1126
|
on (event: '*', listener: (type: string, event: Events.Controller.Any) => void): this
|
|
@@ -1230,10 +1317,10 @@ export namespace Sdl {
|
|
|
1230
1317
|
}
|
|
1231
1318
|
|
|
1232
1319
|
export interface AudioOptions {
|
|
1233
|
-
channels?: 1 | 2 | 4 | 6
|
|
1234
|
-
frequency?: number
|
|
1235
|
-
format?: Format
|
|
1236
|
-
buffered?: number
|
|
1320
|
+
readonly channels?: 1 | 2 | 4 | 6
|
|
1321
|
+
readonly frequency?: number
|
|
1322
|
+
readonly format?: Format
|
|
1323
|
+
readonly buffered?: number
|
|
1237
1324
|
}
|
|
1238
1325
|
|
|
1239
1326
|
interface Module {
|
|
@@ -1276,9 +1363,9 @@ export namespace Sdl {
|
|
|
1276
1363
|
| 'charged'
|
|
1277
1364
|
|
|
1278
1365
|
export interface PowerInfo {
|
|
1279
|
-
state: PowerState | null
|
|
1280
|
-
seconds: number | null
|
|
1281
|
-
percent: number | null
|
|
1366
|
+
readonly state: PowerState | null
|
|
1367
|
+
readonly seconds: number | null
|
|
1368
|
+
readonly percent: number | null
|
|
1282
1369
|
}
|
|
1283
1370
|
|
|
1284
1371
|
interface Module {
|
|
@@ -1293,6 +1380,7 @@ export const info: Sdl.Info
|
|
|
1293
1380
|
export const video: Sdl.Video.Module
|
|
1294
1381
|
export const keyboard: Sdl.Keyboard.Module
|
|
1295
1382
|
export const mouse: Sdl.Mouse.Module
|
|
1383
|
+
export const touch: Sdl.Touch.Module
|
|
1296
1384
|
export const joystick: Sdl.Joystick.Module
|
|
1297
1385
|
export const controller: Sdl.Controller.Module
|
|
1298
1386
|
export const sensor: Sdl.Sensor.Module
|