@kmamal/sdl 0.3.4 → 0.3.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 +1 -1
- package/package.json +1 -1
- package/src/native/sdl-helpers.cpp +28 -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
|
|
package/package.json
CHANGED
|
@@ -968,35 +968,32 @@ 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
|
-
|
|
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
|
+
}
|
|
981
|
+
SDL_Rect src_rect = { 0, 0, w, h };
|
|
984
982
|
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
983
|
+
SDL_Surface * window_surface = SDL_GetWindowSurface(window);
|
|
984
|
+
if (window_surface == nullptr) {
|
|
985
|
+
RETURN_ERROR("SDL_GetWindowSurface(%d) error: %s\n", window_id, SDL_GetError());
|
|
986
|
+
}
|
|
987
|
+
SDL_Rect window_rect = { 0, 0, window_surface->w, window_surface->h };
|
|
990
988
|
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
989
|
+
if (SDL_LowerBlit(src_surface, &src_rect, window_surface, &window_rect) != 0) {
|
|
990
|
+
RETURN_ERROR("SDL_LowerBlit(%d) error: %s\n", window_id, SDL_GetError());
|
|
991
|
+
}
|
|
994
992
|
|
|
995
|
-
|
|
993
|
+
SDL_FreeSurface(src_surface);
|
|
996
994
|
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
}
|
|
995
|
+
if (SDL_UpdateWindowSurface(window) != 0) {
|
|
996
|
+
RETURN_ERROR("SDL_UpdateWindowSurface(%d) error: %s\n", window_id, SDL_GetError());
|
|
1000
997
|
}
|
|
1001
998
|
|
|
1002
999
|
return nullptr;
|
|
@@ -1198,7 +1195,7 @@ packageEvent (const SDL_Event & event, Variant & object)
|
|
|
1198
1195
|
SET_STRING(object, "type", event.type == SDL_KEYDOWN
|
|
1199
1196
|
? "keyDown"
|
|
1200
1197
|
: "keyUp");
|
|
1201
|
-
SET_NUM(object, "window", event.
|
|
1198
|
+
SET_NUM(object, "window", event.key.windowID);
|
|
1202
1199
|
|
|
1203
1200
|
SDL_Keysym symbol = event.key.keysym;
|
|
1204
1201
|
SET_NUM(object, "scancode", symbol.scancode);
|
|
@@ -1236,7 +1233,7 @@ packageEvent (const SDL_Event & event, Variant & object)
|
|
|
1236
1233
|
case SDL_MOUSEMOTION: {
|
|
1237
1234
|
SET_STRING(object, "family", "mouse");
|
|
1238
1235
|
SET_STRING(object, "type", "mouseMove");
|
|
1239
|
-
SET_NUM(object, "window", event.
|
|
1236
|
+
SET_NUM(object, "window", event.motion.windowID);
|
|
1240
1237
|
SET_BOOL(object, "touch", event.motion.which == SDL_TOUCH_MOUSEID);
|
|
1241
1238
|
SET_NUM(object, "x", event.motion.x);
|
|
1242
1239
|
SET_NUM(object, "y", event.motion.y);
|
|
@@ -1248,8 +1245,8 @@ packageEvent (const SDL_Event & event, Variant & object)
|
|
|
1248
1245
|
SET_STRING(object, "type", event.type == SDL_MOUSEBUTTONDOWN
|
|
1249
1246
|
? "mouseButtonDown"
|
|
1250
1247
|
: "mouseButtonUp");
|
|
1251
|
-
SET_NUM(object, "window", event.
|
|
1252
|
-
SET_BOOL(object, "touch", event.
|
|
1248
|
+
SET_NUM(object, "window", event.button.windowID);
|
|
1249
|
+
SET_BOOL(object, "touch", event.button.which == SDL_TOUCH_MOUSEID);
|
|
1253
1250
|
SET_NUM(object, "button", event.button.button);
|
|
1254
1251
|
SET_NUM(object, "x", event.button.x);
|
|
1255
1252
|
SET_NUM(object, "y", event.button.y);
|
|
@@ -1258,11 +1255,11 @@ packageEvent (const SDL_Event & event, Variant & object)
|
|
|
1258
1255
|
case SDL_MOUSEWHEEL: {
|
|
1259
1256
|
SET_STRING(object, "family", "mouse");
|
|
1260
1257
|
SET_STRING(object, "type", "mouseWheel");
|
|
1261
|
-
SET_NUM(object, "window", event.
|
|
1262
|
-
SET_BOOL(object, "touch", event.
|
|
1258
|
+
SET_NUM(object, "window", event.wheel.windowID);
|
|
1259
|
+
SET_BOOL(object, "touch", event.wheel.which == SDL_TOUCH_MOUSEID);
|
|
1263
1260
|
|
|
1264
1261
|
int x, y;
|
|
1265
|
-
|
|
1262
|
+
SDL_GetMouseState(&x, &y);
|
|
1266
1263
|
SET_NUM(object, "x", x);
|
|
1267
1264
|
SET_NUM(object, "y", y);
|
|
1268
1265
|
|