@kmamal/sdl 0.6.7 → 0.6.8
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 +23 -18
- package/package.json +1 -1
- package/src/javascript/events/index.js +30 -32
- package/src/javascript/events/quit.js +7 -4
- package/src/javascript/video/window.js +1 -1
- package/src/types/index.d.ts +94 -78
package/README.md
CHANGED
|
@@ -13,7 +13,11 @@ Prebuilt binaries are available for x64 architectures, and arm-based Macs.
|
|
|
13
13
|
|
|
14
14
|
#### Canvas, WebGL, and WebGPU
|
|
15
15
|
|
|
16
|
-
One goal of this project is to allow using Canvas (the 2D rendering context API), WebGL and WebGPU without a browser.
|
|
16
|
+
One goal of this project is to allow using Canvas (the 2D rendering context API), WebGL, and WebGPU without a browser.
|
|
17
|
+
You can already use [@kmamal/gl](https://github.com/kmamal/headless-gl#readme) to draw on windows using WebGL.
|
|
18
|
+
WebGPU is also working, but it's not been fully integrated: you can use [@kmamal/gpu](https://github.com/kmamal/gpu#readme) for compute and render, but it can't yet render directly to windows; that will come in a future version.
|
|
19
|
+
Right now you have to go through an intermediate buffer.
|
|
20
|
+
Same with the Canvas API, where you can use the [canvas](https://www.npmjs.com/package/canvas) package to draw to a buffer and then draw that to a window.
|
|
17
21
|
|
|
18
22
|
|
|
19
23
|
## Installation
|
|
@@ -29,7 +33,9 @@ npm install @kmamal/sdl
|
|
|
29
33
|
(But if things go wrong do look over [here](#building-from-source))
|
|
30
34
|
|
|
31
35
|
|
|
32
|
-
##
|
|
36
|
+
## Examples
|
|
37
|
+
|
|
38
|
+
### "Hello, World!"
|
|
33
39
|
|
|
34
40
|
```js
|
|
35
41
|
const sdl = require('@kmamal/sdl')
|
|
@@ -38,12 +44,12 @@ const window = sdl.video.createWindow({ title: "Hello, World!" })
|
|
|
38
44
|
window.on('*', console.log)
|
|
39
45
|
```
|
|
40
46
|
|
|
41
|
-
|
|
47
|
+
### Canvas
|
|
42
48
|
```js
|
|
43
49
|
import sdl from '@kmamal/sdl'
|
|
44
50
|
import canvas from 'canvas'
|
|
45
51
|
|
|
46
|
-
const window = sdl.video.createWindow({
|
|
52
|
+
const window = sdl.video.createWindow({ title: "Canvas" })
|
|
47
53
|
const { width, height } = window
|
|
48
54
|
const canvas = canvas.createCanvas(width, height)
|
|
49
55
|
const ctx = canvas.getContext('2d')
|
|
@@ -55,15 +61,12 @@ const buffer = canvas.toBuffer('raw')
|
|
|
55
61
|
window.render(width, height, width * 4, 'bgra32', buffer)
|
|
56
62
|
```
|
|
57
63
|
|
|
58
|
-
|
|
64
|
+
### WebGL
|
|
59
65
|
```js
|
|
60
66
|
const sdl = require('@kmamal/sdl')
|
|
61
67
|
const createContext = require('@kmamal/gl')
|
|
62
68
|
|
|
63
|
-
const window = sdl.video.createWindow({
|
|
64
|
-
title: "WebGL",
|
|
65
|
-
opengl: true,
|
|
66
|
-
})
|
|
69
|
+
const window = sdl.video.createWindow({title: "WebGL", opengl: true })
|
|
67
70
|
const { width, height, native } = window
|
|
68
71
|
const gl = createContext(width, height, { window: native })
|
|
69
72
|
|
|
@@ -73,7 +76,7 @@ gl.clear(gl.COLOR_BUFFER_BIT)
|
|
|
73
76
|
gl.swap()
|
|
74
77
|
```
|
|
75
78
|
|
|
76
|
-
There are more examples [in the `examples/` folder](https://github.com/kmamal/node-sdl/tree/master/examples)
|
|
79
|
+
There are more examples [in the `examples/` folder](https://github.com/kmamal/node-sdl/tree/master/examples).
|
|
77
80
|
|
|
78
81
|
|
|
79
82
|
# API Reference
|
|
@@ -179,7 +182,7 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
179
182
|
* [Event: 'deviceAdd'](#joystick-event-device-add)
|
|
180
183
|
* [Event: 'deviceRemove'](#joystick-event-device-remove)
|
|
181
184
|
* [sdl.joystick.devices](#sdljoystickdevices)
|
|
182
|
-
* [sdl.joystick.openDevice(device)](#sdljoystickopendevicedevice
|
|
185
|
+
* [sdl.joystick.openDevice(device)](#sdljoystickopendevicedevice)
|
|
183
186
|
* [class JoystickInstance](#class-joystickinstance)
|
|
184
187
|
* [Event: 'axisMotion'](#joystick-instance-event-axismotion)
|
|
185
188
|
* [Event: 'ballMotion'](#event-ballmotion)
|
|
@@ -210,7 +213,7 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
210
213
|
* [Event: 'deviceRemove'](#controller-event-device-remove)
|
|
211
214
|
* [sdl.controller.addMappings(mappings)](#sdlcontrolleraddmappingsmappings)
|
|
212
215
|
* [sdl.controller.devices](#sdlcontrollerdevices)
|
|
213
|
-
* [sdl.controller.openDevice(device)](#sdlcontrolleropendevicedevice
|
|
216
|
+
* [sdl.controller.openDevice(device)](#sdlcontrolleropendevicedevice)
|
|
214
217
|
* [class ControllerInstance](#class-controllerinstance)
|
|
215
218
|
* [Event: 'axisMotion'](#controller-instance-event-axismotion)
|
|
216
219
|
* [Event: 'buttonDown'](#controller-instance-event-buttondown)
|
|
@@ -1397,7 +1400,7 @@ Sample output:
|
|
|
1397
1400
|
]
|
|
1398
1401
|
```
|
|
1399
1402
|
|
|
1400
|
-
### sdl.joystick.openDevice(device
|
|
1403
|
+
### sdl.joystick.openDevice(device)
|
|
1401
1404
|
|
|
1402
1405
|
* `device: <object>` An object from [`sdl.joystick.devices`](#sdljoystickdevices) that should be opened.
|
|
1403
1406
|
* Returns: [`<joystickInstance>`](#class-joystickinstance) an object representing the opened joystick device instance.
|
|
@@ -1407,7 +1410,7 @@ Initializes a joystick device and returns a corresponding instance.
|
|
|
1407
1410
|
## class JoystickInstance
|
|
1408
1411
|
|
|
1409
1412
|
This class is not directly exposed by the API so you can't use it with the `new` operator.
|
|
1410
|
-
Instead, objects returned by [`sdl.joystick.openDevice()`](#sdljoystickopendevicedevice
|
|
1413
|
+
Instead, objects returned by [`sdl.joystick.openDevice()`](#sdljoystickopendevicedevice) are of this type.
|
|
1411
1414
|
|
|
1412
1415
|
<a id="joystick-instance-event-axismotion"></a>
|
|
1413
1416
|
|
|
@@ -1584,7 +1587,8 @@ With a pure joystick instance it's impossible to know which axis or button corre
|
|
|
1584
1587
|
|
|
1585
1588
|
Because controllers are an abstraction over joysticks, they operate on the same set of devices (if a joystick device and a controller device have the same id, then they refer to the same underlying physical device).
|
|
1586
1589
|
For a joystick device to also be available as a controller device it needs a "mapping".
|
|
1587
|
-
A mapping is a string that consists of the device's name, it's GUID, and a series of pairings between one joystick axis/button and the corresponding controller axis/button name.
|
|
1590
|
+
A mapping is a string that consists of the device's name, it's GUID, and a series of pairings between one joystick axis/button and the corresponding controller axis/button name.
|
|
1591
|
+
See the sample output [`here`](#sdlcontrollerdevices) for an example.
|
|
1588
1592
|
SDL has pretty good default controller mappings, but if you need more, there's a community sourced database available on https://github.com/gabomdq/SDL_GameControllerDB.
|
|
1589
1593
|
You can add them via:
|
|
1590
1594
|
```js
|
|
@@ -1653,7 +1657,7 @@ Sample output:
|
|
|
1653
1657
|
]
|
|
1654
1658
|
```
|
|
1655
1659
|
|
|
1656
|
-
### sdl.controller.openDevice(device
|
|
1660
|
+
### sdl.controller.openDevice(device)
|
|
1657
1661
|
|
|
1658
1662
|
* `device: <object>` An object from [`sdl.controller.devices`](#sdlcontrollerdevices) that should be opened.
|
|
1659
1663
|
* Returns: [`<ControllerInstance>`](#class-controllerinstance) an object representing the opened controller device instance.
|
|
@@ -1663,7 +1667,7 @@ Initializes an controller device and returns a corresponding instance.
|
|
|
1663
1667
|
## class ControllerInstance
|
|
1664
1668
|
|
|
1665
1669
|
This class is not directly exposed by the API so you can't use it with the `new` operator.
|
|
1666
|
-
Instead, objects returned by [`sdl.controller.openDevice()`](#sdlcontrolleropendevicedevice
|
|
1670
|
+
Instead, objects returned by [`sdl.controller.openDevice()`](#sdlcontrolleropendevicedevice) are of this type.
|
|
1667
1671
|
|
|
1668
1672
|
<a id="controller-instance-event-axismotion"></a>
|
|
1669
1673
|
|
|
@@ -2236,7 +2240,8 @@ You will need to have `cmake` installed for that to work.
|
|
|
2236
2240
|
|
|
2237
2241
|
---
|
|
2238
2242
|
|
|
2239
|
-
You could also have found your way to the "Building from source" section because you are trying to contribute to this package.
|
|
2243
|
+
You could also have found your way to the "Building from source" section because you are trying to contribute to this package.
|
|
2244
|
+
There are some npm scripts in `package.json` that could be of use to you:
|
|
2240
2245
|
* `npm run clean` deletes all folders that are created during the build, as well as `node_modules`.
|
|
2241
2246
|
* `npm run download-release` downloads the prebuilt binaries. This is the first thing the install script tries to do.
|
|
2242
2247
|
* `npm run download-sdl` downloads the SDL headers and libraries from `@kmamal/build-sdl` so you can compile against them in later steps. This is the second step in the install script, after `download-release` has failed.
|
package/package.json
CHANGED
|
@@ -36,12 +36,16 @@ const reconcileDevices = (emitter, mainList, currList, compare) => {
|
|
|
36
36
|
currDevice = currList[++currIndex]
|
|
37
37
|
} else if (cmp < 0) {
|
|
38
38
|
mainList.splice(mainIndex, 1)
|
|
39
|
-
|
|
39
|
+
const type = 'deviceRemove'
|
|
40
|
+
const event = { type, device: mainDevice }
|
|
41
|
+
emitter.emit(type, event)
|
|
40
42
|
mainDevice = mainList[mainIndex]
|
|
41
43
|
} else {
|
|
42
44
|
mainList.splice(mainIndex, 0, currDevice)
|
|
43
45
|
mainDevice = mainList[++mainIndex]
|
|
44
|
-
|
|
46
|
+
const type = 'deviceAdd'
|
|
47
|
+
const event = { type, device: currDevice }
|
|
48
|
+
emitter.emit(type, event)
|
|
45
49
|
currDevice = currList[++currIndex]
|
|
46
50
|
}
|
|
47
51
|
}
|
|
@@ -49,12 +53,16 @@ const reconcileDevices = (emitter, mainList, currList, compare) => {
|
|
|
49
53
|
if (mainIndex < mainList.length) {
|
|
50
54
|
while (mainIndex < mainList.length) {
|
|
51
55
|
[ mainDevice ] = mainList.splice(mainIndex, 1)
|
|
52
|
-
|
|
56
|
+
const type = 'deviceRemove'
|
|
57
|
+
const event = { type, device: mainDevice }
|
|
58
|
+
emitter.emit(type, event)
|
|
53
59
|
}
|
|
54
60
|
} else {
|
|
55
61
|
while (currIndex < currList.length) {
|
|
56
62
|
mainList.push(currDevice)
|
|
57
|
-
|
|
63
|
+
const type = 'deviceAdd'
|
|
64
|
+
const event = { type, device: currDevice }
|
|
65
|
+
emitter.emit(type, event)
|
|
58
66
|
currDevice = currList[++currIndex]
|
|
59
67
|
}
|
|
60
68
|
}
|
|
@@ -67,7 +75,7 @@ const handleEvents = () => {
|
|
|
67
75
|
const { family, type } = event
|
|
68
76
|
if (family === undefined || type === undefined) { continue }
|
|
69
77
|
delete event.family
|
|
70
|
-
|
|
78
|
+
event.type = Enums.eventTypeNames[type]
|
|
71
79
|
|
|
72
80
|
switch (family) {
|
|
73
81
|
case Enums.eventFamily.app: {
|
|
@@ -140,25 +148,23 @@ const handleEvents = () => {
|
|
|
140
148
|
case Enums.eventType.close: {
|
|
141
149
|
let shouldPrevent = false
|
|
142
150
|
const prevent = () => { shouldPrevent = true }
|
|
143
|
-
|
|
151
|
+
const type2 = 'beforeClose'
|
|
152
|
+
const event2 = { type: type2, prevent }
|
|
153
|
+
window.emit(type2, event2)
|
|
144
154
|
if (shouldPrevent) { continue }
|
|
145
155
|
} break
|
|
146
156
|
|
|
147
157
|
default: continue
|
|
148
158
|
}
|
|
149
159
|
|
|
150
|
-
|
|
151
|
-
window.emit(Enums.eventTypeNames[type], event)
|
|
152
|
-
} else {
|
|
153
|
-
window.emit(Enums.eventTypeNames[type])
|
|
154
|
-
}
|
|
160
|
+
window.emit(event.type, event)
|
|
155
161
|
|
|
156
162
|
if (type === Enums.eventType.close) { window.destroy() }
|
|
157
163
|
} break
|
|
158
164
|
|
|
159
165
|
case Enums.eventFamily.keyboard: {
|
|
160
166
|
const { windowId } = event
|
|
161
|
-
delete event.
|
|
167
|
+
delete event.windowId
|
|
162
168
|
|
|
163
169
|
const window = Globals.windows.all.get(windowId)
|
|
164
170
|
if (!window) { continue }
|
|
@@ -166,11 +172,7 @@ const handleEvents = () => {
|
|
|
166
172
|
const { key } = event
|
|
167
173
|
event.key = mapping[key] ?? (key?.length === 1 ? key : null)
|
|
168
174
|
|
|
169
|
-
|
|
170
|
-
window.emit(Enums.eventTypeNames[type], event)
|
|
171
|
-
} else {
|
|
172
|
-
window.emit(Enums.eventTypeNames[type])
|
|
173
|
-
}
|
|
175
|
+
window.emit(event.type, event)
|
|
174
176
|
} break
|
|
175
177
|
|
|
176
178
|
case Enums.eventFamily.mouse:
|
|
@@ -182,11 +184,7 @@ const handleEvents = () => {
|
|
|
182
184
|
const window = Globals.windows.all.get(windowId)
|
|
183
185
|
if (!window) { continue }
|
|
184
186
|
|
|
185
|
-
|
|
186
|
-
window.emit(Enums.eventTypeNames[type], event)
|
|
187
|
-
} else {
|
|
188
|
-
window.emit(Enums.eventTypeNames[type])
|
|
189
|
-
}
|
|
187
|
+
window.emit(event.type, event)
|
|
190
188
|
} break
|
|
191
189
|
|
|
192
190
|
case Enums.eventFamily.joystickDevice: {
|
|
@@ -249,7 +247,7 @@ const handleEvents = () => {
|
|
|
249
247
|
case Enums.eventType.axisMotion: {
|
|
250
248
|
for (const joystickInstance of collection) {
|
|
251
249
|
joystickInstance._axes[event.axis] = event.value
|
|
252
|
-
joystickInstance.emit(
|
|
250
|
+
joystickInstance.emit(event.type, event)
|
|
253
251
|
}
|
|
254
252
|
} break
|
|
255
253
|
|
|
@@ -258,20 +256,20 @@ const handleEvents = () => {
|
|
|
258
256
|
const ball = joystickInstance._balls[event.ball]
|
|
259
257
|
ball.x = event.x
|
|
260
258
|
ball.y = event.y
|
|
261
|
-
joystickInstance.emit(
|
|
259
|
+
joystickInstance.emit(event.type, event)
|
|
262
260
|
}
|
|
263
261
|
} break
|
|
264
262
|
|
|
265
263
|
case Enums.eventType.buttonDown: {
|
|
266
264
|
for (const joystickInstance of collection) {
|
|
267
265
|
joystickInstance._buttons[event.button] = true
|
|
268
|
-
joystickInstance.emit(
|
|
266
|
+
joystickInstance.emit(event.type, event)
|
|
269
267
|
}
|
|
270
268
|
} break
|
|
271
269
|
case Enums.eventType.buttonUp: {
|
|
272
270
|
for (const joystickInstance of collection) {
|
|
273
271
|
joystickInstance._buttons[event.button] = false
|
|
274
|
-
joystickInstance.emit(
|
|
272
|
+
joystickInstance.emit(event.type, event)
|
|
275
273
|
}
|
|
276
274
|
} break
|
|
277
275
|
|
|
@@ -279,7 +277,7 @@ const handleEvents = () => {
|
|
|
279
277
|
event.value = Enums.hatPositionNames[event.value]
|
|
280
278
|
for (const joystickInstance of collection) {
|
|
281
279
|
joystickInstance._hats[event.hat] = event.value
|
|
282
|
-
joystickInstance.emit(
|
|
280
|
+
joystickInstance.emit(event.type, event)
|
|
283
281
|
}
|
|
284
282
|
} break
|
|
285
283
|
|
|
@@ -299,7 +297,7 @@ const handleEvents = () => {
|
|
|
299
297
|
event.axis = Enums.controllerAxisNames[event.axis]
|
|
300
298
|
for (const controllerInstance of collection.values()) {
|
|
301
299
|
controllerInstance._axes[event.axis] = event.value
|
|
302
|
-
controllerInstance.emit(
|
|
300
|
+
controllerInstance.emit(event.type, event)
|
|
303
301
|
}
|
|
304
302
|
} break
|
|
305
303
|
|
|
@@ -307,7 +305,7 @@ const handleEvents = () => {
|
|
|
307
305
|
event.button = Enums.controllerButtonNames[event.button]
|
|
308
306
|
for (const controllerInstance of collection.values()) {
|
|
309
307
|
controllerInstance._axes[event.button] = true
|
|
310
|
-
controllerInstance.emit(
|
|
308
|
+
controllerInstance.emit(event.type, event)
|
|
311
309
|
}
|
|
312
310
|
} break
|
|
313
311
|
|
|
@@ -315,7 +313,7 @@ const handleEvents = () => {
|
|
|
315
313
|
event.button = Enums.controllerButtonNames[event.button]
|
|
316
314
|
for (const controllerInstance of collection.values()) {
|
|
317
315
|
controllerInstance._axes[event.button] = true
|
|
318
|
-
controllerInstance.emit(
|
|
316
|
+
controllerInstance.emit(event.type, event)
|
|
319
317
|
}
|
|
320
318
|
} break
|
|
321
319
|
|
|
@@ -327,7 +325,7 @@ const handleEvents = () => {
|
|
|
327
325
|
for (const controllerInstance of collection.values()) {
|
|
328
326
|
Object.assign(controllerInstance._axes, axes)
|
|
329
327
|
Object.assign(controllerInstance._buttons, buttons)
|
|
330
|
-
controllerInstance.emit(
|
|
328
|
+
controllerInstance.emit(event.type, event)
|
|
331
329
|
}
|
|
332
330
|
} break
|
|
333
331
|
|
|
@@ -363,7 +361,7 @@ const handleEvents = () => {
|
|
|
363
361
|
} break
|
|
364
362
|
|
|
365
363
|
case Enums.eventFamily.clipboard: {
|
|
366
|
-
clipboardModule.emit(
|
|
364
|
+
clipboardModule.emit(event.type, event)
|
|
367
365
|
} break
|
|
368
366
|
|
|
369
367
|
default: continue
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
const Globals = require('../globals')
|
|
2
2
|
const { sdl } = require('../sdl')
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
const maybeTriggerQuit = () => {
|
|
5
6
|
if (Globals.windows.all.size > 0) { return }
|
|
6
7
|
|
|
7
8
|
let shouldPrevent = false
|
|
8
9
|
const prevent = () => { shouldPrevent = true }
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
sdl.emit(
|
|
11
|
+
const type1 = 'beforeQuit'
|
|
12
|
+
const event1 = { type: type1, prevent }
|
|
13
|
+
sdl.emit(type1, event1)
|
|
13
14
|
|
|
14
15
|
if (shouldPrevent) { return }
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
const type2 = 'quit'
|
|
18
|
+
const event2 = { type: type2 }
|
|
19
|
+
sdl.emit(type2, event2)
|
|
17
20
|
process.exit()
|
|
18
21
|
}
|
|
19
22
|
|
|
@@ -122,7 +122,7 @@ class Window extends EventsViaPoll {
|
|
|
122
122
|
|
|
123
123
|
// This also keeps Node.js alive while windows are open
|
|
124
124
|
this.on('close', () => {
|
|
125
|
-
this.removeAllListeners()
|
|
125
|
+
process.nextTick(() => { this.removeAllListeners() })
|
|
126
126
|
})
|
|
127
127
|
|
|
128
128
|
// Manually emit an initial resize event for convenience
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
|
|
2
2
|
export namespace Events {
|
|
3
3
|
|
|
4
|
-
interface BaseEvent {}
|
|
4
|
+
interface BaseEvent { readonly type: string }
|
|
5
5
|
|
|
6
6
|
type PreventCallback = () => void
|
|
7
7
|
|
|
8
8
|
namespace App {
|
|
9
9
|
|
|
10
10
|
interface BeforeQuit extends BaseEvent {
|
|
11
|
+
readonly type: 'beforeQuit'
|
|
11
12
|
readonly prevent: PreventCallback
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
interface Quit extends BaseEvent { readonly type: 'quit' }
|
|
15
16
|
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -31,65 +32,75 @@ export namespace Events {
|
|
|
31
32
|
readonly numlock: number
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
interface KeyDownEvent extends KeyEvent {
|
|
36
|
+
readonly type: 'keyDown'
|
|
37
|
+
readonly repeat: number
|
|
38
|
+
}
|
|
39
|
+
interface KeyUpEvent extends KeyEvent { readonly type: 'keyUp' }
|
|
40
|
+
|
|
41
|
+
interface TextInput extends WindowEvent {
|
|
42
|
+
readonly type: 'textInput'
|
|
43
|
+
readonly text: string
|
|
44
|
+
}
|
|
45
|
+
|
|
34
46
|
interface MouseEvent extends WindowEvent {
|
|
35
47
|
readonly x: number
|
|
36
48
|
readonly y: number
|
|
37
49
|
readonly touch: boolean
|
|
38
50
|
}
|
|
39
51
|
|
|
52
|
+
interface MouseMoveEvent extends MouseEvent { readonly type: 'mouseMove' }
|
|
53
|
+
|
|
40
54
|
interface MouseButtonEvent extends MouseEvent {
|
|
41
55
|
readonly button: number
|
|
42
56
|
}
|
|
43
57
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
interface MouseButtonDownEvent extends MouseButtonEvent { readonly type: 'mouseButtonDown' }
|
|
59
|
+
interface MouseButtonUpEvent extends MouseButtonEvent { readonly type: 'mouseButtonUp' }
|
|
60
|
+
|
|
61
|
+
interface MouseWheelEvent extends MouseEvent {
|
|
62
|
+
readonly type: 'flipped'
|
|
63
|
+
readonly dx: number
|
|
64
|
+
readonly dy: number
|
|
65
|
+
readonly flipped: boolean
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface Show extends WindowEvent { readonly type: 'show' }
|
|
69
|
+
interface Hide extends WindowEvent { readonly type: 'hide' }
|
|
70
|
+
interface Expose extends WindowEvent { readonly type: 'expose' }
|
|
71
|
+
interface Minimize extends WindowEvent { readonly type: 'minimize' }
|
|
72
|
+
interface Maximize extends WindowEvent { readonly type: 'maximize' }
|
|
73
|
+
interface Restore extends WindowEvent { readonly type: 'restore' }
|
|
50
74
|
interface Move extends WindowEvent {
|
|
75
|
+
readonly type: 'move'
|
|
51
76
|
readonly x: number,
|
|
52
77
|
readonly y: number
|
|
53
78
|
}
|
|
54
79
|
interface Resize extends WindowEvent {
|
|
80
|
+
readonly type: 'resize'
|
|
55
81
|
readonly width: number,
|
|
56
82
|
readonly height: number
|
|
57
83
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
84
|
+
interface Focus extends WindowEvent { readonly type: 'focus' }
|
|
85
|
+
interface Blur extends WindowEvent { readonly type: 'blur' }
|
|
86
|
+
interface Hover extends WindowEvent { readonly type: 'hover' }
|
|
87
|
+
interface Leave extends WindowEvent { readonly type: 'leave' }
|
|
62
88
|
interface BeforeClose extends WindowEvent {
|
|
89
|
+
readonly type: 'beforeClose'
|
|
63
90
|
readonly prevent: PreventCallback
|
|
64
91
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
interface KeyDown extends KeyEvent {
|
|
68
|
-
readonly repeat: number
|
|
69
|
-
}
|
|
70
|
-
interface KeyUp extends KeyEvent {}
|
|
92
|
+
interface Close extends WindowEvent { readonly type: 'close' }
|
|
71
93
|
|
|
72
|
-
interface
|
|
73
|
-
readonly text: string
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
interface MouseButtonDown extends MouseButtonEvent {}
|
|
77
|
-
interface MouseButtonUp extends MouseButtonEvent {}
|
|
78
|
-
interface MouseMove extends MouseEvent {}
|
|
79
|
-
interface MouseWheel extends MouseEvent {
|
|
80
|
-
readonly dx: number
|
|
81
|
-
readonly dy: number
|
|
82
|
-
readonly flipped: boolean
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// interface DropBegin extends WindowEvent {}
|
|
94
|
+
interface DropBegin extends WindowEvent { readonly type: 'dropBegin' }
|
|
86
95
|
interface DropText extends WindowEvent {
|
|
96
|
+
readonly type: 'dropText'
|
|
87
97
|
readonly text: string
|
|
88
98
|
}
|
|
89
99
|
interface DropFile extends WindowEvent {
|
|
100
|
+
readonly type: 'dropFile'
|
|
90
101
|
readonly file: string
|
|
91
102
|
}
|
|
92
|
-
|
|
103
|
+
interface DropComplete extends WindowEvent { readonly type: 'dropComplete' }
|
|
93
104
|
|
|
94
105
|
}
|
|
95
106
|
|
|
@@ -99,34 +110,37 @@ export namespace Events {
|
|
|
99
110
|
readonly device: Sdl.Joystick.Device
|
|
100
111
|
}
|
|
101
112
|
|
|
102
|
-
interface DeviceAdd extends DeviceEvent {}
|
|
103
|
-
interface DeviceRemove extends DeviceEvent {}
|
|
113
|
+
interface DeviceAdd extends DeviceEvent { readonly type: 'deviceAdd' }
|
|
114
|
+
interface DeviceRemove extends DeviceEvent { readonly type: 'deviceRemove' }
|
|
104
115
|
|
|
105
116
|
interface JoystickEvent extends BaseEvent {}
|
|
106
117
|
|
|
107
118
|
interface AxisMotion extends JoystickEvent {
|
|
108
|
-
|
|
109
|
-
|
|
119
|
+
readonly type: 'axisMotion'
|
|
120
|
+
readonly axis: number,
|
|
121
|
+
readonly value: number
|
|
110
122
|
}
|
|
111
123
|
|
|
112
124
|
interface BallMotion extends JoystickEvent {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
125
|
+
readonly type: 'ballMotion'
|
|
126
|
+
readonly ball: number,
|
|
127
|
+
readonly x: number
|
|
128
|
+
readonly y: number
|
|
116
129
|
}
|
|
117
130
|
|
|
118
131
|
interface ButtonEvent extends JoystickEvent {
|
|
119
|
-
button: number
|
|
132
|
+
readonly button: number
|
|
120
133
|
}
|
|
121
|
-
interface ButtonDown extends ButtonEvent {}
|
|
122
|
-
interface ButtonUp extends ButtonEvent {}
|
|
134
|
+
interface ButtonDown extends ButtonEvent { readonly type: 'buttonDown' }
|
|
135
|
+
interface ButtonUp extends ButtonEvent { readonly type: 'buttonUp' }
|
|
123
136
|
|
|
124
137
|
interface HatMotion extends JoystickEvent {
|
|
125
|
-
|
|
126
|
-
|
|
138
|
+
readonly type: 'hatMotion'
|
|
139
|
+
readonly hat: number,
|
|
140
|
+
readonly value: Sdl.Joystick.HatPosition
|
|
127
141
|
}
|
|
128
142
|
|
|
129
|
-
|
|
143
|
+
interface Close extends JoystickEvent { readonly type: 'close' }
|
|
130
144
|
|
|
131
145
|
}
|
|
132
146
|
|
|
@@ -136,25 +150,26 @@ export namespace Events {
|
|
|
136
150
|
readonly device: Sdl.Controller.Device
|
|
137
151
|
}
|
|
138
152
|
|
|
139
|
-
interface DeviceAdd extends DeviceEvent {}
|
|
140
|
-
interface DeviceRemove extends DeviceEvent {}
|
|
153
|
+
interface DeviceAdd extends DeviceEvent { readonly type: 'deviceAdd' }
|
|
154
|
+
interface DeviceRemove extends DeviceEvent { readonly type: 'deviceRemove' }
|
|
141
155
|
|
|
142
156
|
interface ControllerEvent extends BaseEvent {}
|
|
143
157
|
|
|
144
158
|
interface AxisMotion extends ControllerEvent {
|
|
145
|
-
|
|
146
|
-
|
|
159
|
+
readonly type: 'axisMotion'
|
|
160
|
+
readonly axis: number,
|
|
161
|
+
readonly value: number
|
|
147
162
|
}
|
|
148
163
|
|
|
149
164
|
interface ButtonEvent extends ControllerEvent {
|
|
150
|
-
button: number
|
|
165
|
+
readonly button: number
|
|
151
166
|
}
|
|
152
|
-
interface ButtonDown extends ButtonEvent {}
|
|
153
|
-
interface ButtonUp extends ButtonEvent {}
|
|
167
|
+
interface ButtonDown extends ButtonEvent { readonly type: 'buttonDown' }
|
|
168
|
+
interface ButtonUp extends ButtonEvent { readonly type: 'buttonUp' }
|
|
154
169
|
|
|
155
|
-
interface Remap extends ControllerEvent {}
|
|
170
|
+
interface Remap extends ControllerEvent { readonly type: 'remap' }
|
|
156
171
|
|
|
157
|
-
|
|
172
|
+
interface Close extends ControllerEvent { readonly type: 'close' }
|
|
158
173
|
|
|
159
174
|
}
|
|
160
175
|
|
|
@@ -164,16 +179,17 @@ export namespace Events {
|
|
|
164
179
|
readonly device: Sdl.Audio.Device
|
|
165
180
|
}
|
|
166
181
|
|
|
167
|
-
interface DeviceAdd extends DeviceEvent {}
|
|
168
|
-
interface DeviceRemove extends DeviceEvent {}
|
|
182
|
+
interface DeviceAdd extends DeviceEvent { readonly type: 'deviceAdd' }
|
|
183
|
+
interface DeviceRemove extends DeviceEvent { readonly type: 'deviceRemove' }
|
|
184
|
+
|
|
185
|
+
interface AudioEvent extends BaseEvent {}
|
|
169
186
|
|
|
170
|
-
|
|
171
|
-
// interface Close extends AudioEvent {}
|
|
187
|
+
interface Close extends AudioEvent { readonly type: 'close' }
|
|
172
188
|
}
|
|
173
189
|
|
|
174
190
|
namespace Clipboard {
|
|
175
191
|
|
|
176
|
-
interface Update extends BaseEvent {}
|
|
192
|
+
interface Update extends BaseEvent { readonly type: 'update' }
|
|
177
193
|
|
|
178
194
|
}
|
|
179
195
|
}
|
|
@@ -271,20 +287,20 @@ export namespace Sdl {
|
|
|
271
287
|
}
|
|
272
288
|
|
|
273
289
|
class Window {
|
|
274
|
-
on (event: 'show', listener: () => void): this
|
|
275
|
-
on (event: 'hide', listener: () => void): this
|
|
276
|
-
on (event: 'expose', listener: () => void): this
|
|
277
|
-
on (event: 'minimize', listener: () => void): this
|
|
278
|
-
on (event: 'maximize', listener: () => void): this
|
|
279
|
-
on (event: 'restore', listener: () => void): this
|
|
290
|
+
on (event: 'show', listener: (event: Events.Window.Show) => void): this
|
|
291
|
+
on (event: 'hide', listener: (event: Events.Window.Hide) => void): this
|
|
292
|
+
on (event: 'expose', listener: (event: Events.Window.Expose) => void): this
|
|
293
|
+
on (event: 'minimize', listener: (event: Events.Window.Minimize) => void): this
|
|
294
|
+
on (event: 'maximize', listener: (event: Events.Window.Maximize) => void): this
|
|
295
|
+
on (event: 'restore', listener: (event: Events.Window.Restore) => void): this
|
|
280
296
|
on (event: 'move', listener: (event: Events.Window.Move) => void): this
|
|
281
297
|
on (event: 'resize', listener: (event: Events.Window.Resize) => void): this
|
|
282
|
-
on (event: 'focus', listener: () => void): this
|
|
283
|
-
on (event: 'blur', listener: () => void): this
|
|
284
|
-
on (event: 'hover', listener: () => void): this
|
|
285
|
-
on (event: 'leave', listener: () => void): this
|
|
298
|
+
on (event: 'focus', listener: (event: Event.Window.Focus) => void): this
|
|
299
|
+
on (event: 'blur', listener: (event: Event.Window.Blur) => void): this
|
|
300
|
+
on (event: 'hover', listener: (event: Event.Window.Hover) => void): this
|
|
301
|
+
on (event: 'leave', listener: (event: Event.Window.Leave) => void): this
|
|
286
302
|
on (event: 'beforeClose', listener: (event: Events.Window.BeforeClose) => void): this
|
|
287
|
-
on (event: 'close', listener: () => void): this
|
|
303
|
+
on (event: 'close', listener: (event: Event.Window.Close) => void): this
|
|
288
304
|
on (event: 'keyDown', listener: (event: Events.Window.KeyDown) => void): this
|
|
289
305
|
on (event: 'keyUp', listener: (event: Events.Window.KeyUp) => void): this
|
|
290
306
|
on (event: 'textInput', listener: (event: Events.Window.TextInput) => void): this
|
|
@@ -292,10 +308,10 @@ export namespace Sdl {
|
|
|
292
308
|
on (event: 'mouseButtonUp', listener: (event: Events.Window.MouseButtonUp) => void): this
|
|
293
309
|
on (event: 'mouseMove', listener: (event: Events.Window.MouseMove) => void): this
|
|
294
310
|
on (event: 'mouseWheel', listener: (event: Events.Window.MouseWheel) => void): this
|
|
295
|
-
on (event: 'dropBegin', listener: () => void): this
|
|
311
|
+
on (event: 'dropBegin', listener: (event: Event.Window.DropBegin) => void): this
|
|
296
312
|
on (event: 'dropText', listener: (event: Events.Window.DropText) => void): this
|
|
297
313
|
on (event: 'dropFile', listener: (event: Events.Window.DropFile) => void): this
|
|
298
|
-
on (event: 'dropComplete', listener: () => void): this
|
|
314
|
+
on (event: 'dropComplete', listener: (event: Event.Window.DropComplete) => void): this
|
|
299
315
|
|
|
300
316
|
readonly id: number
|
|
301
317
|
|
|
@@ -729,7 +745,7 @@ export namespace Sdl {
|
|
|
729
745
|
on (event: 'buttonDown', listener: (event: Events.Joystick.ButtonDown) => void): this
|
|
730
746
|
on (event: 'buttonUp', listener: (event: Events.Joystick.ButtonUp) => void): this
|
|
731
747
|
on (event: 'hatMotion', listener: (event: Events.Joystick.HatMotion) => void): this
|
|
732
|
-
on (event: 'close', listener: () => void): this
|
|
748
|
+
on (event: 'close', listener: (event: Events.Joystick.Close) => void): this
|
|
733
749
|
|
|
734
750
|
readonly device: Device
|
|
735
751
|
readonly firmwareVersion: number
|
|
@@ -787,7 +803,7 @@ export namespace Sdl {
|
|
|
787
803
|
on (event: 'buttonDown', listener: (event: Events.Controller.ButtonDown) => void): this
|
|
788
804
|
on (event: 'buttonUp', listener: (event: Events.Controller.ButtonUp) => void): this
|
|
789
805
|
on (event: 'remap', listener: (event: Events.Controller.Remap) => void): this
|
|
790
|
-
on (event: 'close', listener: () => void): this
|
|
806
|
+
on (event: 'close', listener: (event: Events.Controller.Close) => void): this
|
|
791
807
|
|
|
792
808
|
readonly device: Device
|
|
793
809
|
readonly firmwareVersion: number
|
|
@@ -890,7 +906,7 @@ export namespace Sdl {
|
|
|
890
906
|
}
|
|
891
907
|
|
|
892
908
|
class AudioInstance {
|
|
893
|
-
on (event: 'close', listener: () => void): this
|
|
909
|
+
on (event: 'close', listener: (event: Events.Audio.Close) => void): this
|
|
894
910
|
|
|
895
911
|
readonly id: number
|
|
896
912
|
readonly device: Device
|
|
@@ -954,7 +970,7 @@ export namespace Sdl {
|
|
|
954
970
|
namespace Clipboard {
|
|
955
971
|
|
|
956
972
|
interface Module {
|
|
957
|
-
on (event: 'update', listener: () => void): this
|
|
973
|
+
on (event: 'update', listener: (event: Events.Clipboard.Update) => void): this
|
|
958
974
|
|
|
959
975
|
readonly text: string
|
|
960
976
|
setText (text: string): void
|
|
@@ -964,7 +980,7 @@ export namespace Sdl {
|
|
|
964
980
|
|
|
965
981
|
interface Module {
|
|
966
982
|
on (event: 'beforeQuit', listener: (event: Events.App.BeforeQuit) => void): this
|
|
967
|
-
on (event: 'quit', listener: () => void): this
|
|
983
|
+
on (event: 'quit', listener: (event: Events.App.Quit) => void): this
|
|
968
984
|
|
|
969
985
|
readonly info: Info
|
|
970
986
|
readonly video: Video.Module
|