@kmamal/sdl 0.11.11 → 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 +10 -1
- package/README.md +66 -4
- package/binding.gyp +1 -0
- package/package.json +12 -8
- package/src/javascript/events/index.js +20 -0
- package/src/javascript/globals.js +1 -0
- package/src/javascript/index.js +2 -0
- package/src/javascript/touch/index.js +15 -0
- package/src/javascript/video/window.js +3 -0
- package/src/native/events.cpp +34 -24
- package/src/native/events.h +4 -0
- package/src/native/global.cpp +10 -0
- package/src/native/joystick.cpp +3 -3
- package/src/native/module.cpp +3 -0
- package/src/native/touch.cpp +46 -0
- package/src/native/touch.h +16 -0
- package/src/types/index.d.ts +74 -20
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [v0.11.12] - 2025-07-24
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Touch support
|
|
13
|
+
- Added `sdl.touch` which lists the available touch devices.
|
|
14
|
+
- Added `fingerDown`, `fingerUp`, and `fingerMove` events to window.
|
|
15
|
+
|
|
8
16
|
## [v0.11.11] - 2025-07-21
|
|
9
17
|
|
|
10
18
|
### Added
|
|
@@ -40,7 +48,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
40
48
|
|
|
41
49
|
- Started keeping this changelog.
|
|
42
50
|
|
|
43
|
-
[unreleased]: https://github.com/kmamal/node-sdl/compare/v0.11.
|
|
51
|
+
[unreleased]: https://github.com/kmamal/node-sdl/compare/v0.11.12...HEAD
|
|
52
|
+
[v0.11.12]: https://github.com/kmamal/node-sdl/compare/v0.11.11...v0.11.12
|
|
44
53
|
[v0.11.11]: https://github.com/kmamal/node-sdl/compare/v0.11.10...v0.11.11
|
|
45
54
|
[v0.11.10]: https://github.com/kmamal/node-sdl/compare/v0.11.9...v0.11.10
|
|
46
55
|
[v0.11.9]: https://github.com/kmamal/node-sdl/compare/v0.11.8...v0.11.9
|
package/README.md
CHANGED
|
@@ -169,6 +169,9 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
|
|
|
169
169
|
- [Event: 'mouseButtonUp'](#event-mousebuttonup)
|
|
170
170
|
- [Event: 'mouseMove'](#event-mousemove)
|
|
171
171
|
- [Event: 'mouseWheel'](#event-mousewheel)
|
|
172
|
+
- [Event: 'fingerDown'](#event-fingerdown)
|
|
173
|
+
- [Event: 'fingerUp'](#event-fingerup)
|
|
174
|
+
- [Event: 'fingerMove'](#event-fingermove)
|
|
172
175
|
- [Event: 'dropBegin'](#event-dropbegin)
|
|
173
176
|
- [Event: 'dropText'](#event-droptext)
|
|
174
177
|
- [Event: 'dropFile'](#event-dropfile)
|
|
@@ -804,6 +807,41 @@ Fired when the mouse moves.
|
|
|
804
807
|
|
|
805
808
|
Fired when the mouse wheel is scrolled.
|
|
806
809
|
|
|
810
|
+
### Event: 'fingerDown'
|
|
811
|
+
|
|
812
|
+
- `device: <object>`: An object from [`sdl.touch.devices`](#sdltouchdevices) indicating the touch device that caused the event.
|
|
813
|
+
- `fingerId: <number>` The id of the finger that coused the event.
|
|
814
|
+
- `x: <number>` The finger's x position when the event happened, normalized in the range from `0` to `1`.
|
|
815
|
+
- `y: <number>` The finger's y position when the event happened, normalized in the range from `0` to `1`.
|
|
816
|
+
- `pressure: <number>` The finger's pressure when the event happened, normalized in the range from `0` to `1`.
|
|
817
|
+
- `mouse: <boolean>` Is `true` if the event was caused by a mouse event.
|
|
818
|
+
|
|
819
|
+
Fired when a finger is presed to the touch surface.
|
|
820
|
+
|
|
821
|
+
### Event: 'fingerUp'
|
|
822
|
+
|
|
823
|
+
- `device: <object>`: An object from [`sdl.touch.devices`](#sdltouchdevices) indicating the touch device that caused the event.
|
|
824
|
+
- `fingerId: <number>` The id of the finger that coused the event.
|
|
825
|
+
- `x: <number>` The finger's x position when the event happened, normalized in the range from `0` to `1`.
|
|
826
|
+
- `y: <number>` The finger's y position when the event happened, normalized in the range from `0` to `1`.
|
|
827
|
+
- `pressure: <number>` The finger's pressure when the event happened, normalized in the range from `0` to `1`.
|
|
828
|
+
- `mouse: <boolean>` Is `true` if the event was caused by a mouse event.
|
|
829
|
+
|
|
830
|
+
Fired when a finger is lifted from the touch surface.
|
|
831
|
+
|
|
832
|
+
### Event: 'fingerMove'
|
|
833
|
+
|
|
834
|
+
- `device: <object>`: An object from [`sdl.touch.devices`](#sdltouchdevices) indicating the touch device that caused the event.
|
|
835
|
+
- `fingerId: <number>` The id of the finger that coused the event.
|
|
836
|
+
- `x: <number>` The finger's x position when the event happened, normalized in the range from `0` to `1`.
|
|
837
|
+
- `y: <number>` The finger's y position when the event happened, normalized in the range from `0` to `1`.
|
|
838
|
+
- `dx: <number>` The finger's x position when the event happened, normalized in the range from `-1` to `1`.
|
|
839
|
+
- `dy: <number>` The finger's y position when the event happened, normalized in the range from `-1` to `1`.
|
|
840
|
+
- `pressure: <number>` The finger's pressure when the event happened, normalized in the range from `0` to `1`.
|
|
841
|
+
- `mouse: <boolean>` Is `true` if the event was caused by a mouse event.
|
|
842
|
+
|
|
843
|
+
Fired when a finger moves on the touch surface.
|
|
844
|
+
|
|
807
845
|
### Event: 'dropBegin'
|
|
808
846
|
|
|
809
847
|
When you drop a set of items onto a window, first the [`'dropBegin'`](#event-dropbegin) event is fired, then a number of [`'dropText'`](#event-droptext) and/or [`'dropFile'`](#event-dropfile) events are fired, corresponding to the contents of the drop, then finally the [`'dropComplete'`](#event-dropcomplete) event is fired.
|
|
@@ -1578,6 +1616,30 @@ When the mouse has been captured you will continue receiving mouse events even i
|
|
|
1578
1616
|
|
|
1579
1617
|
Equivalent to [`sdl.mouse.capture(false)`](#sdlmousecapturecapture).
|
|
1580
1618
|
|
|
1619
|
+
## sdl.touch
|
|
1620
|
+
|
|
1621
|
+
### sdl.touch.devices
|
|
1622
|
+
|
|
1623
|
+
- `<object>[]`
|
|
1624
|
+
- `id: <number>` The unique id for the device.
|
|
1625
|
+
- `name: <string>|<null>` The name of the device, or `null` if it can't be determined.
|
|
1626
|
+
- `type: <TouchDeviceType>|<null>` The type of the device, or `null` if it can't be determined.
|
|
1627
|
+
|
|
1628
|
+
A list of all the detected touch devices.
|
|
1629
|
+
On some platforms SDL only sees the touch device after it has actually been used.
|
|
1630
|
+
Therefore the returned list might be empty, although devices are available.
|
|
1631
|
+
After using all devices at least once the number will be correct.
|
|
1632
|
+
|
|
1633
|
+
Possible values for `type` are `null` if it is unknown, or one of:
|
|
1634
|
+
|
|
1635
|
+
| Value | Corresponding `SDL_TouchDeviceType` |
|
|
1636
|
+
| --- | --- |
|
|
1637
|
+
| `'direct'` | `SDL_TOUCH_DEVICE_DIRECT` |
|
|
1638
|
+
| `'indirectAbsolute'` | `SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE` |
|
|
1639
|
+
| `'indirectRelative'` | `SDL_TOUCH_DEVICE_INDIRECT_RELATIVE` |
|
|
1640
|
+
|
|
1641
|
+
// TODO Sample output
|
|
1642
|
+
|
|
1581
1643
|
## sdl.joystick
|
|
1582
1644
|
|
|
1583
1645
|
### Hat positions
|
|
@@ -1632,7 +1694,7 @@ When this event is emitted, all instances that were opened from the removed devi
|
|
|
1632
1694
|
|
|
1633
1695
|
- `<object>[]`
|
|
1634
1696
|
- `id: <number>` The unique id for the device.
|
|
1635
|
-
- `name: <string>` The name of the device.
|
|
1697
|
+
- `name: <string>|<null>` The name of the device.
|
|
1636
1698
|
- `path: <string>|<null>` The implementation dependent path of the device, or `null` if it can't be determined.
|
|
1637
1699
|
- `type: <JoystickType>|<null>` The type of the device, or `null` if it can't be determined.
|
|
1638
1700
|
- `guid: <string>|<null>` The GUID of the device, or `null` if it can't be determined.
|
|
@@ -1765,7 +1827,7 @@ The joystick's serial number, or `null` if it is not available.
|
|
|
1765
1827
|
- `<number>[]`
|
|
1766
1828
|
|
|
1767
1829
|
An array of values, each corresponding to the position of one of the joystick's axes.
|
|
1768
|
-
The values are normalized from `-1` to `+1`.
|
|
1830
|
+
The values are normalized in the range from `-1` to `+1`.
|
|
1769
1831
|
It may be necessary to impose certain tolerances on these values to account for jitter.
|
|
1770
1832
|
|
|
1771
1833
|
### joystickInstance.balls
|
|
@@ -1922,7 +1984,7 @@ This may cause already opened controller instances to be [remapped](#event-remap
|
|
|
1922
1984
|
|
|
1923
1985
|
- `<object>[]`
|
|
1924
1986
|
- `id: <number>` The unique id for the device.
|
|
1925
|
-
- `name: <string>` The name of the device.
|
|
1987
|
+
- `name: <string>|<null>` The name of the device.
|
|
1926
1988
|
- `path: <string>|<null>` The implementation dependent path of the device, or `null` if it can't be determined.
|
|
1927
1989
|
- `type: <string>|<null>` The type of the device, or `null` if it can't be determined.
|
|
1928
1990
|
- `guid: <string>|<null>` The GUID of the device, or `null` if it can't be determined.
|
|
@@ -2070,7 +2132,7 @@ The `Buffer` contains an `InputHandle_t` for the controller that can be used wit
|
|
|
2070
2132
|
- `rightTrigger: <number>` Right trigger position
|
|
2071
2133
|
|
|
2072
2134
|
An object mapping each axis of the controller's axes to its position.
|
|
2073
|
-
The values are normalized from `-1` to `+1`.
|
|
2135
|
+
The values are normalized in the range from `-1` to `+1`.
|
|
2074
2136
|
It may be necessary to impose certain tolerances on these values to account for jitter.
|
|
2075
2137
|
|
|
2076
2138
|
### controllerInstance.buttons
|
package/binding.gyp
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.11.
|
|
2
|
+
"version": "0.11.12",
|
|
3
3
|
"name": "@kmamal/sdl",
|
|
4
4
|
"description": "SDL bindings for Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sdl",
|
|
7
7
|
"sdl2",
|
|
8
|
+
"game",
|
|
8
9
|
"gui",
|
|
9
10
|
"desktop",
|
|
10
11
|
"canvas",
|
|
@@ -14,9 +15,10 @@
|
|
|
14
15
|
"window",
|
|
15
16
|
"screen",
|
|
16
17
|
"video",
|
|
17
|
-
"input",
|
|
18
|
-
"mouse",
|
|
19
18
|
"keyboard",
|
|
19
|
+
"mouse",
|
|
20
|
+
"touch",
|
|
21
|
+
"multitouch",
|
|
20
22
|
"joystick",
|
|
21
23
|
"controller",
|
|
22
24
|
"gamepad",
|
|
@@ -26,10 +28,12 @@
|
|
|
26
28
|
"speaker",
|
|
27
29
|
"microphone",
|
|
28
30
|
"mic",
|
|
31
|
+
"sensor",
|
|
32
|
+
"accelerometer",
|
|
33
|
+
"gyroscope",
|
|
29
34
|
"clipboard",
|
|
30
35
|
"power",
|
|
31
|
-
"battery"
|
|
32
|
-
"game"
|
|
36
|
+
"battery"
|
|
33
37
|
],
|
|
34
38
|
"license": "MIT",
|
|
35
39
|
"repository": {
|
|
@@ -63,9 +67,9 @@
|
|
|
63
67
|
"tar": "^7.4.3"
|
|
64
68
|
},
|
|
65
69
|
"devDependencies": {
|
|
66
|
-
"@kmamal/evdev": "^0.0.
|
|
67
|
-
"@kmamal/testing": "^0.0.
|
|
68
|
-
"@types/node": "^24.0
|
|
70
|
+
"@kmamal/evdev": "^0.0.6",
|
|
71
|
+
"@kmamal/testing": "^0.0.33",
|
|
72
|
+
"@types/node": "^24.1.0",
|
|
69
73
|
"node-addon-api": "^8.5.0",
|
|
70
74
|
"node-gyp": "^11.2.0"
|
|
71
75
|
},
|
|
@@ -171,6 +171,26 @@ const handleEvent = (event) => {
|
|
|
171
171
|
window.emit(type, event)
|
|
172
172
|
} break
|
|
173
173
|
|
|
174
|
+
case 'touch': {
|
|
175
|
+
const { touchId } = event
|
|
176
|
+
delete event.touchId
|
|
177
|
+
|
|
178
|
+
let device = Globals.touchState.devices.find(({ id }) => id === touchId)
|
|
179
|
+
if (device === undefined) {
|
|
180
|
+
Globals.touchDevices = Bindings.touch_getDevices()
|
|
181
|
+
device = Globals.touchState.devices.find(({ id }) => id === touchId)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const { windowId } = event
|
|
185
|
+
delete event.windowId
|
|
186
|
+
|
|
187
|
+
const window = Globals.windows.all.get(windowId)
|
|
188
|
+
if (!window) { return }
|
|
189
|
+
|
|
190
|
+
event.device = device
|
|
191
|
+
window.emit(type, event)
|
|
192
|
+
} break
|
|
193
|
+
|
|
174
194
|
case 'joystickDevice': {
|
|
175
195
|
if (type === 'deviceRemove') {
|
|
176
196
|
const { joystickId } = event
|
package/src/javascript/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const info = Bindings.global_initialize()
|
|
|
8
8
|
const { video } = require('./video')
|
|
9
9
|
const { keyboard } = require('./keyboard')
|
|
10
10
|
const { mouse } = require('./mouse')
|
|
11
|
+
const { touch } = require('./touch')
|
|
11
12
|
const { joystick } = require('./joystick')
|
|
12
13
|
const { controller } = require('./controller')
|
|
13
14
|
const { sensor } = require('./sensor')
|
|
@@ -23,6 +24,7 @@ module.exports = {
|
|
|
23
24
|
video,
|
|
24
25
|
keyboard,
|
|
25
26
|
mouse,
|
|
27
|
+
touch,
|
|
26
28
|
joystick,
|
|
27
29
|
controller,
|
|
28
30
|
sensor,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const Globals = require('../globals')
|
|
2
|
+
const Bindings = require('../bindings')
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Globals.touchDevices = Bindings.touch_getDevices()
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const touch = {
|
|
9
|
+
get devices () {
|
|
10
|
+
Globals.events.poll()
|
|
11
|
+
return Globals.touchDevices
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = { touch }
|
package/src/native/events.cpp
CHANGED
|
@@ -18,6 +18,7 @@ std::string events::families::KEYMAP;
|
|
|
18
18
|
std::string events::families::KEYBOARD;
|
|
19
19
|
std::string events::families::TEXT;
|
|
20
20
|
std::string events::families::MOUSE;
|
|
21
|
+
std::string events::families::TOUCH;
|
|
21
22
|
std::string events::families::JOYSTICK_DEVICE;
|
|
22
23
|
std::string events::families::JOYSTICK;
|
|
23
24
|
std::string events::families::CONTROLLER;
|
|
@@ -56,6 +57,9 @@ std::string events::types::DROP_FILE;
|
|
|
56
57
|
std::string events::types::DROP_TEXT;
|
|
57
58
|
std::string events::types::CLOSE;
|
|
58
59
|
std::string events::types::KEYMAP_CHANGE;
|
|
60
|
+
std::string events::types::FINGER_DOWN;
|
|
61
|
+
std::string events::types::FINGER_UP;
|
|
62
|
+
std::string events::types::FINGER_MOVE;
|
|
59
63
|
std::string events::types::DEVICE_ADD;
|
|
60
64
|
std::string events::types::DEVICE_REMOVE;
|
|
61
65
|
std::string events::types::AXIS_MOTION;
|
|
@@ -292,6 +296,36 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
292
296
|
break;
|
|
293
297
|
}
|
|
294
298
|
|
|
299
|
+
case SDL_FINGERUP:
|
|
300
|
+
case SDL_FINGERDOWN: {
|
|
301
|
+
packed.Set("family", events::families::TOUCH);
|
|
302
|
+
packed.Set("type", event.type == SDL_FINGERUP
|
|
303
|
+
? events::types::FINGER_UP
|
|
304
|
+
: events::types::FINGER_DOWN);
|
|
305
|
+
packed.Set("windowId", event.tfinger.windowID);
|
|
306
|
+
packed.Set("mouse", event.tfinger.touchId == SDL_MOUSE_TOUCHID);
|
|
307
|
+
packed.Set("touchId", event.tfinger.touchId);
|
|
308
|
+
packed.Set("fingerId", event.tfinger.fingerId);
|
|
309
|
+
packed.Set("x", event.tfinger.x);
|
|
310
|
+
packed.Set("y", event.tfinger.y);
|
|
311
|
+
packed.Set("pressure", event.tfinger.pressure);
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
case SDL_FINGERMOTION: {
|
|
315
|
+
packed.Set("family", events::families::TOUCH);
|
|
316
|
+
packed.Set("type", events::types::FINGER_MOVE);
|
|
317
|
+
packed.Set("windowId", event.tfinger.windowID);
|
|
318
|
+
packed.Set("mouse", event.tfinger.touchId == SDL_MOUSE_TOUCHID);
|
|
319
|
+
packed.Set("touchId", event.tfinger.touchId);
|
|
320
|
+
packed.Set("fingerId", event.tfinger.fingerId);
|
|
321
|
+
packed.Set("x", event.tfinger.x);
|
|
322
|
+
packed.Set("y", event.tfinger.y);
|
|
323
|
+
packed.Set("dx", event.tfinger.dx);
|
|
324
|
+
packed.Set("dy", event.tfinger.dy);
|
|
325
|
+
packed.Set("pressure", event.tfinger.pressure);
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
|
|
295
329
|
case SDL_JOYDEVICEADDED: {
|
|
296
330
|
packed.Set("family", events::families::JOYSTICK_DEVICE);
|
|
297
331
|
packed.Set("type", events::types::DEVICE_ADD);
|
|
@@ -464,30 +498,6 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
464
498
|
packed.Set("type", events::types::UPDATE);
|
|
465
499
|
break;
|
|
466
500
|
}
|
|
467
|
-
|
|
468
|
-
// case SDL_FINGERUP:
|
|
469
|
-
// case SDL_FINGERDOWN: {
|
|
470
|
-
// SET_STRING(object, "type", event.type == SDL_FINGERUP
|
|
471
|
-
// ? "fingerUp"
|
|
472
|
-
// : "fingerDown");
|
|
473
|
-
// packed.Set("touch_id", event.tfinger.touchId);
|
|
474
|
-
// packed.Set("finger_id", event.tfinger.fingerId);
|
|
475
|
-
// packed.Set("pressure", event.tfinger.pressure);
|
|
476
|
-
// packed.Set("x", event.tfinger.x);
|
|
477
|
-
// packed.Set("y", event.tfinger.y);
|
|
478
|
-
// break;
|
|
479
|
-
// }
|
|
480
|
-
// case SDL_FINGERMOTION: {
|
|
481
|
-
// SET_STRING(object, "type", "fingerMotion");
|
|
482
|
-
// packed.Set("touch_id", event.tfinger.touchId);
|
|
483
|
-
// packed.Set("finger_id", event.tfinger.fingerId);
|
|
484
|
-
// packed.Set("pressure", event.tfinger.pressure);
|
|
485
|
-
// packed.Set("x", event.tfinger.x);
|
|
486
|
-
// packed.Set("y", event.tfinger.y);
|
|
487
|
-
// packed.Set("dx", event.tfinger.dx);
|
|
488
|
-
// packed.Set("dy", event.tfinger.dy);
|
|
489
|
-
// break;
|
|
490
|
-
// }
|
|
491
501
|
}
|
|
492
502
|
|
|
493
503
|
poll_callback->Call(poll_env->Global(), { packed });
|
package/src/native/events.h
CHANGED
|
@@ -16,6 +16,7 @@ namespace events {
|
|
|
16
16
|
extern std::string KEYBOARD;
|
|
17
17
|
extern std::string TEXT;
|
|
18
18
|
extern std::string MOUSE;
|
|
19
|
+
extern std::string TOUCH;
|
|
19
20
|
extern std::string JOYSTICK_DEVICE;
|
|
20
21
|
extern std::string JOYSTICK;
|
|
21
22
|
extern std::string CONTROLLER;
|
|
@@ -56,6 +57,9 @@ namespace events {
|
|
|
56
57
|
extern std::string DROP_TEXT;
|
|
57
58
|
extern std::string CLOSE;
|
|
58
59
|
extern std::string KEYMAP_CHANGE;
|
|
60
|
+
extern std::string FINGER_DOWN;
|
|
61
|
+
extern std::string FINGER_UP;
|
|
62
|
+
extern std::string FINGER_MOVE;
|
|
59
63
|
extern std::string DEVICE_ADD;
|
|
60
64
|
extern std::string DEVICE_REMOVE;
|
|
61
65
|
extern std::string AXIS_MOTION;
|
package/src/native/global.cpp
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#include "events.h"
|
|
3
3
|
#include "keyboard.h"
|
|
4
4
|
#include "video.h"
|
|
5
|
+
#include "touch.h"
|
|
5
6
|
#include "joystick.h"
|
|
6
7
|
#include "controller.h"
|
|
7
8
|
#include "sensor.h"
|
|
@@ -49,6 +50,7 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
49
50
|
events::families::KEYBOARD = "keyboard";
|
|
50
51
|
events::families::TEXT = "text";
|
|
51
52
|
events::families::MOUSE = "mouse";
|
|
53
|
+
events::families::TOUCH = "touch";
|
|
52
54
|
events::families::JOYSTICK_DEVICE = "joystickDevice";
|
|
53
55
|
events::families::JOYSTICK = "joystick";
|
|
54
56
|
events::families::CONTROLLER = "controller";
|
|
@@ -87,6 +89,9 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
87
89
|
events::types::DROP_TEXT = "dropText";
|
|
88
90
|
events::types::CLOSE = "close";
|
|
89
91
|
events::types::KEYMAP_CHANGE = "keymapChange";
|
|
92
|
+
events::types::FINGER_DOWN = "fingerDown";
|
|
93
|
+
events::types::FINGER_UP = "fingerUp";
|
|
94
|
+
events::types::FINGER_MOVE = "fingerMove";
|
|
90
95
|
events::types::DEVICE_ADD = "deviceAdd";
|
|
91
96
|
events::types::DEVICE_REMOVE = "deviceRemove";
|
|
92
97
|
events::types::AXIS_MOTION = "axisMotion";
|
|
@@ -142,6 +147,11 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
142
147
|
video::formats[SDL_PIXELFORMAT_NV12] = "nv12";
|
|
143
148
|
video::formats[SDL_PIXELFORMAT_NV21] = "nv21";
|
|
144
149
|
|
|
150
|
+
// touch::device_types[SDL_TOUCH_DEVICE_INVALID] = nullptr;
|
|
151
|
+
touch::device_types[SDL_TOUCH_DEVICE_DIRECT] = "direct";
|
|
152
|
+
touch::device_types[SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE] = "indirectAbsolute";
|
|
153
|
+
touch::device_types[SDL_TOUCH_DEVICE_INDIRECT_RELATIVE] = "indirectRelative";
|
|
154
|
+
|
|
145
155
|
// joystick::types[SDL_JOYSTICK_TYPE_UNKNOWN] = nullptr;
|
|
146
156
|
joystick::types[SDL_JOYSTICK_TYPE_GAMECONTROLLER] = "gamecontroller";
|
|
147
157
|
joystick::types[SDL_JOYSTICK_TYPE_WHEEL] = "wheel";
|
package/src/native/joystick.cpp
CHANGED
|
@@ -85,9 +85,9 @@ joystick::_getDevices (Napi::Env &env)
|
|
|
85
85
|
? Napi::Number::New(env, _product)
|
|
86
86
|
: env.Null();
|
|
87
87
|
|
|
88
|
-
int
|
|
89
|
-
Napi::Value version =
|
|
90
|
-
? Napi::Number::New(env,
|
|
88
|
+
int _version = SDL_JoystickGetDeviceProductVersion(i);
|
|
89
|
+
Napi::Value version = _version != 0
|
|
90
|
+
? Napi::Number::New(env, _version)
|
|
91
91
|
: env.Null();
|
|
92
92
|
|
|
93
93
|
int _player = SDL_JoystickGetDevicePlayerIndex(i);
|
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,6 +61,8 @@ 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
68
|
exports.Set("joystick_setLed", Napi::Function::New<joystick::setLed>(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
|
|
@@ -223,7 +246,9 @@ export namespace Events {
|
|
|
223
246
|
export interface Add extends DeviceEvent { readonly type: 'deviceAdd' }
|
|
224
247
|
export interface Remove extends DeviceEvent { readonly type: 'deviceRemove' }
|
|
225
248
|
|
|
226
|
-
export type Any
|
|
249
|
+
export type Any
|
|
250
|
+
= Add
|
|
251
|
+
| Remove
|
|
227
252
|
|
|
228
253
|
}
|
|
229
254
|
|
|
@@ -294,7 +319,9 @@ export namespace Events {
|
|
|
294
319
|
export interface Add extends DeviceEvent { readonly type: 'deviceAdd' }
|
|
295
320
|
export interface Remove extends DeviceEvent { readonly type: 'deviceRemove' }
|
|
296
321
|
|
|
297
|
-
export type Any
|
|
322
|
+
export type Any
|
|
323
|
+
= Add
|
|
324
|
+
| Remove
|
|
298
325
|
|
|
299
326
|
}
|
|
300
327
|
|
|
@@ -304,7 +331,8 @@ export namespace Events {
|
|
|
304
331
|
|
|
305
332
|
export interface Close extends AudioEvent { readonly type: 'close' }
|
|
306
333
|
|
|
307
|
-
export type Any
|
|
334
|
+
export type Any
|
|
335
|
+
= Close
|
|
308
336
|
|
|
309
337
|
}
|
|
310
338
|
|
|
@@ -317,7 +345,9 @@ export namespace Events {
|
|
|
317
345
|
export interface Add extends DeviceEvent { readonly type: 'deviceAdd' }
|
|
318
346
|
export interface Remove extends DeviceEvent { readonly type: 'deviceRemove' }
|
|
319
347
|
|
|
320
|
-
export type Any
|
|
348
|
+
export type Any
|
|
349
|
+
= Add
|
|
350
|
+
| Remove
|
|
321
351
|
|
|
322
352
|
}
|
|
323
353
|
|
|
@@ -325,7 +355,8 @@ export namespace Events {
|
|
|
325
355
|
|
|
326
356
|
export interface Update extends BaseEvent { readonly type: 'update' }
|
|
327
357
|
|
|
328
|
-
export type Any
|
|
358
|
+
export type Any
|
|
359
|
+
= Update
|
|
329
360
|
|
|
330
361
|
}
|
|
331
362
|
|
|
@@ -358,12 +389,12 @@ export namespace Sdl {
|
|
|
358
389
|
}
|
|
359
390
|
}
|
|
360
391
|
readonly initialized: {
|
|
361
|
-
video: boolean
|
|
362
|
-
audio: boolean
|
|
363
|
-
joystick: boolean
|
|
364
|
-
controller: boolean
|
|
365
|
-
haptic: boolean
|
|
366
|
-
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
|
|
367
398
|
}
|
|
368
399
|
}
|
|
369
400
|
|
|
@@ -465,6 +496,9 @@ export namespace Sdl {
|
|
|
465
496
|
on (event: 'mouseButtonUp', listener: (event: Events.Window.MouseButtonUp) => void): this
|
|
466
497
|
on (event: 'mouseMove', listener: (event: Events.Window.MouseMove) => void): this
|
|
467
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
|
|
468
502
|
on (event: 'dropBegin', listener: (event: Events.Window.DropBegin) => void): this
|
|
469
503
|
on (event: 'dropText', listener: (event: Events.Window.DropText) => void): this
|
|
470
504
|
on (event: 'dropFile', listener: (event: Events.Window.DropFile) => void): this
|
|
@@ -901,11 +935,30 @@ export namespace Sdl {
|
|
|
901
935
|
|
|
902
936
|
}
|
|
903
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
|
+
|
|
904
957
|
export namespace Joystick {
|
|
905
958
|
|
|
906
959
|
export interface BallPosition {
|
|
907
|
-
x: number
|
|
908
|
-
y: number
|
|
960
|
+
readonly x: number
|
|
961
|
+
readonly y: number
|
|
909
962
|
}
|
|
910
963
|
|
|
911
964
|
export type JoystickType
|
|
@@ -1264,10 +1317,10 @@ export namespace Sdl {
|
|
|
1264
1317
|
}
|
|
1265
1318
|
|
|
1266
1319
|
export interface AudioOptions {
|
|
1267
|
-
channels?: 1 | 2 | 4 | 6
|
|
1268
|
-
frequency?: number
|
|
1269
|
-
format?: Format
|
|
1270
|
-
buffered?: number
|
|
1320
|
+
readonly channels?: 1 | 2 | 4 | 6
|
|
1321
|
+
readonly frequency?: number
|
|
1322
|
+
readonly format?: Format
|
|
1323
|
+
readonly buffered?: number
|
|
1271
1324
|
}
|
|
1272
1325
|
|
|
1273
1326
|
interface Module {
|
|
@@ -1310,9 +1363,9 @@ export namespace Sdl {
|
|
|
1310
1363
|
| 'charged'
|
|
1311
1364
|
|
|
1312
1365
|
export interface PowerInfo {
|
|
1313
|
-
state: PowerState | null
|
|
1314
|
-
seconds: number | null
|
|
1315
|
-
percent: number | null
|
|
1366
|
+
readonly state: PowerState | null
|
|
1367
|
+
readonly seconds: number | null
|
|
1368
|
+
readonly percent: number | null
|
|
1316
1369
|
}
|
|
1317
1370
|
|
|
1318
1371
|
interface Module {
|
|
@@ -1327,6 +1380,7 @@ export const info: Sdl.Info
|
|
|
1327
1380
|
export const video: Sdl.Video.Module
|
|
1328
1381
|
export const keyboard: Sdl.Keyboard.Module
|
|
1329
1382
|
export const mouse: Sdl.Mouse.Module
|
|
1383
|
+
export const touch: Sdl.Touch.Module
|
|
1330
1384
|
export const joystick: Sdl.Joystick.Module
|
|
1331
1385
|
export const controller: Sdl.Controller.Module
|
|
1332
1386
|
export const sensor: Sdl.Sensor.Module
|