@kmamal/sdl 0.10.12 → 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 +20 -12
- package/package.json +1 -1
- package/src/javascript/video/window.js +17 -2
- package/src/native/window.cpp +11 -1
- package/src/types/index.d.ts +9 -1
package/README.md
CHANGED
|
@@ -206,7 +206,7 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
|
|
|
206
206
|
* [window.popupMenu](#windowpopupmenu)
|
|
207
207
|
* [window.tooltip](#windowtooltip)
|
|
208
208
|
* [window.utility](#windowutility)
|
|
209
|
-
* [window.render(width, height, stride, format, buffer[,
|
|
209
|
+
* [window.render(width, height, stride, format, buffer[, options])](#windowrenderwidth-height-stride-format-buffer-options)
|
|
210
210
|
* [window.setIcon(width, height, stride, format, buffer)](#windowseticonwidth-height-stride-format-buffer)
|
|
211
211
|
* [window.flash(untilFocused)](#windowflashuntilfocused)
|
|
212
212
|
* [window.stopFlashing()](#windowstopflashing)
|
|
@@ -359,9 +359,9 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
|
|
|
359
359
|
* `<object>`
|
|
360
360
|
* `version: <object>`
|
|
361
361
|
* `compile: <object>` The SDL version the bindings were compiled against.
|
|
362
|
-
* `major, minor, patch: <
|
|
362
|
+
* `major, minor, patch: <Semver>` The components of the version.
|
|
363
363
|
* `runtime: <object>` The SDL version of the dynamic library the is loaded.
|
|
364
|
-
* `major, minor, patch: <
|
|
364
|
+
* `major, minor, patch: <Semver>` The components of the version.
|
|
365
365
|
* `platform: <string>` The name of the platform we are running on. Possible values are: `'Linux'`, `'Windows'`, and `'Mac OS X'`.
|
|
366
366
|
* `drivers: <object>`
|
|
367
367
|
* `video: <object>`
|
|
@@ -407,7 +407,7 @@ Sample data for Ubuntu:
|
|
|
407
407
|
|
|
408
408
|
There are 3 places in the API where you will need to provide an image to the library:
|
|
409
409
|
|
|
410
|
-
* [`window.render()`](#windowrenderwidth-height-stride-format-buffer-
|
|
410
|
+
* [`window.render()`](#windowrenderwidth-height-stride-format-buffer-options)
|
|
411
411
|
* [`window.setIcon()`](#windowseticonwidth-height-stride-format-buffer)
|
|
412
412
|
* [`mouse.setCursorImage()`](#sdlmousesetcursorimagewidth-height-stride-format-buffer-x-y)
|
|
413
413
|
|
|
@@ -606,7 +606,7 @@ The following restrictions apply:
|
|
|
606
606
|
* The `accelerated` and `vsync` options have no effect if either `opengl` or `webgpu` is also specified.
|
|
607
607
|
|
|
608
608
|
If you set the `opengl` or `webgpu` options, then you can only render to the window with OpenGL/WebGPU calls.
|
|
609
|
-
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-
|
|
609
|
+
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-options) will fail.
|
|
610
610
|
|
|
611
611
|
## class Window
|
|
612
612
|
|
|
@@ -948,7 +948,7 @@ If you have set the `opengl` or `webgpu` options, then calls to this function wi
|
|
|
948
948
|
|
|
949
949
|
Will be `true` if the window was created in OpenGl mode.
|
|
950
950
|
In OpenGL mode, you can only render to the window with OpenGL calls.
|
|
951
|
-
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-
|
|
951
|
+
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-options) will fail.
|
|
952
952
|
|
|
953
953
|
### window.webgpu
|
|
954
954
|
|
|
@@ -956,7 +956,7 @@ Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-scaling) wi
|
|
|
956
956
|
|
|
957
957
|
Will be `true` if the window was created in WebGPU mode.
|
|
958
958
|
In WebGPU mode, you can only render to the window with WebGPU calls.
|
|
959
|
-
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-
|
|
959
|
+
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-options) will fail.
|
|
960
960
|
|
|
961
961
|
### window.native
|
|
962
962
|
|
|
@@ -1037,13 +1037,21 @@ X11 only.
|
|
|
1037
1037
|
Will be `true` if the window was created with `utility: true`.
|
|
1038
1038
|
Such a window will always be treated as a utility window.
|
|
1039
1039
|
|
|
1040
|
-
### window.render(width, height, stride, format, buffer[,
|
|
1040
|
+
### window.render(width, height, stride, format, buffer[, options])
|
|
1041
1041
|
|
|
1042
1042
|
* `width, height, stride, format, buffer: `[`<Image>`](#image-data) The image to display on the window.
|
|
1043
|
-
* `
|
|
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.
|
|
1044
1047
|
|
|
1045
1048
|
Displays an image in the window.
|
|
1046
|
-
|
|
1049
|
+
|
|
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.
|
|
1047
1055
|
The `scaling` argument controls how exactly the scaling is implemented.
|
|
1048
1056
|
Possible values are:
|
|
1049
1057
|
|
|
@@ -1053,8 +1061,8 @@ Possible values are:
|
|
|
1053
1061
|
| `'linear'` | `SDL_ScaleModeLinear` | linear filtering |
|
|
1054
1062
|
| `'best'` | `SDL_ScaleModeBest` | anisotropic filtering |
|
|
1055
1063
|
|
|
1056
|
-
If
|
|
1057
|
-
Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-
|
|
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.
|
|
1058
1066
|
|
|
1059
1067
|
### window.setIcon(width, height, stride, format, buffer)
|
|
1060
1068
|
|
package/package.json
CHANGED
|
@@ -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 }) }
|
|
@@ -374,13 +379,23 @@ class Window extends EventsViaPoll {
|
|
|
374
379
|
if (buffer.length < stride * height) { throw Object.assign(new Error("buffer is smaller than expected"), { buffer, stride, height }) }
|
|
375
380
|
if (scaling !== undefined && typeof scaling !== 'string') { throw Object.assign(new Error("scaling must be a string"), { scaling }) }
|
|
376
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
|
+
}
|
|
391
|
+
|
|
377
392
|
const _format = Enums.pixelFormat[format]
|
|
378
393
|
if (_format === undefined) { throw Object.assign(new Error("invalid format"), { format }) }
|
|
379
394
|
|
|
380
395
|
const _scaling = Enums.scaleMode[scaling]
|
|
381
396
|
if (_scaling === undefined) { throw Object.assign(new Error("invalid scaling"), { scaling }) }
|
|
382
397
|
|
|
383
|
-
Bindings.window_render(this._id, width, height, stride, _format, buffer, _scaling)
|
|
398
|
+
Bindings.window_render(this._id, width, height, stride, _format, buffer, _scaling, dstRect)
|
|
384
399
|
}
|
|
385
400
|
|
|
386
401
|
setIcon (width, height, stride, format, buffer) {
|
package/src/native/window.cpp
CHANGED
|
@@ -530,6 +530,16 @@ window::render (const Napi::CallbackInfo &info)
|
|
|
530
530
|
unsigned int format = info[4].As<Napi::Number>().Int32Value();
|
|
531
531
|
void *pixels = info[5].As<Napi::Buffer<char>>().Data();
|
|
532
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
|
+
}
|
|
533
543
|
|
|
534
544
|
SDL_Window *window = SDL_GetWindowFromID(window_id);
|
|
535
545
|
if (window == nullptr) {
|
|
@@ -589,7 +599,7 @@ window::render (const Napi::CallbackInfo &info)
|
|
|
589
599
|
throw Napi::Error::New(env, message.str());
|
|
590
600
|
}
|
|
591
601
|
|
|
592
|
-
if (SDL_RenderCopy(renderer, texture, nullptr, nullptr) < 0) {
|
|
602
|
+
if (SDL_RenderCopy(renderer, texture, nullptr, hasDstRect ? &rect : nullptr) < 0) {
|
|
593
603
|
SDL_DestroyTexture(texture);
|
|
594
604
|
SDL_FreeSurface(surface);
|
|
595
605
|
|
package/src/types/index.d.ts
CHANGED
|
@@ -467,7 +467,15 @@ export namespace Sdl {
|
|
|
467
467
|
readonly tooltip: boolean
|
|
468
468
|
readonly utility: boolean
|
|
469
469
|
|
|
470
|
-
render (width: number, height: number, stride: number, format: Format, buffer: Buffer,
|
|
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
|
|
471
479
|
|
|
472
480
|
setIcon (width: number, height: number, stride: number, format: Format, buffer: Buffer): void
|
|
473
481
|
|