@kmamal/sdl 0.7.8 → 0.8.0

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 CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Package](https://img.shields.io/npm/v/%2540kmamal%252Fsdl)](https://www.npmjs.com/package/@kmamal/sdl)
4
4
  [![Dependencies](https://img.shields.io/librariesio/release/npm/@kmamal/sdl)](https://libraries.io/npm/@kmamal%2Fsdl)
5
- [![Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/%2540kmamal%252Fsdl)](https://snyk.io/test/npm/@kmamal/sdl)
6
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
6
 
8
7
  SDL bindings for Node.js.
@@ -50,7 +49,7 @@ import sdl from '@kmamal/sdl'
50
49
  import { createCanvas } from 'canvas'
51
50
 
52
51
  const window = sdl.video.createWindow({ title: "Canvas" })
53
- const { width, height } = window
52
+ const { pixelWidth: width, pixelHeight: height } = window
54
53
  const canvas = createCanvas(width, height)
55
54
  const ctx = canvas.getContext('2d')
56
55
 
@@ -67,7 +66,7 @@ import sdl from '@kmamal/sdl'
67
66
  import createContext from '@kmamal/gl'
68
67
 
69
68
  const window = sdl.video.createWindow({title: "WebGL", opengl: true })
70
- const { width, height, native } = window
69
+ const { pixelWidth: width, pixelHeight: height, native } = window
71
70
  const gl = createContext(width, height, { window: native })
72
71
 
73
72
  // Clear screen to red
@@ -88,6 +87,7 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
88
87
  * [sdl.video](#sdlvideo)
89
88
  * [Image data](#image-data)
90
89
  * [Pixel formats](#pixel-formats)
90
+ * [High-DPI](#highdpi)
91
91
  * [sdl.video.displays](#sdlvideodisplays)
92
92
  * [sdl.video.windows](#sdlvideowindows)
93
93
  * [sdl.video.focused](#sdlvideofocused)
@@ -127,6 +127,8 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
127
127
  * [window.setPosition(x, y)](#windowsetpositionx-y)
128
128
  * [window.width](#windowwidth)
129
129
  * [window.height](#windowheight)
130
+ * [window.pixelWidth](#windowpixelwidth)
131
+ * [window.pixelHeight](#windowpixelheight)
130
132
  * [window.setSize(width, height)](#windowsetsizewidth-height)
131
133
  * [window.visible](#windowvisible)
132
134
  * [window.show([show])](#windowshowshow)
@@ -356,7 +358,7 @@ All three of these functions accept the image as a series of arguments:
356
358
  So for example, to fill the window with a red+green gradient you could do:
357
359
 
358
360
  ```js
359
- const { width, height } = window
361
+ const { pixelWidth: width, pixelHeight: height } = window
360
362
  const stride = width * 4
361
363
  const buffer = Buffer.alloc(stride * height)
362
364
 
@@ -416,6 +418,16 @@ String values used to represent how the pixels of an image are stored in a Buffe
416
418
  | `'nv12'` | `SDL_PIXELFORMAT_NV12` | planar mode: Y + U/V interleaved (2 planes) |
417
419
  | `'nv21'` | `SDL_PIXELFORMAT_NV21` | planar mode: Y + V/U interleaved (2 planes) |
418
420
 
421
+
422
+ ### High-DPI
423
+
424
+ On a high-dpi display, windows have more pixels that their `width` and `height` would indicate.
425
+ On such systems `width` and `height` (and all other measurements such as `x` and `y`) are in "points".
426
+ Points are abstract and don't have to correspond to pixels.
427
+ If you need to know a window's width and height in pixels, you should use the `pixelWidth` and `pixelHeight` properties.
428
+ You should be doing this always, since you don't know beforehand if your program will be running on a high-dpi system.
429
+
430
+
419
431
  ### sdl.video.displays
420
432
 
421
433
  * `<object>[]`
@@ -547,6 +559,8 @@ Fired when the window changes position.
547
559
 
548
560
  * `width: <number>` The window's new width.
549
561
  * `height: <number>` The window's new height.
562
+ * `pixelWidth: <number>` The window's new width in pixels. See [high-dpi](#high-dpi).
563
+ * `pixelHeight: <number>` The window's new height in pixels. See [high-dpi](#high-dpi).
550
564
 
551
565
  Fired when the window changes size.
552
566
 
@@ -720,6 +734,18 @@ The window's width.
720
734
 
721
735
  The window's height.
722
736
 
737
+ ### window.pixelWidth
738
+
739
+ * `<number>`
740
+
741
+ The window's width in pixels. This will be larger than `width` on [high-dpi](#high-dpi) displays.
742
+
743
+ ### window.pixelHeight
744
+
745
+ * `<number>`
746
+
747
+ The window's height in pixels. This will be larger than `height` on [high-dpi](#high-dpi) displays.
748
+
723
749
  ### window.setSize(width, height)
724
750
 
725
751
  * `width: <number>`: The new width.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.8",
2
+ "version": "0.8.0",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -92,6 +92,8 @@ const poll = () => {
92
92
  case Enums.eventType.resize: {
93
93
  window._width = event.width
94
94
  window._height = event.height
95
+ window._pixelWidth = event.pixelWidth
96
+ window._pixelHeight = event.pixelHeight
95
97
  } break
96
98
 
97
99
  case Enums.eventType.show: {
@@ -115,6 +115,8 @@ class Window extends EventsViaPoll {
115
115
  this._y = result.y
116
116
  this._width = result.width
117
117
  this._height = result.height
118
+ this._pixelWidth = result.pixelWidth
119
+ this._pixelHeight = result.pixelHeight
118
120
  this._fullscreen = result.fullscreen
119
121
  this._resizable = result.resizable
120
122
  this._borderless = result.borderless
@@ -157,6 +159,8 @@ class Window extends EventsViaPoll {
157
159
  this.emit('resize', {
158
160
  width: this._width,
159
161
  height: this._height,
162
+ pixelWidth: this._pixelWidth,
163
+ pixelHeight: this._pixelHeight,
160
164
  type: 'resize',
161
165
  })
162
166
  })
@@ -197,11 +201,16 @@ class Window extends EventsViaPoll {
197
201
  if (!Number.isFinite(height)) { throw Object.assign(new Error("height must be a number"), { height }) }
198
202
  if (height <= 0) { throw Object.assign(new Error("invalid height"), { height }) }
199
203
 
200
- Bindings.window_setSize(this._id, width, height)
204
+ const { pixelWidth, pixelHeight } = Bindings.window_setSize(this._id, width, height)
201
205
  this._width = width
202
206
  this._height = height
207
+ this._pixelWidth = pixelWidth
208
+ this._pixelHeight = pixelHeight
203
209
  }
204
210
 
211
+ get pixelWidth () { return this._pixelWidth }
212
+ get pixelHeight () { return this._pixelHeight }
213
+
205
214
  get visible () { return this._visible }
206
215
  show (show = true) {
207
216
  if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
@@ -341,30 +341,31 @@ window_create(napi_env env, napi_callback_info info)
341
341
  CALL_NAPI(napi_get_value_int32, argv[5], y);
342
342
  }
343
343
 
344
- bool visible, fullscreen, resizable, borderless, alwaysOnTop,
344
+ bool visible, fullscreen, resizable, borderless, always_on_top,
345
345
  accelerated, vsync, opengl,
346
- skipTaskbar, popupMenu, tooltip, utility;
346
+ skip_taskbar, popup_menu, tooltip, utility;
347
347
  CALL_NAPI(napi_get_value_bool, argv[6], &visible);
348
348
  CALL_NAPI(napi_get_value_bool, argv[7], &fullscreen);
349
349
  CALL_NAPI(napi_get_value_bool, argv[8], &resizable);
350
350
  CALL_NAPI(napi_get_value_bool, argv[9], &borderless);
351
- CALL_NAPI(napi_get_value_bool, argv[10], &alwaysOnTop);
351
+ CALL_NAPI(napi_get_value_bool, argv[10], &always_on_top);
352
352
  CALL_NAPI(napi_get_value_bool, argv[11], &accelerated);
353
353
  CALL_NAPI(napi_get_value_bool, argv[12], &vsync);
354
354
  CALL_NAPI(napi_get_value_bool, argv[13], &opengl);
355
- CALL_NAPI(napi_get_value_bool, argv[14], &skipTaskbar);
356
- CALL_NAPI(napi_get_value_bool, argv[15], &popupMenu);
355
+ CALL_NAPI(napi_get_value_bool, argv[14], &skip_taskbar);
356
+ CALL_NAPI(napi_get_value_bool, argv[15], &popup_menu);
357
357
  CALL_NAPI(napi_get_value_bool, argv[16], &tooltip);
358
358
  CALL_NAPI(napi_get_value_bool, argv[17], &utility);
359
359
 
360
- int window_id;
361
- int native_pointer_size;
360
+ int pixel_width, pixel_height, window_id, native_pointer_size;
361
+
362
362
  CALL_SDL_HELPER(window_create,
363
363
  title, display,
364
364
  &x, &y, &width, &height,
365
- visible, &fullscreen, &resizable, &borderless, &alwaysOnTop,
365
+ &pixel_width, &pixel_height,
366
+ visible, &fullscreen, &resizable, &borderless, &always_on_top,
366
367
  &accelerated, &vsync, opengl,
367
- &skipTaskbar, &popupMenu, &tooltip, &utility,
368
+ &skip_taskbar, &popup_menu, &tooltip, &utility,
368
369
  &window_id, &native_pointer, &native_pointer_size
369
370
  );
370
371
 
@@ -391,6 +392,14 @@ window_create(napi_env env, napi_callback_info info)
391
392
  CALL_NAPI(napi_create_string_latin1, "height", 6, &key);
392
393
  CALL_NAPI(napi_set_property, result, key, value);
393
394
 
395
+ CALL_NAPI(napi_create_int32, pixel_width, &value);
396
+ CALL_NAPI(napi_create_string_latin1, "pixelWidth", 10, &key);
397
+ CALL_NAPI(napi_set_property, result, key, value);
398
+
399
+ CALL_NAPI(napi_create_int32, pixel_height, &value);
400
+ CALL_NAPI(napi_create_string_latin1, "pixelHeight", 11, &key);
401
+ CALL_NAPI(napi_set_property, result, key, value);
402
+
394
403
  CALL_NAPI(napi_create_int32, fullscreen, &value);
395
404
  CALL_NAPI(napi_coerce_to_bool, value, &value);
396
405
  CALL_NAPI(napi_create_string_latin1, "fullscreen", 10, &key);
@@ -406,7 +415,7 @@ window_create(napi_env env, napi_callback_info info)
406
415
  CALL_NAPI(napi_create_string_latin1, "borderless", 10, &key);
407
416
  CALL_NAPI(napi_set_property, result, key, value);
408
417
 
409
- CALL_NAPI(napi_create_int32, alwaysOnTop, &value);
418
+ CALL_NAPI(napi_create_int32, always_on_top, &value);
410
419
  CALL_NAPI(napi_coerce_to_bool, value, &value);
411
420
  CALL_NAPI(napi_create_string_latin1, "alwaysOnTop", 11, &key);
412
421
  CALL_NAPI(napi_set_property, result, key, value);
@@ -421,12 +430,12 @@ window_create(napi_env env, napi_callback_info info)
421
430
  CALL_NAPI(napi_create_string_latin1, "vsync", 5, &key);
422
431
  CALL_NAPI(napi_set_property, result, key, value);
423
432
 
424
- CALL_NAPI(napi_create_int32, skipTaskbar, &value);
433
+ CALL_NAPI(napi_create_int32, skip_taskbar, &value);
425
434
  CALL_NAPI(napi_coerce_to_bool, value, &value);
426
435
  CALL_NAPI(napi_create_string_latin1, "skipTaskbar", 11, &key);
427
436
  CALL_NAPI(napi_set_property, result, key, value);
428
437
 
429
- CALL_NAPI(napi_create_int32, popupMenu, &value);
438
+ CALL_NAPI(napi_create_int32, popup_menu, &value);
430
439
  CALL_NAPI(napi_coerce_to_bool, value, &value);
431
440
  CALL_NAPI(napi_create_string_latin1, "popupMenu", 9, &key);
432
441
  CALL_NAPI(napi_set_property, result, key, value);
@@ -505,6 +514,8 @@ window_setPosition(napi_env env, napi_callback_info info)
505
514
  napi_value
506
515
  window_setSize(napi_env env, napi_callback_info info)
507
516
  {
517
+ napi_value result = nullptr;
518
+
508
519
  napi_value argv[3];
509
520
  size_t argc = sizeof(argv) / sizeof(napi_value);
510
521
  CALL_NAPI(napi_get_cb_info, info, &argc, argv, nullptr, nullptr);
@@ -516,10 +527,25 @@ window_setSize(napi_env env, napi_callback_info info)
516
527
  CALL_NAPI(napi_get_value_int32, argv[1], &width);
517
528
  CALL_NAPI(napi_get_value_int32, argv[2], &height);
518
529
 
519
- CALL_SDL_HELPER(window_setSize, window_id, width, height);
530
+ int pixel_width, pixel_height;
531
+ CALL_SDL_HELPER(window_setSize,
532
+ window_id, width, height,
533
+ &pixel_width, &pixel_height
534
+ );
535
+
536
+ napi_value key, value;
537
+ CALL_NAPI(napi_create_object, &result);
538
+
539
+ CALL_NAPI(napi_create_int32, pixel_width, &value);
540
+ CALL_NAPI(napi_create_string_latin1, "pixelWidth", 10, &key);
541
+ CALL_NAPI(napi_set_property, result, key, value);
542
+
543
+ CALL_NAPI(napi_create_int32, pixel_height, &value);
544
+ CALL_NAPI(napi_create_string_latin1, "pixelHeight", 11, &key);
545
+ CALL_NAPI(napi_set_property, result, key, value);
520
546
 
521
547
  cleanup:
522
- return nullptr;
548
+ return result;
523
549
  }
524
550
 
525
551
  napi_value
@@ -839,6 +839,87 @@ initialize (Variant & object)
839
839
  }
840
840
 
841
841
 
842
+ ErrorMessage *
843
+ _windowGetPixelSize(SDL_Window * window, int * pixel_width, int * pixel_height)
844
+ {
845
+ SDL_Renderer * renderer = SDL_GetRenderer(window);
846
+ if (renderer == nullptr) {
847
+ RETURN_ERROR("SDL_GetRenderer() error: %s\n", SDL_GetError());
848
+ }
849
+
850
+ if (SDL_GetRendererOutputSize(renderer, pixel_width, pixel_height) != 0) {
851
+ RETURN_ERROR("SDL_GetRendererOutputSize() error: %s\n", SDL_GetError());
852
+ }
853
+
854
+ return nullptr;
855
+ }
856
+
857
+ ErrorMessage *
858
+ _windowUpdateTexture(
859
+ SDL_Window * window,
860
+ SDL_Renderer * renderer,
861
+ int pixel_width, int pixel_height,
862
+ SDL_Texture ** texture_dst
863
+ ) {
864
+ int window_id = SDL_GetWindowID(window);
865
+
866
+ int format = SDL_GetWindowPixelFormat(window);
867
+ SDL_Texture * texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STREAMING, pixel_width, pixel_height);
868
+ if (texture == nullptr) {
869
+ RETURN_ERROR("SDL_CreateTexture(%d) error: %s\n", window_id, SDL_GetError());
870
+ }
871
+
872
+ if (SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_NONE)) {
873
+ RETURN_ERROR("SDL_SetTextureBlendMode(%d) error: %s\n", window_id, SDL_GetError());
874
+ }
875
+
876
+ SDL_Texture * old_texture = (SDL_Texture *) SDL_SetWindowData(window, "texture", texture);
877
+ if (old_texture != nullptr) { SDL_DestroyTexture(old_texture); }
878
+
879
+ if (texture_dst != nullptr) { *texture_dst = texture; }
880
+
881
+ return nullptr;
882
+ }
883
+
884
+ ErrorMessage *
885
+ _windowUpdateRenderer(
886
+ SDL_Window * window,
887
+ bool * accelerated,
888
+ bool * vsync
889
+ ) {
890
+ int window_id = SDL_GetWindowID(window);
891
+
892
+ SDL_Renderer * old_renderer = SDL_GetRenderer(window);
893
+ if (old_renderer != nullptr) { SDL_DestroyRenderer(old_renderer); }
894
+
895
+ int renderer_flags = 0
896
+ | (*accelerated ? SDL_RENDERER_ACCELERATED : SDL_RENDERER_SOFTWARE)
897
+ | (*accelerated && *vsync ? SDL_RENDERER_PRESENTVSYNC : 0);
898
+
899
+ SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, renderer_flags);
900
+ if (renderer == nullptr) {
901
+ RETURN_ERROR("SDL_CreateRenderer(%d, %d) error: %s\n", window_id, renderer_flags, SDL_GetError());
902
+ }
903
+
904
+ SDL_RendererInfo info;
905
+ SDL_GetRendererInfo(renderer, &info);
906
+
907
+ *accelerated = info.flags & SDL_RENDERER_ACCELERATED;
908
+ *vsync = info.flags & SDL_RENDERER_PRESENTVSYNC;
909
+
910
+ ErrorMessage * error;
911
+
912
+ int pixel_width, pixel_height;
913
+ error = _windowGetPixelSize(window, &pixel_width, &pixel_height);
914
+ if (error != nullptr) { return error; }
915
+
916
+ error = _windowUpdateTexture(window, renderer, pixel_width, pixel_height, nullptr);
917
+ if (error != nullptr) { return error; }
918
+
919
+ return nullptr;
920
+ }
921
+
922
+
842
923
  ErrorMessage *
843
924
  _controllerGetState (SDL_GameController * controller, Variant & object)
844
925
  {
@@ -924,9 +1005,20 @@ packageEvent (const SDL_Event & event, Variant & object)
924
1005
  break;
925
1006
  }
926
1007
  case SDL_WINDOWEVENT_SIZE_CHANGED: {
1008
+ SDL_Window * window = SDL_GetWindowFromID(event.window.windowID);
1009
+ if (window == nullptr) {
1010
+ RETURN_ERROR("SDL_CreateWindow() error: %s\n", SDL_GetError());
1011
+ }
1012
+
1013
+ int pixel_width, pixel_height;
1014
+ ErrorMessage * error = _windowGetPixelSize(window, &pixel_width, &pixel_height);
1015
+ if (error != nullptr) { return error; }
1016
+
927
1017
  SET_NUM(object, "type", (int) EventType::RESIZE);
928
1018
  SET_NUM(object, "width", event.window.data1);
929
1019
  SET_NUM(object, "height", event.window.data2);
1020
+ SET_NUM(object, "pixelWidth", pixel_width);
1021
+ SET_NUM(object, "pixelHeight", pixel_height);
930
1022
  break;
931
1023
  }
932
1024
  case SDL_WINDOWEVENT_MINIMIZED: { SET_NUM(object, "type", (int) EventType::MINIMIZE); break; }
@@ -1203,7 +1295,8 @@ events_poll (Variant & object)
1203
1295
 
1204
1296
  if (!got_event) { return nullptr; }
1205
1297
 
1206
- packageEvent(event, object);
1298
+ ErrorMessage * error = packageEvent(event, object);
1299
+ if (error != nullptr) { return error; }
1207
1300
 
1208
1301
  return nullptr;
1209
1302
  }
@@ -1218,7 +1311,8 @@ events_wait (int timeout, Variant & object)
1218
1311
 
1219
1312
  if (!got_event) { return nullptr; }
1220
1313
 
1221
- packageEvent(event, object);
1314
+ ErrorMessage * error = packageEvent(event, object);
1315
+ if (error != nullptr) { return error; }
1222
1316
 
1223
1317
  return nullptr;
1224
1318
  }
@@ -1307,87 +1401,26 @@ video_getDisplays(Variant & list)
1307
1401
  return nullptr;
1308
1402
  }
1309
1403
 
1310
- ErrorMessage *
1311
- _windowUpdateTexture(
1312
- SDL_Window * window,
1313
- SDL_Renderer * renderer,
1314
- int width, int height,
1315
- SDL_Texture ** texture_dst
1316
- ) {
1317
- int window_id = SDL_GetWindowID(window);
1318
-
1319
- int format = SDL_GetWindowPixelFormat(window);
1320
- SDL_Texture * texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STREAMING, width, height);
1321
- if (texture == nullptr) {
1322
- RETURN_ERROR("SDL_CreateTexture(%d) error: %s\n", window_id, SDL_GetError());
1323
- }
1324
-
1325
- if (SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_NONE)) {
1326
- RETURN_ERROR("SDL_SetTextureBlendMode(%d) error: %s\n", window_id, SDL_GetError());
1327
- }
1328
-
1329
- SDL_Texture * old_texture = (SDL_Texture *) SDL_SetWindowData(window, "texture", texture);
1330
- if (old_texture != nullptr) { SDL_DestroyTexture(old_texture); }
1331
-
1332
- if (texture_dst != nullptr) { *texture_dst = texture; }
1333
-
1334
- return nullptr;
1335
- }
1336
-
1337
- ErrorMessage *
1338
- _windowUpdateRenderer(
1339
- SDL_Window * window,
1340
- bool * accelerated,
1341
- bool * vsync
1342
- ) {
1343
- int window_id = SDL_GetWindowID(window);
1344
-
1345
- SDL_Renderer * old_renderer = SDL_GetRenderer(window);
1346
- if (old_renderer != nullptr) { SDL_DestroyRenderer(old_renderer); }
1347
-
1348
- int renderer_flags = 0
1349
- | (*accelerated ? SDL_RENDERER_ACCELERATED : SDL_RENDERER_SOFTWARE)
1350
- | (*accelerated && *vsync ? SDL_RENDERER_PRESENTVSYNC : 0);
1351
-
1352
- SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, renderer_flags);
1353
- if (renderer == nullptr) {
1354
- RETURN_ERROR("SDL_CreateRenderer(%d, %d) error: %s\n", window_id, renderer_flags, SDL_GetError());
1355
- }
1356
-
1357
- SDL_RendererInfo info;
1358
- SDL_GetRendererInfo(renderer, &info);
1359
-
1360
- *accelerated = info.flags & SDL_RENDERER_ACCELERATED;
1361
- *vsync = info.flags & SDL_RENDERER_PRESENTVSYNC;
1362
-
1363
- int width, height;
1364
- SDL_GetWindowSize(window, &width, &height);
1365
- ErrorMessage * error = _windowUpdateTexture(window, renderer, width, height, nullptr);
1366
- if (error != nullptr) { return error; }
1367
-
1368
- return nullptr;
1369
- }
1370
1404
 
1371
1405
  ErrorMessage *
1372
1406
  window_create (
1373
1407
  const char * title, int display,
1374
1408
  int ** x, int ** y, int ** width, int ** height,
1409
+ int * pixel_width, int * pixel_height,
1375
1410
  bool visible,
1376
1411
  bool * fullscreen,
1377
1412
  bool * resizable,
1378
1413
  bool * borderless,
1379
- bool * alwaysOnTop,
1414
+ bool * always_on_top,
1380
1415
  bool * accelerated,
1381
1416
  bool * vsync,
1382
1417
  bool opengl,
1383
- bool * skipTaskbar,
1384
- bool * popupMenu,
1418
+ bool * skip_taskbar,
1419
+ bool * popup_menu,
1385
1420
  bool * tooltip,
1386
1421
  bool * utility,
1387
1422
  int * window_id, void ** native_pointer, int * native_pointer_size
1388
1423
  ) {
1389
- SDL_Window * window;
1390
-
1391
1424
  if (*x == nullptr) {
1392
1425
  *x = (int *) malloc(sizeof(int));
1393
1426
  **x = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
@@ -1405,18 +1438,18 @@ window_create (
1405
1438
  **height = 480;
1406
1439
  }
1407
1440
  int desired_flags = 0
1408
- | SDL_WINDOW_HIDDEN
1441
+ | SDL_WINDOW_HIDDEN | SDL_WINDOW_ALLOW_HIGHDPI
1409
1442
  | (*fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)
1410
1443
  | (*resizable ? SDL_WINDOW_RESIZABLE : 0)
1411
1444
  | (*borderless ? SDL_WINDOW_BORDERLESS : 0)
1412
- | (*alwaysOnTop ? SDL_WINDOW_ALWAYS_ON_TOP : 0)
1445
+ | (*always_on_top ? SDL_WINDOW_ALWAYS_ON_TOP : 0)
1413
1446
  | (opengl ? SDL_WINDOW_OPENGL : 0)
1414
- | (*skipTaskbar ? SDL_WINDOW_SKIP_TASKBAR : 0)
1415
- | (*popupMenu ? SDL_WINDOW_POPUP_MENU : 0)
1447
+ | (*skip_taskbar ? SDL_WINDOW_SKIP_TASKBAR : 0)
1448
+ | (*popup_menu ? SDL_WINDOW_POPUP_MENU : 0)
1416
1449
  | (*tooltip ? SDL_WINDOW_TOOLTIP : 0)
1417
1450
  | (*utility ? SDL_WINDOW_UTILITY : 0);
1418
1451
 
1419
- window = SDL_CreateWindow(title, **x, **y, **width, **height, desired_flags);
1452
+ SDL_Window * window = SDL_CreateWindow(title, **x, **y, **width, **height, desired_flags);
1420
1453
  if (window == nullptr) {
1421
1454
  RETURN_ERROR("SDL_CreateWindow() error: %s\n", SDL_GetError());
1422
1455
  }
@@ -1427,9 +1460,9 @@ window_create (
1427
1460
  *fullscreen = actual_flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP);
1428
1461
  *resizable = actual_flags & SDL_WINDOW_RESIZABLE;
1429
1462
  *borderless = actual_flags & SDL_WINDOW_BORDERLESS;
1430
- *alwaysOnTop = actual_flags & SDL_WINDOW_ALWAYS_ON_TOP;
1431
- *skipTaskbar = actual_flags & SDL_WINDOW_SKIP_TASKBAR;
1432
- *popupMenu = actual_flags & SDL_WINDOW_POPUP_MENU;
1463
+ *always_on_top = actual_flags & SDL_WINDOW_ALWAYS_ON_TOP;
1464
+ *skip_taskbar = actual_flags & SDL_WINDOW_SKIP_TASKBAR;
1465
+ *popup_menu = actual_flags & SDL_WINDOW_POPUP_MENU;
1433
1466
  *tooltip = actual_flags & SDL_WINDOW_TOOLTIP;
1434
1467
  *utility = actual_flags & SDL_WINDOW_UTILITY;
1435
1468
 
@@ -1453,7 +1486,12 @@ window_create (
1453
1486
  *native_pointer_size = size;
1454
1487
  }
1455
1488
 
1456
- ErrorMessage * error = _windowUpdateRenderer(window, accelerated, vsync);
1489
+ ErrorMessage * error;
1490
+
1491
+ error = _windowUpdateRenderer(window, accelerated, vsync);
1492
+ if (error != nullptr) { return error; }
1493
+
1494
+ error = _windowGetPixelSize(window, pixel_width, pixel_height);
1457
1495
  if (error != nullptr) { return error; }
1458
1496
 
1459
1497
  if (visible) { SDL_ShowWindow(window); }
@@ -1488,7 +1526,7 @@ window_setPosition (int window_id, int x, int y)
1488
1526
  }
1489
1527
 
1490
1528
  ErrorMessage *
1491
- window_setSize (int window_id, int width, int height)
1529
+ window_setSize (int window_id, int width, int height, int * pixel_width, int * pixel_height)
1492
1530
  {
1493
1531
  SDL_Window * window = SDL_GetWindowFromID(window_id);
1494
1532
  if (window == nullptr) {
@@ -1497,6 +1535,9 @@ window_setSize (int window_id, int width, int height)
1497
1535
 
1498
1536
  SDL_SetWindowSize(window, width, height);
1499
1537
 
1538
+ ErrorMessage * error = _windowGetPixelSize(window, pixel_width, pixel_height);
1539
+ if (error != nullptr) { return error; }
1540
+
1500
1541
  return nullptr;
1501
1542
  }
1502
1543
 
@@ -1694,14 +1735,15 @@ window_render (
1694
1735
  RETURN_ERROR("SDL_QueryTexture(%d) error: %s\n", window_id, SDL_GetError());
1695
1736
  }
1696
1737
 
1697
- int window_width, window_height;
1698
- SDL_GetWindowSize(window, &window_width, &window_height);
1738
+ int pixel_width, pixel_height;
1739
+ ErrorMessage * error = _windowGetPixelSize(window, &pixel_width, &pixel_height);
1740
+ if (error != nullptr) { return error; }
1699
1741
 
1700
- if (window_width != texture_width || window_height != texture_height) {
1701
- ErrorMessage * error = _windowUpdateTexture(window, renderer, window_width, window_height, &texture);
1742
+ if (pixel_width != texture_width || pixel_height != texture_height) {
1743
+ ErrorMessage * error = _windowUpdateTexture(window, renderer, pixel_width, pixel_height, &texture);
1702
1744
  if (error != nullptr) { return error; }
1703
- texture_width = window_width;
1704
- texture_height = window_height;
1745
+ texture_width = pixel_width;
1746
+ texture_height = pixel_height;
1705
1747
  }
1706
1748
 
1707
1749
  SDL_Surface * src_surface = SDL_CreateRGBSurfaceWithFormatFrom(pixels, w, h, SDL_BITSPERPIXEL(format), stride, format);
@@ -56,6 +56,7 @@ ErrorMessage * video_getDisplays (Variant & list);
56
56
  ErrorMessage * window_create (
57
57
  const char * title, int display,
58
58
  int ** x, int ** y, int ** width, int ** height,
59
+ int * pixel_width, int * pixel_height,
59
60
  bool visible,
60
61
  bool * fullscreen,
61
62
  bool * resizable,
@@ -72,7 +73,10 @@ ErrorMessage * window_create (
72
73
  );
73
74
  ErrorMessage * window_setTitle (int window_id, const char * title);
74
75
  ErrorMessage * window_setPosition (int window_id, int x, int y);
75
- ErrorMessage * window_setSize (int window_id, int width, int height);
76
+ ErrorMessage * window_setSize (
77
+ int window_id, int width, int height,
78
+ int * pixel_width, int * pixel_height
79
+ );
76
80
  ErrorMessage * window_setFullscreen (int window_id, bool * fullscreen);
77
81
  ErrorMessage * window_setResizable (int window_id, bool * resizable);
78
82
  ErrorMessage * window_setBorderless (int window_id, bool * borderless);
@@ -67,8 +67,10 @@ export namespace Events {
67
67
  }
68
68
  interface Resize extends WindowEvent {
69
69
  readonly type: 'resize'
70
- readonly width: number,
70
+ readonly width: number
71
71
  readonly height: number
72
+ readonly pixelWidth: number
73
+ readonly pixelHeight: number
72
74
  }
73
75
  interface Focus extends WindowEvent { readonly type: 'focus' }
74
76
  interface Blur extends WindowEvent { readonly type: 'blur' }
@@ -380,6 +382,9 @@ export namespace Sdl {
380
382
  readonly height: number
381
383
  setSize (width: number, height: number): void
382
384
 
385
+ readonly pixelWidth: number
386
+ readonly pixelHeight: number
387
+
383
388
  readonly visible: boolean
384
389
  show (show?: boolean): void
385
390
  hide (): void