@kmamal/sdl 1.0.0-5 → 1.0.0-9
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 +12 -6
- package/README.md +2 -2
- package/binding.gyp +21 -4
- package/package.json +5 -12
- package/scripts/build.mjs +3 -1
- package/scripts/install.mjs +2 -0
- package/scripts/util/common.js +3 -2
- package/src/javascript/audio/audio-playback-stream.js +9 -10
- package/src/javascript/audio/audio-recording-stream.js +9 -8
- package/src/javascript/audio/audio-stream.js +101 -44
- package/src/javascript/audio/conversion.js +41 -0
- package/src/javascript/audio/devices.js +11 -0
- package/src/javascript/audio/events.js +65 -0
- package/src/javascript/audio/format-helpers.js +8 -4
- package/src/javascript/audio/index.js +25 -20
- package/src/javascript/audio/prevent-exit.js +13 -10
- package/src/javascript/audio/validate.js +9 -0
- package/src/javascript/cleanup.js +9 -6
- package/src/javascript/clipboard/index.js +8 -3
- package/src/javascript/device-instance.js +61 -0
- package/src/javascript/events/events-via-poll.js +32 -28
- package/src/javascript/events/index.js +85 -479
- package/src/javascript/events/try.js +25 -0
- package/src/javascript/gamepad/{device.js → devices.js} +4 -5
- package/src/javascript/gamepad/events.js +66 -0
- package/src/javascript/gamepad/gamepad-instance.js +12 -160
- package/src/javascript/gamepad/index.js +15 -16
- package/src/javascript/globals.js +10 -1
- package/src/javascript/index.js +2 -5
- package/src/javascript/joystick/devices.js +43 -0
- package/src/javascript/joystick/events.js +129 -0
- package/src/javascript/joystick/index.js +9 -18
- package/src/javascript/joystick/joystick-device-instance.js +176 -0
- package/src/javascript/joystick/joystick-instance.js +12 -158
- package/src/javascript/keyboard/index.js +20 -10
- package/src/javascript/keyboard/key-mapping.js +46 -27
- package/src/javascript/mouse/index.js +36 -29
- package/src/javascript/sensor/events.js +21 -0
- package/src/javascript/sensor/index.js +13 -2
- package/src/javascript/sensor/sensor-instance.js +7 -47
- package/src/javascript/subsystems.js +56 -0
- package/src/javascript/touch/index.js +9 -4
- package/src/javascript/validate.js +119 -0
- package/src/javascript/video/conversion.js +63 -0
- package/src/javascript/video/events.js +179 -0
- package/src/javascript/video/format-helpers.js +10 -8
- package/src/javascript/video/index.js +28 -14
- package/src/javascript/video/validate.js +45 -0
- package/src/javascript/video/window.js +196 -167
- package/src/native/audio.cpp +457 -153
- package/src/native/audio.h +25 -19
- package/src/native/clipboard.cpp +8 -37
- package/src/native/clipboard.h +2 -2
- package/src/native/enums.cpp +16 -1
- package/src/native/enums.h +1 -1
- package/src/native/events.cpp +351 -357
- package/src/native/events.h +70 -68
- package/src/native/gamepad.cpp +147 -103
- package/src/native/gamepad.h +10 -11
- package/src/native/global.cpp +183 -340
- package/src/native/global.h +51 -5
- package/src/native/joystick.cpp +204 -275
- package/src/native/joystick.h +21 -15
- package/src/native/keyboard.cpp +63 -25
- package/src/native/keyboard.h +5 -4
- package/src/native/module.cpp +23 -3
- package/src/native/mouse.cpp +28 -59
- package/src/native/mouse.h +9 -9
- package/src/native/packed.cpp +99 -0
- package/src/native/packed.h +86 -0
- package/src/native/power.cpp +13 -1
- package/src/native/power.h +3 -3
- package/src/native/sensor.cpp +78 -69
- package/src/native/sensor.h +7 -7
- package/src/native/testing.cpp +148 -0
- package/src/native/testing.h +17 -0
- package/src/native/threads.cpp +301 -0
- package/src/native/threads.h +36 -0
- package/src/native/touch.cpp +38 -44
- package/src/native/touch.h +3 -2
- package/src/native/video.cpp +211 -98
- package/src/native/video.h +7 -4
- package/src/native/window.cpp +201 -219
- package/src/native/window.h +24 -20
- package/src/types/index.d.ts +157 -70
- package/src/javascript/audio/device.js +0 -37
- package/src/javascript/joystick/device.js +0 -13
- package/src/javascript/joystick/shared.js +0 -90
- package/src/javascript/worker.js +0 -88
- package/src/types/worker.d.ts +0 -71
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
const Globals = require('../globals')
|
|
2
2
|
const Bindings = require('../bindings')
|
|
3
3
|
const Enums = require('../enums')
|
|
4
|
-
const { VideoFormatHelpers } = require('./format-helpers')
|
|
5
4
|
const { EventsViaPoll } = require('../events/events-via-poll')
|
|
5
|
+
const { tryEmit } = require('../events/try')
|
|
6
|
+
const {
|
|
7
|
+
validateBoolean,
|
|
8
|
+
validateString,
|
|
9
|
+
validateObject,
|
|
10
|
+
validateFunction,
|
|
11
|
+
validateInt32,
|
|
12
|
+
validateFloat,
|
|
13
|
+
validatePositiveFloat,
|
|
14
|
+
validatePositiveInt32,
|
|
15
|
+
validateNotDestroyed,
|
|
16
|
+
} = require('../validate')
|
|
17
|
+
const {
|
|
18
|
+
validateVsync,
|
|
19
|
+
validateImage,
|
|
20
|
+
validateRenderableFormat,
|
|
21
|
+
validateRgbFormat,
|
|
22
|
+
} = require('./validate')
|
|
6
23
|
|
|
7
24
|
const validEvents = [
|
|
8
25
|
'show',
|
|
@@ -11,6 +28,8 @@ const validEvents = [
|
|
|
11
28
|
'minimize',
|
|
12
29
|
'maximize',
|
|
13
30
|
'restore',
|
|
31
|
+
'enterFullscreen',
|
|
32
|
+
'leaveFullscreen',
|
|
14
33
|
'move',
|
|
15
34
|
'resize',
|
|
16
35
|
'displayChange',
|
|
@@ -37,17 +56,40 @@ const validEvents = [
|
|
|
37
56
|
'dropComplete',
|
|
38
57
|
]
|
|
39
58
|
|
|
59
|
+
const handleHitTest = (windowId, x, y) => {
|
|
60
|
+
const window = Globals.windows.all.get(windowId)
|
|
61
|
+
if (!window?._hitTest) { return Enums.hitTestResult.normal }
|
|
62
|
+
|
|
63
|
+
let value
|
|
64
|
+
hitTestDepth++
|
|
65
|
+
try {
|
|
66
|
+
Globals.events.withoutPolling(() => {
|
|
67
|
+
try {
|
|
68
|
+
const result = window._hitTest(x, y)
|
|
69
|
+
value = result === undefined ? Enums.hitTestResult.normal : Enums.hitTestResult[result]
|
|
70
|
+
if (value === undefined) { throw Object.assign(new Error("invalid hit test result"), { result }) }
|
|
71
|
+
}
|
|
72
|
+
catch (error) { tryEmit(window, 'error', error) }
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
finally { hitTestDepth-- }
|
|
76
|
+
return value ?? Enums.hitTestResult.normal
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let hitTestDepth = 0
|
|
80
|
+
let hitTestHandlerRegistered = false
|
|
81
|
+
|
|
40
82
|
class Window extends EventsViaPoll {
|
|
41
83
|
constructor (options = {}) {
|
|
42
84
|
super(validEvents)
|
|
43
85
|
|
|
44
|
-
|
|
86
|
+
validateObject('options', options)
|
|
45
87
|
|
|
46
88
|
const {
|
|
47
89
|
title = "",
|
|
48
|
-
display
|
|
49
|
-
x
|
|
50
|
-
width
|
|
90
|
+
display,
|
|
91
|
+
x, y,
|
|
92
|
+
width, height,
|
|
51
93
|
visible = true,
|
|
52
94
|
fullscreen = false,
|
|
53
95
|
resizable = false,
|
|
@@ -62,52 +104,42 @@ class Window extends EventsViaPoll {
|
|
|
62
104
|
const hasAccelerated = accelerated !== undefined
|
|
63
105
|
const hasVsync = vsync !== undefined
|
|
64
106
|
|
|
65
|
-
|
|
66
|
-
if (display !==
|
|
67
|
-
if (x !==
|
|
68
|
-
if (
|
|
69
|
-
if (
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
if (typeof resizable !== 'boolean') { throw Object.assign(new Error("resizable must be a boolean"), { resizable }) }
|
|
82
|
-
if (typeof borderless !== 'boolean') { throw Object.assign(new Error("borderless must be a boolean"), { borderless }) }
|
|
83
|
-
if (typeof alwaysOnTop !== 'boolean') { throw Object.assign(new Error("alwaysOnTop must be a boolean"), { alwaysOnTop }) }
|
|
84
|
-
if (hasAccelerated && typeof accelerated !== 'boolean') { throw Object.assign(new Error("accelerated must be a boolean"), { accelerated }) }
|
|
85
|
-
if (hasVsync) {
|
|
86
|
-
if (!Number.isInteger(vsync)) { throw Object.assign(new Error("vsync must be an integer"), { vsync }) }
|
|
87
|
-
if (vsync < -1 || vsync > 2 ** 31 - 1) { throw Object.assign(new Error("vsync must be -1 or a non-negative 32-bit integer"), { vsync }) }
|
|
88
|
-
}
|
|
89
|
-
if (typeof opengl !== 'boolean') { throw Object.assign(new Error("opengl must be a boolean"), { opengl }) }
|
|
90
|
-
if (typeof webgpu !== 'boolean') { throw Object.assign(new Error("webgpu must be a boolean"), { webgpu }) }
|
|
91
|
-
if (display !== null && (x !== null || y !== null)) { throw Object.assign(new Error("display and x/y are mutually exclusive"), { display, x, y }) }
|
|
107
|
+
validateString('title', title)
|
|
108
|
+
if (display !== undefined) { validateObject('display', display) }
|
|
109
|
+
if (x !== undefined) { validateInt32('x', x) }
|
|
110
|
+
if (y !== undefined) { validateInt32('y', y) }
|
|
111
|
+
if (width !== undefined) { validatePositiveInt32('width', width) }
|
|
112
|
+
if (height !== undefined) { validatePositiveInt32('height', height) }
|
|
113
|
+
validateBoolean('visible', visible)
|
|
114
|
+
validateBoolean('fullscreen', fullscreen)
|
|
115
|
+
validateBoolean('resizable', resizable)
|
|
116
|
+
validateBoolean('borderless', borderless)
|
|
117
|
+
validateBoolean('alwaysOnTop', alwaysOnTop)
|
|
118
|
+
if (hasAccelerated) { validateBoolean('accelerated', accelerated) }
|
|
119
|
+
if (hasVsync) { validateVsync(vsync) }
|
|
120
|
+
validateBoolean('opengl', opengl)
|
|
121
|
+
validateBoolean('webgpu', webgpu)
|
|
122
|
+
if (display !== undefined && (x !== undefined || y !== undefined)) { throw Object.assign(new Error("display and x/y are mutually exclusive"), { display, x, y }) }
|
|
92
123
|
if (resizable && borderless) { throw Object.assign(new Error("resizable and borderless are mutually exclusive"), { resizable, borderless }) }
|
|
93
124
|
if (opengl && webgpu) { throw Object.assign(new Error("opengl and webgpu are mutually exclusive"), { opengl, webgpu }) }
|
|
94
125
|
if (opengl && (hasAccelerated || hasVsync)) { throw Object.assign(new Error("opengl and accelerated/vsync are mutually exclusive"), { opengl, accelerated, vsync }) }
|
|
95
126
|
if (webgpu && (hasAccelerated || hasVsync)) { throw Object.assign(new Error("webgpu and accelerated/vsync are mutually exclusive"), { webgpu, accelerated, vsync }) }
|
|
96
127
|
|
|
97
128
|
let displayId = 0
|
|
98
|
-
if (display) {
|
|
129
|
+
if (display !== undefined) {
|
|
99
130
|
Globals.events.poll()
|
|
100
|
-
|
|
101
|
-
|
|
131
|
+
const found = Globals.displays.find(({ id }) => id === display.id)
|
|
132
|
+
if (!found) { throw Object.assign(new Error("display must be from sdl.video.displays"), { display }) }
|
|
133
|
+
displayId = found.id
|
|
102
134
|
}
|
|
103
135
|
|
|
104
136
|
const result = Bindings.window_create(
|
|
105
137
|
title,
|
|
106
138
|
displayId,
|
|
107
|
-
x,
|
|
108
|
-
y,
|
|
109
|
-
width,
|
|
110
|
-
height,
|
|
139
|
+
x ?? null,
|
|
140
|
+
y ?? null,
|
|
141
|
+
width ?? null,
|
|
142
|
+
height ?? null,
|
|
111
143
|
visible,
|
|
112
144
|
fullscreen,
|
|
113
145
|
resizable,
|
|
@@ -120,6 +152,8 @@ class Window extends EventsViaPoll {
|
|
|
120
152
|
)
|
|
121
153
|
|
|
122
154
|
this._id = result.id
|
|
155
|
+
this._title = result.title
|
|
156
|
+
this._visible = result.visible
|
|
123
157
|
this._x = result.x
|
|
124
158
|
this._y = result.y
|
|
125
159
|
this._width = result.width
|
|
@@ -135,26 +169,24 @@ class Window extends EventsViaPoll {
|
|
|
135
169
|
this._vsync = result.vsync
|
|
136
170
|
this._native = result.native
|
|
137
171
|
|
|
138
|
-
this._title = title
|
|
139
|
-
this._visible = visible
|
|
140
172
|
this._opengl = opengl
|
|
141
173
|
this._webgpu = webgpu
|
|
142
174
|
|
|
143
|
-
this._minimized =
|
|
144
|
-
this._maximized =
|
|
175
|
+
this._minimized = result.minimized
|
|
176
|
+
this._maximized = result.maximized
|
|
145
177
|
this._relativeMouseMode = false
|
|
178
|
+
this._hitTest = null
|
|
146
179
|
this._destroyed = false
|
|
147
180
|
|
|
148
181
|
Globals.windows.all.set(this._id, this)
|
|
149
182
|
|
|
150
|
-
//
|
|
151
|
-
|
|
152
|
-
this.on('close', keepAlive)
|
|
153
|
-
this.on('removeListener', (type, listener) => {
|
|
154
|
-
if (listener === keepAlive && !this._destroyed) { this.on('close', keepAlive) }
|
|
155
|
-
})
|
|
183
|
+
// Keep Node.js alive while windows are open
|
|
184
|
+
Globals.events.ref()
|
|
156
185
|
|
|
157
|
-
// Manually emit some initial events for convenience
|
|
186
|
+
// Manually emit some initial events for convenience.
|
|
187
|
+
// Note that these can duplicate real events.
|
|
188
|
+
// Something may have polled synchronously before this tick runs, e.g. a getter read right after createWindow().
|
|
189
|
+
// In that case the real move/resize/expose events have already fired and the ones below repeat them with the same values.
|
|
158
190
|
process.nextTick(() => {
|
|
159
191
|
if (this._destroyed) { return }
|
|
160
192
|
Globals.events.withoutPolling(() => {
|
|
@@ -190,181 +222,177 @@ class Window extends EventsViaPoll {
|
|
|
190
222
|
|
|
191
223
|
get id () { return this._id }
|
|
192
224
|
|
|
193
|
-
get title () {
|
|
225
|
+
get title () {
|
|
226
|
+
validateNotDestroyed(this)
|
|
227
|
+
|
|
228
|
+
return this._title
|
|
229
|
+
}
|
|
230
|
+
|
|
194
231
|
setTitle (title) {
|
|
195
|
-
|
|
232
|
+
validateNotDestroyed(this)
|
|
196
233
|
|
|
197
|
-
|
|
234
|
+
validateString('title', title)
|
|
198
235
|
|
|
199
|
-
Bindings.window_setTitle(this._id, title)
|
|
200
|
-
this._title = title
|
|
236
|
+
this._title = Bindings.window_setTitle(this._id, title)
|
|
201
237
|
}
|
|
202
238
|
|
|
203
239
|
get x () {
|
|
204
240
|
Globals.events.poll()
|
|
205
|
-
|
|
241
|
+
validateNotDestroyed(this)
|
|
206
242
|
|
|
207
243
|
return this._x
|
|
208
244
|
}
|
|
209
245
|
|
|
210
246
|
get y () {
|
|
211
247
|
Globals.events.poll()
|
|
212
|
-
|
|
248
|
+
validateNotDestroyed(this)
|
|
213
249
|
|
|
214
250
|
return this._y
|
|
215
251
|
}
|
|
216
252
|
|
|
217
253
|
setPosition (x, y) {
|
|
218
|
-
|
|
254
|
+
validateNotDestroyed(this)
|
|
219
255
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (!Number.isInteger(y)) { throw Object.assign(new Error("y must be an integer"), { y }) }
|
|
223
|
-
if (y < -(2 ** 31) || y > 2 ** 31 - 1) { throw Object.assign(new Error("y must be a 32-bit integer"), { y }) }
|
|
256
|
+
validateInt32('x', x)
|
|
257
|
+
validateInt32('y', y)
|
|
224
258
|
|
|
225
259
|
Bindings.window_setPosition(this._id, x, y)
|
|
226
260
|
}
|
|
227
261
|
|
|
228
262
|
get width () {
|
|
229
263
|
Globals.events.poll()
|
|
230
|
-
|
|
264
|
+
validateNotDestroyed(this)
|
|
231
265
|
|
|
232
266
|
return this._width
|
|
233
267
|
}
|
|
234
268
|
|
|
235
269
|
get height () {
|
|
236
270
|
Globals.events.poll()
|
|
237
|
-
|
|
271
|
+
validateNotDestroyed(this)
|
|
238
272
|
|
|
239
273
|
return this._height
|
|
240
274
|
}
|
|
241
275
|
|
|
242
276
|
setSize (width, height) {
|
|
243
|
-
|
|
277
|
+
validateNotDestroyed(this)
|
|
244
278
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (!Number.isInteger(height)) { throw Object.assign(new Error("height must be an integer"), { height }) }
|
|
248
|
-
if (height <= 0 || height > 2 ** 31 - 1) { throw Object.assign(new Error("height must be a positive 32-bit integer"), { height }) }
|
|
279
|
+
validatePositiveInt32('width', width)
|
|
280
|
+
validatePositiveInt32('height', height)
|
|
249
281
|
|
|
250
282
|
Bindings.window_setSize(this._id, width, height, false)
|
|
251
283
|
}
|
|
252
284
|
|
|
253
285
|
setSizeInPixels (pixelWidth, pixelHeight) {
|
|
254
|
-
|
|
255
|
-
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
286
|
+
validateNotDestroyed(this)
|
|
256
287
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (!Number.isInteger(pixelHeight)) { throw Object.assign(new Error("pixelHeight must be an integer"), { pixelHeight }) }
|
|
260
|
-
if (pixelHeight <= 0 || pixelHeight > 2 ** 31 - 1) { throw Object.assign(new Error("pixelHeight must be a positive 32-bit integer"), { pixelHeight }) }
|
|
288
|
+
validatePositiveInt32('pixelWidth', pixelWidth)
|
|
289
|
+
validatePositiveInt32('pixelHeight', pixelHeight)
|
|
261
290
|
|
|
262
291
|
Bindings.window_setSize(this._id, pixelWidth, pixelHeight, true)
|
|
263
292
|
}
|
|
264
293
|
|
|
265
294
|
get pixelWidth () {
|
|
266
295
|
Globals.events.poll()
|
|
267
|
-
|
|
296
|
+
validateNotDestroyed(this)
|
|
268
297
|
|
|
269
298
|
return this._pixelWidth
|
|
270
299
|
}
|
|
271
300
|
|
|
272
301
|
get pixelHeight () {
|
|
273
302
|
Globals.events.poll()
|
|
274
|
-
|
|
303
|
+
validateNotDestroyed(this)
|
|
275
304
|
|
|
276
305
|
return this._pixelHeight
|
|
277
306
|
}
|
|
278
307
|
|
|
279
308
|
get display () {
|
|
280
309
|
Globals.events.poll()
|
|
281
|
-
|
|
310
|
+
validateNotDestroyed(this)
|
|
282
311
|
|
|
283
312
|
return Globals.displays.find((a) => a.id === this._displayId) ?? null
|
|
284
313
|
}
|
|
285
314
|
|
|
286
315
|
get visible () {
|
|
287
316
|
Globals.events.poll()
|
|
288
|
-
|
|
317
|
+
validateNotDestroyed(this)
|
|
289
318
|
|
|
290
319
|
return this._visible
|
|
291
320
|
}
|
|
292
321
|
|
|
293
322
|
show (show = true) {
|
|
294
|
-
|
|
323
|
+
validateNotDestroyed(this)
|
|
295
324
|
|
|
296
|
-
|
|
325
|
+
validateBoolean('show', show)
|
|
297
326
|
|
|
298
327
|
show ? Bindings.window_show(this._id) : Bindings.window_hide(this._id)
|
|
299
|
-
this._visible = show
|
|
300
328
|
}
|
|
301
329
|
|
|
302
330
|
hide () { this.show(false) }
|
|
303
331
|
|
|
304
332
|
get fullscreen () {
|
|
305
333
|
Globals.events.poll()
|
|
306
|
-
|
|
334
|
+
validateNotDestroyed(this)
|
|
307
335
|
|
|
308
336
|
return this._fullscreen
|
|
309
337
|
}
|
|
310
338
|
|
|
311
339
|
setFullscreen (fullscreen) {
|
|
312
|
-
|
|
340
|
+
validateNotDestroyed(this)
|
|
313
341
|
|
|
314
|
-
|
|
342
|
+
validateBoolean('fullscreen', fullscreen)
|
|
315
343
|
|
|
316
344
|
Bindings.window_setFullscreen(this._id, fullscreen)
|
|
317
345
|
}
|
|
318
346
|
|
|
319
347
|
get resizable () {
|
|
320
|
-
|
|
348
|
+
validateNotDestroyed(this)
|
|
321
349
|
|
|
322
350
|
return this._resizable
|
|
323
351
|
}
|
|
324
352
|
|
|
325
353
|
setResizable (resizable) {
|
|
326
|
-
|
|
354
|
+
validateNotDestroyed(this)
|
|
327
355
|
|
|
328
|
-
|
|
356
|
+
validateBoolean('resizable', resizable)
|
|
329
357
|
if (resizable && this._borderless) { throw Object.assign(new Error("resizable and borderless are mutually exclusive"), { resizable, borderless: this._borderless }) }
|
|
330
358
|
|
|
331
359
|
this._resizable = Bindings.window_setResizable(this._id, resizable)
|
|
332
360
|
}
|
|
333
361
|
|
|
334
362
|
get borderless () {
|
|
335
|
-
|
|
363
|
+
validateNotDestroyed(this)
|
|
336
364
|
|
|
337
365
|
return this._borderless
|
|
338
366
|
}
|
|
339
367
|
|
|
340
368
|
setBorderless (borderless) {
|
|
341
|
-
|
|
369
|
+
validateNotDestroyed(this)
|
|
342
370
|
|
|
343
|
-
|
|
371
|
+
validateBoolean('borderless', borderless)
|
|
344
372
|
if (borderless && this._resizable) { throw Object.assign(new Error("resizable and borderless are mutually exclusive"), { resizable: this._resizable, borderless }) }
|
|
345
373
|
|
|
346
374
|
this._borderless = Bindings.window_setBorderless(this._id, borderless)
|
|
347
375
|
}
|
|
348
376
|
|
|
349
377
|
get alwaysOnTop () {
|
|
350
|
-
|
|
378
|
+
validateNotDestroyed(this)
|
|
351
379
|
|
|
352
380
|
return this._alwaysOnTop
|
|
353
381
|
}
|
|
354
382
|
|
|
355
383
|
get accelerated () {
|
|
356
|
-
|
|
384
|
+
validateNotDestroyed(this)
|
|
357
385
|
|
|
358
386
|
return this._accelerated
|
|
359
387
|
}
|
|
360
388
|
|
|
361
389
|
setAccelerated (accelerated) {
|
|
362
|
-
|
|
390
|
+
validateNotDestroyed(this)
|
|
363
391
|
|
|
364
392
|
if (this._opengl) { throw new Error("can't call setAccelerated in opengl mode") }
|
|
365
393
|
if (this._webgpu) { throw new Error("can't call setAccelerated in webgpu mode") }
|
|
366
394
|
|
|
367
|
-
|
|
395
|
+
validateBoolean('accelerated', accelerated)
|
|
368
396
|
|
|
369
397
|
const result = Bindings.window_setAcceleratedAndVsync(this._id, accelerated, this._vsync)
|
|
370
398
|
this._accelerated = result.accelerated
|
|
@@ -372,19 +400,18 @@ class Window extends EventsViaPoll {
|
|
|
372
400
|
}
|
|
373
401
|
|
|
374
402
|
get vsync () {
|
|
375
|
-
|
|
403
|
+
validateNotDestroyed(this)
|
|
376
404
|
|
|
377
405
|
return this._vsync
|
|
378
406
|
}
|
|
379
407
|
|
|
380
408
|
setVsync (vsync) {
|
|
381
|
-
|
|
409
|
+
validateNotDestroyed(this)
|
|
382
410
|
|
|
383
411
|
if (this._opengl) { throw new Error("can't call setVsync in opengl mode") }
|
|
384
412
|
if (this._webgpu) { throw new Error("can't call setVsync in webgpu mode") }
|
|
385
413
|
|
|
386
|
-
|
|
387
|
-
if (vsync < -1 || vsync > 2 ** 31 - 1) { throw Object.assign(new Error("vsync must be -1 or a non-negative 32-bit integer"), { vsync }) }
|
|
414
|
+
validateVsync(vsync)
|
|
388
415
|
|
|
389
416
|
const result = Bindings.window_setAcceleratedAndVsync(this._id, this._accelerated, vsync)
|
|
390
417
|
this._accelerated = result.accelerated
|
|
@@ -392,45 +419,45 @@ class Window extends EventsViaPoll {
|
|
|
392
419
|
}
|
|
393
420
|
|
|
394
421
|
get opengl () {
|
|
395
|
-
|
|
422
|
+
validateNotDestroyed(this)
|
|
396
423
|
|
|
397
424
|
return this._opengl
|
|
398
425
|
}
|
|
399
426
|
|
|
400
427
|
get webgpu () {
|
|
401
|
-
|
|
428
|
+
validateNotDestroyed(this)
|
|
402
429
|
|
|
403
430
|
return this._webgpu
|
|
404
431
|
}
|
|
405
432
|
|
|
406
433
|
get native () {
|
|
407
|
-
|
|
434
|
+
validateNotDestroyed(this)
|
|
408
435
|
|
|
409
436
|
return this._native
|
|
410
437
|
}
|
|
411
438
|
|
|
412
439
|
get minimized () {
|
|
413
440
|
Globals.events.poll()
|
|
414
|
-
|
|
441
|
+
validateNotDestroyed(this)
|
|
415
442
|
|
|
416
443
|
return this._minimized
|
|
417
444
|
}
|
|
418
445
|
|
|
419
446
|
minimize () {
|
|
420
|
-
|
|
447
|
+
validateNotDestroyed(this)
|
|
421
448
|
|
|
422
449
|
Bindings.window_minimize(this._id)
|
|
423
450
|
}
|
|
424
451
|
|
|
425
452
|
get maximized () {
|
|
426
453
|
Globals.events.poll()
|
|
427
|
-
|
|
454
|
+
validateNotDestroyed(this)
|
|
428
455
|
|
|
429
456
|
return this._maximized
|
|
430
457
|
}
|
|
431
458
|
|
|
432
459
|
maximize () {
|
|
433
|
-
|
|
460
|
+
validateNotDestroyed(this)
|
|
434
461
|
|
|
435
462
|
if (!this._resizable) { throw new Error("can't maximize a non-resizable window") }
|
|
436
463
|
|
|
@@ -438,90 +465,99 @@ class Window extends EventsViaPoll {
|
|
|
438
465
|
}
|
|
439
466
|
|
|
440
467
|
restore () {
|
|
441
|
-
|
|
468
|
+
validateNotDestroyed(this)
|
|
442
469
|
|
|
443
470
|
Bindings.window_restore(this._id)
|
|
444
471
|
}
|
|
445
472
|
|
|
446
473
|
get focused () {
|
|
447
474
|
Globals.events.poll()
|
|
448
|
-
|
|
475
|
+
validateNotDestroyed(this)
|
|
449
476
|
|
|
450
477
|
return Globals.windows.focused === this
|
|
451
478
|
}
|
|
452
479
|
|
|
453
480
|
focus () {
|
|
454
|
-
|
|
481
|
+
validateNotDestroyed(this)
|
|
455
482
|
|
|
456
483
|
Bindings.window_focus(this._id)
|
|
457
484
|
}
|
|
458
485
|
|
|
459
486
|
get hovered () {
|
|
460
487
|
Globals.events.poll()
|
|
461
|
-
|
|
488
|
+
validateNotDestroyed(this)
|
|
462
489
|
|
|
463
490
|
return Globals.windows.hovered === this
|
|
464
491
|
}
|
|
465
492
|
|
|
466
493
|
get mouseCaptured () {
|
|
467
494
|
Globals.events.poll()
|
|
468
|
-
|
|
495
|
+
validateNotDestroyed(this)
|
|
469
496
|
|
|
470
497
|
return Bindings.window_getMouseCaptured(this._id)
|
|
471
498
|
}
|
|
472
499
|
|
|
473
500
|
get relativeMouseMode () {
|
|
474
|
-
|
|
501
|
+
validateNotDestroyed(this)
|
|
475
502
|
|
|
476
503
|
return this._relativeMouseMode
|
|
477
504
|
}
|
|
478
505
|
|
|
479
506
|
setRelativeMouseMode (relative = true) {
|
|
480
|
-
|
|
507
|
+
validateNotDestroyed(this)
|
|
481
508
|
|
|
482
|
-
|
|
509
|
+
validateBoolean('relative', relative)
|
|
483
510
|
|
|
484
511
|
this._relativeMouseMode = Bindings.window_setRelativeMouseMode(this._id, relative)
|
|
485
512
|
}
|
|
486
513
|
|
|
487
514
|
unsetRelativeMouseMode () { this.setRelativeMouseMode(false) }
|
|
488
515
|
|
|
516
|
+
setHitTest (hitTest) {
|
|
517
|
+
validateNotDestroyed(this)
|
|
518
|
+
|
|
519
|
+
if (hitTest !== null) { validateFunction('hitTest', hitTest) }
|
|
520
|
+
|
|
521
|
+
if (!hitTestHandlerRegistered) {
|
|
522
|
+
Bindings.window_registerHitTestHandler(handleHitTest)
|
|
523
|
+
hitTestHandlerRegistered = true
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const previous = this._hitTest
|
|
527
|
+
this._hitTest = hitTest
|
|
528
|
+
if ((hitTest !== null) !== (previous !== null)) {
|
|
529
|
+
try { Bindings.window_setHitTest(this._id, hitTest !== null) }
|
|
530
|
+
catch (error) {
|
|
531
|
+
this._hitTest = previous
|
|
532
|
+
throw error
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
unsetHitTest () { this.setHitTest(null) }
|
|
538
|
+
|
|
489
539
|
render (width, height, stride, format, buffer, options = {}) {
|
|
490
|
-
|
|
540
|
+
validateNotDestroyed(this)
|
|
491
541
|
|
|
492
542
|
if (this._opengl) { throw new Error("can't call render in opengl mode") }
|
|
493
543
|
if (this._webgpu) { throw new Error("can't call render in webgpu mode") }
|
|
494
544
|
|
|
495
|
-
|
|
545
|
+
validateObject('options', options)
|
|
496
546
|
|
|
497
547
|
const {
|
|
498
548
|
scaling = 'nearest',
|
|
499
|
-
dstRect
|
|
549
|
+
dstRect,
|
|
500
550
|
} = options
|
|
501
551
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
if (
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
if (stride < helpers.minStride(width)) { throw Object.assign(new Error("stride is smaller than expected"), { stride, width, format }) }
|
|
512
|
-
if (stride > 2 ** 31 - 1) { throw Object.assign(new Error("stride must be a 32-bit integer"), { stride }) }
|
|
513
|
-
if (!(buffer instanceof Buffer)) { throw Object.assign(new Error("buffer must be a Buffer"), { buffer }) }
|
|
514
|
-
if (buffer.length < helpers.minBufferSize(stride, height)) { throw Object.assign(new Error("buffer is smaller than expected"), { buffer, stride, height, format }) }
|
|
515
|
-
if (typeof scaling !== 'string') { throw Object.assign(new Error("scaling must be a string"), { scaling }) }
|
|
516
|
-
|
|
517
|
-
if (dstRect !== null) {
|
|
518
|
-
if (typeof dstRect !== 'object') { throw Object.assign(new Error("dstRect must be an object"), { dstRect }) }
|
|
519
|
-
if (!Number.isFinite(dstRect.x)) { throw Object.assign(new Error("dstRect.x must be a number"), { dstRect }) }
|
|
520
|
-
if (!Number.isFinite(dstRect.y)) { throw Object.assign(new Error("dstRect.y must be a number"), { dstRect }) }
|
|
521
|
-
if (!Number.isFinite(dstRect.width)) { throw Object.assign(new Error("dstRect.width must be a number"), { dstRect }) }
|
|
522
|
-
if (dstRect.width <= 0) { throw Object.assign(new Error("dstRect.width must be positive"), { dstRect }) }
|
|
523
|
-
if (!Number.isFinite(dstRect.height)) { throw Object.assign(new Error("dstRect.height must be a number"), { dstRect }) }
|
|
524
|
-
if (dstRect.height <= 0) { throw Object.assign(new Error("dstRect.height must be positive"), { dstRect }) }
|
|
552
|
+
validateImage(width, height, stride, format, buffer, validateRenderableFormat)
|
|
553
|
+
validateString('scaling', scaling)
|
|
554
|
+
|
|
555
|
+
if (dstRect !== undefined) {
|
|
556
|
+
validateObject('dstRect', dstRect)
|
|
557
|
+
validateFloat('dstRect.x', dstRect.x)
|
|
558
|
+
validateFloat('dstRect.y', dstRect.y)
|
|
559
|
+
validatePositiveFloat('dstRect.width', dstRect.width)
|
|
560
|
+
validatePositiveFloat('dstRect.height', dstRect.height)
|
|
525
561
|
}
|
|
526
562
|
|
|
527
563
|
const _format = Enums.pixelFormat[format]
|
|
@@ -529,25 +565,13 @@ class Window extends EventsViaPoll {
|
|
|
529
565
|
const _scaling = Enums.scaleMode[scaling]
|
|
530
566
|
if (_scaling === undefined) { throw Object.assign(new Error("scaling must be 'nearest' or 'linear'"), { scaling }) }
|
|
531
567
|
|
|
532
|
-
Bindings.window_render(this._id, width, height, stride, _format, buffer, _scaling, dstRect)
|
|
568
|
+
Bindings.window_render(this._id, width, height, stride, _format, buffer, _scaling, dstRect ?? null)
|
|
533
569
|
}
|
|
534
570
|
|
|
535
571
|
setIcon (width, height, stride, format, buffer) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
if (width <= 0 || width > 2 ** 31 - 1) { throw Object.assign(new Error("width must be a positive 32-bit integer"), { width }) }
|
|
540
|
-
if (!Number.isInteger(height)) { throw Object.assign(new Error("height must be an integer"), { height }) }
|
|
541
|
-
if (height <= 0 || height > 2 ** 31 - 1) { throw Object.assign(new Error("height must be a positive 32-bit integer"), { height }) }
|
|
542
|
-
if (!Number.isInteger(stride)) { throw Object.assign(new Error("stride must be an integer"), { stride }) }
|
|
543
|
-
if (typeof format !== 'string') { throw Object.assign(new Error("format must be a string"), { format }) }
|
|
544
|
-
const helpers = VideoFormatHelpers[format]
|
|
545
|
-
if (helpers === undefined) { throw Object.assign(new Error("invalid format"), { format }) }
|
|
546
|
-
if (helpers.isYuv) { throw Object.assign(new Error("format must be an RGB format"), { format }) }
|
|
547
|
-
if (stride < helpers.minStride(width)) { throw Object.assign(new Error("stride is smaller than expected"), { stride, width, format }) }
|
|
548
|
-
if (stride > 2 ** 31 - 1) { throw Object.assign(new Error("stride must be a 32-bit integer"), { stride }) }
|
|
549
|
-
if (!(buffer instanceof Buffer)) { throw Object.assign(new Error("buffer must be a Buffer"), { buffer }) }
|
|
550
|
-
if (buffer.length < helpers.minBufferSize(stride, height)) { throw Object.assign(new Error("buffer is smaller than expected"), { buffer, stride, height, format }) }
|
|
572
|
+
validateNotDestroyed(this)
|
|
573
|
+
|
|
574
|
+
validateImage(width, height, stride, format, buffer, validateRgbFormat)
|
|
551
575
|
|
|
552
576
|
const _format = Enums.pixelFormat[format]
|
|
553
577
|
|
|
@@ -555,36 +579,41 @@ class Window extends EventsViaPoll {
|
|
|
555
579
|
}
|
|
556
580
|
|
|
557
581
|
flash (untilFocused = false) {
|
|
558
|
-
|
|
582
|
+
validateNotDestroyed(this)
|
|
559
583
|
|
|
560
|
-
|
|
584
|
+
validateBoolean('untilFocused', untilFocused)
|
|
561
585
|
|
|
562
586
|
Bindings.window_flash(this._id, untilFocused ? 2 : 1)
|
|
563
587
|
}
|
|
564
588
|
|
|
565
589
|
stopFlashing () {
|
|
566
|
-
|
|
590
|
+
validateNotDestroyed(this)
|
|
567
591
|
|
|
568
592
|
Bindings.window_flash(this._id, 0)
|
|
569
593
|
}
|
|
570
594
|
|
|
571
595
|
get destroyed () { return this._destroyed }
|
|
572
596
|
destroy () {
|
|
573
|
-
|
|
597
|
+
validateNotDestroyed(this)
|
|
574
598
|
|
|
599
|
+
this._destroyed = true
|
|
600
|
+
Globals.events.unref()
|
|
601
|
+
Globals.windows.all.delete(this._id)
|
|
575
602
|
if (Globals.windows.hovered === this) { Globals.windows.hovered = null }
|
|
576
603
|
if (Globals.windows.focused === this) { Globals.windows.focused = null }
|
|
577
604
|
|
|
605
|
+
const destroyNative = () => {
|
|
606
|
+
try { Bindings.window_destroy(this._id) }
|
|
607
|
+
catch {}
|
|
608
|
+
}
|
|
609
|
+
|
|
578
610
|
// Defer the native destruction until the pump has unwound.
|
|
579
|
-
if (Bindings.events_isDispatchingFromWatch()) {
|
|
580
|
-
process.nextTick(
|
|
611
|
+
if (hitTestDepth > 0 || Bindings.events_isDispatchingFromWatch()) {
|
|
612
|
+
process.nextTick(destroyNative)
|
|
581
613
|
}
|
|
582
614
|
else {
|
|
583
|
-
|
|
615
|
+
destroyNative()
|
|
584
616
|
}
|
|
585
|
-
this._destroyed = true
|
|
586
|
-
|
|
587
|
-
Globals.windows.all.delete(this._id)
|
|
588
617
|
|
|
589
618
|
// We might be inside an event listener
|
|
590
619
|
this._retire(() => Object.assign(new Error("window is destroyed"), { id: this._id }))
|
|
@@ -596,7 +625,7 @@ class Window extends EventsViaPoll {
|
|
|
596
625
|
}
|
|
597
626
|
|
|
598
627
|
destroyGently () {
|
|
599
|
-
|
|
628
|
+
validateNotDestroyed(this)
|
|
600
629
|
|
|
601
630
|
let shouldPrevent = false
|
|
602
631
|
Globals.events.withoutPolling(() => {
|