@kmamal/sdl 0.11.4 → 0.11.7
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 +70 -16
- package/binding.gyp +1 -0
- package/package.json +1 -1
- 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 +61 -123
- 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/javascript/video/window.js +6 -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 +161 -79
- package/src/native/events.h +2 -0
- package/src/native/global.cpp +47 -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 +41 -29
- package/src/types/index.d.ts +65 -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
|
@@ -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;
|
|
@@ -221,24 +228,25 @@ window::create (const Napi::CallbackInfo &info)
|
|
|
221
228
|
if (is_visible) { SDL_ShowWindow(window); }
|
|
222
229
|
|
|
223
230
|
Napi::Object result = Napi::Object::New(env);
|
|
224
|
-
result.Set("id",
|
|
225
|
-
result.Set("x",
|
|
226
|
-
result.Set("y",
|
|
227
|
-
result.Set("width",
|
|
228
|
-
result.Set("height",
|
|
229
|
-
result.Set("pixelWidth",
|
|
230
|
-
result.Set("pixelHeight",
|
|
231
|
-
result.Set("
|
|
232
|
-
result.Set("
|
|
233
|
-
result.Set("
|
|
234
|
-
result.Set("
|
|
235
|
-
result.Set("
|
|
236
|
-
result.Set("
|
|
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);
|
|
237
245
|
result.Set("native", native);
|
|
238
|
-
result.Set("skipTaskbar",
|
|
239
|
-
result.Set("popupMenu",
|
|
240
|
-
result.Set("tooltip",
|
|
241
|
-
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);
|
|
242
250
|
|
|
243
251
|
return result;
|
|
244
252
|
}
|
|
@@ -309,8 +317,8 @@ window::setSize (const Napi::CallbackInfo &info)
|
|
|
309
317
|
SDL_GetWindowSizeInPixels(window, &pixel_width, &pixel_height);
|
|
310
318
|
|
|
311
319
|
Napi::Object result = Napi::Object::New(env);
|
|
312
|
-
result.Set("pixelWidth",
|
|
313
|
-
result.Set("pixelHeight",
|
|
320
|
+
result.Set("pixelWidth", pixel_width);
|
|
321
|
+
result.Set("pixelHeight", pixel_height);
|
|
314
322
|
|
|
315
323
|
return result;
|
|
316
324
|
}
|
|
@@ -412,8 +420,8 @@ window::setAcceleratedAndVsync (const Napi::CallbackInfo &info)
|
|
|
412
420
|
updateRenderer(env, window, &is_accelerated, &is_vsync);
|
|
413
421
|
|
|
414
422
|
Napi::Object result = Napi::Object::New(env);
|
|
415
|
-
result.Set("accelerated",
|
|
416
|
-
result.Set("vsync",
|
|
423
|
+
result.Set("accelerated", is_accelerated);
|
|
424
|
+
result.Set("vsync", is_vsync);
|
|
417
425
|
|
|
418
426
|
return result;
|
|
419
427
|
}
|
|
@@ -584,22 +592,20 @@ window::render (const Napi::CallbackInfo &info)
|
|
|
584
592
|
|| cached.width != width
|
|
585
593
|
|| cached.height != height
|
|
586
594
|
|| cached.format != format
|
|
587
|
-
|| cached.scaling != scaling
|
|
588
595
|
) {
|
|
589
596
|
if (texture != nullptr) { SDL_DestroyTexture(texture); }
|
|
590
597
|
|
|
591
598
|
texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STREAMING, width, height);
|
|
592
|
-
|
|
593
|
-
if (SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_NONE) < 0) {
|
|
599
|
+
if (texture == nullptr) {
|
|
594
600
|
std::ostringstream message;
|
|
595
|
-
message << "
|
|
601
|
+
message << "SDL_CreateTexture(" << width << ", " << height << ", " << format << ") error: " << SDL_GetError();
|
|
596
602
|
SDL_ClearError();
|
|
597
603
|
throw Napi::Error::New(env, message.str());
|
|
598
604
|
}
|
|
599
605
|
|
|
600
|
-
if(
|
|
606
|
+
if (SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_NONE) < 0) {
|
|
601
607
|
std::ostringstream message;
|
|
602
|
-
message << "
|
|
608
|
+
message << "SDL_SetTextureBlendMode(" << window_id << ") error: " << SDL_GetError();
|
|
603
609
|
SDL_ClearError();
|
|
604
610
|
throw Napi::Error::New(env, message.str());
|
|
605
611
|
}
|
|
@@ -608,7 +614,13 @@ window::render (const Napi::CallbackInfo &info)
|
|
|
608
614
|
cached.width = width;
|
|
609
615
|
cached.height = height;
|
|
610
616
|
cached.format = format;
|
|
611
|
-
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
if(SDL_SetTextureScaleMode(texture, scaling) < 0) {
|
|
620
|
+
std::ostringstream message;
|
|
621
|
+
message << "SDL_SetTextureScaleMode(" << window_id << ", " << scaling << ") error: " << SDL_GetError();
|
|
622
|
+
SDL_ClearError();
|
|
623
|
+
throw Napi::Error::New(env, message.str());
|
|
612
624
|
}
|
|
613
625
|
|
|
614
626
|
SDL_UpdateTexture(texture, nullptr, pixels, stride);
|