@kmamal/sdl 0.6.6 → 0.6.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 +39 -18
- package/package.json +6 -1
- package/scripts/build.mjs +12 -5
- package/scripts/install.mjs +3 -1
- package/scripts/release.mjs +4 -1
package/README.md
CHANGED
|
@@ -7,11 +7,14 @@
|
|
|
7
7
|
|
|
8
8
|
SDL bindings for Node.js.
|
|
9
9
|
Provides window management, input events (keyboard, mouse, joystick, controller), audio playback and recording, and clipboard manipulation.
|
|
10
|
-
You can also use it together with [@kmamal/gl](https://github.com/kmamal/headless-gl#readme) to get native WebGL drawing without having to use a browser.
|
|
11
10
|
|
|
12
11
|
It should work on Linux, Mac, and Windows.
|
|
13
12
|
Prebuilt binaries are available for x64 architectures, and arm-based Macs.
|
|
14
13
|
|
|
14
|
+
#### Canvas, WebGL, and WebGPU
|
|
15
|
+
|
|
16
|
+
One goal of this project is to allow using Canvas (the 2D rendering context API), WebGL and WebGPU without a browser. You can already use [@kmamal/gl](https://github.com/kmamal/headless-gl#readme) to draw on windows using WebGL. WebGPU is also working, but it's not been fully integrated: you can use [@kmamal/gpu](https://github.com/kmamal/gpu#readme) for WebGPU compute and render, but it can't yet render directly to windows; that will come in a future version. Right now you have to go through an intermediate buffer. 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
|
+
|
|
15
18
|
|
|
16
19
|
## Installation
|
|
17
20
|
|
|
@@ -35,19 +38,36 @@ const window = sdl.video.createWindow({ title: "Hello, World!" })
|
|
|
35
38
|
window.on('*', console.log)
|
|
36
39
|
```
|
|
37
40
|
|
|
41
|
+
## Canvas example
|
|
42
|
+
```js
|
|
43
|
+
import sdl from '@kmamal/sdl'
|
|
44
|
+
import canvas from 'canvas'
|
|
45
|
+
|
|
46
|
+
const window = sdl.video.createWindow({ resizable: true })
|
|
47
|
+
const { width, height } = window
|
|
48
|
+
const canvas = canvas.createCanvas(width, height)
|
|
49
|
+
const ctx = canvas.getContext('2d')
|
|
50
|
+
|
|
51
|
+
// Clear screen to red
|
|
52
|
+
ctx.fillStyle = 'red'
|
|
53
|
+
ctx.fillRect(0, 0, width, height)
|
|
54
|
+
const buffer = canvas.toBuffer('raw')
|
|
55
|
+
window.render(width, height, width * 4, 'bgra32', buffer)
|
|
56
|
+
```
|
|
57
|
+
|
|
38
58
|
## WebGL example
|
|
39
59
|
```js
|
|
40
60
|
const sdl = require('@kmamal/sdl')
|
|
41
61
|
const createContext = require('@kmamal/gl')
|
|
42
62
|
|
|
43
63
|
const window = sdl.video.createWindow({
|
|
44
|
-
title: "WebGL
|
|
64
|
+
title: "WebGL",
|
|
45
65
|
opengl: true,
|
|
46
66
|
})
|
|
47
|
-
|
|
48
|
-
// Clear screen to red
|
|
49
67
|
const { width, height, native } = window
|
|
50
68
|
const gl = createContext(width, height, { window: native })
|
|
69
|
+
|
|
70
|
+
// Clear screen to red
|
|
51
71
|
gl.clearColor(1, 0, 0, 1)
|
|
52
72
|
gl.clear(gl.COLOR_BUFFER_BIT)
|
|
53
73
|
gl.swap()
|
|
@@ -146,12 +166,12 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
146
166
|
* [sdl.mouse.getButton(button)](#sdlmousegetbuttonbutton)
|
|
147
167
|
* [sdl.mouse.position](#sdlmouseposition)
|
|
148
168
|
* [sdl.mouse.setPosition(x, y)](#sdlmousesetpositionx-y)
|
|
149
|
-
* [sdl.mouse.setCursor(cursor)](#
|
|
169
|
+
* [sdl.mouse.setCursor(cursor)](#sdlmousesetcursorcursor)
|
|
150
170
|
* [sdl.mouse.setCursorImage(width, height, stride, format, buffer, x, y)](#sdlmousesetcursorimagewidth-height-stride-format-buffer-x-y)
|
|
151
171
|
* [sdl.mouse.showCursor([show])](#sdlmouseshowcursorshow)
|
|
152
172
|
* [sdl.mouse.hideCursor()](#sdlmousehidecursor)
|
|
153
173
|
* [sdl.mouse.capture([capture])](#sdlmousecapturecapture)
|
|
154
|
-
* [sdl.mouse.uncapture()](#
|
|
174
|
+
* [sdl.mouse.uncapture()](#sdlmouseuncapture)
|
|
155
175
|
* [sdl.joystick](#sdljoystick)
|
|
156
176
|
* [Joystick types](#joystick-types)
|
|
157
177
|
* [Hat positions](#hat-positions)
|
|
@@ -159,7 +179,7 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
159
179
|
* [Event: 'deviceAdd'](#joystick-event-device-add)
|
|
160
180
|
* [Event: 'deviceRemove'](#joystick-event-device-remove)
|
|
161
181
|
* [sdl.joystick.devices](#sdljoystickdevices)
|
|
162
|
-
* [sdl.joystick.openDevice(device)](#sdljoystickopendevicedevice)
|
|
182
|
+
* [sdl.joystick.openDevice(device)](#sdljoystickopendevicedevice-options)
|
|
163
183
|
* [class JoystickInstance](#class-joystickinstance)
|
|
164
184
|
* [Event: 'axisMotion'](#joystick-instance-event-axismotion)
|
|
165
185
|
* [Event: 'ballMotion'](#event-ballmotion)
|
|
@@ -176,12 +196,12 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
176
196
|
* [joystickInstance.hats](#joystickinstancehats)
|
|
177
197
|
* [joystickInstance.power](#joystickinstancepower)
|
|
178
198
|
* [joystickInstance.hasLed](#joystickinstancehasled)
|
|
179
|
-
* [joystickInstance.setLed(red, green, blue)](#
|
|
199
|
+
* [joystickInstance.setLed(red, green, blue)](#joystickinstancesetledred-green-blue)
|
|
180
200
|
* [joystickInstance.hasRumble](#joystickinstancehasrumble)
|
|
181
|
-
* [joystickInstance.rumble([low[, high[, duration]]])](#
|
|
201
|
+
* [joystickInstance.rumble([low[, high[, duration]]])](#joystickinstancerumblelow-high-duration)
|
|
182
202
|
* [joystickInstance.stopRumble()](#joystickinstancestoprumble)
|
|
183
203
|
* [joystickInstance.hasRumbleTriggers](#joystickinstancehasrumbletriggers)
|
|
184
|
-
* [joystickInstance.rumbleTriggers([left[, right[, duration]]])](#
|
|
204
|
+
* [joystickInstance.rumbleTriggers([left[, right[, duration]]])](#joystickinstancerumbletriggersleft-right-duration)
|
|
185
205
|
* [joystickInstance.stopRumbleTriggers()](#joystickinstancestoprumbletriggers)
|
|
186
206
|
* [joystickInstance.closed](#joystickinstanceclosed)
|
|
187
207
|
* [joystickInstance.close()](#joystickinstanceclose)
|
|
@@ -190,7 +210,7 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
190
210
|
* [Event: 'deviceRemove'](#controller-event-device-remove)
|
|
191
211
|
* [sdl.controller.addMappings(mappings)](#sdlcontrolleraddmappingsmappings)
|
|
192
212
|
* [sdl.controller.devices](#sdlcontrollerdevices)
|
|
193
|
-
* [sdl.controller.openDevice(device)](#sdlcontrolleropendevicedevice)
|
|
213
|
+
* [sdl.controller.openDevice(device)](#sdlcontrolleropendevicedevice-options)
|
|
194
214
|
* [class ControllerInstance](#class-controllerinstance)
|
|
195
215
|
* [Event: 'axisMotion'](#controller-instance-event-axismotion)
|
|
196
216
|
* [Event: 'buttonDown'](#controller-instance-event-buttondown)
|
|
@@ -204,12 +224,12 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
204
224
|
* [controllerInstance.buttons](#controllerinstancebuttons)
|
|
205
225
|
* [controllerInstance.power](#controllerinstancepower)
|
|
206
226
|
* [controllerInstance.hasLed](#controllerinstancehasled)
|
|
207
|
-
* [controllerInstance.setLed(red, green, blue)](#
|
|
227
|
+
* [controllerInstance.setLed(red, green, blue)](#controllerinstancesetledred-green-blue)
|
|
208
228
|
* [controllerInstance.hasRumble](#controllerinstancehasrumble)
|
|
209
|
-
* [controllerInstance.rumble([low[, high[, duration]]])](#
|
|
229
|
+
* [controllerInstance.rumble([low[, high[, duration]]])](#controllerinstancerumblelow-high-duration)
|
|
210
230
|
* [controllerInstance.stopRumble()](#controllerinstancestoprumble)
|
|
211
231
|
* [controllerInstance.hasRumbleTriggers](#controllerinstancehasrumbletriggers)
|
|
212
|
-
* [controllerInstance.rumbleTriggers([left[, right[, duration]]])](#
|
|
232
|
+
* [controllerInstance.rumbleTriggers([left[, right[, duration]]])](#controllerinstancerumbletriggersleft-right-duration)
|
|
213
233
|
* [controllerInstance.stopRumbleTriggers()](#controllerinstancestoprumbletriggers)
|
|
214
234
|
* [controllerInstance.closed](#controllerinstanceclosed)
|
|
215
235
|
* [controllerInstance.close()](#controllerinstanceclose)
|
|
@@ -231,7 +251,6 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
231
251
|
* [class AudioInstance](#class-audioinstance)
|
|
232
252
|
* [Event: 'close'](#audio-instance-event-close)
|
|
233
253
|
* [audioInstance.id](#audioinstanceid)
|
|
234
|
-
* [audioInstance.name](#audioinstancename)
|
|
235
254
|
* [audioInstance.channels](#audioinstancechannels)
|
|
236
255
|
* [audioInstance.frequency](#audioinstancefrequency)
|
|
237
256
|
* [audioInstance.format](#audioinstanceformat)
|
|
@@ -636,7 +655,7 @@ Fired when the mouse wheel is scrolled.
|
|
|
636
655
|
|
|
637
656
|
### Event: 'dropBegin'
|
|
638
657
|
|
|
639
|
-
When dropping a set of items onto a window, first the `'
|
|
658
|
+
When dropping a set of items onto a window, first the [`'dropBegin'`](#event-dropbegin) event will be fired, then a number of [`'dropText'`](#event-droptext) and/or [`'dropFile'`](#event-dropfile) events will be fired, corresponding to the contents of the drop, then finally the [`'dropComplete'`](#event-dropcomplete) event will be fired.
|
|
640
659
|
|
|
641
660
|
### Event: 'dropText'
|
|
642
661
|
|
|
@@ -1388,7 +1407,7 @@ Initializes a joystick device and returns a corresponding instance.
|
|
|
1388
1407
|
## class JoystickInstance
|
|
1389
1408
|
|
|
1390
1409
|
This class is not directly exposed by the API so you can't use it with the `new` operator.
|
|
1391
|
-
Instead, objects returned by [`sdl.joystick.openDevice()`](#sdljoystickopendevicedevice) are of this type.
|
|
1410
|
+
Instead, objects returned by [`sdl.joystick.openDevice()`](#sdljoystickopendevicedevice-options) are of this type.
|
|
1392
1411
|
|
|
1393
1412
|
<a id="joystick-instance-event-axismotion"></a>
|
|
1394
1413
|
|
|
@@ -1576,6 +1595,8 @@ const mappings = text.split('\n')
|
|
|
1576
1595
|
sdl.controller.addMappings(mappings)
|
|
1577
1596
|
```
|
|
1578
1597
|
|
|
1598
|
+
<a id="controller-event-device-add"></a>
|
|
1599
|
+
|
|
1579
1600
|
### Event: 'deviceAdd'
|
|
1580
1601
|
|
|
1581
1602
|
* `device: <object>`: An object from [`sdl.controller.devices`](#sdlcontrollerdevices) indicating the device that caused the event.
|
|
@@ -1642,7 +1663,7 @@ Initializes an controller device and returns a corresponding instance.
|
|
|
1642
1663
|
## class ControllerInstance
|
|
1643
1664
|
|
|
1644
1665
|
This class is not directly exposed by the API so you can't use it with the `new` operator.
|
|
1645
|
-
Instead, objects returned by [`sdl.controller.openDevice()`](#sdlcontrolleropendevicedevice) are of this type.
|
|
1666
|
+
Instead, objects returned by [`sdl.controller.openDevice()`](#sdlcontrolleropendevicedevice-options) are of this type.
|
|
1646
1667
|
|
|
1647
1668
|
<a id="controller-instance-event-axismotion"></a>
|
|
1648
1669
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.6.
|
|
2
|
+
"version": "0.6.7",
|
|
3
3
|
"name": "@kmamal/sdl",
|
|
4
4
|
"description": "SDL bindings for Node.js",
|
|
5
5
|
"keywords": [
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
"sdl2",
|
|
8
8
|
"gui",
|
|
9
9
|
"desktop",
|
|
10
|
+
"canvas",
|
|
11
|
+
"webgl",
|
|
12
|
+
"opengl",
|
|
13
|
+
"webgpu",
|
|
10
14
|
"window",
|
|
11
15
|
"screen",
|
|
12
16
|
"video",
|
|
@@ -20,6 +24,7 @@
|
|
|
20
24
|
"audio",
|
|
21
25
|
"sound",
|
|
22
26
|
"speaker",
|
|
27
|
+
"microphone",
|
|
23
28
|
"mic",
|
|
24
29
|
"clipboard",
|
|
25
30
|
"game"
|
package/scripts/build.mjs
CHANGED
|
@@ -12,8 +12,8 @@ await Promise.all([
|
|
|
12
12
|
}))
|
|
13
13
|
|
|
14
14
|
console.log("build in", C.dir.build)
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const SDL_INC = Path.join(C.dir.sdl, 'include')
|
|
16
|
+
const SDL_LIB = Path.join(C.dir.sdl, 'lib')
|
|
17
17
|
|
|
18
18
|
let archFlag = ''
|
|
19
19
|
if (process.env.CROSS_COMPILE_ARCH) {
|
|
@@ -21,7 +21,14 @@ if (process.env.CROSS_COMPILE_ARCH) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
process.chdir(C.dir.root)
|
|
24
|
-
execSync(`npx node-gyp rebuild ${archFlag} -j max --verbose`, {
|
|
24
|
+
execSync(`npx node-gyp rebuild ${archFlag} -j max --verbose`, {
|
|
25
|
+
stdio: 'inherit',
|
|
26
|
+
env: {
|
|
27
|
+
...process.env,
|
|
28
|
+
SDL_INC,
|
|
29
|
+
SDL_LIB,
|
|
30
|
+
},
|
|
31
|
+
})
|
|
25
32
|
|
|
26
33
|
console.log("install to", C.dir.dist)
|
|
27
34
|
await Fs.promises.rm(C.dir.dist, { recursive: true }).catch(() => {})
|
|
@@ -32,11 +39,11 @@ await Promise.all([
|
|
|
32
39
|
Path.join(C.dir.dist, 'sdl.node'),
|
|
33
40
|
),
|
|
34
41
|
(async () => {
|
|
35
|
-
const libs = await Fs.promises.readdir(
|
|
42
|
+
const libs = await Fs.promises.readdir(SDL_LIB)
|
|
36
43
|
await Promise.all(libs.map(async (name) => {
|
|
37
44
|
if (C.platform === 'win32' && name !== 'SDL2.dll') { return }
|
|
38
45
|
await Fs.promises.cp(
|
|
39
|
-
Path.join(
|
|
46
|
+
Path.join(SDL_LIB, name),
|
|
40
47
|
Path.join(C.dir.dist, name),
|
|
41
48
|
{ verbatimSymlinks: true },
|
|
42
49
|
)
|
package/scripts/install.mjs
CHANGED
|
@@ -3,7 +3,9 @@ if (!process.env.NODE_SDL_FROM_SOURCE) {
|
|
|
3
3
|
try {
|
|
4
4
|
await import('./download-release.mjs')
|
|
5
5
|
process.exit(0)
|
|
6
|
-
} catch (error) {
|
|
6
|
+
} catch (error) {
|
|
7
|
+
console.log("failed to download release")
|
|
8
|
+
}
|
|
7
9
|
} else {
|
|
8
10
|
console.log("skip download and build from source")
|
|
9
11
|
}
|
package/scripts/release.mjs
CHANGED
|
@@ -2,9 +2,12 @@ import { execSync } from 'node:child_process'
|
|
|
2
2
|
|
|
3
3
|
await import('./clean.mjs')
|
|
4
4
|
|
|
5
|
-
process.env.NODE_SDL_FROM_SOURCE = 1
|
|
6
5
|
execSync('npm install', {
|
|
7
6
|
stdio: 'inherit',
|
|
7
|
+
env: {
|
|
8
|
+
...process.env,
|
|
9
|
+
NODE_SDL_FROM_SOURCE: 1,
|
|
10
|
+
},
|
|
8
11
|
})
|
|
9
12
|
|
|
10
13
|
await import('./upload-release.mjs')
|