@kmamal/sdl 0.11.5 → 0.11.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +49 -10
- package/binding.gyp +1 -0
- package/package.json +2 -2
- package/scripts/build-sdl.mjs +4 -1
- package/scripts/install.mjs +6 -3
- package/scripts/util/fetch.js +6 -3
- package/src/javascript/audio/audio-instance.js +2 -3
- package/src/javascript/audio/device.js +1 -10
- package/src/javascript/audio/index.js +5 -7
- package/src/javascript/controller/controller-instance.js +2 -0
- package/src/javascript/controller/device.js +14 -3
- package/src/javascript/controller/index.js +5 -11
- package/src/javascript/events/index.js +56 -126
- package/src/javascript/events/reconcile-audio-devices.js +15 -0
- package/src/javascript/events/reconcile-displays.js +16 -0
- package/src/javascript/events/reconcile-joystick-and-controller-devices.js +37 -0
- package/src/javascript/events/reconcile.js +61 -0
- package/src/javascript/joystick/device.js +9 -3
- package/src/javascript/joystick/index.js +13 -5
- package/src/javascript/joystick/joystick-instance.js +2 -0
- package/src/javascript/sensor/sensor-instance.js +2 -0
- package/src/javascript/video/display.js +4 -0
- package/src/javascript/video/index.js +1 -0
- package/src/native/audio.cpp +10 -12
- package/src/native/audio.h +4 -0
- package/src/native/controller.cpp +72 -56
- package/src/native/controller.h +3 -0
- package/src/native/enums.cpp +315 -315
- package/src/native/events.cpp +156 -80
- package/src/native/events.h +1 -0
- package/src/native/global.cpp +46 -20
- package/src/native/joystick.cpp +87 -48
- package/src/native/joystick.h +3 -2
- package/src/native/keyboard.cpp +1 -1
- package/src/native/mouse.cpp +2 -2
- package/src/native/power.cpp +9 -3
- package/src/native/sensor.cpp +24 -13
- package/src/native/video.cpp +21 -13
- package/src/native/video.h +1 -0
- package/src/native/window.cpp +28 -22
- package/src/types/index.d.ts +57 -17
package/src/native/joystick.cpp
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#include "joystick.h"
|
|
2
|
+
#include "controller.h"
|
|
2
3
|
#include "global.h"
|
|
3
4
|
#include <SDL.h>
|
|
4
5
|
#include <string>
|
|
@@ -7,14 +8,23 @@
|
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
std::map<Uint8, std::string> joystick::hat_positions;
|
|
10
|
-
std::map<SDL_JoystickType, std::string> joystick::
|
|
11
|
+
std::map<SDL_JoystickType, std::string> joystick::types;
|
|
11
12
|
std::map<SDL_JoystickPowerLevel, std::string> joystick::power_levels;
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
double
|
|
15
|
-
joystick::mapAxis (int
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
joystick::mapAxis (SDL_Joystick *joystick, int axis) {
|
|
17
|
+
return mapAxisValue(joystick, axis, SDL_JoystickGetAxis(joystick, axis));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
double
|
|
21
|
+
joystick::mapAxisValue (SDL_Joystick *joystick, int axis, int value) {
|
|
22
|
+
Sint16 initial;
|
|
23
|
+
if (!SDL_JoystickGetAxisInitialState(joystick, axis, &initial)) { initial = 0; }
|
|
24
|
+
double range = value < initial
|
|
25
|
+
? initial - SDL_JOYSTICK_AXIS_MIN
|
|
26
|
+
: SDL_JOYSTICK_AXIS_MAX - initial;
|
|
27
|
+
return (value - initial) / range;
|
|
18
28
|
}
|
|
19
29
|
|
|
20
30
|
Napi::Array
|
|
@@ -39,9 +49,6 @@ joystick::_getDevices (Napi::Env &env)
|
|
|
39
49
|
throw Napi::Error::New(env, message.str());
|
|
40
50
|
}
|
|
41
51
|
|
|
42
|
-
SDL_JoystickType type = SDL_JoystickGetDeviceType(i);
|
|
43
|
-
// This function can only error if the index is invalid.
|
|
44
|
-
|
|
45
52
|
const char *name = SDL_JoystickNameForIndex(i);
|
|
46
53
|
if (name == nullptr) {
|
|
47
54
|
std::ostringstream message;
|
|
@@ -58,53 +65,89 @@ joystick::_getDevices (Napi::Env &env)
|
|
|
58
65
|
throw Napi::Error::New(env, message.str());
|
|
59
66
|
}
|
|
60
67
|
|
|
61
|
-
SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(i);
|
|
62
68
|
// This function can only error if the index is invalid.
|
|
69
|
+
SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(i);
|
|
63
70
|
|
|
64
71
|
char guid_string[33];
|
|
65
72
|
SDL_JoystickGetGUIDString(guid, guid_string, 33);
|
|
66
73
|
|
|
74
|
+
// This function can only error if the index is invalid.
|
|
75
|
+
SDL_JoystickType _type = SDL_JoystickGetDeviceType(i);
|
|
76
|
+
Napi::Value type = _type != SDL_JOYSTICK_TYPE_UNKNOWN
|
|
77
|
+
? Napi::String::New(env, joystick::types[_type])
|
|
78
|
+
: env.Null();
|
|
79
|
+
|
|
67
80
|
int _vendor = SDL_JoystickGetDeviceVendor(i);
|
|
68
|
-
Napi::Value vendor = _vendor
|
|
81
|
+
Napi::Value vendor = _vendor != 0
|
|
82
|
+
? Napi::Number::New(env, _vendor)
|
|
83
|
+
: env.Null();
|
|
69
84
|
|
|
70
85
|
int _product = SDL_JoystickGetDeviceProduct(i);
|
|
71
|
-
Napi::Value product = _product
|
|
86
|
+
Napi::Value product = _product != 0
|
|
87
|
+
? Napi::Number::New(env, _product)
|
|
88
|
+
: env.Null();
|
|
72
89
|
|
|
73
90
|
int _Version = SDL_JoystickGetDeviceProductVersion(i);
|
|
74
|
-
Napi::Value version = _Version
|
|
91
|
+
Napi::Value version = _Version != 0
|
|
92
|
+
? Napi::Number::New(env, _Version)
|
|
93
|
+
: env.Null();
|
|
75
94
|
|
|
76
95
|
int _player = SDL_JoystickGetDevicePlayerIndex(i);
|
|
77
|
-
Napi::Value player = _player
|
|
96
|
+
Napi::Value player = _player != -1
|
|
97
|
+
? Napi::Number::New(env, _player)
|
|
98
|
+
: env.Null();
|
|
78
99
|
|
|
79
100
|
bool is_controller = SDL_IsGameController(i);
|
|
80
101
|
|
|
81
|
-
Napi::Value
|
|
102
|
+
Napi::Value controller_mapping;
|
|
103
|
+
Napi::Value controller_name;
|
|
104
|
+
Napi::Value controller_type;
|
|
105
|
+
|
|
82
106
|
if (is_controller) {
|
|
83
|
-
const char *
|
|
84
|
-
if (
|
|
107
|
+
const char *_controller_mapping = SDL_GameControllerMappingForDeviceIndex(i);
|
|
108
|
+
if (_controller_mapping == nullptr) {
|
|
85
109
|
std::ostringstream message;
|
|
86
110
|
message << "SDL_GameControllerMappingForDeviceIndex(" << i << ") error: " << SDL_GetError();
|
|
87
111
|
SDL_ClearError();
|
|
88
112
|
throw Napi::Error::New(env, message.str());
|
|
89
113
|
}
|
|
90
|
-
|
|
114
|
+
controller_mapping = Napi::String::New(env, _controller_mapping);
|
|
115
|
+
|
|
116
|
+
const char *_controller_name = SDL_GameControllerNameForIndex(i);
|
|
117
|
+
if (_controller_name == nullptr) {
|
|
118
|
+
std::ostringstream message;
|
|
119
|
+
message << "SDL_GameControllerNameForIndex(" << i << ") error: " << SDL_GetError();
|
|
120
|
+
SDL_ClearError();
|
|
121
|
+
throw Napi::Error::New(env, message.str());
|
|
122
|
+
}
|
|
123
|
+
controller_name = Napi::String::New(env, _controller_name);
|
|
124
|
+
|
|
125
|
+
// This function can only error if the index is invalid.
|
|
126
|
+
SDL_GameControllerType _controller_type = SDL_GameControllerTypeForIndex(i);
|
|
127
|
+
controller_type = _controller_type != SDL_CONTROLLER_TYPE_UNKNOWN
|
|
128
|
+
? Napi::String::New(env, controller::types[_controller_type])
|
|
129
|
+
: env.Null();
|
|
91
130
|
} else {
|
|
92
|
-
|
|
131
|
+
controller_mapping = env.Null();
|
|
132
|
+
controller_name = env.Null();
|
|
133
|
+
controller_type = env.Null();
|
|
93
134
|
}
|
|
94
135
|
|
|
95
136
|
Napi::Object device = Napi::Object::New(env);
|
|
96
|
-
device.Set("_index",
|
|
97
|
-
device.Set("id",
|
|
98
|
-
device.Set("
|
|
99
|
-
device.Set("
|
|
100
|
-
device.Set("
|
|
101
|
-
device.Set("
|
|
137
|
+
device.Set("_index", i);
|
|
138
|
+
device.Set("id", id);
|
|
139
|
+
device.Set("name", name);
|
|
140
|
+
device.Set("path", path);
|
|
141
|
+
device.Set("guid", guid_string);
|
|
142
|
+
device.Set("type", type);
|
|
102
143
|
device.Set("vendor", vendor);
|
|
103
144
|
device.Set("product", product);
|
|
104
145
|
device.Set("version", version);
|
|
105
146
|
device.Set("player", player);
|
|
106
|
-
device.Set("isController",
|
|
107
|
-
device.Set("
|
|
147
|
+
device.Set("isController", is_controller);
|
|
148
|
+
device.Set("controllerMapping", controller_mapping);
|
|
149
|
+
device.Set("controllerName", controller_name);
|
|
150
|
+
device.Set("controllerType", controller_type);
|
|
108
151
|
|
|
109
152
|
devices.Set(i, device);
|
|
110
153
|
}
|
|
@@ -136,19 +179,20 @@ joystick::open (const Napi::CallbackInfo &info)
|
|
|
136
179
|
throw Napi::Error::New(env, message.str());
|
|
137
180
|
}
|
|
138
181
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
SDL_ClearError();
|
|
144
|
-
throw Napi::Error::New(env, message.str());
|
|
145
|
-
}
|
|
182
|
+
// SDL_JoystickOpen produces errors even though it succeeds
|
|
183
|
+
const char *error = SDL_GetError();
|
|
184
|
+
if (error != global::no_error) { fprintf(stderr, "SDL silent error: %s\n", error); }
|
|
185
|
+
SDL_ClearError();
|
|
146
186
|
|
|
147
187
|
int _firmware_version = SDL_JoystickGetFirmwareVersion(joystick);
|
|
148
|
-
Napi::Value firmware_version = _firmware_version
|
|
188
|
+
Napi::Value firmware_version = _firmware_version != 0
|
|
189
|
+
? Napi::Number::New(env, _firmware_version)
|
|
190
|
+
: env.Null();
|
|
149
191
|
|
|
150
192
|
const char *_serial_number = SDL_JoystickGetSerial(joystick);
|
|
151
|
-
Napi::Value serial_number = _serial_number
|
|
193
|
+
Napi::Value serial_number = _serial_number != nullptr
|
|
194
|
+
? Napi::String::New(env, _serial_number)
|
|
195
|
+
: env.Null();
|
|
152
196
|
|
|
153
197
|
SDL_bool has_led = SDL_JoystickHasLED(joystick);
|
|
154
198
|
SDL_bool has_rumble = SDL_JoystickHasRumble(joystick);
|
|
@@ -164,12 +208,8 @@ joystick::open (const Napi::CallbackInfo &info)
|
|
|
164
208
|
|
|
165
209
|
Napi::Array axes = Napi::Array::New(env, num_axes);
|
|
166
210
|
|
|
167
|
-
const char *error = SDL_GetError();
|
|
168
|
-
if (error != global::no_error) { fprintf(stderr, "SDL silent error: %s\n", error); }
|
|
169
|
-
SDL_ClearError();
|
|
170
|
-
|
|
171
211
|
for (int i = 0; i < num_axes; i++) {
|
|
172
|
-
double value = joystick::mapAxis(
|
|
212
|
+
double value = joystick::mapAxis(joystick, i);
|
|
173
213
|
error = SDL_GetError();
|
|
174
214
|
if (error != global::no_error) {
|
|
175
215
|
std::ostringstream message;
|
|
@@ -177,7 +217,7 @@ joystick::open (const Napi::CallbackInfo &info)
|
|
|
177
217
|
SDL_ClearError();
|
|
178
218
|
throw Napi::Error::New(env, message.str());
|
|
179
219
|
}
|
|
180
|
-
axes.Set(i,
|
|
220
|
+
axes.Set(i, value);
|
|
181
221
|
}
|
|
182
222
|
|
|
183
223
|
int num_balls = SDL_JoystickNumBalls(joystick);
|
|
@@ -200,8 +240,8 @@ joystick::open (const Napi::CallbackInfo &info)
|
|
|
200
240
|
}
|
|
201
241
|
|
|
202
242
|
Napi::Object ball = Napi::Object::New(env);
|
|
203
|
-
ball.Set("x",
|
|
204
|
-
ball.Set("y",
|
|
243
|
+
ball.Set("x", dx);
|
|
244
|
+
ball.Set("y", dy);
|
|
205
245
|
|
|
206
246
|
balls.Set(i, ball);
|
|
207
247
|
}
|
|
@@ -217,8 +257,8 @@ joystick::open (const Napi::CallbackInfo &info)
|
|
|
217
257
|
Napi::Array buttons = Napi::Array::New(env, num_buttons);
|
|
218
258
|
|
|
219
259
|
for (int i = 0; i < num_buttons; i++) {
|
|
220
|
-
|
|
221
|
-
buttons.Set(i,
|
|
260
|
+
bool pressed = SDL_JoystickGetButton(joystick, i);
|
|
261
|
+
buttons.Set(i, pressed);
|
|
222
262
|
}
|
|
223
263
|
|
|
224
264
|
int num_hats = SDL_JoystickNumHats(joystick);
|
|
@@ -237,12 +277,11 @@ joystick::open (const Napi::CallbackInfo &info)
|
|
|
237
277
|
}
|
|
238
278
|
|
|
239
279
|
Napi::Object result = Napi::Object::New(env);
|
|
240
|
-
// result.Set("id", Napi::Number::New(env, joystick_id)); // NOTE: Unused. Same as the device id
|
|
241
280
|
result.Set("firmwareVersion", firmware_version);
|
|
242
281
|
result.Set("serialNumber", serial_number);
|
|
243
|
-
result.Set("hasLed",
|
|
244
|
-
result.Set("hasRumble",
|
|
245
|
-
result.Set("hasRumbleTriggers",
|
|
282
|
+
result.Set("hasLed", !!has_led);
|
|
283
|
+
result.Set("hasRumble", !!has_rumble);
|
|
284
|
+
result.Set("hasRumbleTriggers", !!has_rumble_triggers);
|
|
246
285
|
result.Set("axes", axes);
|
|
247
286
|
result.Set("balls", balls);
|
|
248
287
|
result.Set("buttons", buttons);
|
package/src/native/joystick.h
CHANGED
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
namespace joystick {
|
|
10
10
|
|
|
11
|
-
extern std::map<SDL_JoystickType, std::string>
|
|
11
|
+
extern std::map<SDL_JoystickType, std::string> types;
|
|
12
12
|
extern std::map<Uint8, std::string> hat_positions;
|
|
13
13
|
extern std::map<SDL_JoystickPowerLevel, std::string> power_levels;
|
|
14
14
|
|
|
15
|
-
double mapAxis (int
|
|
15
|
+
double mapAxis (SDL_Joystick *joystick, int axis);
|
|
16
|
+
double mapAxisValue (SDL_Joystick *joystick, int axis, int value);
|
|
16
17
|
Napi::Array _getDevices (Napi::Env &env);
|
|
17
18
|
|
|
18
19
|
Napi::Value getDevices(const Napi::CallbackInfo &info);
|
package/src/native/keyboard.cpp
CHANGED
|
@@ -50,7 +50,7 @@ keyboard::getState(const Napi::CallbackInfo &info)
|
|
|
50
50
|
Napi::Array result = Napi::Array::New(env, keyboard::num_keys);
|
|
51
51
|
|
|
52
52
|
for (int i = 0 ; i < keyboard::num_keys; i++) {
|
|
53
|
-
result.Set(i,
|
|
53
|
+
result.Set(i, !!keyboard::keys[i]);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
return result;
|
package/src/native/mouse.cpp
CHANGED
|
@@ -28,8 +28,8 @@ mouse::getPosition (const Napi::CallbackInfo &info)
|
|
|
28
28
|
SDL_GetGlobalMouseState(&x, &y);
|
|
29
29
|
|
|
30
30
|
Napi::Object result = Napi::Object::New(env);
|
|
31
|
-
result.Set("x",
|
|
32
|
-
result.Set("y",
|
|
31
|
+
result.Set("x", x);
|
|
32
|
+
result.Set("y", y);
|
|
33
33
|
|
|
34
34
|
return result;
|
|
35
35
|
}
|
package/src/native/power.cpp
CHANGED
|
@@ -14,9 +14,15 @@ power::getInfo (const Napi::CallbackInfo &info)
|
|
|
14
14
|
int _seconds, _percent;
|
|
15
15
|
SDL_PowerState _state = SDL_GetPowerInfo(&_seconds, &_percent);
|
|
16
16
|
|
|
17
|
-
Napi::Value state = _state
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
Napi::Value state = _state != SDL_POWERSTATE_UNKNOWN
|
|
18
|
+
? Napi::String::New(env, power::states[_state])
|
|
19
|
+
: env.Null();
|
|
20
|
+
Napi::Value seconds = _seconds != -1
|
|
21
|
+
? Napi::Number::New(env, _seconds)
|
|
22
|
+
: env.Null();
|
|
23
|
+
Napi::Value percent = _percent != -1
|
|
24
|
+
? Napi::Number::New(env, _percent)
|
|
25
|
+
: env.Null();
|
|
20
26
|
|
|
21
27
|
Napi::Object result = Napi::Object::New(env);
|
|
22
28
|
result.Set("state", state);
|
package/src/native/sensor.cpp
CHANGED
|
@@ -33,18 +33,26 @@ sensor::getDevices (const Napi::CallbackInfo &info)
|
|
|
33
33
|
throw Napi::Error::New(env, message.str());
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
SDL_SensorType _type = SDL_SensorGetDeviceType(i);
|
|
37
36
|
// This function can only error if the index is invalid.
|
|
38
|
-
|
|
39
|
-
Napi::Value
|
|
37
|
+
SDL_SensorType _type = SDL_SensorGetDeviceType(i);
|
|
38
|
+
Napi::Value type = _type != SDL_SENSOR_UNKNOWN
|
|
39
|
+
? Napi::String::New(env, sensor::types[_type])
|
|
40
|
+
: env.Null();
|
|
41
|
+
Napi::Value side = (
|
|
42
|
+
_type != SDL_SENSOR_UNKNOWN &&
|
|
43
|
+
_type != SDL_SENSOR_ACCEL &&
|
|
44
|
+
_type != SDL_SENSOR_GYRO
|
|
45
|
+
)
|
|
46
|
+
? Napi::String::New(env, sensor::sides[_type])
|
|
47
|
+
: env.Null();
|
|
40
48
|
|
|
41
|
-
const char *name = SDL_SensorGetDeviceName(i);
|
|
42
49
|
// This function can only error if the index is invalid.
|
|
50
|
+
const char *name = SDL_SensorGetDeviceName(i);
|
|
43
51
|
|
|
44
52
|
Napi::Object device = Napi::Object::New(env);
|
|
45
|
-
device.Set("_index",
|
|
46
|
-
device.Set("id",
|
|
47
|
-
device.Set("name",
|
|
53
|
+
device.Set("_index", i);
|
|
54
|
+
device.Set("id", id);
|
|
55
|
+
device.Set("name", name);
|
|
48
56
|
device.Set("type", type);
|
|
49
57
|
device.Set("side", side);
|
|
50
58
|
|
|
@@ -87,20 +95,23 @@ sensor::getData (const Napi::CallbackInfo &info)
|
|
|
87
95
|
throw Napi::Error::New(env, message.str());
|
|
88
96
|
}
|
|
89
97
|
|
|
90
|
-
Uint64
|
|
98
|
+
Uint64 _timestamp;
|
|
91
99
|
float data[3];
|
|
92
|
-
if (SDL_SensorGetDataWithTimestamp(sensor, &
|
|
100
|
+
if (SDL_SensorGetDataWithTimestamp(sensor, &_timestamp, data, 3) == -1) {
|
|
93
101
|
std::ostringstream message;
|
|
94
102
|
message << "SDL_SensorGetDataWithTimestamp(" << sensor_id << ") error: " << SDL_GetError();
|
|
95
103
|
SDL_ClearError();
|
|
96
104
|
throw Napi::Error::New(env, message.str());
|
|
97
105
|
}
|
|
106
|
+
Napi::Value timestamp = _timestamp != 0
|
|
107
|
+
? Napi::Number::New(env, _timestamp)
|
|
108
|
+
: env.Null();
|
|
98
109
|
|
|
99
110
|
Napi::Object result = Napi::Object::New(env);
|
|
100
|
-
result.Set("timestamp", timestamp
|
|
101
|
-
result.Set("x",
|
|
102
|
-
result.Set("y",
|
|
103
|
-
result.Set("z",
|
|
111
|
+
result.Set("timestamp", timestamp);
|
|
112
|
+
result.Set("x", data[0]);
|
|
113
|
+
result.Set("y", data[1]);
|
|
114
|
+
result.Set("z", data[2]);
|
|
104
115
|
|
|
105
116
|
return result;
|
|
106
117
|
}
|
package/src/native/video.cpp
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#include <map>
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
std::map<SDL_DisplayOrientation, std::string> video::orientations;
|
|
8
9
|
std::map<SDL_PixelFormatEnum, std::string> video::formats;
|
|
9
10
|
|
|
10
11
|
|
|
@@ -49,10 +50,10 @@ video::getDisplays(const Napi::CallbackInfo &info)
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
Napi::Object geometry = Napi::Object::New(env);
|
|
52
|
-
geometry.Set("x",
|
|
53
|
-
geometry.Set("y",
|
|
54
|
-
geometry.Set("width",
|
|
55
|
-
geometry.Set("height",
|
|
53
|
+
geometry.Set("x", rect.x);
|
|
54
|
+
geometry.Set("y", rect.y);
|
|
55
|
+
geometry.Set("width", rect.w);
|
|
56
|
+
geometry.Set("height", rect.h);
|
|
56
57
|
|
|
57
58
|
if(SDL_GetDisplayUsableBounds(i, &rect) < 0) {
|
|
58
59
|
std::ostringstream message;
|
|
@@ -62,10 +63,10 @@ video::getDisplays(const Napi::CallbackInfo &info)
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
Napi::Object usable = Napi::Object::New(env);
|
|
65
|
-
usable.Set("x",
|
|
66
|
-
usable.Set("y",
|
|
67
|
-
usable.Set("width",
|
|
68
|
-
usable.Set("height",
|
|
66
|
+
usable.Set("x", rect.x);
|
|
67
|
+
usable.Set("y", rect.y);
|
|
68
|
+
usable.Set("width", rect.w);
|
|
69
|
+
usable.Set("height", rect.h);
|
|
69
70
|
|
|
70
71
|
Napi::Value dpi;
|
|
71
72
|
float ddpi, hdpi, vdpi;
|
|
@@ -73,19 +74,26 @@ video::getDisplays(const Napi::CallbackInfo &info)
|
|
|
73
74
|
dpi = env.Null();
|
|
74
75
|
} else {
|
|
75
76
|
Napi::Object dpi_obj = Napi::Object::New(env);
|
|
76
|
-
dpi_obj.Set("diagonal",
|
|
77
|
-
dpi_obj.Set("horizontal",
|
|
78
|
-
dpi_obj.Set("vertical",
|
|
77
|
+
dpi_obj.Set("diagonal", ddpi);
|
|
78
|
+
dpi_obj.Set("horizontal", hdpi);
|
|
79
|
+
dpi_obj.Set("vertical", vdpi);
|
|
79
80
|
dpi = dpi_obj;
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
SDL_DisplayOrientation _orientation = SDL_GetDisplayOrientation(i);
|
|
84
|
+
Napi::Value orientation = _orientation != SDL_ORIENTATION_UNKNOWN
|
|
85
|
+
? Napi::String::New(env, video::orientations[_orientation])
|
|
86
|
+
: env.Null();
|
|
87
|
+
|
|
82
88
|
Napi::Object display = Napi::Object::New(env);
|
|
83
|
-
display.Set("
|
|
89
|
+
display.Set("_index", i);
|
|
90
|
+
display.Set("name", name);
|
|
84
91
|
display.Set("format", video::formats[(SDL_PixelFormatEnum) mode.format]);
|
|
85
|
-
display.Set("frequency",
|
|
92
|
+
display.Set("frequency", mode.refresh_rate);
|
|
86
93
|
display.Set("geometry", geometry);
|
|
87
94
|
display.Set("usable", usable);
|
|
88
95
|
display.Set("dpi", dpi);
|
|
96
|
+
display.Set("orientation", orientation);
|
|
89
97
|
|
|
90
98
|
displays.Set(i, display);
|
|
91
99
|
}
|
package/src/native/video.h
CHANGED
package/src/native/window.cpp
CHANGED
|
@@ -228,25 +228,25 @@ window::create (const Napi::CallbackInfo &info)
|
|
|
228
228
|
if (is_visible) { SDL_ShowWindow(window); }
|
|
229
229
|
|
|
230
230
|
Napi::Object result = Napi::Object::New(env);
|
|
231
|
-
result.Set("id",
|
|
232
|
-
result.Set("x",
|
|
233
|
-
result.Set("y",
|
|
234
|
-
result.Set("width",
|
|
235
|
-
result.Set("height",
|
|
236
|
-
result.Set("pixelWidth",
|
|
237
|
-
result.Set("pixelHeight",
|
|
238
|
-
result.Set("displayIndex",
|
|
239
|
-
result.Set("fullscreen",
|
|
240
|
-
result.Set("resizable",
|
|
241
|
-
result.Set("borderless",
|
|
242
|
-
result.Set("alwaysOnTop",
|
|
243
|
-
result.Set("accelerated",
|
|
244
|
-
result.Set("vsync",
|
|
231
|
+
result.Set("id", window_id);
|
|
232
|
+
result.Set("x", x);
|
|
233
|
+
result.Set("y", y);
|
|
234
|
+
result.Set("width", width);
|
|
235
|
+
result.Set("height", height);
|
|
236
|
+
result.Set("pixelWidth", pixel_width);
|
|
237
|
+
result.Set("pixelHeight", pixel_height);
|
|
238
|
+
result.Set("displayIndex", display);
|
|
239
|
+
result.Set("fullscreen", is_fullscreen);
|
|
240
|
+
result.Set("resizable", is_resizable);
|
|
241
|
+
result.Set("borderless", is_borderless);
|
|
242
|
+
result.Set("alwaysOnTop", is_always_on_top);
|
|
243
|
+
result.Set("accelerated", is_accelerated);
|
|
244
|
+
result.Set("vsync", is_vsync);
|
|
245
245
|
result.Set("native", native);
|
|
246
|
-
result.Set("skipTaskbar",
|
|
247
|
-
result.Set("popupMenu",
|
|
248
|
-
result.Set("tooltip",
|
|
249
|
-
result.Set("utility",
|
|
246
|
+
result.Set("skipTaskbar", should_skip_taskbar);
|
|
247
|
+
result.Set("popupMenu", is_popup_menu);
|
|
248
|
+
result.Set("tooltip", is_tooltip);
|
|
249
|
+
result.Set("utility", is_utility);
|
|
250
250
|
|
|
251
251
|
return result;
|
|
252
252
|
}
|
|
@@ -317,8 +317,8 @@ window::setSize (const Napi::CallbackInfo &info)
|
|
|
317
317
|
SDL_GetWindowSizeInPixels(window, &pixel_width, &pixel_height);
|
|
318
318
|
|
|
319
319
|
Napi::Object result = Napi::Object::New(env);
|
|
320
|
-
result.Set("pixelWidth",
|
|
321
|
-
result.Set("pixelHeight",
|
|
320
|
+
result.Set("pixelWidth", pixel_width);
|
|
321
|
+
result.Set("pixelHeight", pixel_height);
|
|
322
322
|
|
|
323
323
|
return result;
|
|
324
324
|
}
|
|
@@ -420,8 +420,8 @@ window::setAcceleratedAndVsync (const Napi::CallbackInfo &info)
|
|
|
420
420
|
updateRenderer(env, window, &is_accelerated, &is_vsync);
|
|
421
421
|
|
|
422
422
|
Napi::Object result = Napi::Object::New(env);
|
|
423
|
-
result.Set("accelerated",
|
|
424
|
-
result.Set("vsync",
|
|
423
|
+
result.Set("accelerated", is_accelerated);
|
|
424
|
+
result.Set("vsync", is_vsync);
|
|
425
425
|
|
|
426
426
|
return result;
|
|
427
427
|
}
|
|
@@ -596,6 +596,12 @@ window::render (const Napi::CallbackInfo &info)
|
|
|
596
596
|
if (texture != nullptr) { SDL_DestroyTexture(texture); }
|
|
597
597
|
|
|
598
598
|
texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STREAMING, width, height);
|
|
599
|
+
if (texture == nullptr) {
|
|
600
|
+
std::ostringstream message;
|
|
601
|
+
message << "SDL_CreateTexture(" << width << ", " << height << ", " << format << ") error: " << SDL_GetError();
|
|
602
|
+
SDL_ClearError();
|
|
603
|
+
throw Napi::Error::New(env, message.str());
|
|
604
|
+
}
|
|
599
605
|
|
|
600
606
|
if (SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_NONE) < 0) {
|
|
601
607
|
std::ostringstream message;
|
package/src/types/index.d.ts
CHANGED
|
@@ -11,11 +11,25 @@ export namespace Events {
|
|
|
11
11
|
readonly display: Sdl.Video.Display
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export interface Add extends DisplayEvent {
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
export interface Add extends DisplayEvent {
|
|
15
|
+
readonly type: 'deviceAdd'
|
|
16
|
+
readonly device: Sdl.Video.Display
|
|
17
|
+
}
|
|
18
|
+
export interface Remove extends DisplayEvent {
|
|
19
|
+
readonly type: 'deviceRemove'
|
|
20
|
+
readonly device: Sdl.Video.Display
|
|
21
|
+
}
|
|
22
|
+
export interface Orient extends DisplayEvent {
|
|
23
|
+
readonly type: 'deviceOrient'
|
|
24
|
+
readonly device: Sdl.Video.Display
|
|
25
|
+
readonly orientation: Sdl.Video.Orientation
|
|
26
|
+
}
|
|
27
|
+
export interface Move extends DisplayEvent {
|
|
28
|
+
readonly type: 'deviceMove'
|
|
29
|
+
readonly device: Sdl.Video.Display
|
|
30
|
+
}
|
|
17
31
|
|
|
18
|
-
export type Any = Add | Remove | Orient
|
|
32
|
+
export type Any = Add | Remove | Orient | Move
|
|
19
33
|
|
|
20
34
|
}
|
|
21
35
|
|
|
@@ -318,6 +332,12 @@ export namespace Sdl {
|
|
|
318
332
|
|
|
319
333
|
export namespace Video {
|
|
320
334
|
|
|
335
|
+
export type Orientation
|
|
336
|
+
= 'portrait'
|
|
337
|
+
| 'portraitFlipped'
|
|
338
|
+
| 'landscape'
|
|
339
|
+
| 'landscapeFlipped'
|
|
340
|
+
|
|
321
341
|
export type Format
|
|
322
342
|
= 'rgb332'
|
|
323
343
|
| 'rgb444'
|
|
@@ -382,6 +402,7 @@ export namespace Sdl {
|
|
|
382
402
|
readonly vertical: number
|
|
383
403
|
readonly diagonal: number
|
|
384
404
|
} | null
|
|
405
|
+
readonly orientation: Orientation | null
|
|
385
406
|
}
|
|
386
407
|
|
|
387
408
|
export class Window {
|
|
@@ -499,6 +520,7 @@ export namespace Sdl {
|
|
|
499
520
|
on (event: 'displayAdd', listener: (event: Events.Display.Add) => void): this
|
|
500
521
|
on (event: 'displayRemove', listener: (event: Events.Display.Remove) => void): this
|
|
501
522
|
on (event: 'displayOrient', listener: (event: Events.Display.Orient) => void): this
|
|
523
|
+
on (event: 'displayMove', listener: (event: Events.Display.Move) => void): this
|
|
502
524
|
on (event: '*', listener: (type: string, event: Events.Display.Any) => void): this
|
|
503
525
|
|
|
504
526
|
readonly displays: Display[]
|
|
@@ -848,7 +870,8 @@ export namespace Sdl {
|
|
|
848
870
|
}
|
|
849
871
|
|
|
850
872
|
export type JoystickType
|
|
851
|
-
=
|
|
873
|
+
= null
|
|
874
|
+
| 'gamecontroller'
|
|
852
875
|
| 'wheel'
|
|
853
876
|
| 'arcadestick'
|
|
854
877
|
| 'flightstick'
|
|
@@ -879,10 +902,10 @@ export namespace Sdl {
|
|
|
879
902
|
|
|
880
903
|
export interface Device {
|
|
881
904
|
readonly id: number
|
|
882
|
-
readonly type: JoystickType
|
|
883
905
|
readonly name: string
|
|
884
906
|
readonly path: string
|
|
885
907
|
readonly guid: string
|
|
908
|
+
readonly type: JoystickType | null
|
|
886
909
|
readonly vendor: number | null
|
|
887
910
|
readonly product: number | null
|
|
888
911
|
readonly version: number | null
|
|
@@ -941,17 +964,21 @@ export namespace Sdl {
|
|
|
941
964
|
|
|
942
965
|
export namespace Controller {
|
|
943
966
|
|
|
944
|
-
export
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
967
|
+
export type ControllerType
|
|
968
|
+
= null
|
|
969
|
+
| 'xbox360'
|
|
970
|
+
| 'xboxOne'
|
|
971
|
+
| 'ps3'
|
|
972
|
+
| 'ps4'
|
|
973
|
+
| 'nintendoSwitchPro'
|
|
974
|
+
| 'virtual'
|
|
975
|
+
| 'ps5'
|
|
976
|
+
| 'amazonLuna'
|
|
977
|
+
| 'googleStadia'
|
|
978
|
+
| 'nvidiaShield'
|
|
979
|
+
| 'nintendoSwitchJoyconLeft'
|
|
980
|
+
| 'nintendoSwitchJoyconRight'
|
|
981
|
+
| 'nintendoSwitchJoyconPair'
|
|
955
982
|
|
|
956
983
|
export type Axis
|
|
957
984
|
= 'leftStickX'
|
|
@@ -982,6 +1009,19 @@ export namespace Sdl {
|
|
|
982
1009
|
| 'paddle3'
|
|
983
1010
|
| 'paddle4'
|
|
984
1011
|
|
|
1012
|
+
export interface Device {
|
|
1013
|
+
readonly id: number
|
|
1014
|
+
readonly name: string
|
|
1015
|
+
readonly path: string
|
|
1016
|
+
readonly guid: string
|
|
1017
|
+
readonly type: ControllerType | null;
|
|
1018
|
+
readonly vendor: number | null
|
|
1019
|
+
readonly product: number | null
|
|
1020
|
+
readonly version: number | null
|
|
1021
|
+
readonly player: number | null
|
|
1022
|
+
readonly mapping: string
|
|
1023
|
+
}
|
|
1024
|
+
|
|
985
1025
|
export class ControllerInstance {
|
|
986
1026
|
on (event: 'axisMotion', listener: (event: Events.Controller.AxisMotion) => void): this
|
|
987
1027
|
on (event: 'buttonDown', listener: (event: Events.Controller.ButtonDown) => void): this
|