@kmamal/sdl 0.10.11 → 0.10.13

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
@@ -25,7 +25,7 @@ SDL is bundled along with the binaries so a separate installation is not necessa
25
25
  This package is self-contained.
26
26
  Just run:
27
27
 
28
- ```
28
+ ```bash
29
29
  npm install @kmamal/sdl
30
30
  ```
31
31
 
@@ -44,6 +44,7 @@ window.on('*', console.log)
44
44
  ```
45
45
 
46
46
  ### Canvas
47
+
47
48
  ```js
48
49
  import sdl from '@kmamal/sdl'
49
50
  import { createCanvas } from 'canvas'
@@ -64,6 +65,7 @@ window.render(width, height, width * 4, 'bgra32', buffer)
64
65
  ```
65
66
 
66
67
  ### WebGL
68
+
67
69
  ```js
68
70
  import sdl from '@kmamal/sdl'
69
71
  import createContext from '@kmamal/gl'
@@ -82,6 +84,7 @@ gl.swap()
82
84
  ```
83
85
 
84
86
  ### WebGPU
87
+
85
88
  ```js
86
89
  import sdl from '@kmamal/sdl'
87
90
  import gpu from '@kmamal/gpu'
@@ -203,7 +206,7 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
203
206
  * [window.popupMenu](#windowpopupmenu)
204
207
  * [window.tooltip](#windowtooltip)
205
208
  * [window.utility](#windowutility)
206
- * [window.render(width, height, stride, format, buffer)](#windowrenderwidth-height-stride-format-buffer)
209
+ * [window.render(width, height, stride, format, buffer[, options])](#windowrenderwidth-height-stride-format-buffer-options)
207
210
  * [window.setIcon(width, height, stride, format, buffer)](#windowseticonwidth-height-stride-format-buffer)
208
211
  * [window.flash(untilFocused)](#windowflashuntilfocused)
209
212
  * [window.stopFlashing()](#windowstopflashing)
@@ -231,6 +234,7 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
231
234
  * [sdl.mouse.uncapture()](#sdlmouseuncapture)
232
235
  * [sdl.joystick](#sdljoystick)
233
236
  * [Hat positions](#hat-positions)
237
+ * [Power levels](#power-levels)
234
238
  * [Event: 'deviceAdd'](#joystick-event-deviceadd)
235
239
  * [Event: 'deviceRemove'](#joystick-event-deviceremove)
236
240
  * [sdl.joystick.devices](#sdljoystickdevices)
@@ -340,7 +344,7 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
340
344
  * [class AudioRecordingInstance extends AudioInstance](#class-audiorecordinginstance-extends-audioinstance)
341
345
  * [recordingInstance.dequeue(buffer[, bytes])](#recordinginstancedequeuebuffer-bytes)
342
346
  * [sdl.clipboard](#sdlclipboard)
343
- * [Event: 'update'](#event-update)
347
+ * [Event: 'update'](#clipboard-event-update)
344
348
  * [sdl.clipboard.text](#sdlclipboardtext)
345
349
  * [sdl.clipboard.setText(text)](#sdlclipboardsettexttext)
346
350
  * [sdl.power](#sdlpower)
@@ -355,9 +359,9 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
355
359
  * `<object>`
356
360
  * `version: <object>`
357
361
  * `compile: <object>` The SDL version the bindings were compiled against.
358
- * `major, minor, patch: <semver>` The components of the version.
362
+ * `major, minor, patch: <Semver>` The components of the version.
359
363
  * `runtime: <object>` The SDL version of the dynamic library the is loaded.
360
- * `major, minor, patch: <semver>` The components of the version.
364
+ * `major, minor, patch: <Semver>` The components of the version.
361
365
  * `platform: <string>` The name of the platform we are running on. Possible values are: `'Linux'`, `'Windows'`, and `'Mac OS X'`.
362
366
  * `drivers: <object>`
363
367
  * `video: <object>`
@@ -402,11 +406,13 @@ Sample data for Ubuntu:
402
406
  ### Image data
403
407
 
404
408
  There are 3 places in the API where you will need to provide an image to the library:
405
- * [`window.render()`](#windowrenderwidth-height-stride-format-buffer)
409
+
410
+ * [`window.render()`](#windowrenderwidth-height-stride-format-buffer-options)
406
411
  * [`window.setIcon()`](#windowseticonwidth-height-stride-format-buffer)
407
412
  * [`mouse.setCursorImage()`](#sdlmousesetcursorimagewidth-height-stride-format-buffer-x-y)
408
413
 
409
414
  All three of these functions accept the image as a series of arguments:
415
+
410
416
  * `width: <number>` The width of the image in pixels.
411
417
  * `height: <number>` The height of the image in pixels.
412
418
  * `stride: <number>` How many bytes each row of the image takes up in the buffer. This is usually equal to `width * bytesPerPixel`, but can be larger if the rows of the buffer are padded to always be some multiple of bytes.
@@ -592,6 +598,7 @@ The window that the mouse is hovered over, or `null` if the mouse is not over a
592
598
  Creates a new window.
593
599
 
594
600
  The following restrictions apply:
601
+
595
602
  * If you specify the `display` option, you can't also specify the `x` or `y` options, and vice-versa.
596
603
  * The `resizable` and `borderless` options are mutually exclusive.
597
604
  * The `opengl` and `webgpu` options are mutually exclusive.
@@ -599,7 +606,7 @@ The following restrictions apply:
599
606
  * The `accelerated` and `vsync` options have no effect if either `opengl` or `webgpu` is also specified.
600
607
 
601
608
  If you set the `opengl` or `webgpu` options, then you can only render to the window with OpenGL/WebGPU calls.
602
- Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer) will fail.
609
+ Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-options) will fail.
603
610
 
604
611
  ## class Window
605
612
 
@@ -941,7 +948,7 @@ If you have set the `opengl` or `webgpu` options, then calls to this function wi
941
948
 
942
949
  Will be `true` if the window was created in OpenGl mode.
943
950
  In OpenGL mode, you can only render to the window with OpenGL calls.
944
- Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer) will fail.
951
+ Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-options) will fail.
945
952
 
946
953
  ### window.webgpu
947
954
 
@@ -949,7 +956,7 @@ Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer) will fail.
949
956
 
950
957
  Will be `true` if the window was created in WebGPU mode.
951
958
  In WebGPU mode, you can only render to the window with WebGPU calls.
952
- Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer) will fail.
959
+ Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-options) will fail.
953
960
 
954
961
  ### window.native
955
962
 
@@ -1030,15 +1037,32 @@ X11 only.
1030
1037
  Will be `true` if the window was created with `utility: true`.
1031
1038
  Such a window will always be treated as a utility window.
1032
1039
 
1033
- ### window.render(width, height, stride, format, buffer)
1040
+ ### window.render(width, height, stride, format, buffer[, options])
1034
1041
 
1035
1042
  * `width, height, stride, format, buffer: `[`<Image>`](#image-data) The image to display on the window.
1043
+ * `options: <object>`
1044
+ * `scaling: <string>` How to scale the image to match the window size. Default: `'nearest'`
1045
+ * `dstRect: <object>` Where exactly on the window to draw the image. Default: whole window.
1046
+ * `x, y, width, height: <rect>` The components of the rectangle.
1036
1047
 
1037
1048
  Displays an image in the window.
1038
- The provided image will be stretched over the entire window.
1039
1049
 
1040
- If you set the `opengl` or `webgpu` options, then you can only render to the window with OpenGL/WebGPU calls.
1041
- Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer) will fail.
1050
+ By default the image is displayed over the entire surface of the window.
1051
+ You can pass the optional `dstRect` parameter to set where exactly on the window to display the image.
1052
+ The rest of the window will be filled with black.
1053
+
1054
+ If the dimensions of the image do not match the dimensions of the area it should be displayed in, then the image will be stretched to match.
1055
+ The `scaling` argument controls how exactly the scaling is implemented.
1056
+ Possible values are:
1057
+
1058
+ | Value | Corresponding `SDL_ScaleMode` | Description |
1059
+ | --- | --- | --- |
1060
+ | `'nearest'` | `SDL_ScaleModeNearest` | nearest pixel sampling |
1061
+ | `'linear'` | `SDL_ScaleModeLinear` | linear filtering |
1062
+ | `'best'` | `SDL_ScaleModeBest` | anisotropic filtering |
1063
+
1064
+ If the window was created with either of the `opengl` or `webgpu` options, then you can only render to the window with OpenGL/WebGPU calls.
1065
+ Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-options) will fail.
1042
1066
 
1043
1067
  ### window.setIcon(width, height, stride, format, buffer)
1044
1068
 
@@ -1116,6 +1140,7 @@ The same key will always produce the same scancode.
1116
1140
  Values are based on the [USB usage page standard](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf).
1117
1141
 
1118
1142
  <details>
1143
+
1119
1144
  <summary>Click to expand table</summary>
1120
1145
 
1121
1146
  | Value | Corresponding `SDL_Scancode` | Comment |
@@ -1362,6 +1387,7 @@ Values are based on the [USB usage page standard](https://www.usb.org/sites/defa
1362
1387
  | `sdl.keyboard.SCANCODE.APP2` | `SDL_SCANCODE_APP2` | |
1363
1388
  | `sdl.keyboard.SCANCODE.AUDIOREWIND` | `SDL_SCANCODE_AUDIOREWIND` | |
1364
1389
  | `sdl.keyboard.SCANCODE.AUDIOFASTFORWARD` | `SDL_SCANCODE_AUDIOFASTFORWARD` | |
1390
+
1365
1391
  </details>
1366
1392
 
1367
1393
  ### sdl.keyboard.getKey(scancode)
@@ -1503,6 +1529,19 @@ String values used to represent the positions of a joystick hat
1503
1529
  | `'leftup'` | `SDL_HAT_LEFTUP` |
1504
1530
  | `'leftdown'` | `SDL_HAT_LEFTDOWN` |
1505
1531
 
1532
+ ### Power levels
1533
+
1534
+ String values used to represent the power level of a joystick or controller
1535
+
1536
+ | Value | Corresponding `SDL_JoystickPowerLevel` |
1537
+ | --- | --- |
1538
+ | `'empty'` | `SDL_JOYSTICK_POWER_EMPTY` |
1539
+ | `'low'` | `SDL_JOYSTICK_POWER_LOW` |
1540
+ | `'medium'` | `SDL_JOYSTICK_POWER_MEDIUM` |
1541
+ | `'full'` | `SDL_JOYSTICK_POWER_FULL` |
1542
+ | `'wired'` | `SDL_JOYSTICK_POWER_WIRED` |
1543
+ | `'max'` | `SDL_JOYSTICK_POWER_MAX` |
1544
+
1506
1545
  <a id="joystick-event-deviceadd"></a>
1507
1546
 
1508
1547
  ### Event: 'deviceAdd'
@@ -1677,21 +1716,10 @@ An array of values, each corresponding to the position of one of the joystick's
1677
1716
 
1678
1717
  ### joystickInstance.power
1679
1718
 
1680
- * `<PowerLevel>|<null>`
1719
+ * [`<PowerLevel>`](#power-levels)`|<null>`
1681
1720
 
1682
1721
  The current power level of the joystick device, or `null` if it is unknown.
1683
1722
 
1684
- Possible values are:
1685
-
1686
- | Value | Corresponding `SDL_JoystickPowerLevel` |
1687
- | --- | --- |
1688
- | `'empty'` | `SDL_JOYSTICK_POWER_EMPTY` |
1689
- | `'low'` | `SDL_JOYSTICK_POWER_LOW` |
1690
- | `'medium'` | `SDL_JOYSTICK_POWER_MEDIUM` |
1691
- | `'full'` | `SDL_JOYSTICK_POWER_FULL` |
1692
- | `'wired'` | `SDL_JOYSTICK_POWER_WIRED` |
1693
- | `'max'` | `SDL_JOYSTICK_POWER_MAX` |
1694
-
1695
1723
  ### joystickInstance.setPlayer(index)
1696
1724
 
1697
1725
  * `index: <number>` The player index to assign to the joystick.
@@ -1781,6 +1809,7 @@ A mapping is a string that consists of the device's name, it's GUID, and a serie
1781
1809
  See the sample output [`here`](#sdlcontrollerdevices) for an example.
1782
1810
  SDL has pretty good default controller mappings, but if you need more, there's a community sourced database available on https://github.com/gabomdq/SDL_GameControllerDB.
1783
1811
  You can add them via:
1812
+
1784
1813
  ```js
1785
1814
  const url = 'https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt'
1786
1815
  const result = await fetch(url)
@@ -1956,9 +1985,9 @@ The values will be `true` for buttons that are pressed and `false` otherwise.
1956
1985
 
1957
1986
  ### controllerInstance.power
1958
1987
 
1959
- * [`<PowerLevel>`](#power-levels)
1988
+ * [`<PowerLevel>`](#power-levels)`|<null>`
1960
1989
 
1961
- The current power level of the controller device.
1990
+ The current power level of the joystick device, or `null` if it is unknown.
1962
1991
 
1963
1992
  ### controllerInstance.setPlayer(index)
1964
1993
 
@@ -2075,7 +2104,7 @@ Instead, objects returned by [`sdl.sensor.openDevice()`](#sdlsensoropendevicedev
2075
2104
  ### Event: 'update'
2076
2105
 
2077
2106
  Fired when the sensor's data changes.
2078
- Get the new data by accessing [`sensorInstance.data`](#sensorInstancedata)
2107
+ Get the new data by accessing [`sensorInstance.data`](#sensorinstancedata)
2079
2108
 
2080
2109
  <a id="sensor-instance-event-close"></a>
2081
2110
 
@@ -2093,7 +2122,7 @@ The [device](#sdlsensordevices) from which this instance was opened.
2093
2122
  ### sensorInstance.data
2094
2123
 
2095
2124
  * `<object>`
2096
- * `timestamp: <number>|<null>` The time this measurement was taken **in microseconds**, or `null` if that's not available.
2125
+ * `timestamp: <number>|<null>` The time this measurement was taken __in microseconds__, or `null` if that's not available.
2097
2126
  * `x: <number>` X axis value.
2098
2127
  * `y: <number>` Y axis value.
2099
2128
  * `z: <number>` Z axis value.
@@ -2135,6 +2164,7 @@ An audio buffer is a sequence of frames, and each frame is a sequence of samples
2135
2164
  A _sample_ is a single number representing the intensity of an audio channel at a point in time.
2136
2165
  For audio with multiple channels, each point in time is represented by multiple samples (one per channel) that together make up a _frame_.
2137
2166
  The samples in a frame are arranged as follows:
2167
+
2138
2168
  * For 1 channel (mono) a frame contains just the one sample.
2139
2169
  * For 2 channels (stereo) the frame's first sample will be the one for the left channel, followed by the one for the right channel.
2140
2170
  * For 4 channels (quad) the layout is front-left, front-right, rear-left, rear-right.
@@ -2500,6 +2530,8 @@ Takes recorded audio data that has been put on the queue, and writes it to the p
2500
2530
 
2501
2531
  ## sdl.clipboard
2502
2532
 
2533
+ <a id="clipboard-event-update"></a>
2534
+
2503
2535
  ### Event: 'update'
2504
2536
 
2505
2537
  Fired when the contents of the clipboard have changed.
@@ -2523,7 +2555,7 @@ Changes the text contents of the clipboard.
2523
2555
  ### sdl.power.info
2524
2556
 
2525
2557
  * `<object>`
2526
- * `state: <string>|null` One of `'noBattery'`, `'battery'`, `'charging'`, `'charged'`. Will be `null` if it can't be determinded.
2558
+ * `state: <string>|<null>` One of `'noBattery'`, `'battery'`, `'charging'`, `'charged'`. Will be `null` if it can't be determinded.
2527
2559
  * `seconds: <number>|<null>` Seconds of battery life left. Will be `null` if not running on battery, or if it can't be determinded.
2528
2560
  * `percent: <number>|<null>` Percentage of battery life left. Will be `null` if not running on battery, or if it can't be determinded.
2529
2561
 
@@ -2542,12 +2574,13 @@ This is still possible! Even if the threads do not have access to the SDL-relate
2542
2574
  Since these are just helpers and don't call any SLD code underneath it's safe to use them. They are made available through the `@kmamal/sdl/helpers` sub-module that does not load any of the native code. For an example of their use see [this example](https://github.com/kmamal/node-sdl/blob/master/examples/12-audio-thread/audio-worker.js).
2543
2575
 
2544
2576
  The functions included in `@kmamal/sdl/helpers` are:
2545
- - [`sdl.audio.bytesPerSample`](#sdlaudiobytespersampleformat)
2546
- - [`sdl.audio.minSampleValue`](#sdlaudiominsamplevalueformat)
2547
- - [`sdl.audio.maxSampleValue`](#sdlaudiomaxsamplevalueformat)
2548
- - [`sdl.audio.zeroSampleValue`](#sdlaudiozerosamplevalueformat)
2549
- - [`sdl.audio.readSample`](#sdlaudioreadsampleformat-buffer-offset)
2550
- - [`sdl.audio.writeSample`](#sdlaudiowritesampleformat-buffer-value-offset)
2577
+
2578
+ * [`sdl.audio.bytesPerSample`](#sdlaudiobytespersampleformat)
2579
+ * [`sdl.audio.minSampleValue`](#sdlaudiominsamplevalueformat)
2580
+ * [`sdl.audio.maxSampleValue`](#sdlaudiomaxsamplevalueformat)
2581
+ * [`sdl.audio.zeroSampleValue`](#sdlaudiozerosamplevalueformat)
2582
+ * [`sdl.audio.readSample`](#sdlaudioreadsampleformat-buffer-offset)
2583
+ * [`sdl.audio.writeSample`](#sdlaudiowritesampleformat-buffer-value-offset)
2551
2584
 
2552
2585
 
2553
2586
  ## Building from source
@@ -2569,6 +2602,7 @@ You will need to have `cmake` installed for that to work.
2569
2602
 
2570
2603
  You could also have found your way to the "Building from source" section because you are trying to contribute to this package.
2571
2604
  There are some npm scripts in `package.json` that could be of use to you:
2605
+
2572
2606
  * `npm run clean` deletes all folders that are created during the build, as well as `node_modules`.
2573
2607
  * `npm run download-release` downloads the prebuilt binaries. This is the first thing the install script tries to do.
2574
2608
  * `npm run download-sdl` downloads the SDL headers and libraries from `@kmamal/build-sdl` so you can compile against them in later steps. This is the second step in the install script, after `download-release` has failed.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.10.11",
2
+ "version": "0.10.13",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -357,12 +357,17 @@ class Window extends EventsViaPoll {
357
357
  get tooltip () { return this._tooltip }
358
358
  get utility () { return this._utility }
359
359
 
360
- render (width, height, stride, format, buffer) {
360
+ render (width, height, stride, format, buffer, options = {}) {
361
361
  if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
362
362
 
363
363
  if (this._opengl) { throw new Error("can't call render in opengl mode") }
364
364
  if (this._webgpu) { throw new Error("can't call render in webgpu mode") }
365
365
 
366
+ const {
367
+ scaling = 'nearest',
368
+ dstRect = null,
369
+ } = options
370
+
366
371
  if (!Number.isInteger(width)) { throw Object.assign(new Error("width must be an integer"), { width }) }
367
372
  if (width <= 0) { throw Object.assign(new Error("invalid width"), { width }) }
368
373
  if (!Number.isInteger(height)) { throw Object.assign(new Error("height must be an integer"), { height }) }
@@ -372,11 +377,25 @@ class Window extends EventsViaPoll {
372
377
  if (typeof format !== 'string') { throw Object.assign(new Error("format must be a string"), { format }) }
373
378
  if (!(buffer instanceof Buffer)) { throw Object.assign(new Error("buffer must be a Buffer"), { buffer }) }
374
379
  if (buffer.length < stride * height) { throw Object.assign(new Error("buffer is smaller than expected"), { buffer, stride, height }) }
380
+ if (scaling !== undefined && typeof scaling !== 'string') { throw Object.assign(new Error("scaling must be a string"), { scaling }) }
381
+
382
+ if (dstRect !== null) {
383
+ if (typeof dstRect !== 'object') { throw Object.assign(new Error("dstRect must be an object"), { dstRect }) }
384
+ if (!Number.isInteger(dstRect.x)) { throw Object.assign(new Error("dstRect.x must be an integer"), { dstRect }) }
385
+ if (!Number.isInteger(dstRect.y)) { throw Object.assign(new Error("dstRect.y must be an integer"), { dstRect }) }
386
+ if (!Number.isInteger(dstRect.width)) { throw Object.assign(new Error("dstRect.width must be an integer"), { dstRect }) }
387
+ if (dstRect.width <= 0) { throw Object.assign(new Error("invalid dstRect.width"), { dstRect }) }
388
+ if (!Number.isInteger(dstRect.height)) { throw Object.assign(new Error("dstRect.height must be an integer"), { dstRect }) }
389
+ if (dstRect.height <= 0) { throw Object.assign(new Error("invalid dstRect.height"), { dstRect }) }
390
+ }
375
391
 
376
392
  const _format = Enums.pixelFormat[format]
377
393
  if (_format === undefined) { throw Object.assign(new Error("invalid format"), { format }) }
378
394
 
379
- Bindings.window_render(this._id, width, height, stride, _format, buffer)
395
+ const _scaling = Enums.scaleMode[scaling]
396
+ if (_scaling === undefined) { throw Object.assign(new Error("invalid scaling"), { scaling }) }
397
+
398
+ Bindings.window_render(this._id, width, height, stride, _format, buffer, _scaling, dstRect)
380
399
  }
381
400
 
382
401
  setIcon (width, height, stride, format, buffer) {
@@ -44,6 +44,11 @@ enums::get(const Napi::CallbackInfo &info)
44
44
  pixel_formats.Set("nv12", Napi::Number::New(env, SDL_PIXELFORMAT_NV12));
45
45
  pixel_formats.Set("nv21", Napi::Number::New(env, SDL_PIXELFORMAT_NV21));
46
46
 
47
+ Napi::Object scale_mode = Napi::Object::New(env);
48
+ scale_mode.Set("nearest", Napi::Number::New(env, SDL_ScaleModeNearest));
49
+ scale_mode.Set("linear", Napi::Number::New(env, SDL_ScaleModeLinear));
50
+ scale_mode.Set("best", Napi::Number::New(env, SDL_ScaleModeBest));
51
+
47
52
  Napi::Object audio_formats = Napi::Object::New(env);
48
53
  audio_formats.Set("s8", Napi::Number::New(env, AUDIO_S8));
49
54
  audio_formats.Set("u8", Napi::Number::New(env, AUDIO_U8));
@@ -330,6 +335,7 @@ enums::get(const Napi::CallbackInfo &info)
330
335
 
331
336
  Napi::Object all = Napi::Object::New(env);
332
337
  all.Set("pixelFormat", pixel_formats);
338
+ all.Set("scaleMode", scale_mode);
333
339
  all.Set("audioFormat", audio_formats);
334
340
  all.Set("scancodes", scancodes);
335
341
  all.Set("mouseButtons", mouse_buttons);
@@ -529,6 +529,17 @@ window::render (const Napi::CallbackInfo &info)
529
529
  int stride = info[3].As<Napi::Number>().Int32Value();
530
530
  unsigned int format = info[4].As<Napi::Number>().Int32Value();
531
531
  void *pixels = info[5].As<Napi::Buffer<char>>().Data();
532
+ SDL_ScaleMode scaling = static_cast<SDL_ScaleMode>(info[6].As<Napi::Number>().Int32Value());
533
+ Napi::Value dstRectVal = info[7];
534
+ bool hasDstRect = !dstRectVal.IsNull();
535
+ SDL_Rect rect;
536
+ if (hasDstRect) {
537
+ Napi::Object dstRect = dstRectVal.As<Napi::Object>();
538
+ rect.x = dstRect.Get("x").As<Napi::Number>().Int32Value();
539
+ rect.y = dstRect.Get("y").As<Napi::Number>().Int32Value();
540
+ rect.w = dstRect.Get("width").As<Napi::Number>().Int32Value();
541
+ rect.h = dstRect.Get("height").As<Napi::Number>().Int32Value();
542
+ }
532
543
 
533
544
  SDL_Window *window = SDL_GetWindowFromID(window_id);
534
545
  if (window == nullptr) {
@@ -571,6 +582,13 @@ window::render (const Napi::CallbackInfo &info)
571
582
  throw Napi::Error::New(env, message.str());
572
583
  }
573
584
 
585
+ if(SDL_SetTextureScaleMode(texture, scaling) < 0) {
586
+ std::ostringstream message;
587
+ message << "SDL_SetTextureScaleMode(" << window_id << ", " << scaling << ") error: " << SDL_GetError();
588
+ SDL_ClearError();
589
+ throw Napi::Error::New(env, message.str());
590
+ }
591
+
574
592
  if (SDL_RenderClear(renderer) < 0) {
575
593
  SDL_DestroyTexture(texture);
576
594
  SDL_FreeSurface(surface);
@@ -581,7 +599,7 @@ window::render (const Napi::CallbackInfo &info)
581
599
  throw Napi::Error::New(env, message.str());
582
600
  }
583
601
 
584
- if (SDL_RenderCopy(renderer, texture, nullptr, nullptr) < 0) {
602
+ if (SDL_RenderCopy(renderer, texture, nullptr, hasDstRect ? &rect : nullptr) < 0) {
585
603
  SDL_DestroyTexture(texture);
586
604
  SDL_FreeSurface(surface);
587
605
 
@@ -351,6 +351,11 @@ export namespace Sdl {
351
351
  | 'nv12'
352
352
  | 'nv21'
353
353
 
354
+ export type Scaling
355
+ = 'nearest'
356
+ | 'linear'
357
+ | 'best'
358
+
354
359
  export interface Display {
355
360
  readonly name: string
356
361
  readonly format: Format
@@ -417,6 +422,7 @@ export namespace Sdl {
417
422
 
418
423
  readonly pixelWidth: number
419
424
  readonly pixelHeight: number
425
+ setSizeInPixels (pixelWidth: number, pixelHeight: number): void
420
426
 
421
427
  readonly visible: boolean
422
428
  show (show?: boolean): void
@@ -461,7 +467,15 @@ export namespace Sdl {
461
467
  readonly tooltip: boolean
462
468
  readonly utility: boolean
463
469
 
464
- render (width: number, height: number, stride: number, format: Format, buffer: Buffer): void
470
+ render (width: number, height: number, stride: number, format: Format, buffer: Buffer, options?: {
471
+ scaling?: Scaling,
472
+ dstRect?: {
473
+ x: number,
474
+ y: number,
475
+ width: number,
476
+ height: number,
477
+ }
478
+ }): void
465
479
 
466
480
  setIcon (width: number, height: number, stride: number, format: Format, buffer: Buffer): void
467
481
 
@@ -470,6 +484,7 @@ export namespace Sdl {
470
484
 
471
485
  readonly destroyed: boolean
472
486
  destroy (): void
487
+ destroyGently (): void
473
488
  }
474
489
 
475
490
  interface Module {