@kmamal/sdl 0.3.3 → 0.3.6
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 +2 -2
- package/package.json +3 -3
- package/src/javascript/keyboard/index.js +3 -1
- package/src/native/sdl-helpers.cpp +26 -31
package/README.md
CHANGED
|
@@ -446,7 +446,7 @@ Fired to indicate that the user has requested the window to close (usually by cl
|
|
|
446
446
|
|
|
447
447
|
### Event: 'close'
|
|
448
448
|
|
|
449
|
-
Indicates that the
|
|
449
|
+
Indicates that the window is about to be destroyed. Handle any cleanup here. This event will be followed by a call to `window.destroy()`.
|
|
450
450
|
|
|
451
451
|
### Event: 'keyDown'
|
|
452
452
|
|
|
@@ -704,7 +704,7 @@ Will be `true` if the mouse is over the window.
|
|
|
704
704
|
|
|
705
705
|
* `width, height, stride, format, buffer: `[`<Image>`](#image-data) The image to display on the window.
|
|
706
706
|
|
|
707
|
-
Displays an image in the window.
|
|
707
|
+
Displays an image in the window. This functions preforms no scaling (or positioning). To fill the whole window you must provide an image that matches the window's `width` and `height`.
|
|
708
708
|
|
|
709
709
|
### window.setIcon(width, height, stride, format, buffer)
|
|
710
710
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.3.
|
|
2
|
+
"version": "0.3.6",
|
|
3
3
|
"name": "@kmamal/sdl",
|
|
4
4
|
"description": "SDL2 bindings for Node.js",
|
|
5
5
|
"keywords": [
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"bindings": "^1.5.0",
|
|
41
|
-
"prebuild-install": "^
|
|
41
|
+
"prebuild-install": "^7.1.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"prebuild": "^
|
|
44
|
+
"prebuild": "^11.0.3"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -16,7 +16,9 @@ const keyboard = {
|
|
|
16
16
|
getScancode (key) {
|
|
17
17
|
if (typeof key !== 'string') { throw Object.assign(new Error("key must be a string"), { key }) }
|
|
18
18
|
|
|
19
|
-
const _key = reverseMapping[key] ?? (Array.from(key).length === 1 ? key :
|
|
19
|
+
const _key = reverseMapping[key] ?? (Array.from(key).length === 1 ? key : null)
|
|
20
|
+
if (_key === null) { throw Object.assign(new Error("invalid key"), { key }) }
|
|
21
|
+
|
|
20
22
|
return Bindings.keyboard_getScancode(_key)
|
|
21
23
|
},
|
|
22
24
|
|
|
@@ -968,35 +968,30 @@ window_render (
|
|
|
968
968
|
unsigned int format,
|
|
969
969
|
void * pixels
|
|
970
970
|
) {
|
|
971
|
-
|
|
972
|
-
{
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
RETURN_ERROR("SDL_GetWindowFromID(%d) error: %s\n", window_id, SDL_GetError());
|
|
976
|
-
}
|
|
971
|
+
SDL_Window * window = SDL_GetWindowFromID(window_id);
|
|
972
|
+
if (window == nullptr) {
|
|
973
|
+
RETURN_ERROR("SDL_GetWindowFromID(%d) error: %s\n", window_id, SDL_GetError());
|
|
974
|
+
}
|
|
977
975
|
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
SDL_Rect src_rect = { 0, 0, w, h };
|
|
976
|
+
SDL_Surface* src_surface = SDL_CreateRGBSurfaceWithFormatFrom(pixels, w, h, SDL_BITSPERPIXEL(format), stride, format);
|
|
977
|
+
SDL_SetSurfaceBlendMode(src_surface, SDL_BLENDMODE_NONE);
|
|
978
|
+
if (src_surface == nullptr) {
|
|
979
|
+
RETURN_ERROR("SDL_CreateRGBSurfaceWithFormatFrom(%d, %d, %d) error: %s\n", w, h, format, SDL_GetError());
|
|
980
|
+
}
|
|
984
981
|
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
SDL_Rect window_rect = { 0, 0, window_surface->w, window_surface->h };
|
|
982
|
+
SDL_Surface * window_surface = SDL_GetWindowSurface(window);
|
|
983
|
+
if (window_surface == nullptr) {
|
|
984
|
+
RETURN_ERROR("SDL_GetWindowSurface(%d) error: %s\n", window_id, SDL_GetError());
|
|
985
|
+
}
|
|
990
986
|
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
987
|
+
if (SDL_BlitSurface(src_surface, NULL, window_surface, NULL) != 0) {
|
|
988
|
+
RETURN_ERROR("SDL_LowerBlit(%d) error: %s\n", window_id, SDL_GetError());
|
|
989
|
+
}
|
|
994
990
|
|
|
995
|
-
|
|
991
|
+
SDL_FreeSurface(src_surface);
|
|
996
992
|
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
}
|
|
993
|
+
if (SDL_UpdateWindowSurface(window) != 0) {
|
|
994
|
+
RETURN_ERROR("SDL_UpdateWindowSurface(%d) error: %s\n", window_id, SDL_GetError());
|
|
1000
995
|
}
|
|
1001
996
|
|
|
1002
997
|
return nullptr;
|
|
@@ -1198,7 +1193,7 @@ packageEvent (const SDL_Event & event, Variant & object)
|
|
|
1198
1193
|
SET_STRING(object, "type", event.type == SDL_KEYDOWN
|
|
1199
1194
|
? "keyDown"
|
|
1200
1195
|
: "keyUp");
|
|
1201
|
-
SET_NUM(object, "window", event.
|
|
1196
|
+
SET_NUM(object, "window", event.key.windowID);
|
|
1202
1197
|
|
|
1203
1198
|
SDL_Keysym symbol = event.key.keysym;
|
|
1204
1199
|
SET_NUM(object, "scancode", symbol.scancode);
|
|
@@ -1236,7 +1231,7 @@ packageEvent (const SDL_Event & event, Variant & object)
|
|
|
1236
1231
|
case SDL_MOUSEMOTION: {
|
|
1237
1232
|
SET_STRING(object, "family", "mouse");
|
|
1238
1233
|
SET_STRING(object, "type", "mouseMove");
|
|
1239
|
-
SET_NUM(object, "window", event.
|
|
1234
|
+
SET_NUM(object, "window", event.motion.windowID);
|
|
1240
1235
|
SET_BOOL(object, "touch", event.motion.which == SDL_TOUCH_MOUSEID);
|
|
1241
1236
|
SET_NUM(object, "x", event.motion.x);
|
|
1242
1237
|
SET_NUM(object, "y", event.motion.y);
|
|
@@ -1248,8 +1243,8 @@ packageEvent (const SDL_Event & event, Variant & object)
|
|
|
1248
1243
|
SET_STRING(object, "type", event.type == SDL_MOUSEBUTTONDOWN
|
|
1249
1244
|
? "mouseButtonDown"
|
|
1250
1245
|
: "mouseButtonUp");
|
|
1251
|
-
SET_NUM(object, "window", event.
|
|
1252
|
-
SET_BOOL(object, "touch", event.
|
|
1246
|
+
SET_NUM(object, "window", event.button.windowID);
|
|
1247
|
+
SET_BOOL(object, "touch", event.button.which == SDL_TOUCH_MOUSEID);
|
|
1253
1248
|
SET_NUM(object, "button", event.button.button);
|
|
1254
1249
|
SET_NUM(object, "x", event.button.x);
|
|
1255
1250
|
SET_NUM(object, "y", event.button.y);
|
|
@@ -1258,11 +1253,11 @@ packageEvent (const SDL_Event & event, Variant & object)
|
|
|
1258
1253
|
case SDL_MOUSEWHEEL: {
|
|
1259
1254
|
SET_STRING(object, "family", "mouse");
|
|
1260
1255
|
SET_STRING(object, "type", "mouseWheel");
|
|
1261
|
-
SET_NUM(object, "window", event.
|
|
1262
|
-
SET_BOOL(object, "touch", event.
|
|
1256
|
+
SET_NUM(object, "window", event.wheel.windowID);
|
|
1257
|
+
SET_BOOL(object, "touch", event.wheel.which == SDL_TOUCH_MOUSEID);
|
|
1263
1258
|
|
|
1264
1259
|
int x, y;
|
|
1265
|
-
|
|
1260
|
+
SDL_GetMouseState(&x, &y);
|
|
1266
1261
|
SET_NUM(object, "x", x);
|
|
1267
1262
|
SET_NUM(object, "y", y);
|
|
1268
1263
|
|