@kmamal/sdl 0.7.8 → 0.8.3
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 +84 -17
- package/package.json +3 -1
- package/src/javascript/controller/index.js +1 -1
- package/src/javascript/events/index.js +21 -0
- package/src/javascript/globals.js +1 -0
- package/src/javascript/index.js +2 -0
- package/src/javascript/joystick/index.js +1 -1
- package/src/javascript/power/index.js +14 -0
- package/src/javascript/video/index.js +18 -13
- package/src/javascript/video/window.js +10 -1
- package/src/native/binding.cpp +66 -15
- package/src/native/sdl-helpers.cpp +176 -83
- package/src/native/sdl-helpers.h +8 -1
- package/src/types/index.d.ts +49 -1
package/README.md
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@kmamal/sdl)
|
|
4
4
|
[](https://libraries.io/npm/@kmamal%2Fsdl)
|
|
5
|
-
[](https://snyk.io/test/npm/@kmamal/sdl)
|
|
6
5
|
[](https://opensource.org/licenses/MIT)
|
|
7
6
|
|
|
8
7
|
SDL bindings for Node.js.
|
|
9
|
-
Provides window management, input events (keyboard, mouse, joystick, controller), audio playback and recording, and
|
|
8
|
+
Provides window management, input events (keyboard, mouse, joystick, controller), audio playback and recording, clipboard manipulation, and battery status.
|
|
10
9
|
|
|
11
10
|
It should work on Linux, Mac, and Windows.
|
|
12
11
|
Prebuilt binaries are available for x64 architectures, arm-based Macs, and Raspberry Pi.
|
|
@@ -50,7 +49,7 @@ import sdl from '@kmamal/sdl'
|
|
|
50
49
|
import { createCanvas } from 'canvas'
|
|
51
50
|
|
|
52
51
|
const window = sdl.video.createWindow({ title: "Canvas" })
|
|
53
|
-
const { width, height } = window
|
|
52
|
+
const { pixelWidth: width, pixelHeight: height } = window
|
|
54
53
|
const canvas = createCanvas(width, height)
|
|
55
54
|
const ctx = canvas.getContext('2d')
|
|
56
55
|
|
|
@@ -67,7 +66,7 @@ import sdl from '@kmamal/sdl'
|
|
|
67
66
|
import createContext from '@kmamal/gl'
|
|
68
67
|
|
|
69
68
|
const window = sdl.video.createWindow({title: "WebGL", opengl: true })
|
|
70
|
-
const { width, height, native } = window
|
|
69
|
+
const { pixelWidth: width, pixelHeight: height, native } = window
|
|
71
70
|
const gl = createContext(width, height, { window: native })
|
|
72
71
|
|
|
73
72
|
// Clear screen to red
|
|
@@ -88,6 +87,10 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
88
87
|
* [sdl.video](#sdlvideo)
|
|
89
88
|
* [Image data](#image-data)
|
|
90
89
|
* [Pixel formats](#pixel-formats)
|
|
90
|
+
* [High-DPI](#highdpi)
|
|
91
|
+
* [Event: 'displayAdd'](#event-displayadd)
|
|
92
|
+
* [Event: 'displayRemove'](#event-displayremove)
|
|
93
|
+
* [Event: 'displayOrient'](#event-displayorient)
|
|
91
94
|
* [sdl.video.displays](#sdlvideodisplays)
|
|
92
95
|
* [sdl.video.windows](#sdlvideowindows)
|
|
93
96
|
* [sdl.video.focused](#sdlvideofocused)
|
|
@@ -127,6 +130,8 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
127
130
|
* [window.setPosition(x, y)](#windowsetpositionx-y)
|
|
128
131
|
* [window.width](#windowwidth)
|
|
129
132
|
* [window.height](#windowheight)
|
|
133
|
+
* [window.pixelWidth](#windowpixelwidth)
|
|
134
|
+
* [window.pixelHeight](#windowpixelheight)
|
|
130
135
|
* [window.setSize(width, height)](#windowsetsizewidth-height)
|
|
131
136
|
* [window.visible](#windowvisible)
|
|
132
137
|
* [window.show([show])](#windowshowshow)
|
|
@@ -182,8 +187,8 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
182
187
|
* [Joystick types](#joystick-types)
|
|
183
188
|
* [Hat positions](#hat-positions)
|
|
184
189
|
* [Power levels](#power-levels)
|
|
185
|
-
* [Event: 'deviceAdd'](#joystick-event-
|
|
186
|
-
* [Event: 'deviceRemove'](#joystick-event-
|
|
190
|
+
* [Event: 'deviceAdd'](#joystick-event-deviceadd)
|
|
191
|
+
* [Event: 'deviceRemove'](#joystick-event-deviceremove)
|
|
187
192
|
* [sdl.joystick.devices](#sdljoystickdevices)
|
|
188
193
|
* [sdl.joystick.openDevice(device)](#sdljoystickopendevicedevice)
|
|
189
194
|
* [class JoystickInstance](#class-joystickinstance)
|
|
@@ -213,8 +218,8 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
213
218
|
* [joystickInstance.closed](#joystickinstanceclosed)
|
|
214
219
|
* [joystickInstance.close()](#joystickinstanceclose)
|
|
215
220
|
* [sdl.controller](#sdlcontroller)
|
|
216
|
-
* [Event: 'deviceAdd'](#controller-event-
|
|
217
|
-
* [Event: 'deviceRemove'](#controller-event-
|
|
221
|
+
* [Event: 'deviceAdd'](#controller-event-deviceadd)
|
|
222
|
+
* [Event: 'deviceRemove'](#controller-event-deviceremove)
|
|
218
223
|
* [sdl.controller.addMappings(mappings)](#sdlcontrolleraddmappingsmappings)
|
|
219
224
|
* [sdl.controller.devices](#sdlcontrollerdevices)
|
|
220
225
|
* [sdl.controller.openDevice(device)](#sdlcontrolleropendevicedevice)
|
|
@@ -244,8 +249,8 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
244
249
|
* [sdl.audio](#sdlaudio)
|
|
245
250
|
* [Audio data](#audio-data)
|
|
246
251
|
* [Sample formats](#sample-formats)
|
|
247
|
-
* [Event: 'deviceAdd'](#audio-event-
|
|
248
|
-
* [Event: 'deviceRemove'](#audio-event-
|
|
252
|
+
* [Event: 'deviceAdd'](#audio-event-deviceadd)
|
|
253
|
+
* [Event: 'deviceRemove'](#audio-event-deviceremove)
|
|
249
254
|
* [sdl.audio.bytesPerSample(format)](#sdlaudiobytespersampleformat)
|
|
250
255
|
* [sdl.audio.minSampleValue(format)](#sdlaudiominsamplevalueformat)
|
|
251
256
|
* [sdl.audio.maxSampleValue(format)](#sdlaudiomaxsamplevalueformat)
|
|
@@ -286,6 +291,8 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
286
291
|
* [Event: 'update'](#event-update)
|
|
287
292
|
* [sdl.clipboard.text](#sdlclipboardtext)
|
|
288
293
|
* [sdl.clipboard.setText(text)](#sdlclipboardsettexttext)
|
|
294
|
+
* [sdl.power](#sdlpower)
|
|
295
|
+
* [sdl.power.info](#sdlpowerinfo)
|
|
289
296
|
|
|
290
297
|
|
|
291
298
|
## sdl
|
|
@@ -356,7 +363,7 @@ All three of these functions accept the image as a series of arguments:
|
|
|
356
363
|
So for example, to fill the window with a red+green gradient you could do:
|
|
357
364
|
|
|
358
365
|
```js
|
|
359
|
-
const { width, height } = window
|
|
366
|
+
const { pixelWidth: width, pixelHeight: height } = window
|
|
360
367
|
const stride = width * 4
|
|
361
368
|
const buffer = Buffer.alloc(stride * height)
|
|
362
369
|
|
|
@@ -416,6 +423,40 @@ String values used to represent how the pixels of an image are stored in a Buffe
|
|
|
416
423
|
| `'nv12'` | `SDL_PIXELFORMAT_NV12` | planar mode: Y + U/V interleaved (2 planes) |
|
|
417
424
|
| `'nv21'` | `SDL_PIXELFORMAT_NV21` | planar mode: Y + V/U interleaved (2 planes) |
|
|
418
425
|
|
|
426
|
+
|
|
427
|
+
### High-DPI
|
|
428
|
+
|
|
429
|
+
On a high-dpi display, windows have more pixels that their `width` and `height` would indicate.
|
|
430
|
+
On such systems `width` and `height` (and all other measurements such as `x` and `y`) are in "points".
|
|
431
|
+
Points are abstract and don't have to correspond to pixels.
|
|
432
|
+
If you need to know a window's width and height in pixels, you should use the `pixelWidth` and `pixelHeight` properties.
|
|
433
|
+
You should be doing this always, since you don't know beforehand if your program will be running on a high-dpi system.
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
### Event: 'displayAdd'
|
|
437
|
+
|
|
438
|
+
* `device: <object>`: An object from [`sdl.video.displays`](#sdlvideodisplays) indicating the display that caused the event.
|
|
439
|
+
|
|
440
|
+
Fired when a display is added to the system.
|
|
441
|
+
Check [`sdl.video.displays`](#sdlvideodisplays) to get the new list of displays.
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
### Event: 'displayRemove'
|
|
445
|
+
|
|
446
|
+
* `device: <object>`: An object from [`sdl.video.displays`](#sdlvideodisplays) indicating the display that caused the event.
|
|
447
|
+
|
|
448
|
+
Fired when a display is removed from the system.
|
|
449
|
+
Check [`sdl.video.displays`](#sdlvideodisplays) to get the new list of displays.
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
### Event: 'displayOrient'
|
|
453
|
+
|
|
454
|
+
* `device: <object>`: An object from [`sdl.video.displays`](#sdlvideodisplays) indicating the display that caused the event.
|
|
455
|
+
|
|
456
|
+
Fired when a display changes orientation.
|
|
457
|
+
Check [`sdl.video.displays`](#sdlvideodisplays) to get the new list of displays.
|
|
458
|
+
|
|
459
|
+
|
|
419
460
|
### sdl.video.displays
|
|
420
461
|
|
|
421
462
|
* `<object>[]`
|
|
@@ -547,6 +588,8 @@ Fired when the window changes position.
|
|
|
547
588
|
|
|
548
589
|
* `width: <number>` The window's new width.
|
|
549
590
|
* `height: <number>` The window's new height.
|
|
591
|
+
* `pixelWidth: <number>` The window's new width in pixels. See [high-dpi](#high-dpi).
|
|
592
|
+
* `pixelHeight: <number>` The window's new height in pixels. See [high-dpi](#high-dpi).
|
|
550
593
|
|
|
551
594
|
Fired when the window changes size.
|
|
552
595
|
|
|
@@ -720,6 +763,18 @@ The window's width.
|
|
|
720
763
|
|
|
721
764
|
The window's height.
|
|
722
765
|
|
|
766
|
+
### window.pixelWidth
|
|
767
|
+
|
|
768
|
+
* `<number>`
|
|
769
|
+
|
|
770
|
+
The window's width in pixels. This will be larger than `width` on [high-dpi](#high-dpi) displays.
|
|
771
|
+
|
|
772
|
+
### window.pixelHeight
|
|
773
|
+
|
|
774
|
+
* `<number>`
|
|
775
|
+
|
|
776
|
+
The window's height in pixels. This will be larger than `height` on [high-dpi](#high-dpi) displays.
|
|
777
|
+
|
|
723
778
|
### window.setSize(width, height)
|
|
724
779
|
|
|
725
780
|
* `width: <number>`: The new width.
|
|
@@ -1383,7 +1438,7 @@ String values used to represent the power level of a joystick device.
|
|
|
1383
1438
|
| `'wired'` | `SDL_JOYSTICK_POWER_WIRED` |
|
|
1384
1439
|
| `'max'` | `SDL_JOYSTICK_POWER_MAX` |
|
|
1385
1440
|
|
|
1386
|
-
<a id="joystick-event-
|
|
1441
|
+
<a id="joystick-event-deviceadd"></a>
|
|
1387
1442
|
|
|
1388
1443
|
### Event: 'deviceAdd'
|
|
1389
1444
|
|
|
@@ -1392,7 +1447,7 @@ String values used to represent the power level of a joystick device.
|
|
|
1392
1447
|
Fired when a new joystick device becomes available.
|
|
1393
1448
|
Check [`sdl.joystick.devices`](#sdljoystickdevices) to get the new list of joystick devices.
|
|
1394
1449
|
|
|
1395
|
-
<a id="joystick-event-
|
|
1450
|
+
<a id="joystick-event-deviceremove"></a>
|
|
1396
1451
|
|
|
1397
1452
|
### Event: 'deviceRemove'
|
|
1398
1453
|
|
|
@@ -1639,7 +1694,7 @@ const mappings = text.split('\n')
|
|
|
1639
1694
|
sdl.controller.addMappings(mappings)
|
|
1640
1695
|
```
|
|
1641
1696
|
|
|
1642
|
-
<a id="controller-event-
|
|
1697
|
+
<a id="controller-event-deviceadd"></a>
|
|
1643
1698
|
|
|
1644
1699
|
### Event: 'deviceAdd'
|
|
1645
1700
|
|
|
@@ -1648,7 +1703,7 @@ sdl.controller.addMappings(mappings)
|
|
|
1648
1703
|
Fired when a new controller device becomes available.
|
|
1649
1704
|
Check [`sdl.controller.devices`](#sdlcontrollerdevices) to get the new list of controller devices.
|
|
1650
1705
|
|
|
1651
|
-
<a id="controller-event-
|
|
1706
|
+
<a id="controller-event-deviceremove"></a>
|
|
1652
1707
|
|
|
1653
1708
|
### Event: 'deviceRemove'
|
|
1654
1709
|
|
|
@@ -1963,7 +2018,7 @@ String values used to represent how audio samples are stored in a Buffer.
|
|
|
1963
2018
|
| `'f32sys'` | `AUDIO_F32SYS` | 32-bit floating point samples in native byte order |
|
|
1964
2019
|
| `'f32'` | `AUDIO_F32` | alias for `'f32lsb'` |
|
|
1965
2020
|
|
|
1966
|
-
<a id="audio-event-
|
|
2021
|
+
<a id="audio-event-deviceadd"></a>
|
|
1967
2022
|
|
|
1968
2023
|
### Event: 'deviceAdd'
|
|
1969
2024
|
|
|
@@ -1972,7 +2027,7 @@ String values used to represent how audio samples are stored in a Buffer.
|
|
|
1972
2027
|
Fired when a new audio device becomes available.
|
|
1973
2028
|
Check [`sdl.audio.devices`](#sdlaudiodevices) to get the new list of audio devices.
|
|
1974
2029
|
|
|
1975
|
-
<a id="audio-event-
|
|
2030
|
+
<a id="audio-event-deviceremove"></a>
|
|
1976
2031
|
|
|
1977
2032
|
### Event: 'deviceRemove'
|
|
1978
2033
|
|
|
@@ -2297,6 +2352,18 @@ The current text value on the clipboard.
|
|
|
2297
2352
|
Changes the text contents of the clipboard.
|
|
2298
2353
|
|
|
2299
2354
|
|
|
2355
|
+
## sdl.power
|
|
2356
|
+
|
|
2357
|
+
### sdl.power.info
|
|
2358
|
+
|
|
2359
|
+
* `<object>`
|
|
2360
|
+
* `state: <string>` One of `'unknown'`, `'noBattery'`, `'battery'`, `'charging'`, `'changed'`.
|
|
2361
|
+
* `seconds: <number | null>` Seconds of battery life left. Will be `null` if not running on battery, or if it can't be determinded.
|
|
2362
|
+
* `percent: <number | null>` Percentage of battery life left. Will be `null` if not running on battery, or if it can't be determinded.
|
|
2363
|
+
|
|
2364
|
+
The curent power state of the device.
|
|
2365
|
+
|
|
2366
|
+
|
|
2300
2367
|
## Building from source
|
|
2301
2368
|
|
|
2302
2369
|
If there are no prebuilt binaries available for your platform, `@kmamal/sdl` will try to compile itself during installation.
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.8.3",
|
|
3
3
|
"name": "@kmamal/sdl",
|
|
4
4
|
"description": "SDL bindings for Node.js",
|
|
5
5
|
"keywords": [
|
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
"microphone",
|
|
28
28
|
"mic",
|
|
29
29
|
"clipboard",
|
|
30
|
+
"power",
|
|
31
|
+
"battery",
|
|
30
32
|
"game"
|
|
31
33
|
],
|
|
32
34
|
"license": "MIT",
|
|
@@ -7,7 +7,7 @@ const {
|
|
|
7
7
|
const { EventsViaPoll } = require('../events/events-via-poll')
|
|
8
8
|
const { ControllerInstance } = require('./controller-instance')
|
|
9
9
|
|
|
10
|
-
Globals.controllerDevices = Bindings.joystick_getDevices(
|
|
10
|
+
Globals.controllerDevices = Bindings.joystick_getDevices()
|
|
11
11
|
.filter(filterControllerDevice)
|
|
12
12
|
for (const controllerDevice of Globals.controllerDevices) {
|
|
13
13
|
makeControllerDevice(controllerDevice)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const Bindings = require('../bindings')
|
|
2
2
|
const Globals = require('../globals')
|
|
3
3
|
const Enums = require('../enums')
|
|
4
|
+
const { video: videoModule } = require('../video')
|
|
4
5
|
const { mapping } = require('../keyboard/key-mapping')
|
|
5
6
|
const { joystick: joystickModule } = require('../joystick')
|
|
6
7
|
const { controller: controllerModule } = require('../controller')
|
|
@@ -77,6 +78,24 @@ const poll = () => {
|
|
|
77
78
|
event.type = Enums.eventTypeNames[type]
|
|
78
79
|
|
|
79
80
|
switch (family) {
|
|
81
|
+
case Enums.eventFamily.display: {
|
|
82
|
+
const { displayIndex } = event
|
|
83
|
+
delete event.displayIndex
|
|
84
|
+
|
|
85
|
+
const oldDisplays = Globals.displays
|
|
86
|
+
Globals.displays = Bindings.video_getDisplays()
|
|
87
|
+
for (const display of Globals.displays) {
|
|
88
|
+
display.format = Enums.pixelFormatNames[display.format]
|
|
89
|
+
}
|
|
90
|
+
const newDisplays = Globals.displays
|
|
91
|
+
|
|
92
|
+
event.display = event.type === Enums.eventType.displayRemove
|
|
93
|
+
? oldDisplays[displayIndex]
|
|
94
|
+
: newDisplays[displayIndex]
|
|
95
|
+
|
|
96
|
+
videoModule.emit(event.type, event)
|
|
97
|
+
} break
|
|
98
|
+
|
|
80
99
|
case Enums.eventFamily.window: {
|
|
81
100
|
const { windowId } = event
|
|
82
101
|
delete event.windowId
|
|
@@ -92,6 +111,8 @@ const poll = () => {
|
|
|
92
111
|
case Enums.eventType.resize: {
|
|
93
112
|
window._width = event.width
|
|
94
113
|
window._height = event.height
|
|
114
|
+
window._pixelWidth = event.pixelWidth
|
|
115
|
+
window._pixelHeight = event.pixelHeight
|
|
95
116
|
} break
|
|
96
117
|
|
|
97
118
|
case Enums.eventType.show: {
|
package/src/javascript/index.js
CHANGED
|
@@ -12,6 +12,7 @@ const { joystick } = require('./joystick')
|
|
|
12
12
|
const { controller } = require('./controller')
|
|
13
13
|
const { audio } = require('./audio')
|
|
14
14
|
const { clipboard } = require('./clipboard')
|
|
15
|
+
const { power } = require('./power')
|
|
15
16
|
|
|
16
17
|
require('./events')
|
|
17
18
|
require('./cleanup')
|
|
@@ -25,4 +26,5 @@ module.exports = {
|
|
|
25
26
|
controller,
|
|
26
27
|
audio,
|
|
27
28
|
clipboard,
|
|
29
|
+
power,
|
|
28
30
|
}
|
|
@@ -4,7 +4,7 @@ const { make: makeJoystickDevice } = require('./device')
|
|
|
4
4
|
const { EventsViaPoll } = require('../events/events-via-poll')
|
|
5
5
|
const { JoystickInstance } = require('./joystick-instance')
|
|
6
6
|
|
|
7
|
-
Globals.joystickDevices = Bindings.joystick_getDevices(
|
|
7
|
+
Globals.joystickDevices = Bindings.joystick_getDevices()
|
|
8
8
|
for (const joystickDevice of Globals.joystickDevices) {
|
|
9
9
|
makeJoystickDevice(joystickDevice)
|
|
10
10
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const Bindings = require('../bindings')
|
|
2
|
+
const Enums = require('../enums')
|
|
3
|
+
|
|
4
|
+
const power = {
|
|
5
|
+
get info () {
|
|
6
|
+
const info = Bindings.power_getInfo()
|
|
7
|
+
if (info.seconds === -1) { info.seconds = null }
|
|
8
|
+
if (info.percent === -1) { info.percent = null }
|
|
9
|
+
info.state = Enums.powerStateNames[info.state]
|
|
10
|
+
return info
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = { power }
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
const Bindings = require('../bindings')
|
|
2
2
|
const Globals = require('../globals')
|
|
3
3
|
const Enums = require('../enums')
|
|
4
|
+
const { EventsViaPoll } = require('../events/events-via-poll')
|
|
4
5
|
const { Window } = require('./window')
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
display.format = Enums.pixelFormatNames[display.format]
|
|
11
|
-
}
|
|
12
|
-
return displays
|
|
13
|
-
},
|
|
7
|
+
Globals.displays = Bindings.video_getDisplays()
|
|
8
|
+
for (const display of Globals.displays) {
|
|
9
|
+
display.format = Enums.pixelFormatNames[display.format]
|
|
10
|
+
}
|
|
14
11
|
|
|
15
|
-
get windows () { return [ ...Globals.windows.all.values() ] },
|
|
16
|
-
get focused () { return Globals.windows.focused },
|
|
17
|
-
get hovered () { return Globals.windows.hovered },
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
const validEvents = [ 'displayAdd', 'displayRemove', 'displayOrient' ]
|
|
14
|
+
|
|
15
|
+
const video = new class extends EventsViaPoll {
|
|
16
|
+
constructor () { super(validEvents) }
|
|
17
|
+
|
|
18
|
+
get displays () { return Globals.displays }
|
|
19
|
+
|
|
20
|
+
get windows () { return [ ...Globals.windows.all.values() ] }
|
|
21
|
+
get focused () { return Globals.windows.focused }
|
|
22
|
+
get hovered () { return Globals.windows.hovered }
|
|
23
|
+
|
|
24
|
+
createWindow (options) { return new Window(options) }
|
|
25
|
+
}()
|
|
21
26
|
|
|
22
27
|
module.exports = { video }
|
|
@@ -115,6 +115,8 @@ class Window extends EventsViaPoll {
|
|
|
115
115
|
this._y = result.y
|
|
116
116
|
this._width = result.width
|
|
117
117
|
this._height = result.height
|
|
118
|
+
this._pixelWidth = result.pixelWidth
|
|
119
|
+
this._pixelHeight = result.pixelHeight
|
|
118
120
|
this._fullscreen = result.fullscreen
|
|
119
121
|
this._resizable = result.resizable
|
|
120
122
|
this._borderless = result.borderless
|
|
@@ -157,6 +159,8 @@ class Window extends EventsViaPoll {
|
|
|
157
159
|
this.emit('resize', {
|
|
158
160
|
width: this._width,
|
|
159
161
|
height: this._height,
|
|
162
|
+
pixelWidth: this._pixelWidth,
|
|
163
|
+
pixelHeight: this._pixelHeight,
|
|
160
164
|
type: 'resize',
|
|
161
165
|
})
|
|
162
166
|
})
|
|
@@ -197,11 +201,16 @@ class Window extends EventsViaPoll {
|
|
|
197
201
|
if (!Number.isFinite(height)) { throw Object.assign(new Error("height must be a number"), { height }) }
|
|
198
202
|
if (height <= 0) { throw Object.assign(new Error("invalid height"), { height }) }
|
|
199
203
|
|
|
200
|
-
Bindings.window_setSize(this._id, width, height)
|
|
204
|
+
const { pixelWidth, pixelHeight } = Bindings.window_setSize(this._id, width, height)
|
|
201
205
|
this._width = width
|
|
202
206
|
this._height = height
|
|
207
|
+
this._pixelWidth = pixelWidth
|
|
208
|
+
this._pixelHeight = pixelHeight
|
|
203
209
|
}
|
|
204
210
|
|
|
211
|
+
get pixelWidth () { return this._pixelWidth }
|
|
212
|
+
get pixelHeight () { return this._pixelHeight }
|
|
213
|
+
|
|
205
214
|
get visible () { return this._visible }
|
|
206
215
|
show (show = true) {
|
|
207
216
|
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
package/src/native/binding.cpp
CHANGED
|
@@ -221,6 +221,15 @@ getEnums(napi_env env, napi_callback_info info)
|
|
|
221
221
|
CALL_NAPI(napi_set_property, result, key, value);
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
{
|
|
225
|
+
SdlHelpers::Variant power_states;
|
|
226
|
+
CALL_SDL_HELPER(enum_getPowerStates, power_states);
|
|
227
|
+
|
|
228
|
+
CALL_NAPI(fromVariant, power_states, &value);
|
|
229
|
+
CALL_NAPI(napi_create_string_latin1, "powerState", 10, &key);
|
|
230
|
+
CALL_NAPI(napi_set_property, result, key, value);
|
|
231
|
+
}
|
|
232
|
+
|
|
224
233
|
cleanup:
|
|
225
234
|
return result;
|
|
226
235
|
}
|
|
@@ -341,30 +350,31 @@ window_create(napi_env env, napi_callback_info info)
|
|
|
341
350
|
CALL_NAPI(napi_get_value_int32, argv[5], y);
|
|
342
351
|
}
|
|
343
352
|
|
|
344
|
-
bool visible, fullscreen, resizable, borderless,
|
|
353
|
+
bool visible, fullscreen, resizable, borderless, always_on_top,
|
|
345
354
|
accelerated, vsync, opengl,
|
|
346
|
-
|
|
355
|
+
skip_taskbar, popup_menu, tooltip, utility;
|
|
347
356
|
CALL_NAPI(napi_get_value_bool, argv[6], &visible);
|
|
348
357
|
CALL_NAPI(napi_get_value_bool, argv[7], &fullscreen);
|
|
349
358
|
CALL_NAPI(napi_get_value_bool, argv[8], &resizable);
|
|
350
359
|
CALL_NAPI(napi_get_value_bool, argv[9], &borderless);
|
|
351
|
-
CALL_NAPI(napi_get_value_bool, argv[10], &
|
|
360
|
+
CALL_NAPI(napi_get_value_bool, argv[10], &always_on_top);
|
|
352
361
|
CALL_NAPI(napi_get_value_bool, argv[11], &accelerated);
|
|
353
362
|
CALL_NAPI(napi_get_value_bool, argv[12], &vsync);
|
|
354
363
|
CALL_NAPI(napi_get_value_bool, argv[13], &opengl);
|
|
355
|
-
CALL_NAPI(napi_get_value_bool, argv[14], &
|
|
356
|
-
CALL_NAPI(napi_get_value_bool, argv[15], &
|
|
364
|
+
CALL_NAPI(napi_get_value_bool, argv[14], &skip_taskbar);
|
|
365
|
+
CALL_NAPI(napi_get_value_bool, argv[15], &popup_menu);
|
|
357
366
|
CALL_NAPI(napi_get_value_bool, argv[16], &tooltip);
|
|
358
367
|
CALL_NAPI(napi_get_value_bool, argv[17], &utility);
|
|
359
368
|
|
|
360
|
-
int window_id;
|
|
361
|
-
|
|
369
|
+
int pixel_width, pixel_height, window_id, native_pointer_size;
|
|
370
|
+
|
|
362
371
|
CALL_SDL_HELPER(window_create,
|
|
363
372
|
title, display,
|
|
364
373
|
&x, &y, &width, &height,
|
|
365
|
-
|
|
374
|
+
&pixel_width, &pixel_height,
|
|
375
|
+
visible, &fullscreen, &resizable, &borderless, &always_on_top,
|
|
366
376
|
&accelerated, &vsync, opengl,
|
|
367
|
-
&
|
|
377
|
+
&skip_taskbar, &popup_menu, &tooltip, &utility,
|
|
368
378
|
&window_id, &native_pointer, &native_pointer_size
|
|
369
379
|
);
|
|
370
380
|
|
|
@@ -391,6 +401,14 @@ window_create(napi_env env, napi_callback_info info)
|
|
|
391
401
|
CALL_NAPI(napi_create_string_latin1, "height", 6, &key);
|
|
392
402
|
CALL_NAPI(napi_set_property, result, key, value);
|
|
393
403
|
|
|
404
|
+
CALL_NAPI(napi_create_int32, pixel_width, &value);
|
|
405
|
+
CALL_NAPI(napi_create_string_latin1, "pixelWidth", 10, &key);
|
|
406
|
+
CALL_NAPI(napi_set_property, result, key, value);
|
|
407
|
+
|
|
408
|
+
CALL_NAPI(napi_create_int32, pixel_height, &value);
|
|
409
|
+
CALL_NAPI(napi_create_string_latin1, "pixelHeight", 11, &key);
|
|
410
|
+
CALL_NAPI(napi_set_property, result, key, value);
|
|
411
|
+
|
|
394
412
|
CALL_NAPI(napi_create_int32, fullscreen, &value);
|
|
395
413
|
CALL_NAPI(napi_coerce_to_bool, value, &value);
|
|
396
414
|
CALL_NAPI(napi_create_string_latin1, "fullscreen", 10, &key);
|
|
@@ -406,7 +424,7 @@ window_create(napi_env env, napi_callback_info info)
|
|
|
406
424
|
CALL_NAPI(napi_create_string_latin1, "borderless", 10, &key);
|
|
407
425
|
CALL_NAPI(napi_set_property, result, key, value);
|
|
408
426
|
|
|
409
|
-
CALL_NAPI(napi_create_int32,
|
|
427
|
+
CALL_NAPI(napi_create_int32, always_on_top, &value);
|
|
410
428
|
CALL_NAPI(napi_coerce_to_bool, value, &value);
|
|
411
429
|
CALL_NAPI(napi_create_string_latin1, "alwaysOnTop", 11, &key);
|
|
412
430
|
CALL_NAPI(napi_set_property, result, key, value);
|
|
@@ -421,12 +439,12 @@ window_create(napi_env env, napi_callback_info info)
|
|
|
421
439
|
CALL_NAPI(napi_create_string_latin1, "vsync", 5, &key);
|
|
422
440
|
CALL_NAPI(napi_set_property, result, key, value);
|
|
423
441
|
|
|
424
|
-
CALL_NAPI(napi_create_int32,
|
|
442
|
+
CALL_NAPI(napi_create_int32, skip_taskbar, &value);
|
|
425
443
|
CALL_NAPI(napi_coerce_to_bool, value, &value);
|
|
426
444
|
CALL_NAPI(napi_create_string_latin1, "skipTaskbar", 11, &key);
|
|
427
445
|
CALL_NAPI(napi_set_property, result, key, value);
|
|
428
446
|
|
|
429
|
-
CALL_NAPI(napi_create_int32,
|
|
447
|
+
CALL_NAPI(napi_create_int32, popup_menu, &value);
|
|
430
448
|
CALL_NAPI(napi_coerce_to_bool, value, &value);
|
|
431
449
|
CALL_NAPI(napi_create_string_latin1, "popupMenu", 9, &key);
|
|
432
450
|
CALL_NAPI(napi_set_property, result, key, value);
|
|
@@ -505,6 +523,8 @@ window_setPosition(napi_env env, napi_callback_info info)
|
|
|
505
523
|
napi_value
|
|
506
524
|
window_setSize(napi_env env, napi_callback_info info)
|
|
507
525
|
{
|
|
526
|
+
napi_value result = nullptr;
|
|
527
|
+
|
|
508
528
|
napi_value argv[3];
|
|
509
529
|
size_t argc = sizeof(argv) / sizeof(napi_value);
|
|
510
530
|
CALL_NAPI(napi_get_cb_info, info, &argc, argv, nullptr, nullptr);
|
|
@@ -516,10 +536,25 @@ window_setSize(napi_env env, napi_callback_info info)
|
|
|
516
536
|
CALL_NAPI(napi_get_value_int32, argv[1], &width);
|
|
517
537
|
CALL_NAPI(napi_get_value_int32, argv[2], &height);
|
|
518
538
|
|
|
519
|
-
|
|
539
|
+
int pixel_width, pixel_height;
|
|
540
|
+
CALL_SDL_HELPER(window_setSize,
|
|
541
|
+
window_id, width, height,
|
|
542
|
+
&pixel_width, &pixel_height
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
napi_value key, value;
|
|
546
|
+
CALL_NAPI(napi_create_object, &result);
|
|
547
|
+
|
|
548
|
+
CALL_NAPI(napi_create_int32, pixel_width, &value);
|
|
549
|
+
CALL_NAPI(napi_create_string_latin1, "pixelWidth", 10, &key);
|
|
550
|
+
CALL_NAPI(napi_set_property, result, key, value);
|
|
551
|
+
|
|
552
|
+
CALL_NAPI(napi_create_int32, pixel_height, &value);
|
|
553
|
+
CALL_NAPI(napi_create_string_latin1, "pixelHeight", 11, &key);
|
|
554
|
+
CALL_NAPI(napi_set_property, result, key, value);
|
|
520
555
|
|
|
521
556
|
cleanup:
|
|
522
|
-
return
|
|
557
|
+
return result;
|
|
523
558
|
}
|
|
524
559
|
|
|
525
560
|
napi_value
|
|
@@ -1443,6 +1478,21 @@ clipboard_setText(napi_env env, napi_callback_info info)
|
|
|
1443
1478
|
}
|
|
1444
1479
|
|
|
1445
1480
|
|
|
1481
|
+
napi_value
|
|
1482
|
+
power_getInfo(napi_env env, napi_callback_info info)
|
|
1483
|
+
{
|
|
1484
|
+
napi_value result = nullptr;
|
|
1485
|
+
|
|
1486
|
+
SdlHelpers::Variant power;
|
|
1487
|
+
CALL_SDL_HELPER(power_getInfo, power);
|
|
1488
|
+
|
|
1489
|
+
CALL_NAPI(fromVariant, power, &result);
|
|
1490
|
+
|
|
1491
|
+
cleanup:
|
|
1492
|
+
return result;
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
|
|
1446
1496
|
napi_value
|
|
1447
1497
|
cleanup(napi_env env, napi_callback_info info)
|
|
1448
1498
|
{
|
|
@@ -1510,10 +1560,11 @@ init (napi_env env, napi_value exports)
|
|
|
1510
1560
|
{ "audio_clearQueue", NULL, audio_clearQueue, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
1511
1561
|
{ "clipboard_getText", NULL, clipboard_getText, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
1512
1562
|
{ "clipboard_setText", NULL, clipboard_setText, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
1563
|
+
{ "power_getInfo", NULL, power_getInfo, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
1513
1564
|
{ "cleanup", NULL, cleanup, NULL, NULL, NULL, napi_enumerable, NULL }
|
|
1514
1565
|
};
|
|
1515
1566
|
|
|
1516
|
-
CALL_NAPI(napi_define_properties, exports,
|
|
1567
|
+
CALL_NAPI(napi_define_properties, exports, 55, desc);
|
|
1517
1568
|
|
|
1518
1569
|
cleanup:
|
|
1519
1570
|
return exports;
|
|
@@ -120,6 +120,7 @@ ErrorMessage::
|
|
|
120
120
|
|
|
121
121
|
|
|
122
122
|
enum class EventFamily {
|
|
123
|
+
DISPLAY,
|
|
123
124
|
WINDOW,
|
|
124
125
|
KEYBOARD,
|
|
125
126
|
MOUSE,
|
|
@@ -137,6 +138,7 @@ enum_getEventFamilies (Variant & families)
|
|
|
137
138
|
{
|
|
138
139
|
MAKE_MAP(families);
|
|
139
140
|
|
|
141
|
+
SET_NUM(families, "display", (int) EventFamily::DISPLAY);
|
|
140
142
|
SET_NUM(families, "window", (int) EventFamily::WINDOW);
|
|
141
143
|
SET_NUM(families, "keyboard", (int) EventFamily::KEYBOARD);
|
|
142
144
|
SET_NUM(families, "mouse", (int) EventFamily::MOUSE);
|
|
@@ -154,6 +156,9 @@ enum_getEventFamilies (Variant & families)
|
|
|
154
156
|
|
|
155
157
|
enum class EventType {
|
|
156
158
|
QUIT,
|
|
159
|
+
DISPLAY_ADD,
|
|
160
|
+
DISPLAY_REMOVE,
|
|
161
|
+
DISPLAY_ORIENT,
|
|
157
162
|
SHOW,
|
|
158
163
|
HIDE,
|
|
159
164
|
EXPOSE,
|
|
@@ -195,6 +200,9 @@ enum_getEventTypes (Variant & types)
|
|
|
195
200
|
MAKE_MAP(types);
|
|
196
201
|
|
|
197
202
|
SET_NUM(types, "quit", (int) EventType::QUIT);
|
|
203
|
+
SET_NUM(types, "displayAdd", (int) EventType::DISPLAY_ADD);
|
|
204
|
+
SET_NUM(types, "displayRemove", (int) EventType::DISPLAY_REMOVE);
|
|
205
|
+
SET_NUM(types, "displayOrient", (int) EventType::DISPLAY_ORIENT);
|
|
198
206
|
SET_NUM(types, "show", (int) EventType::SHOW);
|
|
199
207
|
SET_NUM(types, "hide", (int) EventType::HIDE);
|
|
200
208
|
SET_NUM(types, "expose", (int) EventType::EXPOSE);
|
|
@@ -686,6 +694,21 @@ enum_getControllerButtons (Variant & buttons)
|
|
|
686
694
|
return nullptr;
|
|
687
695
|
}
|
|
688
696
|
|
|
697
|
+
ErrorMessage *
|
|
698
|
+
enum_getPowerStates (Variant & states)
|
|
699
|
+
{
|
|
700
|
+
MAKE_MAP(states);
|
|
701
|
+
|
|
702
|
+
SET_NUM(states, "unknown", SDL_POWERSTATE_UNKNOWN);
|
|
703
|
+
SET_NUM(states, "noBattery", SDL_POWERSTATE_NO_BATTERY);
|
|
704
|
+
SET_NUM(states, "battery", SDL_POWERSTATE_ON_BATTERY);
|
|
705
|
+
SET_NUM(states, "charging", SDL_POWERSTATE_CHARGING);
|
|
706
|
+
SET_NUM(states, "charged", SDL_POWERSTATE_CHARGED);
|
|
707
|
+
|
|
708
|
+
return nullptr;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
|
|
689
712
|
|
|
690
713
|
ErrorMessage *
|
|
691
714
|
initialize (Variant & object)
|
|
@@ -839,6 +862,87 @@ initialize (Variant & object)
|
|
|
839
862
|
}
|
|
840
863
|
|
|
841
864
|
|
|
865
|
+
ErrorMessage *
|
|
866
|
+
_windowGetPixelSize(SDL_Window * window, int * pixel_width, int * pixel_height)
|
|
867
|
+
{
|
|
868
|
+
SDL_Renderer * renderer = SDL_GetRenderer(window);
|
|
869
|
+
if (renderer == nullptr) {
|
|
870
|
+
RETURN_ERROR("SDL_GetRenderer() error: %s\n", SDL_GetError());
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
if (SDL_GetRendererOutputSize(renderer, pixel_width, pixel_height) != 0) {
|
|
874
|
+
RETURN_ERROR("SDL_GetRendererOutputSize() error: %s\n", SDL_GetError());
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
return nullptr;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
ErrorMessage *
|
|
881
|
+
_windowUpdateTexture(
|
|
882
|
+
SDL_Window * window,
|
|
883
|
+
SDL_Renderer * renderer,
|
|
884
|
+
int pixel_width, int pixel_height,
|
|
885
|
+
SDL_Texture ** texture_dst
|
|
886
|
+
) {
|
|
887
|
+
int window_id = SDL_GetWindowID(window);
|
|
888
|
+
|
|
889
|
+
int format = SDL_GetWindowPixelFormat(window);
|
|
890
|
+
SDL_Texture * texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STREAMING, pixel_width, pixel_height);
|
|
891
|
+
if (texture == nullptr) {
|
|
892
|
+
RETURN_ERROR("SDL_CreateTexture(%d) error: %s\n", window_id, SDL_GetError());
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
if (SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_NONE)) {
|
|
896
|
+
RETURN_ERROR("SDL_SetTextureBlendMode(%d) error: %s\n", window_id, SDL_GetError());
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
SDL_Texture * old_texture = (SDL_Texture *) SDL_SetWindowData(window, "texture", texture);
|
|
900
|
+
if (old_texture != nullptr) { SDL_DestroyTexture(old_texture); }
|
|
901
|
+
|
|
902
|
+
if (texture_dst != nullptr) { *texture_dst = texture; }
|
|
903
|
+
|
|
904
|
+
return nullptr;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
ErrorMessage *
|
|
908
|
+
_windowUpdateRenderer(
|
|
909
|
+
SDL_Window * window,
|
|
910
|
+
bool * accelerated,
|
|
911
|
+
bool * vsync
|
|
912
|
+
) {
|
|
913
|
+
int window_id = SDL_GetWindowID(window);
|
|
914
|
+
|
|
915
|
+
SDL_Renderer * old_renderer = SDL_GetRenderer(window);
|
|
916
|
+
if (old_renderer != nullptr) { SDL_DestroyRenderer(old_renderer); }
|
|
917
|
+
|
|
918
|
+
int renderer_flags = 0
|
|
919
|
+
| (*accelerated ? SDL_RENDERER_ACCELERATED : SDL_RENDERER_SOFTWARE)
|
|
920
|
+
| (*accelerated && *vsync ? SDL_RENDERER_PRESENTVSYNC : 0);
|
|
921
|
+
|
|
922
|
+
SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, renderer_flags);
|
|
923
|
+
if (renderer == nullptr) {
|
|
924
|
+
RETURN_ERROR("SDL_CreateRenderer(%d, %d) error: %s\n", window_id, renderer_flags, SDL_GetError());
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
SDL_RendererInfo info;
|
|
928
|
+
SDL_GetRendererInfo(renderer, &info);
|
|
929
|
+
|
|
930
|
+
*accelerated = info.flags & SDL_RENDERER_ACCELERATED;
|
|
931
|
+
*vsync = info.flags & SDL_RENDERER_PRESENTVSYNC;
|
|
932
|
+
|
|
933
|
+
ErrorMessage * error;
|
|
934
|
+
|
|
935
|
+
int pixel_width, pixel_height;
|
|
936
|
+
error = _windowGetPixelSize(window, &pixel_width, &pixel_height);
|
|
937
|
+
if (error != nullptr) { return error; }
|
|
938
|
+
|
|
939
|
+
error = _windowUpdateTexture(window, renderer, pixel_width, pixel_height, nullptr);
|
|
940
|
+
if (error != nullptr) { return error; }
|
|
941
|
+
|
|
942
|
+
return nullptr;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
|
|
842
946
|
ErrorMessage *
|
|
843
947
|
_controllerGetState (SDL_GameController * controller, Variant & object)
|
|
844
948
|
{
|
|
@@ -909,6 +1013,18 @@ packageEvent (const SDL_Event & event, Variant & object)
|
|
|
909
1013
|
|
|
910
1014
|
Variant value;
|
|
911
1015
|
switch (event.type) {
|
|
1016
|
+
case SDL_DISPLAYEVENT: {
|
|
1017
|
+
SET_NUM(object, "family", (int) EventFamily::DISPLAY);
|
|
1018
|
+
SET_NUM(object, "displayIndex", event.display.display);
|
|
1019
|
+
|
|
1020
|
+
switch (event.display.event) {
|
|
1021
|
+
case SDL_DISPLAYEVENT_CONNECTED: { SET_NUM(object, "type", (int) EventType::DISPLAY_ADD); break; }
|
|
1022
|
+
case SDL_DISPLAYEVENT_DISCONNECTED: { SET_NUM(object, "type", (int) EventType::DISPLAY_REMOVE); break; }
|
|
1023
|
+
case SDL_DISPLAYEVENT_ORIENTATION: { SET_NUM(object, "type", (int) EventType::DISPLAY_ORIENT); break; }
|
|
1024
|
+
}
|
|
1025
|
+
break;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
912
1028
|
case SDL_WINDOWEVENT: {
|
|
913
1029
|
SET_NUM(object, "family", (int) EventFamily::WINDOW);
|
|
914
1030
|
SET_NUM(object, "windowId", event.window.windowID);
|
|
@@ -924,9 +1040,20 @@ packageEvent (const SDL_Event & event, Variant & object)
|
|
|
924
1040
|
break;
|
|
925
1041
|
}
|
|
926
1042
|
case SDL_WINDOWEVENT_SIZE_CHANGED: {
|
|
1043
|
+
SDL_Window * window = SDL_GetWindowFromID(event.window.windowID);
|
|
1044
|
+
if (window == nullptr) {
|
|
1045
|
+
RETURN_ERROR("SDL_CreateWindow() error: %s\n", SDL_GetError());
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
int pixel_width, pixel_height;
|
|
1049
|
+
ErrorMessage * error = _windowGetPixelSize(window, &pixel_width, &pixel_height);
|
|
1050
|
+
if (error != nullptr) { return error; }
|
|
1051
|
+
|
|
927
1052
|
SET_NUM(object, "type", (int) EventType::RESIZE);
|
|
928
1053
|
SET_NUM(object, "width", event.window.data1);
|
|
929
1054
|
SET_NUM(object, "height", event.window.data2);
|
|
1055
|
+
SET_NUM(object, "pixelWidth", pixel_width);
|
|
1056
|
+
SET_NUM(object, "pixelHeight", pixel_height);
|
|
930
1057
|
break;
|
|
931
1058
|
}
|
|
932
1059
|
case SDL_WINDOWEVENT_MINIMIZED: { SET_NUM(object, "type", (int) EventType::MINIMIZE); break; }
|
|
@@ -1203,7 +1330,8 @@ events_poll (Variant & object)
|
|
|
1203
1330
|
|
|
1204
1331
|
if (!got_event) { return nullptr; }
|
|
1205
1332
|
|
|
1206
|
-
packageEvent(event, object);
|
|
1333
|
+
ErrorMessage * error = packageEvent(event, object);
|
|
1334
|
+
if (error != nullptr) { return error; }
|
|
1207
1335
|
|
|
1208
1336
|
return nullptr;
|
|
1209
1337
|
}
|
|
@@ -1218,7 +1346,8 @@ events_wait (int timeout, Variant & object)
|
|
|
1218
1346
|
|
|
1219
1347
|
if (!got_event) { return nullptr; }
|
|
1220
1348
|
|
|
1221
|
-
packageEvent(event, object);
|
|
1349
|
+
ErrorMessage * error = packageEvent(event, object);
|
|
1350
|
+
if (error != nullptr) { return error; }
|
|
1222
1351
|
|
|
1223
1352
|
return nullptr;
|
|
1224
1353
|
}
|
|
@@ -1307,87 +1436,26 @@ video_getDisplays(Variant & list)
|
|
|
1307
1436
|
return nullptr;
|
|
1308
1437
|
}
|
|
1309
1438
|
|
|
1310
|
-
ErrorMessage *
|
|
1311
|
-
_windowUpdateTexture(
|
|
1312
|
-
SDL_Window * window,
|
|
1313
|
-
SDL_Renderer * renderer,
|
|
1314
|
-
int width, int height,
|
|
1315
|
-
SDL_Texture ** texture_dst
|
|
1316
|
-
) {
|
|
1317
|
-
int window_id = SDL_GetWindowID(window);
|
|
1318
|
-
|
|
1319
|
-
int format = SDL_GetWindowPixelFormat(window);
|
|
1320
|
-
SDL_Texture * texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STREAMING, width, height);
|
|
1321
|
-
if (texture == nullptr) {
|
|
1322
|
-
RETURN_ERROR("SDL_CreateTexture(%d) error: %s\n", window_id, SDL_GetError());
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
|
-
if (SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_NONE)) {
|
|
1326
|
-
RETURN_ERROR("SDL_SetTextureBlendMode(%d) error: %s\n", window_id, SDL_GetError());
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
SDL_Texture * old_texture = (SDL_Texture *) SDL_SetWindowData(window, "texture", texture);
|
|
1330
|
-
if (old_texture != nullptr) { SDL_DestroyTexture(old_texture); }
|
|
1331
|
-
|
|
1332
|
-
if (texture_dst != nullptr) { *texture_dst = texture; }
|
|
1333
|
-
|
|
1334
|
-
return nullptr;
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
ErrorMessage *
|
|
1338
|
-
_windowUpdateRenderer(
|
|
1339
|
-
SDL_Window * window,
|
|
1340
|
-
bool * accelerated,
|
|
1341
|
-
bool * vsync
|
|
1342
|
-
) {
|
|
1343
|
-
int window_id = SDL_GetWindowID(window);
|
|
1344
|
-
|
|
1345
|
-
SDL_Renderer * old_renderer = SDL_GetRenderer(window);
|
|
1346
|
-
if (old_renderer != nullptr) { SDL_DestroyRenderer(old_renderer); }
|
|
1347
|
-
|
|
1348
|
-
int renderer_flags = 0
|
|
1349
|
-
| (*accelerated ? SDL_RENDERER_ACCELERATED : SDL_RENDERER_SOFTWARE)
|
|
1350
|
-
| (*accelerated && *vsync ? SDL_RENDERER_PRESENTVSYNC : 0);
|
|
1351
|
-
|
|
1352
|
-
SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, renderer_flags);
|
|
1353
|
-
if (renderer == nullptr) {
|
|
1354
|
-
RETURN_ERROR("SDL_CreateRenderer(%d, %d) error: %s\n", window_id, renderer_flags, SDL_GetError());
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
SDL_RendererInfo info;
|
|
1358
|
-
SDL_GetRendererInfo(renderer, &info);
|
|
1359
|
-
|
|
1360
|
-
*accelerated = info.flags & SDL_RENDERER_ACCELERATED;
|
|
1361
|
-
*vsync = info.flags & SDL_RENDERER_PRESENTVSYNC;
|
|
1362
|
-
|
|
1363
|
-
int width, height;
|
|
1364
|
-
SDL_GetWindowSize(window, &width, &height);
|
|
1365
|
-
ErrorMessage * error = _windowUpdateTexture(window, renderer, width, height, nullptr);
|
|
1366
|
-
if (error != nullptr) { return error; }
|
|
1367
|
-
|
|
1368
|
-
return nullptr;
|
|
1369
|
-
}
|
|
1370
1439
|
|
|
1371
1440
|
ErrorMessage *
|
|
1372
1441
|
window_create (
|
|
1373
1442
|
const char * title, int display,
|
|
1374
1443
|
int ** x, int ** y, int ** width, int ** height,
|
|
1444
|
+
int * pixel_width, int * pixel_height,
|
|
1375
1445
|
bool visible,
|
|
1376
1446
|
bool * fullscreen,
|
|
1377
1447
|
bool * resizable,
|
|
1378
1448
|
bool * borderless,
|
|
1379
|
-
bool *
|
|
1449
|
+
bool * always_on_top,
|
|
1380
1450
|
bool * accelerated,
|
|
1381
1451
|
bool * vsync,
|
|
1382
1452
|
bool opengl,
|
|
1383
|
-
bool *
|
|
1384
|
-
bool *
|
|
1453
|
+
bool * skip_taskbar,
|
|
1454
|
+
bool * popup_menu,
|
|
1385
1455
|
bool * tooltip,
|
|
1386
1456
|
bool * utility,
|
|
1387
1457
|
int * window_id, void ** native_pointer, int * native_pointer_size
|
|
1388
1458
|
) {
|
|
1389
|
-
SDL_Window * window;
|
|
1390
|
-
|
|
1391
1459
|
if (*x == nullptr) {
|
|
1392
1460
|
*x = (int *) malloc(sizeof(int));
|
|
1393
1461
|
**x = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
|
|
@@ -1405,18 +1473,18 @@ window_create (
|
|
|
1405
1473
|
**height = 480;
|
|
1406
1474
|
}
|
|
1407
1475
|
int desired_flags = 0
|
|
1408
|
-
| SDL_WINDOW_HIDDEN
|
|
1476
|
+
| SDL_WINDOW_HIDDEN | SDL_WINDOW_ALLOW_HIGHDPI
|
|
1409
1477
|
| (*fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)
|
|
1410
1478
|
| (*resizable ? SDL_WINDOW_RESIZABLE : 0)
|
|
1411
1479
|
| (*borderless ? SDL_WINDOW_BORDERLESS : 0)
|
|
1412
|
-
| (*
|
|
1480
|
+
| (*always_on_top ? SDL_WINDOW_ALWAYS_ON_TOP : 0)
|
|
1413
1481
|
| (opengl ? SDL_WINDOW_OPENGL : 0)
|
|
1414
|
-
| (*
|
|
1415
|
-
| (*
|
|
1482
|
+
| (*skip_taskbar ? SDL_WINDOW_SKIP_TASKBAR : 0)
|
|
1483
|
+
| (*popup_menu ? SDL_WINDOW_POPUP_MENU : 0)
|
|
1416
1484
|
| (*tooltip ? SDL_WINDOW_TOOLTIP : 0)
|
|
1417
1485
|
| (*utility ? SDL_WINDOW_UTILITY : 0);
|
|
1418
1486
|
|
|
1419
|
-
window = SDL_CreateWindow(title, **x, **y, **width, **height, desired_flags);
|
|
1487
|
+
SDL_Window * window = SDL_CreateWindow(title, **x, **y, **width, **height, desired_flags);
|
|
1420
1488
|
if (window == nullptr) {
|
|
1421
1489
|
RETURN_ERROR("SDL_CreateWindow() error: %s\n", SDL_GetError());
|
|
1422
1490
|
}
|
|
@@ -1427,9 +1495,9 @@ window_create (
|
|
|
1427
1495
|
*fullscreen = actual_flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP);
|
|
1428
1496
|
*resizable = actual_flags & SDL_WINDOW_RESIZABLE;
|
|
1429
1497
|
*borderless = actual_flags & SDL_WINDOW_BORDERLESS;
|
|
1430
|
-
*
|
|
1431
|
-
*
|
|
1432
|
-
*
|
|
1498
|
+
*always_on_top = actual_flags & SDL_WINDOW_ALWAYS_ON_TOP;
|
|
1499
|
+
*skip_taskbar = actual_flags & SDL_WINDOW_SKIP_TASKBAR;
|
|
1500
|
+
*popup_menu = actual_flags & SDL_WINDOW_POPUP_MENU;
|
|
1433
1501
|
*tooltip = actual_flags & SDL_WINDOW_TOOLTIP;
|
|
1434
1502
|
*utility = actual_flags & SDL_WINDOW_UTILITY;
|
|
1435
1503
|
|
|
@@ -1453,7 +1521,12 @@ window_create (
|
|
|
1453
1521
|
*native_pointer_size = size;
|
|
1454
1522
|
}
|
|
1455
1523
|
|
|
1456
|
-
ErrorMessage * error
|
|
1524
|
+
ErrorMessage * error;
|
|
1525
|
+
|
|
1526
|
+
error = _windowUpdateRenderer(window, accelerated, vsync);
|
|
1527
|
+
if (error != nullptr) { return error; }
|
|
1528
|
+
|
|
1529
|
+
error = _windowGetPixelSize(window, pixel_width, pixel_height);
|
|
1457
1530
|
if (error != nullptr) { return error; }
|
|
1458
1531
|
|
|
1459
1532
|
if (visible) { SDL_ShowWindow(window); }
|
|
@@ -1488,7 +1561,7 @@ window_setPosition (int window_id, int x, int y)
|
|
|
1488
1561
|
}
|
|
1489
1562
|
|
|
1490
1563
|
ErrorMessage *
|
|
1491
|
-
window_setSize (int window_id, int width, int height)
|
|
1564
|
+
window_setSize (int window_id, int width, int height, int * pixel_width, int * pixel_height)
|
|
1492
1565
|
{
|
|
1493
1566
|
SDL_Window * window = SDL_GetWindowFromID(window_id);
|
|
1494
1567
|
if (window == nullptr) {
|
|
@@ -1497,6 +1570,9 @@ window_setSize (int window_id, int width, int height)
|
|
|
1497
1570
|
|
|
1498
1571
|
SDL_SetWindowSize(window, width, height);
|
|
1499
1572
|
|
|
1573
|
+
ErrorMessage * error = _windowGetPixelSize(window, pixel_width, pixel_height);
|
|
1574
|
+
if (error != nullptr) { return error; }
|
|
1575
|
+
|
|
1500
1576
|
return nullptr;
|
|
1501
1577
|
}
|
|
1502
1578
|
|
|
@@ -1694,14 +1770,15 @@ window_render (
|
|
|
1694
1770
|
RETURN_ERROR("SDL_QueryTexture(%d) error: %s\n", window_id, SDL_GetError());
|
|
1695
1771
|
}
|
|
1696
1772
|
|
|
1697
|
-
int
|
|
1698
|
-
|
|
1773
|
+
int pixel_width, pixel_height;
|
|
1774
|
+
ErrorMessage * error = _windowGetPixelSize(window, &pixel_width, &pixel_height);
|
|
1775
|
+
if (error != nullptr) { return error; }
|
|
1699
1776
|
|
|
1700
|
-
if (
|
|
1701
|
-
ErrorMessage * error = _windowUpdateTexture(window, renderer,
|
|
1777
|
+
if (pixel_width != texture_width || pixel_height != texture_height) {
|
|
1778
|
+
ErrorMessage * error = _windowUpdateTexture(window, renderer, pixel_width, pixel_height, &texture);
|
|
1702
1779
|
if (error != nullptr) { return error; }
|
|
1703
|
-
texture_width =
|
|
1704
|
-
texture_height =
|
|
1780
|
+
texture_width = pixel_width;
|
|
1781
|
+
texture_height = pixel_height;
|
|
1705
1782
|
}
|
|
1706
1783
|
|
|
1707
1784
|
SDL_Surface * src_surface = SDL_CreateRGBSurfaceWithFormatFrom(pixels, w, h, SDL_BITSPERPIXEL(format), stride, format);
|
|
@@ -2372,6 +2449,22 @@ clipboard_setText (const char * text)
|
|
|
2372
2449
|
}
|
|
2373
2450
|
|
|
2374
2451
|
|
|
2452
|
+
ErrorMessage *
|
|
2453
|
+
power_getInfo (Variant & info)
|
|
2454
|
+
{
|
|
2455
|
+
int seconds, percent;
|
|
2456
|
+
SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
|
|
2457
|
+
|
|
2458
|
+
MAKE_MAP(info);
|
|
2459
|
+
|
|
2460
|
+
SET_NUM(info, "state", (int) state);
|
|
2461
|
+
SET_NUM(info, "seconds", seconds);
|
|
2462
|
+
SET_NUM(info, "percent", percent);
|
|
2463
|
+
|
|
2464
|
+
return nullptr;
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
|
|
2375
2468
|
ErrorMessage *
|
|
2376
2469
|
cleanup ()
|
|
2377
2470
|
{
|
package/src/native/sdl-helpers.h
CHANGED
|
@@ -44,6 +44,7 @@ ErrorMessage * enum_getPowerLevels (Variant & object);
|
|
|
44
44
|
ErrorMessage * enum_getJoystickTypes (Variant & object);
|
|
45
45
|
ErrorMessage * enum_getControllerAxes (Variant & object);
|
|
46
46
|
ErrorMessage * enum_getControllerButtons (Variant & object);
|
|
47
|
+
ErrorMessage * enum_getPowerStates (Variant & object);
|
|
47
48
|
|
|
48
49
|
ErrorMessage * initialize (Variant & object);
|
|
49
50
|
ErrorMessage * cleanup ();
|
|
@@ -56,6 +57,7 @@ ErrorMessage * video_getDisplays (Variant & list);
|
|
|
56
57
|
ErrorMessage * window_create (
|
|
57
58
|
const char * title, int display,
|
|
58
59
|
int ** x, int ** y, int ** width, int ** height,
|
|
60
|
+
int * pixel_width, int * pixel_height,
|
|
59
61
|
bool visible,
|
|
60
62
|
bool * fullscreen,
|
|
61
63
|
bool * resizable,
|
|
@@ -72,7 +74,10 @@ ErrorMessage * window_create (
|
|
|
72
74
|
);
|
|
73
75
|
ErrorMessage * window_setTitle (int window_id, const char * title);
|
|
74
76
|
ErrorMessage * window_setPosition (int window_id, int x, int y);
|
|
75
|
-
ErrorMessage * window_setSize (
|
|
77
|
+
ErrorMessage * window_setSize (
|
|
78
|
+
int window_id, int width, int height,
|
|
79
|
+
int * pixel_width, int * pixel_height
|
|
80
|
+
);
|
|
76
81
|
ErrorMessage * window_setFullscreen (int window_id, bool * fullscreen);
|
|
77
82
|
ErrorMessage * window_setResizable (int window_id, bool * resizable);
|
|
78
83
|
ErrorMessage * window_setBorderless (int window_id, bool * borderless);
|
|
@@ -162,6 +167,8 @@ ErrorMessage * audio_dequeue (int audio_id, void * dst, int size, int * num);
|
|
|
162
167
|
ErrorMessage * clipboard_getText (const char ** text);
|
|
163
168
|
ErrorMessage * clipboard_setText (const char * text);
|
|
164
169
|
|
|
170
|
+
ErrorMessage * power_getInfo (Variant & info);
|
|
171
|
+
|
|
165
172
|
} // namespace
|
|
166
173
|
|
|
167
174
|
#endif // _SDL_H_
|
package/src/types/index.d.ts
CHANGED
|
@@ -5,6 +5,20 @@ export namespace Events {
|
|
|
5
5
|
|
|
6
6
|
type PreventCallback = () => void
|
|
7
7
|
|
|
8
|
+
namespace Display {
|
|
9
|
+
|
|
10
|
+
interface DisplayEvent extends BaseEvent {
|
|
11
|
+
readonly display: Sdl.Video.Display
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface Add extends DisplayEvent { readonly type: 'deviceAdd' }
|
|
15
|
+
interface Remove extends DisplayEvent { readonly type: 'deviceRemove' }
|
|
16
|
+
interface Orient extends DisplayEvent { readonly type: 'deviceOrient' }
|
|
17
|
+
|
|
18
|
+
type Any = Add | Remove | Orient
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
8
22
|
namespace Window {
|
|
9
23
|
|
|
10
24
|
interface WindowEvent extends BaseEvent {}
|
|
@@ -67,8 +81,10 @@ export namespace Events {
|
|
|
67
81
|
}
|
|
68
82
|
interface Resize extends WindowEvent {
|
|
69
83
|
readonly type: 'resize'
|
|
70
|
-
readonly width: number
|
|
84
|
+
readonly width: number
|
|
71
85
|
readonly height: number
|
|
86
|
+
readonly pixelWidth: number
|
|
87
|
+
readonly pixelHeight: number
|
|
72
88
|
}
|
|
73
89
|
interface Focus extends WindowEvent { readonly type: 'focus' }
|
|
74
90
|
interface Blur extends WindowEvent { readonly type: 'blur' }
|
|
@@ -117,6 +133,7 @@ export namespace Events {
|
|
|
117
133
|
| DropText
|
|
118
134
|
| DropFile
|
|
119
135
|
| DropComplete
|
|
136
|
+
|
|
120
137
|
}
|
|
121
138
|
|
|
122
139
|
namespace Joystick {
|
|
@@ -380,6 +397,9 @@ export namespace Sdl {
|
|
|
380
397
|
readonly height: number
|
|
381
398
|
setSize (width: number, height: number): void
|
|
382
399
|
|
|
400
|
+
readonly pixelWidth: number
|
|
401
|
+
readonly pixelHeight: number
|
|
402
|
+
|
|
383
403
|
readonly visible: boolean
|
|
384
404
|
show (show?: boolean): void
|
|
385
405
|
hide (): void
|
|
@@ -430,6 +450,11 @@ export namespace Sdl {
|
|
|
430
450
|
}
|
|
431
451
|
|
|
432
452
|
interface Module {
|
|
453
|
+
on (event: 'displayAdd', listener: (event: Events.Display.Add) => void): this
|
|
454
|
+
on (event: 'displayRemove', listener: (event: Events.Display.Remove) => void): this
|
|
455
|
+
on (event: 'displayOrient', listener: (event: Events.Display.Orient) => void): this
|
|
456
|
+
on (event: '*', listener: (event: Events.Display.Any) => void): this
|
|
457
|
+
|
|
433
458
|
readonly displays: Display[]
|
|
434
459
|
|
|
435
460
|
readonly windows: Window[]
|
|
@@ -1055,6 +1080,27 @@ export namespace Sdl {
|
|
|
1055
1080
|
|
|
1056
1081
|
}
|
|
1057
1082
|
|
|
1083
|
+
namespace Power {
|
|
1084
|
+
|
|
1085
|
+
type PowerState
|
|
1086
|
+
= 'unknown'
|
|
1087
|
+
| 'noBattery'
|
|
1088
|
+
| 'battery'
|
|
1089
|
+
| 'charging'
|
|
1090
|
+
| 'charged'
|
|
1091
|
+
|
|
1092
|
+
interface PowerInfo {
|
|
1093
|
+
state: PowerState
|
|
1094
|
+
seconds: number | null
|
|
1095
|
+
percent: number | null
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
interface Module {
|
|
1099
|
+
readonly info: PowerInfo
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1058
1104
|
interface Module {
|
|
1059
1105
|
readonly info: Info
|
|
1060
1106
|
readonly video: Video.Module
|
|
@@ -1064,7 +1110,9 @@ export namespace Sdl {
|
|
|
1064
1110
|
readonly controller: Controller.Module
|
|
1065
1111
|
readonly audio: Audio.Module
|
|
1066
1112
|
readonly clipboard: Clipboard.Module
|
|
1113
|
+
readonly power: Power.Module
|
|
1067
1114
|
}
|
|
1115
|
+
|
|
1068
1116
|
}
|
|
1069
1117
|
|
|
1070
1118
|
declare const sdl: Sdl.Module
|