@kmamal/sdl 0.10.12 → 0.10.14

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
@@ -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[, scaling])](#windowrenderwidth-height-stride-format-buffer-scaling)
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: <semver>` The components of the version.
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: <semver>` The components of the version.
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-scaling)
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-scaling) will fail.
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-scaling) will fail.
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-scaling) will fail.
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[, scaling])
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
- * `scaling: <string>` How to scale the image to match the window size. Default `'nearest'`
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
- If the dimensions of the image do not match the dimansions of the window, then the image will be stretched over the entire surface of the window.
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 you set the `opengl` or `webgpu` options, then you can only render to the window with OpenGL/WebGPU calls.
1057
- Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-scaling) will fail.
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
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.10.12",
2
+ "version": "0.10.14",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -60,6 +60,8 @@
60
60
  "clean": "cd scripts && node clean.mjs"
61
61
  },
62
62
  "dependencies": {
63
+ "node-addon-api": "^8.3.1",
64
+ "node-gyp": "^11.1.0",
63
65
  "tar": "^7.4.3"
64
66
  },
65
67
  "sdl": {
@@ -68,10 +70,8 @@
68
70
  "version": "2.26.4"
69
71
  },
70
72
  "devDependencies": {
71
- "@kmamal/evdev": "^0.0.1",
73
+ "@kmamal/evdev": "^0.0.2",
72
74
  "@kmamal/testing": "^0.0.31",
73
- "@types/node": "^22.10.7",
74
- "node-addon-api": "^8.3.0",
75
- "node-gyp": "^11.0.0"
75
+ "@types/node": "^22.13.5"
76
76
  }
77
77
  }
@@ -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, scaling = 'nearest') {
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) {
@@ -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
 
@@ -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, scaling?: Scaling): 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
471
479
 
472
480
  setIcon (width: number, height: number, stride: number, format: Format, buffer: Buffer): void
473
481
 
package/scripts/clean.mjs DELETED
@@ -1,17 +0,0 @@
1
- import Fs from 'node:fs'
2
- import Path from 'node:path'
3
- import C from './util/common.js'
4
-
5
- const dirs = [
6
- Path.join(C.dir.root, 'node_modules'),
7
- C.dir.sdl,
8
- C.dir.build,
9
- C.dir.dist,
10
- C.dir.publish,
11
- ]
12
-
13
- console.log("delete")
14
- await Promise.all(dirs.map(async (dir) => {
15
- console.log(" ", dir)
16
- await Fs.promises.rm(dir, { recursive: true }).catch(() => {})
17
- }))