@kmamal/sdl 0.10.10 → 0.10.11
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 +11 -2
- package/package.json +1 -1
- package/scripts/install.mjs +2 -2
- package/src/javascript/audio/audio-instance.js +4 -3
- package/src/javascript/audio/audio-playback-instance.js +2 -1
- package/src/javascript/audio/audio-recording-instance.js +2 -1
- package/src/javascript/clipboard/index.js +1 -1
- package/src/javascript/controller/controller-instance.js +6 -4
- package/src/javascript/events/index.js +12 -3
- package/src/javascript/globals.js +1 -1
- package/src/javascript/joystick/joystick-instance.js +10 -8
- package/src/javascript/keyboard/index.js +1 -1
- package/src/javascript/mouse/index.js +8 -8
- package/src/javascript/video/window.js +38 -15
package/README.md
CHANGED
|
@@ -173,6 +173,7 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
|
|
|
173
173
|
* [window.pixelWidth](#windowpixelwidth)
|
|
174
174
|
* [window.pixelHeight](#windowpixelheight)
|
|
175
175
|
* [window.setSize(width, height)](#windowsetsizewidth-height)
|
|
176
|
+
* [window.setSizeInPixels(pixelWidth, pixelHeight)](#windowsetsizeinpixelspixelwidth-pixelheight)
|
|
176
177
|
* [window.visible](#windowvisible)
|
|
177
178
|
* [window.show([show])](#windowshowshow)
|
|
178
179
|
* [window.hide()](#windowhide)
|
|
@@ -819,13 +820,13 @@ The window's height.
|
|
|
819
820
|
|
|
820
821
|
* `<number>`
|
|
821
822
|
|
|
822
|
-
The window's width in pixels. This will be larger than `width` on [high-dpi](#high-dpi) displays.
|
|
823
|
+
The window's width in pixels. This will be larger than [`width`](#windowwidth) on [high-dpi](#high-dpi) displays.
|
|
823
824
|
|
|
824
825
|
### window.pixelHeight
|
|
825
826
|
|
|
826
827
|
* `<number>`
|
|
827
828
|
|
|
828
|
-
The window's height in pixels. This will be larger than `height` on [high-dpi](#high-dpi) displays.
|
|
829
|
+
The window's height in pixels. This will be larger than [`height`](#windowheight) on [high-dpi](#high-dpi) displays.
|
|
829
830
|
|
|
830
831
|
### window.setSize(width, height)
|
|
831
832
|
|
|
@@ -834,6 +835,14 @@ The window's height in pixels. This will be larger than `height` on [high-dpi](#
|
|
|
834
835
|
|
|
835
836
|
Changes the size of the window.
|
|
836
837
|
|
|
838
|
+
### window.setSizeInPixels(pixelWidth, pixelHeight)
|
|
839
|
+
|
|
840
|
+
* `pixelWidth: <number>`: The new width in pixels.
|
|
841
|
+
* `pixelHeight: <number>`: The new height in pixels.
|
|
842
|
+
|
|
843
|
+
Changes the size of the window.
|
|
844
|
+
This function only behaves differently from [`window.setSize()`](#windowsetsizewidth-height) for [high-dpi](#high-dpi) displays.
|
|
845
|
+
|
|
837
846
|
### window.visible
|
|
838
847
|
|
|
839
848
|
* `<boolean>`
|
package/package.json
CHANGED
package/scripts/install.mjs
CHANGED
|
@@ -3,7 +3,7 @@ if (!process.env.NODE_SDL_FROM_SOURCE) {
|
|
|
3
3
|
try {
|
|
4
4
|
await import('./download-release.mjs')
|
|
5
5
|
process.exit(0)
|
|
6
|
-
} catch (
|
|
6
|
+
} catch (_) {
|
|
7
7
|
console.log("failed to download release")
|
|
8
8
|
}
|
|
9
9
|
} else {
|
|
@@ -12,7 +12,7 @@ if (!process.env.NODE_SDL_FROM_SOURCE) {
|
|
|
12
12
|
|
|
13
13
|
try {
|
|
14
14
|
await import('./download-sdl.mjs')
|
|
15
|
-
} catch (
|
|
15
|
+
} catch (_) {
|
|
16
16
|
console.log("failed to download sdl")
|
|
17
17
|
await import('./build-sdl.mjs')
|
|
18
18
|
}
|
|
@@ -22,12 +22,13 @@ class AudioInstance extends EventsViaPoll {
|
|
|
22
22
|
if (name !== undefined && name !== null && typeof name !== 'string') { throw Object.assign(new Error("name must be a string"), { name }) }
|
|
23
23
|
if (typeof type !== 'string') { throw Object.assign(new Error("type must be a string"), { type }) }
|
|
24
24
|
if (type !== 'playback' && type !== 'recording') { throw Object.assign(new Error("type must be either 'playback' or 'recording'"), { type }) }
|
|
25
|
-
if (!Number.
|
|
25
|
+
if (!Number.isInteger(channels)) { throw Object.assign(new Error("channels must be an integer"), { channels }) }
|
|
26
26
|
if (![ 1, 2, 4, 6 ].includes(channels)) { throw Object.assign(new Error("invalid channels"), { channels }) }
|
|
27
|
-
if (!Number.
|
|
27
|
+
if (!Number.isInteger(frequency)) { throw Object.assign(new Error("frequency must be an integer"), { frequency }) }
|
|
28
28
|
if (frequency <= 0) { throw Object.assign(new Error("invalid frequency"), { frequency }) }
|
|
29
29
|
if (typeof format !== 'string') { throw Object.assign(new Error("format must be a string"), { format }) }
|
|
30
|
-
if (!Number.
|
|
30
|
+
if (!Number.isInteger(buffered)) { throw Object.assign(new Error("buffered must be an integer"), { buffered }) }
|
|
31
|
+
if (buffered <= 0) { throw Object.assign(new Error("invalid buffered"), { buffered }) }
|
|
31
32
|
if (buffered !== 2 ** (32 - Math.clz32(buffered) - 1)) { throw Object.assign(new Error("invalid buffered"), { buffered }) }
|
|
32
33
|
|
|
33
34
|
const _format = Enums.audioFormat[format]
|
|
@@ -7,7 +7,8 @@ class AudioPlaybackInstance extends AudioInstance {
|
|
|
7
7
|
if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._id }) }
|
|
8
8
|
|
|
9
9
|
if (!(buffer instanceof Buffer)) { throw Object.assign(new Error("buffer must be a Buffer"), { buffer }) }
|
|
10
|
-
if (!Number.
|
|
10
|
+
if (!Number.isInteger(numBytes)) { throw Object.assign(new Error("numBytes must be an integer"), { numBytes }) }
|
|
11
|
+
if (numBytes <= 0) { throw Object.assign(new Error("invalid numBytes"), { numBytes }) }
|
|
11
12
|
if (buffer.length < numBytes) { throw Object.assign(new Error("buffer is smaller than expected"), { buffer, numBytes }) }
|
|
12
13
|
|
|
13
14
|
Bindings.audio_enqueue(this._id, buffer, numBytes)
|
|
@@ -6,7 +6,8 @@ class AudioRecordingInstance extends AudioInstance {
|
|
|
6
6
|
if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._id }) }
|
|
7
7
|
|
|
8
8
|
if (!(buffer instanceof Buffer)) { throw Object.assign(new Error("buffer must be a Buffer"), { buffer }) }
|
|
9
|
-
if (!Number.
|
|
9
|
+
if (!Number.isInteger(numBytes)) { throw Object.assign(new Error("numBytes must be an integer"), { numBytes }) }
|
|
10
|
+
if (numBytes <= 0) { throw Object.assign(new Error("invalid numBytes"), { numBytes }) }
|
|
10
11
|
if (buffer.length < numBytes) { throw Object.assign(new Error("buffer is smaller than expected"), { buffer, numBytes }) }
|
|
11
12
|
|
|
12
13
|
return Bindings.audio_dequeue(this._id, buffer, numBytes)
|
|
@@ -44,12 +44,12 @@ class ControllerInstance extends EventsViaPoll {
|
|
|
44
44
|
get serialNumber () { return this._serialNumber }
|
|
45
45
|
|
|
46
46
|
get axes () {
|
|
47
|
-
Globals.events.poll()
|
|
47
|
+
Globals.events.poll()
|
|
48
48
|
return this._axes
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
get buttons () {
|
|
52
|
-
Globals.events.poll()
|
|
52
|
+
Globals.events.poll()
|
|
53
53
|
return this._buttons
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -58,8 +58,8 @@ class ControllerInstance extends EventsViaPoll {
|
|
|
58
58
|
setPlayer (player) {
|
|
59
59
|
if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._device.id }) }
|
|
60
60
|
|
|
61
|
-
if (!Number.
|
|
62
|
-
if (player < 0) { throw Object.assign(new Error("player
|
|
61
|
+
if (!Number.isInteger(player)) { throw Object.assign(new Error("player must be an integer"), { player }) }
|
|
62
|
+
if (player < 0) { throw Object.assign(new Error("invalid player"), { player }) }
|
|
63
63
|
|
|
64
64
|
Bindings.joystick_setPlayer(this._device.id, player)
|
|
65
65
|
}
|
|
@@ -93,6 +93,7 @@ class ControllerInstance extends EventsViaPoll {
|
|
|
93
93
|
if (!Number.isFinite(highFreqRumble)) { throw Object.assign(new Error("highFreqRumble must be a number"), { highFreqRumble }) }
|
|
94
94
|
if (highFreqRumble < 0 || highFreqRumble > 1) { throw Object.assign(new Error("highFreqRumble must be between 0 and 1"), { highFreqRumble }) }
|
|
95
95
|
if (!Number.isFinite(duration)) { throw Object.assign(new Error("duration must be a number"), { duration }) }
|
|
96
|
+
if (duration < 0) { throw Object.assign(new Error("invalid duration"), { duration }) }
|
|
96
97
|
|
|
97
98
|
// Globals.events.poll() // Errors if it hasn't been called at least once
|
|
98
99
|
Bindings.joystick_rumble(this._device.id, lowFreqRumble, highFreqRumble, duration)
|
|
@@ -116,6 +117,7 @@ class ControllerInstance extends EventsViaPoll {
|
|
|
116
117
|
if (!Number.isFinite(rightRumble)) { throw Object.assign(new Error("rightRumble must be a number"), { rightRumble }) }
|
|
117
118
|
if (rightRumble < 0 || rightRumble > 1) { throw Object.assign(new Error("rightRumble must be between 0 and 1"), { rightRumble }) }
|
|
118
119
|
if (!Number.isFinite(duration)) { throw Object.assign(new Error("duration must be a number"), { duration }) }
|
|
120
|
+
if (duration < 0) { throw Object.assign(new Error("invalid duration"), { duration }) }
|
|
119
121
|
|
|
120
122
|
// Globals.events.poll() // Errors if it hasn't been called at least once
|
|
121
123
|
Bindings.joystick_rumbleTriggers(this._device.id, leftRumble, rightRumble, duration)
|
|
@@ -312,14 +312,14 @@ const handleEvent = (event) => {
|
|
|
312
312
|
|
|
313
313
|
case 'buttonDown': {
|
|
314
314
|
for (const controllerInstance of collection.values()) {
|
|
315
|
-
controllerInstance.
|
|
315
|
+
controllerInstance._buttons[event.button] = true
|
|
316
316
|
controllerInstance.emit(event.type, event)
|
|
317
317
|
}
|
|
318
318
|
} break
|
|
319
319
|
|
|
320
320
|
case 'buttonUp': {
|
|
321
321
|
for (const controllerInstance of collection.values()) {
|
|
322
|
-
controllerInstance.
|
|
322
|
+
controllerInstance._buttons[event.button] = false
|
|
323
323
|
controllerInstance.emit(event.type, event)
|
|
324
324
|
}
|
|
325
325
|
} break
|
|
@@ -394,7 +394,16 @@ const handleEvent = (event) => {
|
|
|
394
394
|
}
|
|
395
395
|
|
|
396
396
|
|
|
397
|
-
|
|
397
|
+
let polling = false
|
|
398
|
+
|
|
399
|
+
const poll = () => {
|
|
400
|
+
if (polling) { return }
|
|
401
|
+
polling = true
|
|
402
|
+
|
|
403
|
+
Bindings.events_poll(handleEvent)
|
|
404
|
+
|
|
405
|
+
polling = false
|
|
406
|
+
}
|
|
398
407
|
|
|
399
408
|
let pollInterval = null
|
|
400
409
|
|
|
@@ -47,22 +47,22 @@ class JoystickInstance extends EventsViaPoll {
|
|
|
47
47
|
get serialNumber () { return this._serialNumber }
|
|
48
48
|
|
|
49
49
|
get axes () {
|
|
50
|
-
Globals.events.poll()
|
|
50
|
+
Globals.events.poll()
|
|
51
51
|
return this._axes
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
get balls () {
|
|
55
|
-
Globals.events.poll()
|
|
55
|
+
Globals.events.poll()
|
|
56
56
|
return this._balls
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
get buttons () {
|
|
60
|
-
Globals.events.poll()
|
|
60
|
+
Globals.events.poll()
|
|
61
61
|
return this._buttons
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
get hats () {
|
|
65
|
-
Globals.events.poll()
|
|
65
|
+
Globals.events.poll()
|
|
66
66
|
return this._hats
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -71,8 +71,8 @@ class JoystickInstance extends EventsViaPoll {
|
|
|
71
71
|
setPlayer (player) {
|
|
72
72
|
if (this._closed) { throw Object.assign(new Error("instance is closed"), { id: this._device.id }) }
|
|
73
73
|
|
|
74
|
-
if (!Number.
|
|
75
|
-
if (player < 0) { throw Object.assign(new Error("player
|
|
74
|
+
if (!Number.isInteger(player)) { throw Object.assign(new Error("player must be an integer"), { player }) }
|
|
75
|
+
if (player < 0) { throw Object.assign(new Error("invalid player"), { player }) }
|
|
76
76
|
|
|
77
77
|
Bindings.joystick_setPlayer(this._device.id, player)
|
|
78
78
|
}
|
|
@@ -105,7 +105,8 @@ class JoystickInstance extends EventsViaPoll {
|
|
|
105
105
|
if (lowFreqRumble < 0 || lowFreqRumble > 1) { throw Object.assign(new Error("lowFreqRumble must be between 0 and 1"), { lowFreqRumble }) }
|
|
106
106
|
if (!Number.isFinite(highFreqRumble)) { throw Object.assign(new Error("highFreqRumble must be a number"), { highFreqRumble }) }
|
|
107
107
|
if (highFreqRumble < 0 || highFreqRumble > 1) { throw Object.assign(new Error("highFreqRumble must be between 0 and 1"), { highFreqRumble }) }
|
|
108
|
-
if (!Number.
|
|
108
|
+
if (!Number.isInteger(duration)) { throw Object.assign(new Error("duration must be an integer"), { duration }) }
|
|
109
|
+
if (duration < 0) { throw Object.assign(new Error("invalid duration"), { duration }) }
|
|
109
110
|
|
|
110
111
|
// Globals.events.poll() // Errors if it hasn't been called at least once
|
|
111
112
|
Bindings.joystick_rumble(this._device.id, lowFreqRumble, highFreqRumble, duration)
|
|
@@ -128,7 +129,8 @@ class JoystickInstance extends EventsViaPoll {
|
|
|
128
129
|
if (leftRumble < 0 || leftRumble > 1) { throw Object.assign(new Error("leftRumble must be between 0 and 1"), { leftRumble }) }
|
|
129
130
|
if (!Number.isFinite(rightRumble)) { throw Object.assign(new Error("rightRumble must be a number"), { rightRumble }) }
|
|
130
131
|
if (rightRumble < 0 || rightRumble > 1) { throw Object.assign(new Error("rightRumble must be between 0 and 1"), { rightRumble }) }
|
|
131
|
-
if (!Number.
|
|
132
|
+
if (!Number.isInteger(duration)) { throw Object.assign(new Error("duration must be an integer"), { duration }) }
|
|
133
|
+
if (duration < 0) { throw Object.assign(new Error("invalid duration"), { duration }) }
|
|
132
134
|
|
|
133
135
|
// Globals.events.poll() // Errors if it hasn't been called at least once
|
|
134
136
|
Bindings.joystick_rumbleTriggers(this._device.id, leftRumble, rightRumble, duration)
|
|
@@ -7,7 +7,7 @@ const keyboard = {
|
|
|
7
7
|
get SCANCODE () { return Enums.scancodes },
|
|
8
8
|
|
|
9
9
|
getKey (scancode) {
|
|
10
|
-
if (!Number.
|
|
10
|
+
if (!Number.isInteger(scancode)) { throw Object.assign(new Error("scancode must be an integer"), { scancode }) }
|
|
11
11
|
if (scancode < 0 || scancode >= 512) { throw Object.assign(new Error("invalid scancode"), { scancode }) }
|
|
12
12
|
|
|
13
13
|
const _key = Bindings.keyboard_getKey(scancode)
|
|
@@ -5,7 +5,7 @@ const mouse = {
|
|
|
5
5
|
get BUTTON () { return Enums.mouseButtons },
|
|
6
6
|
|
|
7
7
|
getButton (button) {
|
|
8
|
-
if (!Number.
|
|
8
|
+
if (!Number.isInteger(button)) { throw Object.assign(new Error("button must be an integer"), { button }) }
|
|
9
9
|
if (button < 0 || button >= 32) { throw Object.assign(new Error("invalid button"), { button }) }
|
|
10
10
|
|
|
11
11
|
return Bindings.mouse_getButton(button)
|
|
@@ -14,8 +14,8 @@ const mouse = {
|
|
|
14
14
|
get position () { return Bindings.mouse_getPosition() },
|
|
15
15
|
|
|
16
16
|
setPosition (x, y) {
|
|
17
|
-
if (!Number.
|
|
18
|
-
if (!Number.
|
|
17
|
+
if (!Number.isInteger(x)) { throw Object.assign(new Error("x must be an integer"), { x }) }
|
|
18
|
+
if (!Number.isInteger(y)) { throw Object.assign(new Error("y must be an integer"), { y }) }
|
|
19
19
|
|
|
20
20
|
Bindings.mouse_setPosition(x, y)
|
|
21
21
|
},
|
|
@@ -32,18 +32,18 @@ const mouse = {
|
|
|
32
32
|
resetCursor () { Bindings.mouse_resetCursor() },
|
|
33
33
|
|
|
34
34
|
setCursorImage (width, height, stride, format, buffer, x, y) {
|
|
35
|
-
if (!Number.
|
|
35
|
+
if (!Number.isInteger(width)) { throw Object.assign(new Error("width must be an integer"), { width }) }
|
|
36
36
|
if (width <= 0) { throw Object.assign(new Error("invalid width"), { width }) }
|
|
37
|
-
if (!Number.
|
|
37
|
+
if (!Number.isInteger(height)) { throw Object.assign(new Error("height must be an integer"), { height }) }
|
|
38
38
|
if (height <= 0) { throw Object.assign(new Error("invalid height"), { height }) }
|
|
39
|
-
if (!Number.
|
|
39
|
+
if (!Number.isInteger(stride)) { throw Object.assign(new Error("stride must be an integer"), { stride }) }
|
|
40
40
|
if (stride < width) { throw Object.assign(new Error("invalid stride"), { stride, width }) }
|
|
41
41
|
if (typeof format !== 'string') { throw Object.assign(new Error("format must be a string"), { format }) }
|
|
42
42
|
if (!(buffer instanceof Buffer)) { throw Object.assign(new Error("buffer must be a Buffer"), { buffer }) }
|
|
43
43
|
if (buffer.length < stride * height) { throw Object.assign(new Error("buffer is smaller than expected"), { buffer, stride, height }) }
|
|
44
|
-
if (!Number.
|
|
44
|
+
if (!Number.isInteger(x)) { throw Object.assign(new Error("x must be an integer"), { x }) }
|
|
45
45
|
if (x < 0 || x >= width) { throw Object.assign(new Error("invalid x"), { x }) }
|
|
46
|
-
if (!Number.
|
|
46
|
+
if (!Number.isInteger(y)) { throw Object.assign(new Error("y must be an integer"), { y }) }
|
|
47
47
|
if (y < 0 || y >= height) { throw Object.assign(new Error("invalid y"), { y }) }
|
|
48
48
|
|
|
49
49
|
const _format = Enums.pixelFormat[format]
|
|
@@ -57,14 +57,14 @@ class Window extends EventsViaPoll {
|
|
|
57
57
|
|
|
58
58
|
if (typeof title !== 'string') { throw Object.assign(new Error("title must be a string"), { title }) }
|
|
59
59
|
if (display !== null && typeof display !== 'object') { throw Object.assign(new Error("display must be an object"), { display }) }
|
|
60
|
-
if (x !== null && !Number.
|
|
61
|
-
if (y !== null && !Number.
|
|
60
|
+
if (x !== null && !Number.isInteger(x)) { throw Object.assign(new Error("x must be an integer"), { x }) }
|
|
61
|
+
if (y !== null && !Number.isInteger(y)) { throw Object.assign(new Error("y must be an integer"), { y }) }
|
|
62
62
|
if (width !== null) {
|
|
63
|
-
if (!Number.
|
|
63
|
+
if (!Number.isInteger(width)) { throw Object.assign(new Error("width must be an integer"), { width }) }
|
|
64
64
|
if (width <= 0) { throw Object.assign(new Error("invalid width"), { width }) }
|
|
65
65
|
}
|
|
66
66
|
if (height !== null) {
|
|
67
|
-
if (!Number.
|
|
67
|
+
if (!Number.isInteger(height)) { throw Object.assign(new Error("height must be an integer"), { height }) }
|
|
68
68
|
if (height <= 0) { throw Object.assign(new Error("invalid height"), { height }) }
|
|
69
69
|
}
|
|
70
70
|
if (typeof visible !== 'boolean') { throw Object.assign(new Error("visible must be a boolean"), { visible }) }
|
|
@@ -80,7 +80,7 @@ class Window extends EventsViaPoll {
|
|
|
80
80
|
if (typeof popupMenu !== 'boolean') { throw Object.assign(new Error("popupMenu must be a boolean"), { popupMenu }) }
|
|
81
81
|
if (typeof tooltip !== 'boolean') { throw Object.assign(new Error("tooltip must be a boolean"), { tooltip }) }
|
|
82
82
|
if (typeof utility !== 'boolean') { throw Object.assign(new Error("utility must be a boolean"), { utility }) }
|
|
83
|
-
if (display && (
|
|
83
|
+
if (display !== null && (x !== null || y !== null)) { throw Object.assign(new Error("display and x/y are mutually exclusive"), { display, x, y }) }
|
|
84
84
|
if (resizable && borderless) { throw Object.assign(new Error("resizable and borderless are mutually exclusive"), { resizable, borderless }) }
|
|
85
85
|
if (opengl && webgpu) { throw Object.assign(new Error("opengl and webgpu are mutually exclusive"), { opengl, webgpu }) }
|
|
86
86
|
|
|
@@ -186,8 +186,8 @@ class Window extends EventsViaPoll {
|
|
|
186
186
|
setPosition (x, y) {
|
|
187
187
|
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
188
188
|
|
|
189
|
-
if (!Number.
|
|
190
|
-
if (!Number.
|
|
189
|
+
if (!Number.isInteger(x)) { throw Object.assign(new Error("x must be an integer"), { x }) }
|
|
190
|
+
if (!Number.isInteger(y)) { throw Object.assign(new Error("y must be an integer"), { y }) }
|
|
191
191
|
|
|
192
192
|
Bindings.window_setPosition(this._id, x, y)
|
|
193
193
|
this._x = x
|
|
@@ -199,12 +199,35 @@ class Window extends EventsViaPoll {
|
|
|
199
199
|
setSize (width, height) {
|
|
200
200
|
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
201
201
|
|
|
202
|
-
if (!Number.
|
|
202
|
+
if (!Number.isInteger(width)) { throw Object.assign(new Error("width must be an integer"), { width }) }
|
|
203
203
|
if (width <= 0) { throw Object.assign(new Error("invalid width"), { width }) }
|
|
204
|
-
if (!Number.
|
|
204
|
+
if (!Number.isInteger(height)) { throw Object.assign(new Error("height must be an integer"), { height }) }
|
|
205
205
|
if (height <= 0) { throw Object.assign(new Error("invalid height"), { height }) }
|
|
206
206
|
|
|
207
207
|
const { pixelWidth, pixelHeight } = Bindings.window_setSize(this._id, width, height)
|
|
208
|
+
this._width = Math.floor(width)
|
|
209
|
+
this._height = Math.floor(height)
|
|
210
|
+
this._pixelWidth = pixelWidth
|
|
211
|
+
this._pixelHeight = pixelHeight
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
setSizeInPixels (pixelWidth, pixelHeight) {
|
|
215
|
+
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
216
|
+
|
|
217
|
+
if (!Number.isInteger(pixelWidth)) { throw Object.assign(new Error("pixelWidth must be an integer"), { pixelWidth }) }
|
|
218
|
+
if (pixelWidth <= 0) { throw Object.assign(new Error("invalid pixelWidth"), { pixelWidth }) }
|
|
219
|
+
if (!Number.isInteger(pixelHeight)) { throw Object.assign(new Error("pixelHeight must be an integer"), { pixelHeight }) }
|
|
220
|
+
if (pixelHeight <= 0) { throw Object.assign(new Error("invalid pixelHeight"), { pixelHeight }) }
|
|
221
|
+
|
|
222
|
+
const xRatio = this._width / this._pixelWidth
|
|
223
|
+
const yRatio = this._height / this._pixelHeight
|
|
224
|
+
const width = pixelWidth * xRatio
|
|
225
|
+
const height = pixelHeight * yRatio
|
|
226
|
+
|
|
227
|
+
if (!Number.isInteger(width)) { throw Object.assign(new Error(`pixelWidth must be a multiple of ${xRatio}`), { pixelWidth }) }
|
|
228
|
+
if (!Number.isInteger(height)) { throw Object.assign(new Error(`pixelWidth must be a multiple of ${yRatio}`), { pixelWidth }) }
|
|
229
|
+
|
|
230
|
+
Bindings.window_setSize(this._id, width, height)
|
|
208
231
|
this._width = width
|
|
209
232
|
this._height = height
|
|
210
233
|
this._pixelWidth = pixelWidth
|
|
@@ -340,11 +363,11 @@ class Window extends EventsViaPoll {
|
|
|
340
363
|
if (this._opengl) { throw new Error("can't call render in opengl mode") }
|
|
341
364
|
if (this._webgpu) { throw new Error("can't call render in webgpu mode") }
|
|
342
365
|
|
|
343
|
-
if (!Number.
|
|
366
|
+
if (!Number.isInteger(width)) { throw Object.assign(new Error("width must be an integer"), { width }) }
|
|
344
367
|
if (width <= 0) { throw Object.assign(new Error("invalid width"), { width }) }
|
|
345
|
-
if (!Number.
|
|
368
|
+
if (!Number.isInteger(height)) { throw Object.assign(new Error("height must be an integer"), { height }) }
|
|
346
369
|
if (height <= 0) { throw Object.assign(new Error("invalid height"), { height }) }
|
|
347
|
-
if (!Number.
|
|
370
|
+
if (!Number.isInteger(stride)) { throw Object.assign(new Error("stride must be an integer"), { stride }) }
|
|
348
371
|
if (stride < width) { throw Object.assign(new Error("invalid stride"), { stride, width }) }
|
|
349
372
|
if (typeof format !== 'string') { throw Object.assign(new Error("format must be a string"), { format }) }
|
|
350
373
|
if (!(buffer instanceof Buffer)) { throw Object.assign(new Error("buffer must be a Buffer"), { buffer }) }
|
|
@@ -359,11 +382,11 @@ class Window extends EventsViaPoll {
|
|
|
359
382
|
setIcon (width, height, stride, format, buffer) {
|
|
360
383
|
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
361
384
|
|
|
362
|
-
if (!Number.
|
|
385
|
+
if (!Number.isInteger(width)) { throw Object.assign(new Error("width must be an integer"), { width }) }
|
|
363
386
|
if (width <= 0) { throw Object.assign(new Error("invalid width"), { width }) }
|
|
364
|
-
if (!Number.
|
|
387
|
+
if (!Number.isInteger(height)) { throw Object.assign(new Error("height must be an integer"), { height }) }
|
|
365
388
|
if (height <= 0) { throw Object.assign(new Error("invalid height"), { height }) }
|
|
366
|
-
if (!Number.
|
|
389
|
+
if (!Number.isInteger(stride)) { throw Object.assign(new Error("stride must be an integer"), { stride }) }
|
|
367
390
|
if (stride < width) { throw Object.assign(new Error("invalid stride"), { stride, width }) }
|
|
368
391
|
if (typeof format !== 'string') { throw Object.assign(new Error("format must be a string"), { format }) }
|
|
369
392
|
if (!(buffer instanceof Buffer)) { throw Object.assign(new Error("buffer must be a Buffer"), { buffer }) }
|