@windowkit/appkit 0.5.1 → 0.7.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 +72 -0
- package/package.json +2 -2
- package/prebuilds/darwin-arm64/calayers.node +0 -0
- package/prebuilds/darwin-x64/calayers.node +0 -0
- package/src/backend.mm +193 -2
package/README.md
CHANGED
|
@@ -251,6 +251,62 @@ vibrancy materials need private API to reproduce; expose real `NSMenu` instead.
|
|
|
251
251
|
`native.postMouseEvent(win, 'down'|'up'|'move'|'drag', x, y)` synthesizes events through
|
|
252
252
|
the real pump — used by the demo's self-test (`CAL_CLICKS="x,y;x,y" npm run demo`).
|
|
253
253
|
|
|
254
|
+
## Surfaces: blend modes and blits
|
|
255
|
+
|
|
256
|
+
A surface (`native.createSurface(wPx, hPx, scale)`, or `createSurfaceIOSurface` for the
|
|
257
|
+
zero-copy presentation kind) is a `CGBitmapContext` with a top-left origin and the canvas
|
|
258
|
+
drawing verbs over it — `ctxFillRect`, `ctxDrawSurface`, `ctxDrawGlyphs` and the rest.
|
|
259
|
+
Two of those verbs are what a 2d context needs to composite one surface into another
|
|
260
|
+
without paying for a `CGImage`:
|
|
261
|
+
|
|
262
|
+
- **`native.ctxSetBlendMode(surface, mode)`** — canvas's `globalCompositeOperation`, in
|
|
263
|
+
CoreGraphics' spelling. Every canvas name maps to an exact `CGBlendMode`:
|
|
264
|
+
`source-over` (the default) through `xor` and `lighter`, and the separable and
|
|
265
|
+
non-separable blend modes below them, `multiply` … `luminosity`; `clear`,
|
|
266
|
+
`plus-lighter` and `plus-darker` are CoreGraphics' own and go through too. A name off
|
|
267
|
+
that list leaves the mode in force alone and answers `false` — canvas's rule for an
|
|
268
|
+
unknown value, so a caller can keep its own property in step — and a known one answers
|
|
269
|
+
`true`. The mode is graphics state, so `ctxSave`/`ctxRestore` bracket it.
|
|
270
|
+
|
|
271
|
+
`copy` is the one that matters for compositing: it makes a paint a *replacement*
|
|
272
|
+
rather than a blend, alpha included, which is what an offscreen surface presented into
|
|
273
|
+
a window wants and what `PictOp.Src` means on the X11 side.
|
|
274
|
+
|
|
275
|
+
- **`native.blitSurface(src, sx, sy, w, h, dst, dx, dy, clip?)`** — a row `memcpy` of a
|
|
276
|
+
rect of one surface into another, at surfaces of any two sizes, returning the
|
|
277
|
+
destination rect it actually wrote as `[x, y, w, h]` or `null` when the intersection
|
|
278
|
+
came out empty. `copySurfaceRegion` is the same-size special case a swapchain wants;
|
|
279
|
+
this is the general one, for a caller compositing an offscreen surface into a window at
|
|
280
|
+
a translate — a terminal's grid, an element's retained scene. It is exactly what a
|
|
281
|
+
`copy`-mode `ctxDrawSurface` at 1:1 under a translate-only transform produces, byte for
|
|
282
|
+
byte, without building a `CGImage` of the whole source: 2000x1620 into a window-sized
|
|
283
|
+
surface is 1.2ms that way and 0.42ms this way on an M1 Pro.
|
|
284
|
+
|
|
285
|
+
Coordinates are device pixels, top-left origin — the convention `createSurface`'s CTM
|
|
286
|
+
gives user space, and the one `copySurfaceRegion`'s rects already use. Neither the
|
|
287
|
+
destination's CTM nor its clip is visible to a `memcpy`, so `clip`, when given, is
|
|
288
|
+
`[x, y, w, h]` in the **destination's** pixels and the caller passes the clip it is
|
|
289
|
+
drawing under; a damage region of several rects is several calls. The rect copied is
|
|
290
|
+
the destination rect intersected with that clip and with both surfaces' bounds, the
|
|
291
|
+
source origin moving with it. An IOSurface-backed surface at either end wants the usual
|
|
292
|
+
`surfaceLock`/`surfaceUnlock` bracketing, and two handles onto one bitmap — a shared
|
|
293
|
+
IOSurface looked up at both ends, or a surface onto itself — are refused, because
|
|
294
|
+
overlapping `memcpy` rows have no defined result.
|
|
295
|
+
|
|
296
|
+
```js
|
|
297
|
+
const grid = native.createSurface(2000, 1620, 2); // the offscreen scene
|
|
298
|
+
const win = native.createSurface(2200, 1800, 2); // what the window presents
|
|
299
|
+
|
|
300
|
+
// the composite, clipped to the paint pass's damage rect
|
|
301
|
+
native.blitSurface(grid, 0, 0, 2000, 1620, win, 40, 30, [100, 100, 1200, 900]);
|
|
302
|
+
// -> [100, 100, 1200, 900] — the clip, which the blit covered whole
|
|
303
|
+
|
|
304
|
+
// the same pixels the slow way, for anything that is not a 1:1 translate
|
|
305
|
+
native.ctxSetBlendMode(win, 'copy');
|
|
306
|
+
native.ctxDrawSurface(win, grid, 0, 0, 2000, 1620, 40, 30, 2000, 1620);
|
|
307
|
+
native.ctxSetBlendMode(win, 'source-over');
|
|
308
|
+
```
|
|
309
|
+
|
|
254
310
|
## App lifecycle: open-URL, open-file, reopen, quit
|
|
255
311
|
|
|
256
312
|
The OS talks to the application as a whole through Apple Events: a URL for a scheme
|
|
@@ -417,6 +473,22 @@ native.beginDrag(win, {
|
|
|
417
473
|
default — at its own size unless `imageWidth` / `imageHeight` say otherwise.
|
|
418
474
|
A drop on one of our own windows arrives through the destination events of
|
|
419
475
|
that window with `local: true` and the source's `sourceWindowNumber`.
|
|
476
|
+
- **A preview window of your own is the window under the pointer.** A
|
|
477
|
+
renderer that draws its drag preview as a live window of its own — a
|
|
478
|
+
borderless popup following the pointer, instead of the session's image —
|
|
479
|
+
has put a window between the pointer and every destination, and the window
|
|
480
|
+
server finds that one first. Registering it for no dragged types is not a
|
|
481
|
+
way past it: the drag then simply has no destination, and the window
|
|
482
|
+
beneath never hears of it; transparent pixels pass no hit either.
|
|
483
|
+
`createWindow2({ …, ignoresMouseEvents: true })`, or
|
|
484
|
+
`setWindowIgnoresMouseEvents(win, flag)` on a live window, makes it one
|
|
485
|
+
the pointer passes through, so a click or a drag reaches whatever is
|
|
486
|
+
beneath; `getWindowFrame` reports the flag beside `visible` and `key`.
|
|
487
|
+
`windowNumberAtPoint(x, y, belowWindowNumber?)` is the window server's own
|
|
488
|
+
answer to which window a mouse-down at a global top-left point would
|
|
489
|
+
reach, any application's, or 0 — the question the flag changes — and
|
|
490
|
+
handing an answer back as `belowWindowNumber` looks beneath it, which is
|
|
491
|
+
how a test finds its own windows under another application's.
|
|
420
492
|
- **`postDragEvent(win, phase, { x, y, items, operations, local })`** drives
|
|
421
493
|
the destination methods with a dragging info of the bridge's own over a
|
|
422
494
|
private pasteboard — what `postMouseEvent` is to clicks. `'enter'` and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@windowkit/appkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Retained-mode AppKit backend for Node.js: Core Animation (CALayer) layer trees, CoreText layout and drawing, IOSurface presentation, NSMenu, and native control bezels — the macOS half of react-x11.",
|
|
5
5
|
"author": "Andrey Sidorov <andrey.sidorov@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"install": "node scripts/install.js",
|
|
44
44
|
"build": "node-gyp rebuild",
|
|
45
45
|
"demo": "node demo/demo.js",
|
|
46
|
-
"test": "node test/app-lifecycle.js && node test/animation.js && node test/accessibility-display.js"
|
|
46
|
+
"test": "node test/app-lifecycle.js && node test/animation.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/surface-blit.js"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"node-addon-api": "^8.3.0"
|
|
Binary file
|
|
Binary file
|
package/src/backend.mm
CHANGED
|
@@ -503,6 +503,7 @@ static char kDelegateKey;
|
|
|
503
503
|
// title, kind, // 'normal' | 'popup' | 'borderless'
|
|
504
504
|
// x, y, // top-left global, points (optional)
|
|
505
505
|
// resizable, opaque, hasShadow, level, // level: 'normal'|'popup'|'floating'
|
|
506
|
+
// ignoresMouseEvents, // the pointer passes through (below)
|
|
506
507
|
// backgroundColor }) // [r,g,b,a] or absent
|
|
507
508
|
static Napi::Value CreateWindow2(const Napi::CallbackInfo& info) {
|
|
508
509
|
Napi::Env env = info.Env();
|
|
@@ -559,6 +560,14 @@ static Napi::Value CreateWindow2(const Napi::CallbackInfo& info) {
|
|
|
559
560
|
win.opaque = BBoolOr(o, "opaque", true);
|
|
560
561
|
if (!win.opaque) win.backgroundColor = NSColor.clearColor;
|
|
561
562
|
}
|
|
563
|
+
// A window the pointer passes through. The window server hit-tests
|
|
564
|
+
// past it, so a click or a drag reaches whatever is beneath — what a
|
|
565
|
+
// drag preview following the pointer needs. Registering no dragged
|
|
566
|
+
// types is not that: the window under the pointer is found first, an
|
|
567
|
+
// unregistered one is still the one found, and the drag then has no
|
|
568
|
+
// destination at all. Transparent pixels do not pass a hit either.
|
|
569
|
+
if (o.Has("ignoresMouseEvents"))
|
|
570
|
+
win.ignoresMouseEvents = BBoolOr(o, "ignoresMouseEvents", false);
|
|
562
571
|
|
|
563
572
|
CALBackendView* view = [[CALBackendView alloc] initWithFrame:rect];
|
|
564
573
|
view->env_ = (napi_env)env;
|
|
@@ -622,6 +631,15 @@ static Napi::Value SetWindowTitle(const Napi::CallbackInfo& info) {
|
|
|
622
631
|
return info.Env().Undefined();
|
|
623
632
|
}
|
|
624
633
|
|
|
634
|
+
// setWindowIgnoresMouseEvents(win, flag) — createWindow2's option of the
|
|
635
|
+
// same name, changed on a live window; the next hit the window server
|
|
636
|
+
// resolves honours it.
|
|
637
|
+
static Napi::Value SetWindowIgnoresMouseEvents(const Napi::CallbackInfo& info) {
|
|
638
|
+
NSWindow* win = BDeref<NSWindow*>(info[0]);
|
|
639
|
+
win.ignoresMouseEvents = info.Length() > 1 && info[1].ToBoolean().Value();
|
|
640
|
+
return info.Env().Undefined();
|
|
641
|
+
}
|
|
642
|
+
|
|
625
643
|
// setWindowFrame(win, x, y, w, h) — any argument may be null to keep it.
|
|
626
644
|
// x/y are the content's top-left in global top-left coordinates, points.
|
|
627
645
|
static Napi::Value SetWindowFrame(const Napi::CallbackInfo& info) {
|
|
@@ -642,8 +660,8 @@ static Napi::Value SetWindowFrame(const Napi::CallbackInfo& info) {
|
|
|
642
660
|
return info.Env().Undefined();
|
|
643
661
|
}
|
|
644
662
|
|
|
645
|
-
// -> { x, y, width, height, scale, visible, occluded, key }
|
|
646
|
-
// global coordinates, points.
|
|
663
|
+
// -> { x, y, width, height, scale, visible, occluded, key, ignoresMouseEvents }
|
|
664
|
+
// — content rect, top-left global coordinates, points.
|
|
647
665
|
static Napi::Value GetWindowFrame(const Napi::CallbackInfo& info) {
|
|
648
666
|
Napi::Env env = info.Env();
|
|
649
667
|
NSWindow* win = BDeref<NSWindow*>(info[0]);
|
|
@@ -658,9 +676,36 @@ static Napi::Value GetWindowFrame(const Napi::CallbackInfo& info) {
|
|
|
658
676
|
// visible but with no pixel on glass: fully behind another app's window
|
|
659
677
|
r.Set("occluded", win.isVisible && !WindowOnGlass(win));
|
|
660
678
|
r.Set("key", (bool)win.isKeyWindow);
|
|
679
|
+
r.Set("ignoresMouseEvents", (bool)win.ignoresMouseEvents);
|
|
661
680
|
return r;
|
|
662
681
|
}
|
|
663
682
|
|
|
683
|
+
// windowNumberAtPoint(x, y, belowWindowNumber?) -> number — the window the
|
|
684
|
+
// window server would hand a mouse-down at a global top-left point, any
|
|
685
|
+
// application's, or 0 for none. It is the question `ignoresMouseEvents`
|
|
686
|
+
// changes the answer to, and where a drag's destination lookup starts. A
|
|
687
|
+
// window number in `belowWindowNumber` starts the search beneath that
|
|
688
|
+
// window, so walking the answers back in finds what sits under another
|
|
689
|
+
// application's window — a lock screen, a floating panel.
|
|
690
|
+
static Napi::Value WindowNumberAtPoint(const Napi::CallbackInfo& info) {
|
|
691
|
+
Napi::Env env = info.Env();
|
|
692
|
+
if (!info[0].IsNumber() || !info[1].IsNumber()) {
|
|
693
|
+
Napi::TypeError::New(env, "windowNumberAtPoint: x and y must be numbers")
|
|
694
|
+
.ThrowAsJavaScriptException();
|
|
695
|
+
return env.Undefined();
|
|
696
|
+
}
|
|
697
|
+
BEnsureApp();
|
|
698
|
+
double x = info[0].As<Napi::Number>().DoubleValue();
|
|
699
|
+
double y = info[1].As<Napi::Number>().DoubleValue();
|
|
700
|
+
NSInteger below = info.Length() > 2 && info[2].IsNumber()
|
|
701
|
+
? (NSInteger)info[2].As<Napi::Number>().Int64Value()
|
|
702
|
+
: 0;
|
|
703
|
+
NSInteger hit =
|
|
704
|
+
[NSWindow windowNumberAtPoint:NSMakePoint(x, PrimaryScreenTop() - y)
|
|
705
|
+
belowWindowWithWindowNumber:below];
|
|
706
|
+
return Napi::Number::New(env, (double)hit);
|
|
707
|
+
}
|
|
708
|
+
|
|
664
709
|
static Napi::Value SetWindowMinMax(const Napi::CallbackInfo& info) {
|
|
665
710
|
NSWindow* win = BDeref<NSWindow*>(info[0]);
|
|
666
711
|
Napi::Object o = info[1].As<Napi::Object>();
|
|
@@ -1217,6 +1262,98 @@ static Napi::Value CopySurfaceRegion(const Napi::CallbackInfo& info) {
|
|
|
1217
1262
|
return env.Undefined();
|
|
1218
1263
|
}
|
|
1219
1264
|
|
|
1265
|
+
// blitSurface(src, sx, sy, w, h, dst, dx, dy, clip?) -> [x, y, w, h] | null
|
|
1266
|
+
// A row memcpy of a rect of one surface into another, at surfaces of any
|
|
1267
|
+
// two sizes. copySurfaceRegion is the same-size special case a swapchain
|
|
1268
|
+
// wants; this is the general one, for a caller compositing an offscreen
|
|
1269
|
+
// surface into a window at a translate — a terminal's grid, an element's
|
|
1270
|
+
// retained scene — where drawSurface builds a CGImage of the whole source
|
|
1271
|
+
// and blends it. On an M1 Pro, a 2000x1620 grid into a window-sized
|
|
1272
|
+
// surface: 1.2ms that way, 0.42ms this way.
|
|
1273
|
+
//
|
|
1274
|
+
// Straight copy, no blending, alpha included: this is the `copy` op, and a
|
|
1275
|
+
// caller reaches it by setting that blend mode and drawing at 1:1 under a
|
|
1276
|
+
// translate-only transform. Coordinates are device pixels with a top-left
|
|
1277
|
+
// origin — the convention createSurface's CTM gives user space, and the one
|
|
1278
|
+
// copySurfaceRegion's rects already use. Neither the destination's CTM nor
|
|
1279
|
+
// its clip is visible to a memcpy, so `clip`, when given, is [x, y, w, h] in
|
|
1280
|
+
// the DESTINATION's pixels and the caller passes the clip it is drawing
|
|
1281
|
+
// under; a damage region of several rects is several calls. The rect copied
|
|
1282
|
+
// is the destination rect intersected with that clip and with both surfaces'
|
|
1283
|
+
// bounds, the source origin moving with it — returned, or null when the
|
|
1284
|
+
// intersection is empty and nothing moved.
|
|
1285
|
+
//
|
|
1286
|
+
// When either surface is IOSurface-backed the caller owes the usual
|
|
1287
|
+
// surfaceLock bracketing. Two handles onto one bitmap are refused:
|
|
1288
|
+
// overlapping memcpy rows have no defined result, and the check is on the
|
|
1289
|
+
// backing store, not the handle, so the two ends of a shared IOSurface do
|
|
1290
|
+
// not slip through as different handles.
|
|
1291
|
+
static Napi::Value BlitSurface(const Napi::CallbackInfo& info) {
|
|
1292
|
+
Napi::Env env = info.Env();
|
|
1293
|
+
CALSurface* src = SurfaceFrom(info[0]);
|
|
1294
|
+
if (!src) return env.Null();
|
|
1295
|
+
CALSurface* dst = SurfaceFrom(info[5]);
|
|
1296
|
+
if (!dst) return env.Null();
|
|
1297
|
+
|
|
1298
|
+
const uint8_t* sbase = (const uint8_t*)CGBitmapContextGetData(src->ctx);
|
|
1299
|
+
uint8_t* dbase = (uint8_t*)CGBitmapContextGetData(dst->ctx);
|
|
1300
|
+
if (!sbase || !dbase) return env.Null();
|
|
1301
|
+
if (sbase == dbase) {
|
|
1302
|
+
Napi::Error::New(env, "blitSurface: source and destination are one bitmap")
|
|
1303
|
+
.ThrowAsJavaScriptException();
|
|
1304
|
+
return env.Null();
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
long sx = (long)info[1].As<Napi::Number>().Int64Value();
|
|
1308
|
+
long sy = (long)info[2].As<Napi::Number>().Int64Value();
|
|
1309
|
+
long w = (long)info[3].As<Napi::Number>().Int64Value();
|
|
1310
|
+
long h = (long)info[4].As<Napi::Number>().Int64Value();
|
|
1311
|
+
long dx = (long)info[6].As<Napi::Number>().Int64Value();
|
|
1312
|
+
long dy = (long)info[7].As<Napi::Number>().Int64Value();
|
|
1313
|
+
|
|
1314
|
+
// the destination rect trimmed to the clip, the source origin moving by
|
|
1315
|
+
// whatever each edge takes off
|
|
1316
|
+
if (info.Length() > 8 && !info[8].IsNull() && !info[8].IsUndefined()) {
|
|
1317
|
+
if (!info[8].IsArray() || info[8].As<Napi::Array>().Length() < 4) {
|
|
1318
|
+
Napi::TypeError::New(env, "blitSurface: clip must be [x, y, w, h]")
|
|
1319
|
+
.ThrowAsJavaScriptException();
|
|
1320
|
+
return env.Null();
|
|
1321
|
+
}
|
|
1322
|
+
Napi::Array clip = info[8].As<Napi::Array>();
|
|
1323
|
+
long cx = (long)clip.Get((uint32_t)0).As<Napi::Number>().Int64Value();
|
|
1324
|
+
long cy = (long)clip.Get((uint32_t)1).As<Napi::Number>().Int64Value();
|
|
1325
|
+
long cw = (long)clip.Get((uint32_t)2).As<Napi::Number>().Int64Value();
|
|
1326
|
+
long ch = (long)clip.Get((uint32_t)3).As<Napi::Number>().Int64Value();
|
|
1327
|
+
if (dx < cx) { long over = cx - dx; sx += over; dx += over; w -= over; }
|
|
1328
|
+
if (dy < cy) { long over = cy - dy; sy += over; dy += over; h -= over; }
|
|
1329
|
+
if (dx + w > cx + cw) w = cx + cw - dx;
|
|
1330
|
+
if (dy + h > cy + ch) h = cy + ch - dy;
|
|
1331
|
+
}
|
|
1332
|
+
// and to both surfaces
|
|
1333
|
+
if (sx < 0) { dx -= sx; w += sx; sx = 0; }
|
|
1334
|
+
if (sy < 0) { dy -= sy; h += sy; sy = 0; }
|
|
1335
|
+
if (dx < 0) { sx -= dx; w += dx; dx = 0; }
|
|
1336
|
+
if (dy < 0) { sy -= dy; h += dy; dy = 0; }
|
|
1337
|
+
if (sx + w > (long)src->width) w = (long)src->width - sx;
|
|
1338
|
+
if (sy + h > (long)src->height) h = (long)src->height - sy;
|
|
1339
|
+
if (dx + w > (long)dst->width) w = (long)dst->width - dx;
|
|
1340
|
+
if (dy + h > (long)dst->height) h = (long)dst->height - dy;
|
|
1341
|
+
if (w <= 0 || h <= 0) return env.Null();
|
|
1342
|
+
|
|
1343
|
+
size_t srow = CGBitmapContextGetBytesPerRow(src->ctx);
|
|
1344
|
+
size_t drow = CGBitmapContextGetBytesPerRow(dst->ctx);
|
|
1345
|
+
for (long r = 0; r < h; r++) {
|
|
1346
|
+
memcpy(dbase + (size_t)(dy + r) * drow + (size_t)dx * 4,
|
|
1347
|
+
sbase + (size_t)(sy + r) * srow + (size_t)sx * 4, (size_t)w * 4);
|
|
1348
|
+
}
|
|
1349
|
+
Napi::Array out = Napi::Array::New(env, 4);
|
|
1350
|
+
out.Set((uint32_t)0, (double)dx);
|
|
1351
|
+
out.Set((uint32_t)1, (double)dy);
|
|
1352
|
+
out.Set((uint32_t)2, (double)w);
|
|
1353
|
+
out.Set((uint32_t)3, (double)h);
|
|
1354
|
+
return out;
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1220
1357
|
static Napi::Value SurfaceSize(const Napi::CallbackInfo& info) {
|
|
1221
1358
|
CALSurface* s = SurfaceFrom(info[0]);
|
|
1222
1359
|
if (!s) return info.Env().Undefined();
|
|
@@ -2679,6 +2816,56 @@ static Napi::Value CtxSetLineCap(const Napi::CallbackInfo& info) {
|
|
|
2679
2816
|
: kCGLineCapButt);
|
|
2680
2817
|
return info.Env().Undefined();
|
|
2681
2818
|
}
|
|
2819
|
+
// ctxSetBlendMode(surface, mode) -> boolean — canvas's
|
|
2820
|
+
// globalCompositeOperation, in CoreGraphics' spelling. Every one of the
|
|
2821
|
+
// canvas names has an exact CGBlendMode: the Porter-Duff dozen a 2d context
|
|
2822
|
+
// composites with, and the separable and non-separable blend modes below
|
|
2823
|
+
// them. `copy` is the one the compositing paths care about — it is what
|
|
2824
|
+
// makes a paint a replacement rather than a blend, and what lets a
|
|
2825
|
+
// translate-only 1:1 drawSurface take blitSurface's memcpy instead.
|
|
2826
|
+
//
|
|
2827
|
+
// A name the list does not have leaves the context's blend mode alone and
|
|
2828
|
+
// answers false, which is canvas's rule for an unknown value (it is
|
|
2829
|
+
// ignored, not reset) and lets a caller keep its own property in step. The
|
|
2830
|
+
// mode is gstate, so ctxSave/ctxRestore bracket it like any other.
|
|
2831
|
+
static Napi::Value CtxSetBlendMode(const Napi::CallbackInfo& info) {
|
|
2832
|
+
Napi::Env env = info.Env();
|
|
2833
|
+
std::string mode = info[1].As<Napi::String>().Utf8Value();
|
|
2834
|
+
CGBlendMode blend;
|
|
2835
|
+
if (mode == "source-over") blend = kCGBlendModeNormal;
|
|
2836
|
+
else if (mode == "copy") blend = kCGBlendModeCopy;
|
|
2837
|
+
else if (mode == "source-in") blend = kCGBlendModeSourceIn;
|
|
2838
|
+
else if (mode == "source-out") blend = kCGBlendModeSourceOut;
|
|
2839
|
+
else if (mode == "source-atop") blend = kCGBlendModeSourceAtop;
|
|
2840
|
+
else if (mode == "destination-over") blend = kCGBlendModeDestinationOver;
|
|
2841
|
+
else if (mode == "destination-in") blend = kCGBlendModeDestinationIn;
|
|
2842
|
+
else if (mode == "destination-out") blend = kCGBlendModeDestinationOut;
|
|
2843
|
+
else if (mode == "destination-atop") blend = kCGBlendModeDestinationAtop;
|
|
2844
|
+
else if (mode == "xor") blend = kCGBlendModeXOR;
|
|
2845
|
+
else if (mode == "lighter") blend = kCGBlendModePlusLighter;
|
|
2846
|
+
else if (mode == "multiply") blend = kCGBlendModeMultiply;
|
|
2847
|
+
else if (mode == "screen") blend = kCGBlendModeScreen;
|
|
2848
|
+
else if (mode == "overlay") blend = kCGBlendModeOverlay;
|
|
2849
|
+
else if (mode == "darken") blend = kCGBlendModeDarken;
|
|
2850
|
+
else if (mode == "lighten") blend = kCGBlendModeLighten;
|
|
2851
|
+
else if (mode == "color-dodge") blend = kCGBlendModeColorDodge;
|
|
2852
|
+
else if (mode == "color-burn") blend = kCGBlendModeColorBurn;
|
|
2853
|
+
else if (mode == "hard-light") blend = kCGBlendModeHardLight;
|
|
2854
|
+
else if (mode == "soft-light") blend = kCGBlendModeSoftLight;
|
|
2855
|
+
else if (mode == "difference") blend = kCGBlendModeDifference;
|
|
2856
|
+
else if (mode == "exclusion") blend = kCGBlendModeExclusion;
|
|
2857
|
+
else if (mode == "hue") blend = kCGBlendModeHue;
|
|
2858
|
+
else if (mode == "saturation") blend = kCGBlendModeSaturation;
|
|
2859
|
+
else if (mode == "color") blend = kCGBlendModeColor;
|
|
2860
|
+
else if (mode == "luminosity") blend = kCGBlendModeLuminosity;
|
|
2861
|
+
// not canvas's, but CoreGraphics' own and the CSS spelling of two of them
|
|
2862
|
+
else if (mode == "clear") blend = kCGBlendModeClear;
|
|
2863
|
+
else if (mode == "plus-lighter") blend = kCGBlendModePlusLighter;
|
|
2864
|
+
else if (mode == "plus-darker") blend = kCGBlendModePlusDarker;
|
|
2865
|
+
else return Napi::Boolean::New(env, false);
|
|
2866
|
+
CGContextSetBlendMode(CtxOf(info[0]), blend);
|
|
2867
|
+
return Napi::Boolean::New(env, true);
|
|
2868
|
+
}
|
|
2682
2869
|
static Napi::Value CtxSetLineJoin(const Napi::CallbackInfo& info) {
|
|
2683
2870
|
std::string join = info[1].As<Napi::String>().Utf8Value();
|
|
2684
2871
|
CGContextSetLineJoin(CtxOf(info[0]),
|
|
@@ -4970,6 +5157,8 @@ void InitBackend(Napi::Env env, Napi::Object exports) {
|
|
|
4970
5157
|
BFN("showWindow", ShowWindowFn);
|
|
4971
5158
|
BFN("hideWindow", HideWindowFn);
|
|
4972
5159
|
BFN("setWindowTitle", SetWindowTitle);
|
|
5160
|
+
BFN("setWindowIgnoresMouseEvents", SetWindowIgnoresMouseEvents);
|
|
5161
|
+
BFN("windowNumberAtPoint", WindowNumberAtPoint);
|
|
4973
5162
|
BFN("setWindowFrame", SetWindowFrame);
|
|
4974
5163
|
BFN("getWindowFrame", GetWindowFrame);
|
|
4975
5164
|
BFN("setWindowMinMax", SetWindowMinMax);
|
|
@@ -4985,6 +5174,7 @@ void InitBackend(Napi::Env env, Napi::Object exports) {
|
|
|
4985
5174
|
BFN("surfaceLock", SurfaceLock);
|
|
4986
5175
|
BFN("surfaceUnlock", SurfaceUnlock);
|
|
4987
5176
|
BFN("copySurfaceRegion", CopySurfaceRegion);
|
|
5177
|
+
BFN("blitSurface", BlitSurface);
|
|
4988
5178
|
BFN("surfaceSize", SurfaceSize);
|
|
4989
5179
|
BFN("ctxSave", CtxSave);
|
|
4990
5180
|
BFN("ctxRestore", CtxRestore);
|
|
@@ -5008,6 +5198,7 @@ void InitBackend(Napi::Env env, Napi::Object exports) {
|
|
|
5008
5198
|
BFN("ctxSetGlobalAlpha", CtxSetGlobalAlpha);
|
|
5009
5199
|
BFN("ctxSetLineCap", CtxSetLineCap);
|
|
5010
5200
|
BFN("ctxSetLineJoin", CtxSetLineJoin);
|
|
5201
|
+
BFN("ctxSetBlendMode", CtxSetBlendMode);
|
|
5011
5202
|
BFN("ctxSetLineDash", CtxSetLineDash);
|
|
5012
5203
|
BFN("ctxFill", CtxFill);
|
|
5013
5204
|
BFN("ctxStroke", CtxStroke);
|