@kmamal/sdl 0.11.3 → 0.11.5
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 +32 -9
- package/package.json +1 -1
- package/src/javascript/controller/controller-instance.js +2 -0
- package/src/javascript/events/index.js +11 -3
- package/src/javascript/video/window.js +6 -0
- package/src/native/controller.cpp +8 -4
- package/src/native/events.cpp +6 -0
- package/src/native/events.h +1 -0
- package/src/native/global.cpp +1 -0
- package/src/native/joystick.cpp +12 -12
- package/src/native/power.cpp +9 -5
- package/src/native/sensor.cpp +5 -3
- package/src/native/window.cpp +33 -36
- package/src/types/index.d.ts +9 -0
package/README.md
CHANGED
|
@@ -10,13 +10,13 @@ Provides window management, input events (keyboard, mouse, joysticks, controller
|
|
|
10
10
|
It should work on Linux, Mac, and Windows.
|
|
11
11
|
Prebuilt binaries are available for x64 architectures, arm-based Macs, and Raspberry Pi.
|
|
12
12
|
|
|
13
|
-
####
|
|
13
|
+
#### Canvas2D, WebGL, and WebGPU
|
|
14
14
|
|
|
15
|
-
One goal of this project is to allow using
|
|
16
|
-
You can use the [canvas](https://www.npmjs.com/package/canvas) package to render using the
|
|
15
|
+
One goal of this project is to allow using Canvas2D, WebGL, and WebGPU without a browser.
|
|
16
|
+
You can use the [@napi-rs/canvas](https://www.npmjs.com/package/@napi-rs/canvas) package to render using the Canvas2D API.
|
|
17
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
18
|
Both WebGL and WebGPU support rendering directly to the window (without any intermediate buffer copying).
|
|
19
|
-
|
|
19
|
+
Canvas2D still uses an intermediate buffer, but that might change in the future.
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
## Installation
|
|
@@ -43,14 +43,14 @@ const window = sdl.video.createWindow({ title: "Hello, World!" })
|
|
|
43
43
|
window.on('*', console.log)
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
###
|
|
46
|
+
### Canvas2D
|
|
47
47
|
|
|
48
48
|
```js
|
|
49
49
|
import sdl from '@kmamal/sdl'
|
|
50
|
-
import { createCanvas } from 'canvas'
|
|
50
|
+
import { createCanvas } from '@napi-rs/canvas'
|
|
51
51
|
|
|
52
52
|
// Setup
|
|
53
|
-
const window = sdl.video.createWindow({ title: "
|
|
53
|
+
const window = sdl.video.createWindow({ title: "Canvas2D" })
|
|
54
54
|
const { pixelWidth: width, pixelHeight: height } = window
|
|
55
55
|
const canvas = createCanvas(width, height)
|
|
56
56
|
const ctx = canvas.getContext('2d')
|
|
@@ -60,8 +60,8 @@ ctx.fillStyle = 'red'
|
|
|
60
60
|
ctx.fillRect(0, 0, width, height)
|
|
61
61
|
|
|
62
62
|
// Render to window
|
|
63
|
-
const buffer =
|
|
64
|
-
window.render(width, height, width * 4, '
|
|
63
|
+
const buffer = Buffer.from(ctx.getImageData(0, 0, width, height).data)
|
|
64
|
+
window.render(width, height, width * 4, 'rgba32', buffer)
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
### WebGL
|
|
@@ -148,6 +148,7 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
|
|
|
148
148
|
* [Event: 'restore'](#event-restore)
|
|
149
149
|
* [Event: 'move'](#event-move)
|
|
150
150
|
* [Event: 'resize'](#event-resize)
|
|
151
|
+
* [Event: 'displayChange'](#event-displaychange)
|
|
151
152
|
* [Event: 'focus'](#event-focus)
|
|
152
153
|
* [Event: 'blur'](#event-blur)
|
|
153
154
|
* [Event: 'hover'](#event-hover)
|
|
@@ -177,6 +178,7 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
|
|
|
177
178
|
* [window.pixelHeight](#windowpixelheight)
|
|
178
179
|
* [window.setSize(width, height)](#windowsetsizewidth-height)
|
|
179
180
|
* [window.setSizeInPixels(pixelWidth, pixelHeight)](#windowsetsizeinpixelspixelwidth-pixelheight)
|
|
181
|
+
* [window.display](#windowdisplay)
|
|
180
182
|
* [window.visible](#windowvisible)
|
|
181
183
|
* [window.show([show])](#windowshowshow)
|
|
182
184
|
* [window.hide()](#windowhide)
|
|
@@ -281,6 +283,7 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
|
|
|
281
283
|
* [controllerInstance.device](#controllerinstancedevice)
|
|
282
284
|
* [controllerInstance.firmwareVersion](#controllerinstancefirmwareversion)
|
|
283
285
|
* [controllerInstance.serialNumber](#controllerinstanceserialnumber)
|
|
286
|
+
* [controllerInstance.steamHandle](#controllerinstancesteamhandle)
|
|
284
287
|
* [controllerInstance.axes](#controllerinstanceaxes)
|
|
285
288
|
* [controllerInstance.buttons](#controllerinstancebuttons)
|
|
286
289
|
* [controllerInstance.power](#controllerinstancepower)
|
|
@@ -653,6 +656,12 @@ Fired when the window changes position.
|
|
|
653
656
|
|
|
654
657
|
Fired when the window changes size.
|
|
655
658
|
|
|
659
|
+
### Event: 'displayChange'
|
|
660
|
+
|
|
661
|
+
* `display: <object>` An object from [`sdl.video.displays`](#sdlvideodisplays) indicating the window's new display.
|
|
662
|
+
|
|
663
|
+
Fired when a window moves from one display to another.
|
|
664
|
+
|
|
656
665
|
### Event: 'focus'
|
|
657
666
|
|
|
658
667
|
Fired when a window gains the keyboard focus.
|
|
@@ -850,6 +859,13 @@ Changes the size of the window.
|
|
|
850
859
|
Changes the size of the window.
|
|
851
860
|
This function only behaves differently from [`window.setSize()`](#windowsetsizewidth-height) for [high-dpi](#high-dpi) displays.
|
|
852
861
|
|
|
862
|
+
### window.display
|
|
863
|
+
|
|
864
|
+
* `<object>`
|
|
865
|
+
|
|
866
|
+
An object from [`sdl.video.displays`](#sdlvideodisplays) indicating the display this window belongs to.
|
|
867
|
+
If the window spans multiple displays, then the display containing the center of the window is returned.
|
|
868
|
+
|
|
853
869
|
### window.visible
|
|
854
870
|
|
|
855
871
|
* `<boolean>`
|
|
@@ -1947,6 +1963,13 @@ The controller's firmware version.
|
|
|
1947
1963
|
|
|
1948
1964
|
The controller's serial number, or `null` if it's not available.
|
|
1949
1965
|
|
|
1966
|
+
### controllerInstance.steamHandle
|
|
1967
|
+
|
|
1968
|
+
* `<Buffer>|<null>`
|
|
1969
|
+
|
|
1970
|
+
The controller's steam handle, or `null` if it's not available.
|
|
1971
|
+
The `Buffer` will contain an `InputHandle_t` for the controller that can be used with the [Steam Input API](https://partner.steamgames.com/doc/api/ISteamInput)
|
|
1972
|
+
|
|
1950
1973
|
### controllerInstance.axes
|
|
1951
1974
|
|
|
1952
1975
|
* `<object>`
|
package/package.json
CHANGED
|
@@ -21,6 +21,7 @@ class ControllerInstance extends EventsViaPoll {
|
|
|
21
21
|
this._hasLed = result.hasLed
|
|
22
22
|
this._hasRumble = result.hasRumble
|
|
23
23
|
this._hasRumbleTriggers = result.hasRumbleTriggers
|
|
24
|
+
this._steamHandle = result.steamHandle
|
|
24
25
|
this._axes = result.axes
|
|
25
26
|
this._buttons = result.buttons
|
|
26
27
|
|
|
@@ -42,6 +43,7 @@ class ControllerInstance extends EventsViaPoll {
|
|
|
42
43
|
get device () { return this._device }
|
|
43
44
|
get firmwareVersion () { return this._firmwareVersion }
|
|
44
45
|
get serialNumber () { return this._serialNumber }
|
|
46
|
+
get steamHandle () { return this._steamHandle }
|
|
45
47
|
|
|
46
48
|
get axes () {
|
|
47
49
|
Globals.events.poll()
|
|
@@ -33,13 +33,15 @@ const reconcileDevices = (emitter, mainList, currList, compare) => {
|
|
|
33
33
|
if (cmp === 0) {
|
|
34
34
|
mainDevice = mainList[++mainIndex]
|
|
35
35
|
currDevice = currList[++currIndex]
|
|
36
|
-
}
|
|
36
|
+
}
|
|
37
|
+
else if (cmp < 0) {
|
|
37
38
|
mainList.splice(mainIndex, 1)
|
|
38
39
|
const type = 'deviceRemove'
|
|
39
40
|
const event = { type, device: mainDevice }
|
|
40
41
|
emitter.emit(type, event)
|
|
41
42
|
mainDevice = mainList[mainIndex]
|
|
42
|
-
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
43
45
|
mainList.splice(mainIndex, 0, currDevice)
|
|
44
46
|
mainDevice = mainList[++mainIndex]
|
|
45
47
|
const type = 'deviceAdd'
|
|
@@ -56,7 +58,8 @@ const reconcileDevices = (emitter, mainList, currList, compare) => {
|
|
|
56
58
|
const event = { type, device: mainDevice }
|
|
57
59
|
emitter.emit(type, event)
|
|
58
60
|
}
|
|
59
|
-
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
60
63
|
while (currIndex < currList.length) {
|
|
61
64
|
mainList.push(currDevice)
|
|
62
65
|
const type = 'deviceAdd'
|
|
@@ -116,6 +119,11 @@ const handleEvent = (event) => {
|
|
|
116
119
|
window._pixelWidth = event.pixelWidth
|
|
117
120
|
window._pixelHeight = event.pixelHeight
|
|
118
121
|
} break
|
|
122
|
+
case 'displayChange': {
|
|
123
|
+
window._displayIndex = event.displayIndex
|
|
124
|
+
delete event.displayIndex
|
|
125
|
+
event.display = window.display
|
|
126
|
+
} break
|
|
119
127
|
|
|
120
128
|
case 'show': {
|
|
121
129
|
window._visible = true
|
|
@@ -12,6 +12,7 @@ const validEvents = [
|
|
|
12
12
|
'restore',
|
|
13
13
|
'move',
|
|
14
14
|
'resize',
|
|
15
|
+
'displayChange',
|
|
15
16
|
'focus',
|
|
16
17
|
'blur',
|
|
17
18
|
'hover',
|
|
@@ -121,6 +122,7 @@ class Window extends EventsViaPoll {
|
|
|
121
122
|
this._height = result.height
|
|
122
123
|
this._pixelWidth = result.pixelWidth
|
|
123
124
|
this._pixelHeight = result.pixelHeight
|
|
125
|
+
this._displayIndex = result.displayIndex
|
|
124
126
|
this._fullscreen = result.fullscreen
|
|
125
127
|
this._resizable = result.resizable
|
|
126
128
|
this._borderless = result.borderless
|
|
@@ -237,6 +239,10 @@ class Window extends EventsViaPoll {
|
|
|
237
239
|
get pixelWidth () { return this._pixelWidth }
|
|
238
240
|
get pixelHeight () { return this._pixelHeight }
|
|
239
241
|
|
|
242
|
+
get display () {
|
|
243
|
+
return Globals.displays[this._displayIndex]
|
|
244
|
+
}
|
|
245
|
+
|
|
240
246
|
get visible () { return this._visible }
|
|
241
247
|
show (show = true) {
|
|
242
248
|
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
|
@@ -118,16 +118,19 @@ controller::open (const Napi::CallbackInfo &info)
|
|
|
118
118
|
throw Napi::Error::New(env, message.str());
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
int
|
|
122
|
-
Napi::Value firmware_version =
|
|
121
|
+
int _firmware_version = SDL_JoystickGetFirmwareVersion(joystick);
|
|
122
|
+
Napi::Value firmware_version = _firmware_version == 0 ? env.Null() : Napi::Number::New(env, _firmware_version);
|
|
123
123
|
|
|
124
|
-
const char *
|
|
125
|
-
Napi::Value serial_number =
|
|
124
|
+
const char *_serial_number = SDL_JoystickGetSerial(joystick);
|
|
125
|
+
Napi::Value serial_number = _serial_number == 0 ? env.Null() : Napi::String::New(env, _serial_number);
|
|
126
126
|
|
|
127
127
|
bool has_led = SDL_JoystickHasLED(joystick);
|
|
128
128
|
bool has_rumble = SDL_JoystickHasRumble(joystick);
|
|
129
129
|
bool has_rumble_triggers = SDL_JoystickHasRumbleTriggers(joystick);
|
|
130
130
|
|
|
131
|
+
Uint64 _steam_handle = SDL_GameControllerGetSteamHandle(controller);
|
|
132
|
+
Napi::Value steam_handle = _steam_handle == 0 ? env.Null() : Napi::Buffer<Uint64>::Copy(env, &_steam_handle, 1);
|
|
133
|
+
|
|
131
134
|
Napi::Object result = Napi::Object::New(env);
|
|
132
135
|
// result.Set("id", Napi::Number::New(env, joystick_id)); // NOTE: Unused. Same as the device id
|
|
133
136
|
result.Set("firmwareVersion", firmware_version);
|
|
@@ -135,6 +138,7 @@ controller::open (const Napi::CallbackInfo &info)
|
|
|
135
138
|
result.Set("hasLed", Napi::Boolean::New(env, has_led));
|
|
136
139
|
result.Set("hasRumble", Napi::Boolean::New(env, has_rumble));
|
|
137
140
|
result.Set("hasRumbleTriggers", Napi::Boolean::New(env, has_rumble_triggers));
|
|
141
|
+
result.Set("steamHandle", steam_handle);
|
|
138
142
|
|
|
139
143
|
controller::getState(env, controller, result);
|
|
140
144
|
|
package/src/native/events.cpp
CHANGED
|
@@ -27,6 +27,7 @@ std::string events::types::QUIT;
|
|
|
27
27
|
std::string events::types::DISPLAY_ADD;
|
|
28
28
|
std::string events::types::DISPLAY_REMOVE;
|
|
29
29
|
std::string events::types::DISPLAY_ORIENT;
|
|
30
|
+
std::string events::types::DISPLAY_CHANGE;
|
|
30
31
|
std::string events::types::SHOW;
|
|
31
32
|
std::string events::types::HIDE;
|
|
32
33
|
std::string events::types::EXPOSE;
|
|
@@ -128,6 +129,11 @@ events::dispatchEvent(const SDL_Event &event)
|
|
|
128
129
|
packed.Set("pixelHeight", Napi::Number::New(env, pixel_height));
|
|
129
130
|
break;
|
|
130
131
|
}
|
|
132
|
+
case SDL_WINDOWEVENT_DISPLAY_CHANGED: {
|
|
133
|
+
packed.Set("type", events::types::DISPLAY_CHANGE);
|
|
134
|
+
packed.Set("displayIndex", Napi::Number::New(env, event.window.data1));
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
131
137
|
case SDL_WINDOWEVENT_MINIMIZED: { packed.Set("type", events::types::MINIMIZE); break; }
|
|
132
138
|
case SDL_WINDOWEVENT_MAXIMIZED: { packed.Set("type", events::types::MAXIMIZE); break; }
|
|
133
139
|
case SDL_WINDOWEVENT_RESTORED: { packed.Set("type", events::types::RESTORE); break; }
|
package/src/native/events.h
CHANGED
package/src/native/global.cpp
CHANGED
|
@@ -58,6 +58,7 @@ global::initialize(const Napi::CallbackInfo &info)
|
|
|
58
58
|
events::types::DISPLAY_ADD = "displayAdd";
|
|
59
59
|
events::types::DISPLAY_REMOVE = "displayRemove";
|
|
60
60
|
events::types::DISPLAY_ORIENT = "displayOrient";
|
|
61
|
+
events::types::DISPLAY_CHANGE = "displayChange";
|
|
61
62
|
events::types::SHOW = "show";
|
|
62
63
|
events::types::HIDE = "hide";
|
|
63
64
|
events::types::EXPOSE = "expose";
|
package/src/native/joystick.cpp
CHANGED
|
@@ -64,17 +64,17 @@ joystick::_getDevices (Napi::Env &env)
|
|
|
64
64
|
char guid_string[33];
|
|
65
65
|
SDL_JoystickGetGUIDString(guid, guid_string, 33);
|
|
66
66
|
|
|
67
|
-
int
|
|
68
|
-
Napi::Value vendor =
|
|
67
|
+
int _vendor = SDL_JoystickGetDeviceVendor(i);
|
|
68
|
+
Napi::Value vendor = _vendor == 0 ? env.Null() : Napi::Number::New(env, _vendor);
|
|
69
69
|
|
|
70
|
-
int
|
|
71
|
-
Napi::Value product =
|
|
70
|
+
int _product = SDL_JoystickGetDeviceProduct(i);
|
|
71
|
+
Napi::Value product = _product == 0 ? env.Null() : Napi::Number::New(env, _product);
|
|
72
72
|
|
|
73
|
-
int
|
|
74
|
-
Napi::Value version =
|
|
73
|
+
int _Version = SDL_JoystickGetDeviceProductVersion(i);
|
|
74
|
+
Napi::Value version = _Version == 0 ? env.Null() : Napi::Number::New(env, _Version);
|
|
75
75
|
|
|
76
|
-
int
|
|
77
|
-
Napi::Value player =
|
|
76
|
+
int _player = SDL_JoystickGetDevicePlayerIndex(i);
|
|
77
|
+
Napi::Value player = _player == -1 ? env.Null() : Napi::Number::New(env, _player);
|
|
78
78
|
|
|
79
79
|
bool is_controller = SDL_IsGameController(i);
|
|
80
80
|
|
|
@@ -144,11 +144,11 @@ joystick::open (const Napi::CallbackInfo &info)
|
|
|
144
144
|
throw Napi::Error::New(env, message.str());
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
int
|
|
148
|
-
Napi::Value firmware_version =
|
|
147
|
+
int _firmware_version = SDL_JoystickGetFirmwareVersion(joystick);
|
|
148
|
+
Napi::Value firmware_version = _firmware_version == 0 ? env.Null() : Napi::Number::New(env, _firmware_version);
|
|
149
149
|
|
|
150
|
-
const char *
|
|
151
|
-
Napi::Value serial_number =
|
|
150
|
+
const char *_serial_number = SDL_JoystickGetSerial(joystick);
|
|
151
|
+
Napi::Value serial_number = _serial_number == nullptr ? env.Null() : Napi::String::New(env, _serial_number);
|
|
152
152
|
|
|
153
153
|
SDL_bool has_led = SDL_JoystickHasLED(joystick);
|
|
154
154
|
SDL_bool has_rumble = SDL_JoystickHasRumble(joystick);
|
package/src/native/power.cpp
CHANGED
|
@@ -11,13 +11,17 @@ power::getInfo (const Napi::CallbackInfo &info)
|
|
|
11
11
|
{
|
|
12
12
|
Napi::Env env = info.Env();
|
|
13
13
|
|
|
14
|
-
int
|
|
15
|
-
SDL_PowerState
|
|
14
|
+
int _seconds, _percent;
|
|
15
|
+
SDL_PowerState _state = SDL_GetPowerInfo(&_seconds, &_percent);
|
|
16
|
+
|
|
17
|
+
Napi::Value state = _state == SDL_POWERSTATE_UNKNOWN ? env.Null() : Napi::String::New(env, power::states[_state]);
|
|
18
|
+
Napi::Value seconds = _seconds == -1 ? env.Null() : Napi::Number::New(env, _seconds);
|
|
19
|
+
Napi::Value percent = _percent == -1 ? env.Null() : Napi::Number::New(env, _percent);
|
|
16
20
|
|
|
17
21
|
Napi::Object result = Napi::Object::New(env);
|
|
18
|
-
result.Set("state", state
|
|
19
|
-
result.Set("seconds", seconds
|
|
20
|
-
result.Set("percent", percent
|
|
22
|
+
result.Set("state", state);
|
|
23
|
+
result.Set("seconds", seconds);
|
|
24
|
+
result.Set("percent", percent);
|
|
21
25
|
|
|
22
26
|
return result;
|
|
23
27
|
}
|
package/src/native/sensor.cpp
CHANGED
|
@@ -33,8 +33,10 @@ sensor::getDevices (const Napi::CallbackInfo &info)
|
|
|
33
33
|
throw Napi::Error::New(env, message.str());
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
SDL_SensorType
|
|
36
|
+
SDL_SensorType _type = SDL_SensorGetDeviceType(i);
|
|
37
37
|
// This function can only error if the index is invalid.
|
|
38
|
+
Napi::Value type = _type == SDL_SENSOR_UNKNOWN ? env.Null() : Napi::String::New(env, sensor::types[_type]);
|
|
39
|
+
Napi::Value side = _type == SDL_SENSOR_UNKNOWN || _type == SDL_SENSOR_ACCEL || _type == SDL_SENSOR_GYRO ? env.Null() : Napi::String::New(env, sensor::sides[_type]);
|
|
38
40
|
|
|
39
41
|
const char *name = SDL_SensorGetDeviceName(i);
|
|
40
42
|
// This function can only error if the index is invalid.
|
|
@@ -43,8 +45,8 @@ sensor::getDevices (const Napi::CallbackInfo &info)
|
|
|
43
45
|
device.Set("_index", Napi::Number::New(env, i));
|
|
44
46
|
device.Set("id", Napi::Number::New(env, id));
|
|
45
47
|
device.Set("name", Napi::String::New(env, name));
|
|
46
|
-
device.Set("type", type
|
|
47
|
-
device.Set("side",
|
|
48
|
+
device.Set("type", type);
|
|
49
|
+
device.Set("side", side);
|
|
48
50
|
|
|
49
51
|
devices.Set(i, device);
|
|
50
52
|
}
|
package/src/native/window.cpp
CHANGED
|
@@ -10,7 +10,6 @@ struct CachedTexture {
|
|
|
10
10
|
int width;
|
|
11
11
|
int height;
|
|
12
12
|
unsigned int format;
|
|
13
|
-
SDL_ScaleMode scaling;
|
|
14
13
|
};
|
|
15
14
|
|
|
16
15
|
std::map<SDL_Window*, CachedTexture> cachedTextures;
|
|
@@ -168,6 +167,14 @@ window::create (const Napi::CallbackInfo &info)
|
|
|
168
167
|
int pixel_width, pixel_height;
|
|
169
168
|
SDL_GetWindowSizeInPixels(window, &pixel_width, &pixel_height);
|
|
170
169
|
|
|
170
|
+
display = SDL_GetWindowDisplayIndex(window);
|
|
171
|
+
if (display < 0) {
|
|
172
|
+
std::ostringstream message;
|
|
173
|
+
message << "SDL_GetWindowDisplayIndex(" << window_id << ") error: " << SDL_GetError();
|
|
174
|
+
SDL_ClearError();
|
|
175
|
+
throw Napi::Error::New(env, message.str());
|
|
176
|
+
}
|
|
177
|
+
|
|
171
178
|
Napi::Object native = Napi::Object::New(env);
|
|
172
179
|
|
|
173
180
|
SDL_SysWMinfo sys_wm_info;
|
|
@@ -179,48 +186,39 @@ window::create (const Napi::CallbackInfo &info)
|
|
|
179
186
|
throw Napi::Error::New(env, message.str());
|
|
180
187
|
}
|
|
181
188
|
|
|
182
|
-
|
|
183
|
-
Napi::Buffer<char> native_handle_buffer = Napi::Buffer<char>::New(env, native_handle_size);
|
|
184
|
-
NativeWindowHandle *native_handle = (NativeWindowHandle *) native_handle_buffer.Data();
|
|
185
|
-
native.Set("handle", native_handle_buffer);
|
|
186
|
-
|
|
189
|
+
NativeWindowHandle native_handle;
|
|
187
190
|
#if defined(__LINUX__)
|
|
188
|
-
|
|
191
|
+
native_handle = sys_wm_info.info.x11.window;
|
|
189
192
|
#elif defined(__WIN32__)
|
|
190
|
-
|
|
193
|
+
native_handle = sys_wm_info.info.win.window;
|
|
191
194
|
#elif defined(__MACOSX__)
|
|
192
|
-
|
|
195
|
+
native_handle = getCocoaWindowHandle(sys_wm_info.info.cocoa.window);
|
|
193
196
|
#endif
|
|
197
|
+
native.Set("handle", Napi::Buffer<NativeWindowHandle>::Copy(env, &native_handle, 1));
|
|
194
198
|
|
|
195
199
|
if (is_opengl) {
|
|
196
|
-
|
|
197
|
-
Napi::Buffer<char> native_gl_buffer = Napi::Buffer<char>::New(env, native_gl_size);
|
|
198
|
-
GL_NativeWindow *native_gl = (GL_NativeWindow *) native_gl_buffer.Data();
|
|
199
|
-
native.Set("gl", native_gl_buffer);
|
|
200
|
-
|
|
200
|
+
GL_NativeWindow native_gl;
|
|
201
201
|
#if defined(__LINUX__)
|
|
202
|
-
|
|
202
|
+
native_gl = sys_wm_info.info.x11.window;
|
|
203
203
|
#elif defined(__WIN32__)
|
|
204
|
-
|
|
204
|
+
native_gl = sys_wm_info.info.win.window;
|
|
205
205
|
#elif defined(__MACOSX__)
|
|
206
|
-
|
|
206
|
+
native_gl = getCocoaGlView(sys_wm_info.info.cocoa.window);
|
|
207
207
|
#endif
|
|
208
|
+
native.Set("gl", Napi::Buffer<GL_NativeWindow>::Copy(env, &native_gl, 1));
|
|
208
209
|
}
|
|
209
210
|
else if (is_webgpu) {
|
|
210
|
-
|
|
211
|
-
Napi::Buffer<char> native_gpu_buffer = Napi::Buffer<char>::New(env, native_gpu_size);
|
|
212
|
-
GPU_NativeData *native_gpu = (GPU_NativeData *) native_gpu_buffer.Data();
|
|
213
|
-
native.Set("gpu", native_gpu_buffer);
|
|
214
|
-
|
|
211
|
+
GPU_NativeData native_gpu;
|
|
215
212
|
#if defined(__LINUX__)
|
|
216
|
-
native_gpu
|
|
217
|
-
native_gpu
|
|
213
|
+
native_gpu.display = sys_wm_info.info.x11.display;
|
|
214
|
+
native_gpu.window = sys_wm_info.info.x11.window;
|
|
218
215
|
#elif defined(__WIN32__)
|
|
219
|
-
native_gpu
|
|
220
|
-
native_gpu
|
|
216
|
+
native_gpu.hwnd = sys_wm_info.info.win.window;
|
|
217
|
+
native_gpu.hinstance = sys_wm_info.info.win.hinstance;
|
|
221
218
|
#elif defined(__MACOSX__)
|
|
222
|
-
native_gpu
|
|
219
|
+
native_gpu.layer = getCocoaGpuView(sys_wm_info.info.cocoa.window);
|
|
223
220
|
#endif
|
|
221
|
+
native.Set("gpu", Napi::Buffer<GPU_NativeData>::Copy(env, &native_gpu, 1));
|
|
224
222
|
}
|
|
225
223
|
else {
|
|
226
224
|
cachedTextures[window] = {};
|
|
@@ -237,6 +235,7 @@ window::create (const Napi::CallbackInfo &info)
|
|
|
237
235
|
result.Set("height", Napi::Number::New(env, height));
|
|
238
236
|
result.Set("pixelWidth", Napi::Number::New(env, pixel_width));
|
|
239
237
|
result.Set("pixelHeight", Napi::Number::New(env, pixel_height));
|
|
238
|
+
result.Set("displayIndex", Napi::Number::New(env, display));
|
|
240
239
|
result.Set("fullscreen", Napi::Boolean::New(env, is_fullscreen));
|
|
241
240
|
result.Set("resizable", Napi::Boolean::New(env, is_resizable));
|
|
242
241
|
result.Set("borderless", Napi::Boolean::New(env, is_borderless));
|
|
@@ -593,7 +592,6 @@ window::render (const Napi::CallbackInfo &info)
|
|
|
593
592
|
|| cached.width != width
|
|
594
593
|
|| cached.height != height
|
|
595
594
|
|| cached.format != format
|
|
596
|
-
|| cached.scaling != scaling
|
|
597
595
|
) {
|
|
598
596
|
if (texture != nullptr) { SDL_DestroyTexture(texture); }
|
|
599
597
|
|
|
@@ -606,18 +604,17 @@ window::render (const Napi::CallbackInfo &info)
|
|
|
606
604
|
throw Napi::Error::New(env, message.str());
|
|
607
605
|
}
|
|
608
606
|
|
|
609
|
-
if(SDL_SetTextureScaleMode(texture, scaling) < 0) {
|
|
610
|
-
std::ostringstream message;
|
|
611
|
-
message << "SDL_SetTextureScaleMode(" << window_id << ", " << scaling << ") error: " << SDL_GetError();
|
|
612
|
-
SDL_ClearError();
|
|
613
|
-
throw Napi::Error::New(env, message.str());
|
|
614
|
-
}
|
|
615
|
-
|
|
616
607
|
cached.texture = texture;
|
|
617
608
|
cached.width = width;
|
|
618
609
|
cached.height = height;
|
|
619
610
|
cached.format = format;
|
|
620
|
-
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
if(SDL_SetTextureScaleMode(texture, scaling) < 0) {
|
|
614
|
+
std::ostringstream message;
|
|
615
|
+
message << "SDL_SetTextureScaleMode(" << window_id << ", " << scaling << ") error: " << SDL_GetError();
|
|
616
|
+
SDL_ClearError();
|
|
617
|
+
throw Napi::Error::New(env, message.str());
|
|
621
618
|
}
|
|
622
619
|
|
|
623
620
|
SDL_UpdateTexture(texture, nullptr, pixels, stride);
|
package/src/types/index.d.ts
CHANGED
|
@@ -86,6 +86,10 @@ export namespace Events {
|
|
|
86
86
|
readonly pixelWidth: number
|
|
87
87
|
readonly pixelHeight: number
|
|
88
88
|
}
|
|
89
|
+
export interface DisplayChange extends WindowEvent {
|
|
90
|
+
readonly type: 'displayChange'
|
|
91
|
+
readonly display: Sdl.Video.Display
|
|
92
|
+
}
|
|
89
93
|
export interface Focus extends WindowEvent { readonly type: 'focus' }
|
|
90
94
|
export interface Blur extends WindowEvent { readonly type: 'blur' }
|
|
91
95
|
export interface Hover extends WindowEvent { readonly type: 'hover' }
|
|
@@ -123,6 +127,7 @@ export namespace Events {
|
|
|
123
127
|
| Restore
|
|
124
128
|
| Move
|
|
125
129
|
| Resize
|
|
130
|
+
| DisplayChange
|
|
126
131
|
| Focus
|
|
127
132
|
| Blur
|
|
128
133
|
| Hover
|
|
@@ -388,6 +393,7 @@ export namespace Sdl {
|
|
|
388
393
|
on (event: 'restore', listener: (event: Events.Window.Restore) => void): this
|
|
389
394
|
on (event: 'move', listener: (event: Events.Window.Move) => void): this
|
|
390
395
|
on (event: 'resize', listener: (event: Events.Window.Resize) => void): this
|
|
396
|
+
on (event: 'displayChange', listener: (event: Events.Window.DisplayChange) => void): this
|
|
391
397
|
on (event: 'focus', listener: (event: Events.Window.Focus) => void): this
|
|
392
398
|
on (event: 'blur', listener: (event: Events.Window.Blur) => void): this
|
|
393
399
|
on (event: 'hover', listener: (event: Events.Window.Hover) => void): this
|
|
@@ -424,6 +430,8 @@ export namespace Sdl {
|
|
|
424
430
|
readonly pixelHeight: number
|
|
425
431
|
setSizeInPixels (pixelWidth: number, pixelHeight: number): void
|
|
426
432
|
|
|
433
|
+
readonly display: Display
|
|
434
|
+
|
|
427
435
|
readonly visible: boolean
|
|
428
436
|
show (show?: boolean): void
|
|
429
437
|
hide (): void
|
|
@@ -985,6 +993,7 @@ export namespace Sdl {
|
|
|
985
993
|
readonly device: Device
|
|
986
994
|
readonly firmwareVersion: number
|
|
987
995
|
readonly serialNumber: string
|
|
996
|
+
readonly steamHandle: Buffer | null
|
|
988
997
|
|
|
989
998
|
readonly axes: {
|
|
990
999
|
readonly leftStickX: number
|