@kmamal/sdl 0.8.4 → 0.9.1
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 +91 -30
- package/package.json +1 -1
- package/src/javascript/video/window.js +27 -0
- package/src/native/binding.cpp +37 -16
- package/src/native/cocoa-window.h +3 -1
- package/src/native/cocoa-window.mm +11 -1
- package/src/native/sdl-helpers.cpp +118 -82
- package/src/native/sdl-helpers.h +5 -3
- package/src/types/index.d.ts +6 -0
package/README.md
CHANGED
|
@@ -12,11 +12,11 @@ Prebuilt binaries are available for x64 architectures, arm-based Macs, and Raspb
|
|
|
12
12
|
|
|
13
13
|
#### Canvas, WebGL, and WebGPU
|
|
14
14
|
|
|
15
|
-
One goal of this project is to allow using Canvas
|
|
16
|
-
You can
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
One goal of this project is to allow using Canvas, WebGL, and WebGPU without a browser.
|
|
16
|
+
You can use the [canvas](https://www.npmjs.com/package/canvas) package to render using the canvas API.
|
|
17
|
+
For WebGL you can use [@kmamal/gl](https://github.com/kmamal/headless-gl#readme) and for WebGPU you can use [@kmamal/gpu](https://github.com/kmamal/gpu#readme).
|
|
18
|
+
Both WebGL and WebGPU support rendering directly to the window (without any intermediate buffer copying).
|
|
19
|
+
Canvas still uses an intermediate buffer, but that might change in the future.
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
## Installation
|
|
@@ -65,7 +65,7 @@ window.render(width, height, width * 4, 'bgra32', buffer)
|
|
|
65
65
|
import sdl from '@kmamal/sdl'
|
|
66
66
|
import createContext from '@kmamal/gl'
|
|
67
67
|
|
|
68
|
-
const window = sdl.video.createWindow({title: "WebGL", opengl: true })
|
|
68
|
+
const window = sdl.video.createWindow({ title: "WebGL", opengl: true })
|
|
69
69
|
const { pixelWidth: width, pixelHeight: height, native } = window
|
|
70
70
|
const gl = createContext(width, height, { window: native })
|
|
71
71
|
|
|
@@ -75,6 +75,38 @@ gl.clear(gl.COLOR_BUFFER_BIT)
|
|
|
75
75
|
gl.swap()
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
+
### WebGPU
|
|
79
|
+
```js
|
|
80
|
+
import sdl from '@kmamal/sdl'
|
|
81
|
+
import gpu from '@kmamal/gpu'
|
|
82
|
+
|
|
83
|
+
const window = sdl.video.createWindow({ title: "WebGPU", webgpu: true })
|
|
84
|
+
|
|
85
|
+
const instance = gpu.create([])
|
|
86
|
+
const adapter = await instance.requestAdapter()
|
|
87
|
+
const device = await adapter.requestDevice()
|
|
88
|
+
|
|
89
|
+
const renderer = gpu.renderGPUDeviceToWindow({ device, window })
|
|
90
|
+
|
|
91
|
+
// Clear screen to red
|
|
92
|
+
const commandEncoder = device.createCommandEncoder()
|
|
93
|
+
const renderPass = commandEncoder.beginRenderPass({
|
|
94
|
+
colorAttachments: [
|
|
95
|
+
{
|
|
96
|
+
view: renderer.getCurrentTextureView(),
|
|
97
|
+
clearValue: { r: 1.0, g: 0.0, b: 0.0, a: 1.0 },
|
|
98
|
+
loadOp: 'clear',
|
|
99
|
+
storeOp: 'store',
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
})
|
|
103
|
+
renderPass.end()
|
|
104
|
+
device.queue.submit([ commandEncoder.finish() ])
|
|
105
|
+
|
|
106
|
+
renderer.swap()
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
|
|
78
110
|
There are more examples [in the `examples/` folder](https://github.com/kmamal/node-sdl/tree/master/examples).
|
|
79
111
|
|
|
80
112
|
|
|
@@ -148,6 +180,7 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
148
180
|
* [window.vsync](#windowvsync)
|
|
149
181
|
* [window.setVsync(vsync)](#windowsetvsyncvsync)
|
|
150
182
|
* [window.opengl](#windowopengl)
|
|
183
|
+
* [window.webgpu](#windowwebgpu)
|
|
151
184
|
* [window.native](#windownative)
|
|
152
185
|
* [window.maximized](#windowmaximized)
|
|
153
186
|
* [window.maximize()](#windowmaximize)
|
|
@@ -163,6 +196,8 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
|
|
|
163
196
|
* [window.utility](#windowutility)
|
|
164
197
|
* [window.render(width, height, stride, format, buffer)](#windowrenderwidth-height-stride-format-buffer)
|
|
165
198
|
* [window.setIcon(width, height, stride, format, buffer)](#windowseticonwidth-height-stride-format-buffer)
|
|
199
|
+
* [window.flash(untilFocused)](#windowflashuntilfocused)
|
|
200
|
+
* [window.stopFlashing()](#windowstopflashing)
|
|
166
201
|
* [window.destroyed](#windowdestroyed)
|
|
167
202
|
* [window.destroy()](#windowdestroy)
|
|
168
203
|
* [sdl.keyboard](#sdlkeyboard)
|
|
@@ -542,6 +577,7 @@ The window that the mouse is hovered over, or `null` if the mouse is not over a
|
|
|
542
577
|
* `accelerated: <boolean>` Set to `false` to disable hardware accelerated rendering. Default: `true`
|
|
543
578
|
* `vsync: <boolean>` Set to `false` to disable frame rate synchronization. Default: `true`
|
|
544
579
|
* `opengl: <boolean>` Set to `true` to create an OpenGL-compatible window (for use with [@kmamal/gl](https://github.com/kmamal/headless-gl#readme)). Default: `false`
|
|
580
|
+
* `webgpu: <boolean>` Set to `true` to create an WebGPU-compatible window (for use with [@kmamal/gpu](https://github.com/kmamal/gpu#readme)). Default: `false`
|
|
545
581
|
* `skipTaskbar: <boolean>` X11 only. Set to `true` to not add this window to the taskbar. Default: `false`
|
|
546
582
|
* `popupMenu: <boolean>` X11 only. Set to `true` to treat this window like a popup menu. Default: `false`
|
|
547
583
|
* `tooltip: <boolean>` X11 only. Set to `true` to treat this window like a tooltip. Default: `false`
|
|
@@ -553,9 +589,11 @@ Creates a new window.
|
|
|
553
589
|
The following restrictions apply:
|
|
554
590
|
* If you specify the `display` option, you can't also specify the `x` or `y` options, and vice-versa.
|
|
555
591
|
* The `resizable` and `borderless` options are mutually exclusive.
|
|
592
|
+
* The `opengl` and `webgpu` options are mutually exclusive.
|
|
556
593
|
* The `vsync` option only applies to windows that are also `accelerated`.
|
|
594
|
+
* The `accelerated` and `vsync` options have no effect if either `opengl` or `webgpu` is also specified.
|
|
557
595
|
|
|
558
|
-
If you set the `opengl`
|
|
596
|
+
If you set the `opengl` or `webgpu` options, then you can only render to the window with OpenGL/WebGPU calls.
|
|
559
597
|
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer) will fail.
|
|
560
598
|
|
|
561
599
|
## class Window
|
|
@@ -800,8 +838,7 @@ Will be `true` if the window is visible.
|
|
|
800
838
|
|
|
801
839
|
### window.show([show])
|
|
802
840
|
|
|
803
|
-
* `show: <boolean>` Set to `true` to make the window visible, `false` to hide it.
|
|
804
|
-
Default: `true`
|
|
841
|
+
* `show: <boolean>` Set to `true` to make the window visible, `false` to hide it. Default: `true`
|
|
805
842
|
|
|
806
843
|
Shows or hides the window.
|
|
807
844
|
|
|
@@ -867,6 +904,8 @@ Will be `true` if the window is using hardware accelerated rendering.
|
|
|
867
904
|
|
|
868
905
|
Changes the window's accelerated property.
|
|
869
906
|
|
|
907
|
+
If you have set the `opengl` or `webgpu` options, then calls to this function will fail.
|
|
908
|
+
|
|
870
909
|
### window.vsync
|
|
871
910
|
|
|
872
911
|
* `<boolean>`
|
|
@@ -881,6 +920,8 @@ Note that vsync can only be used if that window is also [`accelerated`](#windowa
|
|
|
881
920
|
|
|
882
921
|
Changes the window's vsync property.
|
|
883
922
|
|
|
923
|
+
If you have set the `opengl` or `webgpu` options, then calls to this function will fail.
|
|
924
|
+
|
|
884
925
|
### window.opengl
|
|
885
926
|
|
|
886
927
|
* `<boolean>`
|
|
@@ -889,12 +930,20 @@ Will be `true` if the window was created in OpenGl mode.
|
|
|
889
930
|
In OpenGL mode, you can only render to the window with OpenGL calls.
|
|
890
931
|
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer) will fail.
|
|
891
932
|
|
|
933
|
+
### window.webgpu
|
|
934
|
+
|
|
935
|
+
* `<boolean>`
|
|
936
|
+
|
|
937
|
+
Will be `true` if the window was created in WebGPU mode.
|
|
938
|
+
In WebGPU mode, you can only render to the window with WebGPU calls.
|
|
939
|
+
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer) will fail.
|
|
940
|
+
|
|
892
941
|
### window.native
|
|
893
942
|
|
|
894
943
|
* `<any>`
|
|
895
944
|
|
|
896
945
|
Holds a copy of the native (platform-specific) representation of the window.
|
|
897
|
-
Only used for passing to [@kmamal/gl](https://github.com/kmamal/headless-gl#readme).
|
|
946
|
+
Only used for passing to [@kmamal/gl](https://github.com/kmamal/headless-gl#readme) or [@kmamal/gpu](https://github.com/kmamal/gpu#readme).
|
|
898
947
|
|
|
899
948
|
### window.maximized
|
|
900
949
|
|
|
@@ -975,12 +1024,26 @@ Such a window will always be treated as a utility window.
|
|
|
975
1024
|
Displays an image in the window.
|
|
976
1025
|
The provided image will be stretched over the entire window.
|
|
977
1026
|
|
|
1027
|
+
If you set the `opengl` or `webgpu` options, then you can only render to the window with OpenGL/WebGPU calls.
|
|
1028
|
+
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer) will fail.
|
|
1029
|
+
|
|
978
1030
|
### window.setIcon(width, height, stride, format, buffer)
|
|
979
1031
|
|
|
980
1032
|
* `width, height, stride, format, buffer: `[`<Image>`](#image-data) The image to display as the icon of the window.
|
|
981
1033
|
|
|
982
1034
|
Set's the window's icon, usually displayed in the title bar and the taskbar.
|
|
983
1035
|
|
|
1036
|
+
### window.flash(untilFocused)
|
|
1037
|
+
|
|
1038
|
+
* `untilFocused: <boolean>` Whether to keep flashing the window until the user focuses it. Default: `false`
|
|
1039
|
+
|
|
1040
|
+
Flash the window briefly to get attention.
|
|
1041
|
+
If `untilFocused` is set, the window will flash until the user focuses it.
|
|
1042
|
+
|
|
1043
|
+
### window.stopFlashing()
|
|
1044
|
+
|
|
1045
|
+
Stop the window from flashing.
|
|
1046
|
+
|
|
984
1047
|
### window.destroyed
|
|
985
1048
|
|
|
986
1049
|
* `<boolean>`
|
|
@@ -1378,8 +1441,7 @@ The hotspot represents the pixel that is considered to be under the mouse.
|
|
|
1378
1441
|
|
|
1379
1442
|
### sdl.mouse.showCursor([show])
|
|
1380
1443
|
|
|
1381
|
-
* `show: <boolean>` If `true` then the mouse cursor will be visible.
|
|
1382
|
-
Default `true`.
|
|
1444
|
+
* `show: <boolean>` If `true` then the mouse cursor will be visible. Default: `true`
|
|
1383
1445
|
|
|
1384
1446
|
Changes the visibility of the mouse cursor.
|
|
1385
1447
|
|
|
@@ -1389,8 +1451,7 @@ Equivalent to [`sdl.mouse.showCursor(false)`](#sdlmouseshowcursorshow).
|
|
|
1389
1451
|
|
|
1390
1452
|
### sdl.mouse.capture([capture])
|
|
1391
1453
|
|
|
1392
|
-
* `capture: <boolean>` If `true` the mouse will be captured by the current window.
|
|
1393
|
-
Default `true`.
|
|
1454
|
+
* `capture: <boolean>` If `true` the mouse will be captured by the current window. Default: `true`
|
|
1394
1455
|
|
|
1395
1456
|
When the mouse has been captured you will continue receiving mouse events even if the mouse is not over a window.
|
|
1396
1457
|
|
|
@@ -1639,9 +1700,9 @@ Will be `true` if the joystick has rumble motors.
|
|
|
1639
1700
|
|
|
1640
1701
|
### joystickInstance.rumble([low, [high, [duration]]])
|
|
1641
1702
|
|
|
1642
|
-
* `low: <number>` The intensity of the low frequency rumble motor, from `0` to `1`. Default `1
|
|
1643
|
-
* `high: <number>` The intensity of the high frequency rumble motor, from `0` to `1`. Default `1
|
|
1644
|
-
* `duration: <number>` The duration of the rumble, in ms. Default `1e3
|
|
1703
|
+
* `low: <number>` The intensity of the low frequency rumble motor, from `0` to `1`. Default: `1`
|
|
1704
|
+
* `high: <number>` The intensity of the high frequency rumble motor, from `0` to `1`. Default: `1`
|
|
1705
|
+
* `duration: <number>` The duration of the rumble, in ms. Default: `1e3`
|
|
1645
1706
|
|
|
1646
1707
|
Makes the joystick rumble for a set `duration`.
|
|
1647
1708
|
Calling this function again before `duration` has ran out, overrides the previous call.
|
|
@@ -1659,9 +1720,9 @@ Will be `true` if the joystick has rumble motors on the triggers.
|
|
|
1659
1720
|
|
|
1660
1721
|
### joystickInstance.rumbleTriggers([left, [right, [duration]]])
|
|
1661
1722
|
|
|
1662
|
-
* `left: <number>` The intensity of the left trigger rumble motor, from `0` to `1`. Default `1
|
|
1663
|
-
* `right: <number>` The intensity of the right trigger rumble motor, from `0` to `1`. Default `1
|
|
1664
|
-
* `duration: <number>` The duration of the rumble, in ms. Default `1e3
|
|
1723
|
+
* `left: <number>` The intensity of the left trigger rumble motor, from `0` to `1`. Default: `1`
|
|
1724
|
+
* `right: <number>` The intensity of the right trigger rumble motor, from `0` to `1`. Default: `1`
|
|
1725
|
+
* `duration: <number>` The duration of the rumble, in ms. Default: `1e3`
|
|
1665
1726
|
|
|
1666
1727
|
Makes the joystick triggers rumble for a set `duration`.
|
|
1667
1728
|
Calling this function again before `duration` has ran out, overrides the previous call.
|
|
@@ -1903,9 +1964,9 @@ Will be `true` if the controller has rumble motors.
|
|
|
1903
1964
|
|
|
1904
1965
|
### controllerInstance.rumble([low, [high, [duration]]])
|
|
1905
1966
|
|
|
1906
|
-
* `low: <number>` The intensity of the low frequency rumble motor, from `0` to `1`. Default `1
|
|
1907
|
-
* `high: <number>` The intensity of the high frequency rumble motor, from `0` to `1`. Default `1
|
|
1908
|
-
* `duration: <number>` The duration of the rumble, in ms. Default `1e3
|
|
1967
|
+
* `low: <number>` The intensity of the low frequency rumble motor, from `0` to `1`. Default: `1`
|
|
1968
|
+
* `high: <number>` The intensity of the high frequency rumble motor, from `0` to `1`. Default: `1`
|
|
1969
|
+
* `duration: <number>` The duration of the rumble, in ms. Default: `1e3`
|
|
1909
1970
|
|
|
1910
1971
|
Makes the controller rumble for a set `duration`.
|
|
1911
1972
|
Calling this function again before `duration` has ran out, overrides the previous call.
|
|
@@ -1923,9 +1984,9 @@ Will be `true` if the controller has rumble motors on the triggers.
|
|
|
1923
1984
|
|
|
1924
1985
|
### controllerInstance.rumbleTriggers([left, [right, [duration]]])
|
|
1925
1986
|
|
|
1926
|
-
* `left: <number>` The intensity of the left trigger rumble motor, from `0` to `1`. Default `1
|
|
1927
|
-
* `right: <number>` The intensity of the right trigger rumble motor, from `0` to `1`. Default `1
|
|
1928
|
-
* `duration: <number>` The duration of the rumble, in ms. Default `1e3
|
|
1987
|
+
* `left: <number>` The intensity of the left trigger rumble motor, from `0` to `1`. Default: `1`
|
|
1988
|
+
* `right: <number>` The intensity of the right trigger rumble motor, from `0` to `1`. Default: `1`
|
|
1989
|
+
* `duration: <number>` The duration of the rumble, in ms. Default: `1e3`
|
|
1929
1990
|
|
|
1930
1991
|
Makes the controller triggers rumble for a set `duration`.
|
|
1931
1992
|
Calling this function again before `duration` has ran out, overrides the previous call.
|
|
@@ -2232,10 +2293,10 @@ const playbackInstance = sdl.audio.openDevice({ type: 'playback' })
|
|
|
2232
2293
|
* `type: <string>`: Should be either `'playback'` or `'recording'`.
|
|
2233
2294
|
* `name: <string>|<null>`: The name of the device. Optional.
|
|
2234
2295
|
* `options: <object>`
|
|
2235
|
-
* `channels: <number>`: Number of audio channels. Valid values: `1`, `2`, `4`, `6`. Default `1
|
|
2236
|
-
* `frequency: <number>`: The sampling frequency in frames per second. Default `48e3
|
|
2237
|
-
* `format: `[`<SampleFormat>`](#sample-formats): The binary format for each sample. Default `'f32'
|
|
2238
|
-
* `buffered: <number>`: Number of frames that will be buffered by the driver. Must be a power of `2`. Default `4096
|
|
2296
|
+
* `channels: <number>`: Number of audio channels. Valid values: `1`, `2`, `4`, `6`. Default: `1`
|
|
2297
|
+
* `frequency: <number>`: The sampling frequency in frames per second. Default: `48e3`
|
|
2298
|
+
* `format: `[`<SampleFormat>`](#sample-formats): The binary format for each sample. Default: `'f32'`
|
|
2299
|
+
* `buffered: <number>`: Number of frames that will be buffered by the driver. Must be a power of `2`. Default: `4096`
|
|
2239
2300
|
* Returns: [`<AudioInstance>`](#class-audioinstance) an object representing the opened audio device instance.
|
|
2240
2301
|
|
|
2241
2302
|
Initializes an audio device for playback/recording and returns a corresponding instance.
|
package/package.json
CHANGED
|
@@ -48,6 +48,7 @@ class Window extends EventsViaPoll {
|
|
|
48
48
|
accelerated = true,
|
|
49
49
|
vsync = true,
|
|
50
50
|
opengl = false,
|
|
51
|
+
webgpu = false,
|
|
51
52
|
skipTaskbar = false,
|
|
52
53
|
popupMenu = false,
|
|
53
54
|
tooltip = false,
|
|
@@ -74,12 +75,14 @@ class Window extends EventsViaPoll {
|
|
|
74
75
|
if (typeof accelerated !== 'boolean') { throw Object.assign(new Error("accelerated must be a boolean"), { accelerated }) }
|
|
75
76
|
if (typeof vsync !== 'boolean') { throw Object.assign(new Error("vsync must be a boolean"), { vsync }) }
|
|
76
77
|
if (typeof opengl !== 'boolean') { throw Object.assign(new Error("opengl must be a boolean"), { opengl }) }
|
|
78
|
+
if (typeof webgpu !== 'boolean') { throw Object.assign(new Error("webgpu must be a boolean"), { webgpu }) }
|
|
77
79
|
if (typeof skipTaskbar !== 'boolean') { throw Object.assign(new Error("skipTaskbar must be a boolean"), { skipTaskbar }) }
|
|
78
80
|
if (typeof popupMenu !== 'boolean') { throw Object.assign(new Error("popupMenu must be a boolean"), { popupMenu }) }
|
|
79
81
|
if (typeof tooltip !== 'boolean') { throw Object.assign(new Error("tooltip must be a boolean"), { tooltip }) }
|
|
80
82
|
if (typeof utility !== 'boolean') { throw Object.assign(new Error("utility must be a boolean"), { utility }) }
|
|
81
83
|
if (display && (Number.isFinite(x) || Number.isFinite(y))) { throw Object.assign(new Error("display and x/y are mutually exclusive"), { display, x, y }) }
|
|
82
84
|
if (resizable && borderless) { throw Object.assign(new Error("resizable and borderless are mutually exclusive"), { resizable, borderless }) }
|
|
85
|
+
if (opengl && webgpu) { throw Object.assign(new Error("opengl and webgpu are mutually exclusive"), { opengl, webgpu }) }
|
|
83
86
|
|
|
84
87
|
let displayIndex = 0
|
|
85
88
|
if (display) {
|
|
@@ -104,6 +107,7 @@ class Window extends EventsViaPoll {
|
|
|
104
107
|
accelerated,
|
|
105
108
|
vsync,
|
|
106
109
|
opengl,
|
|
110
|
+
webgpu,
|
|
107
111
|
skipTaskbar,
|
|
108
112
|
popupMenu,
|
|
109
113
|
tooltip,
|
|
@@ -132,6 +136,7 @@ class Window extends EventsViaPoll {
|
|
|
132
136
|
this._title = title
|
|
133
137
|
this._visible = visible
|
|
134
138
|
this._opengl = opengl
|
|
139
|
+
this._webgpu = webgpu
|
|
135
140
|
|
|
136
141
|
this._focused = false
|
|
137
142
|
this._hovered = false
|
|
@@ -256,6 +261,9 @@ class Window extends EventsViaPoll {
|
|
|
256
261
|
setAccelerated (accelerated) {
|
|
257
262
|
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
258
263
|
|
|
264
|
+
if (this._opengl) { throw new Error("can't call setAccelerated in opengl mode") }
|
|
265
|
+
if (this._webgpu) { throw new Error("can't call setAccelerated in webgpu mode") }
|
|
266
|
+
|
|
259
267
|
if (typeof accelerated !== 'boolean') { throw Object.assign(new Error("accelerated must be a boolean"), { accelerated }) }
|
|
260
268
|
|
|
261
269
|
[ this._accelerated, this._vsync ] = Bindings.window_setAcceleratedAndVsync(this._id, accelerated, this._vsync)
|
|
@@ -265,12 +273,16 @@ class Window extends EventsViaPoll {
|
|
|
265
273
|
setVsync (vsync) {
|
|
266
274
|
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
267
275
|
|
|
276
|
+
if (this._opengl) { throw new Error("can't call setVsync in opengl mode") }
|
|
277
|
+
if (this._webgpu) { throw new Error("can't call setVsync in webgpu mode") }
|
|
278
|
+
|
|
268
279
|
if (typeof vsync !== 'boolean') { throw Object.assign(new Error("vsync must be a boolean"), { vsync }) }
|
|
269
280
|
|
|
270
281
|
[ this._accelerated, this._vsync ] = Bindings.window_setAcceleratedAndVsync(this._id, this._accelerated, vsync)
|
|
271
282
|
}
|
|
272
283
|
|
|
273
284
|
get opengl () { return this._opengl }
|
|
285
|
+
get webgpu () { return this._webgpu }
|
|
274
286
|
get native () { return this._native }
|
|
275
287
|
|
|
276
288
|
get minimized () { return this._minimized }
|
|
@@ -325,6 +337,7 @@ class Window extends EventsViaPoll {
|
|
|
325
337
|
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
326
338
|
|
|
327
339
|
if (this._opengl) { throw new Error("can't call render in opengl mode") }
|
|
340
|
+
if (this._webgpu) { throw new Error("can't call render in webgpu mode") }
|
|
328
341
|
|
|
329
342
|
const _format = Enums.pixelFormat[format] ?? null
|
|
330
343
|
|
|
@@ -361,6 +374,20 @@ class Window extends EventsViaPoll {
|
|
|
361
374
|
Bindings.window_setIcon(this._id, width, height, stride, _format, buffer)
|
|
362
375
|
}
|
|
363
376
|
|
|
377
|
+
flash (untilFocused = false) {
|
|
378
|
+
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
379
|
+
|
|
380
|
+
if (typeof untilFocused !== 'boolean') { throw Object.assign(new Error("untilFocused must be a boolean"), { untilFocused }) }
|
|
381
|
+
|
|
382
|
+
Bindings.window_flash(this._id, untilFocused ? 2 : 1)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
stopFlashing () {
|
|
386
|
+
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
387
|
+
|
|
388
|
+
Bindings.window_flash(this._id, 0)
|
|
389
|
+
}
|
|
390
|
+
|
|
364
391
|
get destroyed () { return this._destroyed }
|
|
365
392
|
destroy () {
|
|
366
393
|
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
package/src/native/binding.cpp
CHANGED
|
@@ -321,7 +321,7 @@ window_create(napi_env env, napi_callback_info info)
|
|
|
321
321
|
int * height = nullptr;
|
|
322
322
|
void * native_pointer = nullptr;
|
|
323
323
|
|
|
324
|
-
napi_value argv[
|
|
324
|
+
napi_value argv[19];
|
|
325
325
|
size_t argc = sizeof(argv) / sizeof(napi_value);
|
|
326
326
|
CALL_NAPI(napi_get_cb_info, info, &argc, argv, nullptr, nullptr);
|
|
327
327
|
|
|
@@ -360,7 +360,7 @@ window_create(napi_env env, napi_callback_info info)
|
|
|
360
360
|
}
|
|
361
361
|
|
|
362
362
|
bool visible, fullscreen, resizable, borderless, always_on_top,
|
|
363
|
-
accelerated, vsync, opengl,
|
|
363
|
+
accelerated, vsync, opengl, webgpu,
|
|
364
364
|
skip_taskbar, popup_menu, tooltip, utility;
|
|
365
365
|
CALL_NAPI(napi_get_value_bool, argv[6], &visible);
|
|
366
366
|
CALL_NAPI(napi_get_value_bool, argv[7], &fullscreen);
|
|
@@ -370,21 +370,22 @@ window_create(napi_env env, napi_callback_info info)
|
|
|
370
370
|
CALL_NAPI(napi_get_value_bool, argv[11], &accelerated);
|
|
371
371
|
CALL_NAPI(napi_get_value_bool, argv[12], &vsync);
|
|
372
372
|
CALL_NAPI(napi_get_value_bool, argv[13], &opengl);
|
|
373
|
-
CALL_NAPI(napi_get_value_bool, argv[14], &
|
|
374
|
-
CALL_NAPI(napi_get_value_bool, argv[15], &
|
|
375
|
-
CALL_NAPI(napi_get_value_bool, argv[16], &
|
|
376
|
-
CALL_NAPI(napi_get_value_bool, argv[17], &
|
|
373
|
+
CALL_NAPI(napi_get_value_bool, argv[14], &webgpu);
|
|
374
|
+
CALL_NAPI(napi_get_value_bool, argv[15], &skip_taskbar);
|
|
375
|
+
CALL_NAPI(napi_get_value_bool, argv[16], &popup_menu);
|
|
376
|
+
CALL_NAPI(napi_get_value_bool, argv[17], &tooltip);
|
|
377
|
+
CALL_NAPI(napi_get_value_bool, argv[18], &utility);
|
|
377
378
|
|
|
378
|
-
int pixel_width, pixel_height, window_id,
|
|
379
|
+
int pixel_width, pixel_height, window_id, native_size;
|
|
379
380
|
|
|
380
381
|
CALL_SDL_HELPER(window_create,
|
|
381
382
|
title, display,
|
|
382
383
|
&x, &y, &width, &height,
|
|
383
384
|
&pixel_width, &pixel_height,
|
|
384
385
|
visible, &fullscreen, &resizable, &borderless, &always_on_top,
|
|
385
|
-
&accelerated, &vsync, opengl,
|
|
386
|
+
&accelerated, &vsync, opengl, webgpu,
|
|
386
387
|
&skip_taskbar, &popup_menu, &tooltip, &utility,
|
|
387
|
-
&window_id, &native_pointer, &
|
|
388
|
+
&window_id, &native_pointer, &native_size
|
|
388
389
|
);
|
|
389
390
|
|
|
390
391
|
napi_value key, value;
|
|
@@ -470,7 +471,7 @@ window_create(napi_env env, napi_callback_info info)
|
|
|
470
471
|
|
|
471
472
|
if (native_pointer) {
|
|
472
473
|
CALL_NAPI(napi_create_external_buffer,
|
|
473
|
-
|
|
474
|
+
native_size, native_pointer, freePointer, native_pointer,
|
|
474
475
|
&value);
|
|
475
476
|
CALL_NAPI(napi_create_string_latin1, "native", 6, &key);
|
|
476
477
|
CALL_NAPI(napi_set_property, result, key, value);
|
|
@@ -768,7 +769,7 @@ window_restore(napi_env env, napi_callback_info info)
|
|
|
768
769
|
}
|
|
769
770
|
|
|
770
771
|
napi_value
|
|
771
|
-
|
|
772
|
+
window_render(napi_env env, napi_callback_info info)
|
|
772
773
|
{
|
|
773
774
|
napi_value argv[6];
|
|
774
775
|
size_t argc = sizeof(argv) / sizeof(napi_value);
|
|
@@ -788,14 +789,14 @@ window_setIcon(napi_env env, napi_callback_info info)
|
|
|
788
789
|
void * pixels;
|
|
789
790
|
CALL_NAPI(napi_get_buffer_info, argv[5], &pixels, nullptr);
|
|
790
791
|
|
|
791
|
-
CALL_SDL_HELPER(
|
|
792
|
+
CALL_SDL_HELPER(window_render, window_id, w, h, stride, format, pixels);
|
|
792
793
|
|
|
793
794
|
cleanup:
|
|
794
795
|
return nullptr;
|
|
795
796
|
}
|
|
796
797
|
|
|
797
798
|
napi_value
|
|
798
|
-
|
|
799
|
+
window_setIcon(napi_env env, napi_callback_info info)
|
|
799
800
|
{
|
|
800
801
|
napi_value argv[6];
|
|
801
802
|
size_t argc = sizeof(argv) / sizeof(napi_value);
|
|
@@ -815,7 +816,26 @@ window_render(napi_env env, napi_callback_info info)
|
|
|
815
816
|
void * pixels;
|
|
816
817
|
CALL_NAPI(napi_get_buffer_info, argv[5], &pixels, nullptr);
|
|
817
818
|
|
|
818
|
-
CALL_SDL_HELPER(
|
|
819
|
+
CALL_SDL_HELPER(window_setIcon, window_id, w, h, stride, format, pixels);
|
|
820
|
+
|
|
821
|
+
cleanup:
|
|
822
|
+
return nullptr;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
napi_value
|
|
826
|
+
window_flash(napi_env env, napi_callback_info info)
|
|
827
|
+
{
|
|
828
|
+
napi_value argv[2];
|
|
829
|
+
size_t argc = sizeof(argv) / sizeof(napi_value);
|
|
830
|
+
CALL_NAPI(napi_get_cb_info, info, &argc, argv, nullptr, nullptr);
|
|
831
|
+
|
|
832
|
+
int window_id;
|
|
833
|
+
CALL_NAPI(napi_get_value_int32, argv[0], &window_id);
|
|
834
|
+
|
|
835
|
+
int type;
|
|
836
|
+
CALL_NAPI(napi_get_value_int32, argv[1], &type);
|
|
837
|
+
|
|
838
|
+
CALL_SDL_HELPER(window_flash, window_id, type);
|
|
819
839
|
|
|
820
840
|
cleanup:
|
|
821
841
|
return nullptr;
|
|
@@ -1608,8 +1628,9 @@ init (napi_env env, napi_value exports)
|
|
|
1608
1628
|
{ "window_maximize", NULL, window_maximize, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
1609
1629
|
{ "window_minimize", NULL, window_minimize, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
1610
1630
|
{ "window_restore", NULL, window_restore, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
1611
|
-
{ "window_setIcon", NULL, window_setIcon, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
1612
1631
|
{ "window_render", NULL, window_render, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
1632
|
+
{ "window_setIcon", NULL, window_setIcon, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
1633
|
+
{ "window_flash", NULL, window_flash, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
1613
1634
|
{ "window_destroy", NULL, window_destroy, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
1614
1635
|
{ "keyboard_getKey", NULL, keyboard_getKey, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
1615
1636
|
{ "keyboard_getScancode", NULL, keyboard_getScancode, NULL, NULL, NULL, napi_enumerable, NULL },
|
|
@@ -1650,7 +1671,7 @@ init (napi_env env, napi_value exports)
|
|
|
1650
1671
|
{ "cleanup", NULL, cleanup, NULL, NULL, NULL, napi_enumerable, NULL }
|
|
1651
1672
|
};
|
|
1652
1673
|
|
|
1653
|
-
CALL_NAPI(napi_define_properties, exports,
|
|
1674
|
+
CALL_NAPI(napi_define_properties, exports, 60, desc);
|
|
1654
1675
|
|
|
1655
1676
|
cleanup:
|
|
1656
1677
|
return exports;
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
#include <Cocoa/Cocoa.h>
|
|
2
|
+
#import <QuartzCore/CAMetalLayer.h>
|
|
2
3
|
|
|
3
4
|
#include "cocoa-window.h"
|
|
4
5
|
|
|
5
|
-
extern "C" CALayer *
|
|
6
|
+
extern "C" CALayer * getCocoaGlView(NSWindow * window) {
|
|
6
7
|
NSView * view = window.contentView;
|
|
7
8
|
[view setWantsLayer:YES];
|
|
9
|
+
[[view layer] setContentsScale:[window backingScaleFactor]];
|
|
10
|
+
return view.layer;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
extern "C" CALayer * getCocoaGpuView(NSWindow * window) {
|
|
14
|
+
NSView * view = window.contentView;
|
|
15
|
+
[view setWantsLayer:YES];
|
|
16
|
+
[view setLayer:[CAMetalLayer layer]];
|
|
17
|
+
[[view layer] setContentsScale:[window backingScaleFactor]];
|
|
8
18
|
return view.layer;
|
|
9
19
|
}
|
|
10
20
|
|
|
@@ -11,19 +11,28 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
#if defined(__LINUX__)
|
|
14
|
-
#define
|
|
15
|
-
|
|
14
|
+
#define GL_NativeWindow Window
|
|
15
|
+
struct GPU_NativeData {
|
|
16
|
+
Display *display;
|
|
17
|
+
Window window;
|
|
18
|
+
};
|
|
19
|
+
#define GPU_WINDOW_FLAG SDL_WINDOW_VULKAN
|
|
16
20
|
#elif defined(__WIN32__)
|
|
17
|
-
#define
|
|
18
|
-
|
|
21
|
+
#define GL_NativeWindow HWND
|
|
22
|
+
struct GPU_NativeData {
|
|
23
|
+
HWND hwnd;
|
|
24
|
+
HINSTANCE hinstance;
|
|
25
|
+
};
|
|
26
|
+
#define GPU_WINDOW_FLAG 0
|
|
19
27
|
#elif defined(__MACOSX__)
|
|
20
28
|
#include "cocoa-window.h"
|
|
21
|
-
#define
|
|
22
|
-
|
|
29
|
+
#define GL_NativeWindow CALayer *
|
|
30
|
+
struct GPU_NativeData {
|
|
31
|
+
CALayer *layer;
|
|
32
|
+
};
|
|
33
|
+
#define GPU_WINDOW_FLAG SDL_WINDOW_METAL
|
|
23
34
|
#endif
|
|
24
35
|
|
|
25
|
-
typedef __WINDOW_TYPE__ NativeWindow;
|
|
26
|
-
|
|
27
36
|
|
|
28
37
|
#define RETURN_ERROR(...) do { \
|
|
29
38
|
char * error; \
|
|
@@ -880,21 +889,6 @@ initialize (Variant & object)
|
|
|
880
889
|
}
|
|
881
890
|
|
|
882
891
|
|
|
883
|
-
ErrorMessage *
|
|
884
|
-
_windowGetPixelSize(SDL_Window * window, int * pixel_width, int * pixel_height)
|
|
885
|
-
{
|
|
886
|
-
SDL_Renderer * renderer = SDL_GetRenderer(window);
|
|
887
|
-
if (renderer == nullptr) {
|
|
888
|
-
RETURN_ERROR("SDL_GetRenderer() error: %s\n", SDL_GetError());
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
if (SDL_GetRendererOutputSize(renderer, pixel_width, pixel_height) != 0) {
|
|
892
|
-
RETURN_ERROR("SDL_GetRendererOutputSize() error: %s\n", SDL_GetError());
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
return nullptr;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
892
|
ErrorMessage *
|
|
899
893
|
_windowUpdateTexture(
|
|
900
894
|
SDL_Window * window,
|
|
@@ -951,8 +945,7 @@ _windowUpdateRenderer(
|
|
|
951
945
|
ErrorMessage * error;
|
|
952
946
|
|
|
953
947
|
int pixel_width, pixel_height;
|
|
954
|
-
|
|
955
|
-
if (error != nullptr) { return error; }
|
|
948
|
+
SDL_GetWindowSizeInPixels(window, &pixel_width, &pixel_height);
|
|
956
949
|
|
|
957
950
|
error = _windowUpdateTexture(window, renderer, pixel_width, pixel_height, nullptr);
|
|
958
951
|
if (error != nullptr) { return error; }
|
|
@@ -1064,8 +1057,7 @@ packageEvent (const SDL_Event & event, Variant & object)
|
|
|
1064
1057
|
}
|
|
1065
1058
|
|
|
1066
1059
|
int pixel_width, pixel_height;
|
|
1067
|
-
|
|
1068
|
-
if (error != nullptr) { return error; }
|
|
1060
|
+
SDL_GetWindowSizeInPixels(window, &pixel_width, &pixel_height);
|
|
1069
1061
|
|
|
1070
1062
|
SET_NUM(object, "type", (int) EventType::RESIZE);
|
|
1071
1063
|
SET_NUM(object, "width", event.window.data1);
|
|
@@ -1475,11 +1467,12 @@ window_create (
|
|
|
1475
1467
|
bool * accelerated,
|
|
1476
1468
|
bool * vsync,
|
|
1477
1469
|
bool opengl,
|
|
1470
|
+
bool webgpu,
|
|
1478
1471
|
bool * skip_taskbar,
|
|
1479
1472
|
bool * popup_menu,
|
|
1480
1473
|
bool * tooltip,
|
|
1481
1474
|
bool * utility,
|
|
1482
|
-
int * window_id, void ** native_pointer, int *
|
|
1475
|
+
int * window_id, void ** native_pointer, int * native_size
|
|
1483
1476
|
) {
|
|
1484
1477
|
if (*x == nullptr) {
|
|
1485
1478
|
*x = (int *) malloc(sizeof(int));
|
|
@@ -1504,17 +1497,22 @@ window_create (
|
|
|
1504
1497
|
| (*borderless ? SDL_WINDOW_BORDERLESS : 0)
|
|
1505
1498
|
| (*always_on_top ? SDL_WINDOW_ALWAYS_ON_TOP : 0)
|
|
1506
1499
|
| (opengl ? SDL_WINDOW_OPENGL : 0)
|
|
1500
|
+
| (webgpu ? GPU_WINDOW_FLAG : 0)
|
|
1507
1501
|
| (*skip_taskbar ? SDL_WINDOW_SKIP_TASKBAR : 0)
|
|
1508
1502
|
| (*popup_menu ? SDL_WINDOW_POPUP_MENU : 0)
|
|
1509
1503
|
| (*tooltip ? SDL_WINDOW_TOOLTIP : 0)
|
|
1510
|
-
| (*utility ? SDL_WINDOW_UTILITY : 0)
|
|
1504
|
+
| (*utility ? SDL_WINDOW_UTILITY : 0)
|
|
1505
|
+
;
|
|
1511
1506
|
|
|
1512
1507
|
SDL_Window * window = SDL_CreateWindow(title, **x, **y, **width, **height, desired_flags);
|
|
1513
1508
|
if (window == nullptr) {
|
|
1514
1509
|
RETURN_ERROR("SDL_CreateWindow() error: %s\n", SDL_GetError());
|
|
1515
1510
|
}
|
|
1516
1511
|
|
|
1517
|
-
|
|
1512
|
+
*window_id = SDL_GetWindowID(window);
|
|
1513
|
+
if (*window_id == 0) {
|
|
1514
|
+
RETURN_ERROR("SDL_GetWindowID() error: %s\n", SDL_GetError());
|
|
1515
|
+
}
|
|
1518
1516
|
|
|
1519
1517
|
int actual_flags = SDL_GetWindowFlags(window);
|
|
1520
1518
|
*fullscreen = actual_flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP);
|
|
@@ -1526,12 +1524,10 @@ window_create (
|
|
|
1526
1524
|
*tooltip = actual_flags & SDL_WINDOW_TOOLTIP;
|
|
1527
1525
|
*utility = actual_flags & SDL_WINDOW_UTILITY;
|
|
1528
1526
|
|
|
1529
|
-
*
|
|
1530
|
-
|
|
1531
|
-
RETURN_ERROR("SDL_GetWindowID() error: %s\n", SDL_GetError());
|
|
1532
|
-
}
|
|
1527
|
+
SDL_GetWindowPosition(window, *x, *y);
|
|
1528
|
+
SDL_GetWindowSizeInPixels(window, pixel_width, pixel_height);
|
|
1533
1529
|
|
|
1534
|
-
if (opengl) {
|
|
1530
|
+
if (opengl || webgpu) {
|
|
1535
1531
|
SDL_SysWMinfo info;
|
|
1536
1532
|
SDL_VERSION(&(info.version));
|
|
1537
1533
|
bool got_info = SDL_GetWindowWMInfo(window, &info);
|
|
@@ -1539,20 +1535,41 @@ window_create (
|
|
|
1539
1535
|
RETURN_ERROR("SDL_GetWindowWMInfo(%d) error: %s\n", *window_id, SDL_GetError());
|
|
1540
1536
|
}
|
|
1541
1537
|
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1538
|
+
if (opengl) {
|
|
1539
|
+
int size = sizeof(GL_NativeWindow);
|
|
1540
|
+
GL_NativeWindow *pointer = (GL_NativeWindow *) malloc(size);
|
|
1541
|
+
#if defined(__LINUX__)
|
|
1542
|
+
*pointer = info.info.x11.window;
|
|
1543
|
+
#elif defined(__WIN32__)
|
|
1544
|
+
*pointer = info.info.win.window;
|
|
1545
|
+
#elif defined(__MACOSX__)
|
|
1546
|
+
*pointer = getCocoaGlView(info.info.cocoa.window);
|
|
1547
|
+
#endif
|
|
1548
|
+
|
|
1549
|
+
*native_pointer = pointer;
|
|
1550
|
+
*native_size = size;
|
|
1551
|
+
} else if (webgpu) {
|
|
1552
|
+
int size = sizeof(GPU_NativeData);
|
|
1553
|
+
GPU_NativeData *pointer = (GPU_NativeData *) malloc(size);
|
|
1554
|
+
|
|
1555
|
+
#if defined(__LINUX__)
|
|
1556
|
+
pointer->display = info.info.x11.display;
|
|
1557
|
+
pointer->window = info.info.x11.window;
|
|
1558
|
+
#elif defined(__WIN32__)
|
|
1559
|
+
pointer->hwnd = info.info.win.window;
|
|
1560
|
+
pointer->hinstance = info.info.win.hinstance;
|
|
1561
|
+
#elif defined(__MACOSX__)
|
|
1562
|
+
pointer->layer = getCocoaGpuView(info.info.cocoa.window);
|
|
1563
|
+
#endif
|
|
1564
|
+
|
|
1565
|
+
*native_pointer = pointer;
|
|
1566
|
+
*native_size = size;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
else {
|
|
1570
|
+
ErrorMessage * error = _windowUpdateRenderer(window, accelerated, vsync);
|
|
1571
|
+
if (error != nullptr) { return error; }
|
|
1547
1572
|
}
|
|
1548
|
-
|
|
1549
|
-
ErrorMessage * error;
|
|
1550
|
-
|
|
1551
|
-
error = _windowUpdateRenderer(window, accelerated, vsync);
|
|
1552
|
-
if (error != nullptr) { return error; }
|
|
1553
|
-
|
|
1554
|
-
error = _windowGetPixelSize(window, pixel_width, pixel_height);
|
|
1555
|
-
if (error != nullptr) { return error; }
|
|
1556
1573
|
|
|
1557
1574
|
if (visible) { SDL_ShowWindow(window); }
|
|
1558
1575
|
|
|
@@ -1595,8 +1612,7 @@ window_setSize (int window_id, int width, int height, int * pixel_width, int * p
|
|
|
1595
1612
|
|
|
1596
1613
|
SDL_SetWindowSize(window, width, height);
|
|
1597
1614
|
|
|
1598
|
-
|
|
1599
|
-
if (error != nullptr) { return error; }
|
|
1615
|
+
SDL_GetWindowSizeInPixels(window, pixel_width, pixel_height);
|
|
1600
1616
|
|
|
1601
1617
|
return nullptr;
|
|
1602
1618
|
}
|
|
@@ -1743,30 +1759,6 @@ window_restore (int window_id)
|
|
|
1743
1759
|
return nullptr;
|
|
1744
1760
|
}
|
|
1745
1761
|
|
|
1746
|
-
ErrorMessage *
|
|
1747
|
-
window_setIcon (
|
|
1748
|
-
int window_id,
|
|
1749
|
-
int w, int h, int stride,
|
|
1750
|
-
unsigned int format,
|
|
1751
|
-
void * pixels
|
|
1752
|
-
) {
|
|
1753
|
-
SDL_Window * window = SDL_GetWindowFromID(window_id);
|
|
1754
|
-
if (window == nullptr) {
|
|
1755
|
-
RETURN_ERROR("SDL_GetWindowFromID(%d) error: %s\n", window_id, SDL_GetError());
|
|
1756
|
-
}
|
|
1757
|
-
|
|
1758
|
-
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(pixels, w, h, SDL_BITSPERPIXEL(format), stride, format);
|
|
1759
|
-
if (surface == nullptr) {
|
|
1760
|
-
RETURN_ERROR("SDL_CreateRGBSurfaceWithFormatFrom(%d, %d, %d, %d) error: %s\n", window_id, w, h, format, SDL_GetError());
|
|
1761
|
-
}
|
|
1762
|
-
|
|
1763
|
-
SDL_SetWindowIcon(window, surface);
|
|
1764
|
-
|
|
1765
|
-
SDL_FreeSurface(surface);
|
|
1766
|
-
|
|
1767
|
-
return nullptr;
|
|
1768
|
-
}
|
|
1769
|
-
|
|
1770
1762
|
ErrorMessage *
|
|
1771
1763
|
window_render (
|
|
1772
1764
|
int window_id,
|
|
@@ -1796,8 +1788,7 @@ window_render (
|
|
|
1796
1788
|
}
|
|
1797
1789
|
|
|
1798
1790
|
int pixel_width, pixel_height;
|
|
1799
|
-
|
|
1800
|
-
if (error != nullptr) { return error; }
|
|
1791
|
+
SDL_GetWindowSizeInPixels(window, &pixel_width, &pixel_height);
|
|
1801
1792
|
|
|
1802
1793
|
if (pixel_width != texture_width || pixel_height != texture_height) {
|
|
1803
1794
|
ErrorMessage * error = _windowUpdateTexture(window, renderer, pixel_width, pixel_height, &texture);
|
|
@@ -1842,6 +1833,52 @@ window_render (
|
|
|
1842
1833
|
return nullptr;
|
|
1843
1834
|
}
|
|
1844
1835
|
|
|
1836
|
+
ErrorMessage *
|
|
1837
|
+
window_setIcon (
|
|
1838
|
+
int window_id,
|
|
1839
|
+
int w, int h, int stride,
|
|
1840
|
+
unsigned int format,
|
|
1841
|
+
void * pixels
|
|
1842
|
+
) {
|
|
1843
|
+
SDL_Window * window = SDL_GetWindowFromID(window_id);
|
|
1844
|
+
if (window == nullptr) {
|
|
1845
|
+
RETURN_ERROR("SDL_GetWindowFromID(%d) error: %s\n", window_id, SDL_GetError());
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(pixels, w, h, SDL_BITSPERPIXEL(format), stride, format);
|
|
1849
|
+
if (surface == nullptr) {
|
|
1850
|
+
RETURN_ERROR("SDL_CreateRGBSurfaceWithFormatFrom(%d, %d, %d, %d) error: %s\n", window_id, w, h, format, SDL_GetError());
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
SDL_SetWindowIcon(window, surface);
|
|
1854
|
+
|
|
1855
|
+
SDL_FreeSurface(surface);
|
|
1856
|
+
|
|
1857
|
+
return nullptr;
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
ErrorMessage *
|
|
1861
|
+
window_flash (int window_id, int type)
|
|
1862
|
+
{
|
|
1863
|
+
SDL_Window * window = SDL_GetWindowFromID(window_id);
|
|
1864
|
+
if (window == nullptr) {
|
|
1865
|
+
RETURN_ERROR("SDL_GetWindowFromID(%d) error: %s\n", window_id, SDL_GetError());
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
SDL_FlashOperation op;
|
|
1869
|
+
switch (type) {
|
|
1870
|
+
case 2: op = SDL_FLASH_UNTIL_FOCUSED; break;
|
|
1871
|
+
case 1: op = SDL_FLASH_BRIEFLY; break;
|
|
1872
|
+
default: op = SDL_FLASH_CANCEL; break;
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
if (SDL_FlashWindow(window, op) != 0) {
|
|
1876
|
+
RETURN_ERROR("SDL_FlashWindow(%d, %d) error: %s\n", window_id, type, SDL_GetError());
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
return nullptr;
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1845
1882
|
ErrorMessage *
|
|
1846
1883
|
window_destroy (int window_id)
|
|
1847
1884
|
{
|
|
@@ -1851,14 +1888,13 @@ window_destroy (int window_id)
|
|
|
1851
1888
|
}
|
|
1852
1889
|
|
|
1853
1890
|
SDL_Renderer * renderer = SDL_GetRenderer(window);
|
|
1854
|
-
if (renderer
|
|
1855
|
-
|
|
1856
|
-
}
|
|
1891
|
+
if (renderer != nullptr) {
|
|
1892
|
+
SDL_Texture * texture = (SDL_Texture *) SDL_GetWindowData(window, "texture");
|
|
1857
1893
|
|
|
1858
|
-
|
|
1894
|
+
SDL_DestroyTexture(texture);
|
|
1895
|
+
SDL_DestroyRenderer(renderer);
|
|
1896
|
+
}
|
|
1859
1897
|
|
|
1860
|
-
SDL_DestroyTexture(texture);
|
|
1861
|
-
SDL_DestroyRenderer(renderer);
|
|
1862
1898
|
SDL_DestroyWindow(window);
|
|
1863
1899
|
|
|
1864
1900
|
return nullptr;
|
package/src/native/sdl-helpers.h
CHANGED
|
@@ -67,11 +67,12 @@ ErrorMessage * window_create (
|
|
|
67
67
|
bool * accelerated,
|
|
68
68
|
bool * vsync,
|
|
69
69
|
bool opengl,
|
|
70
|
+
bool webgpu,
|
|
70
71
|
bool * skipTaskbar,
|
|
71
72
|
bool * popupMenu,
|
|
72
73
|
bool * tooltip,
|
|
73
74
|
bool * utility,
|
|
74
|
-
int * window_id, void ** native_pointer, int *
|
|
75
|
+
int * window_id, void ** native_pointer, int * native_size
|
|
75
76
|
);
|
|
76
77
|
ErrorMessage * window_setTitle (int window_id, const char * title);
|
|
77
78
|
ErrorMessage * window_setPosition (int window_id, int x, int y);
|
|
@@ -93,18 +94,19 @@ ErrorMessage * window_hide (int window_id);
|
|
|
93
94
|
ErrorMessage * window_maximize (int window_id);
|
|
94
95
|
ErrorMessage * window_minimize (int window_id);
|
|
95
96
|
ErrorMessage * window_restore (int window_id);
|
|
96
|
-
ErrorMessage *
|
|
97
|
+
ErrorMessage * window_render (
|
|
97
98
|
int window_id,
|
|
98
99
|
int w, int h, int stride,
|
|
99
100
|
unsigned int format,
|
|
100
101
|
void * pixels
|
|
101
102
|
);
|
|
102
|
-
ErrorMessage *
|
|
103
|
+
ErrorMessage * window_setIcon (
|
|
103
104
|
int window_id,
|
|
104
105
|
int w, int h, int stride,
|
|
105
106
|
unsigned int format,
|
|
106
107
|
void * pixels
|
|
107
108
|
);
|
|
109
|
+
ErrorMessage * window_flash (int window_id, int type);
|
|
108
110
|
ErrorMessage * window_destroy (int window_id);
|
|
109
111
|
|
|
110
112
|
ErrorMessage * keyboard_getKey (int scancode, const char ** key);
|
package/src/types/index.d.ts
CHANGED
|
@@ -437,6 +437,8 @@ export namespace Sdl {
|
|
|
437
437
|
readonly vsync: boolean
|
|
438
438
|
setVsync (vsync: boolean): void
|
|
439
439
|
|
|
440
|
+
readonly opengl: boolean
|
|
441
|
+
readonly webgpu: boolean
|
|
440
442
|
readonly native: unknown
|
|
441
443
|
|
|
442
444
|
readonly maximized: boolean
|
|
@@ -461,6 +463,9 @@ export namespace Sdl {
|
|
|
461
463
|
|
|
462
464
|
setIcon (width: number, height: number, stride: number, format: Format, buffer: Buffer): void
|
|
463
465
|
|
|
466
|
+
flash (untilFocused: boolean): void
|
|
467
|
+
stopFlashing (): void
|
|
468
|
+
|
|
464
469
|
readonly destroyed: boolean
|
|
465
470
|
destroy (): void
|
|
466
471
|
}
|
|
@@ -492,6 +497,7 @@ export namespace Sdl {
|
|
|
492
497
|
accelerated?: boolean
|
|
493
498
|
vsync?: boolean
|
|
494
499
|
opengl?: boolean
|
|
500
|
+
webgpu?: boolean
|
|
495
501
|
skipTaskbar?: boolean
|
|
496
502
|
popupMenu?: boolean
|
|
497
503
|
tooltip?: boolean
|