@namzu/computer-use 4.1.0 → 4.1.1
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/CHANGELOG.md +6 -0
- package/dist/presence/helper-script.d.ts +18 -11
- package/dist/presence/helper-script.d.ts.map +1 -1
- package/dist/presence/helper-script.js +301 -86
- package/dist/presence/helper-script.js.map +1 -1
- package/dist/presence/index.d.ts +3 -1
- package/dist/presence/index.d.ts.map +1 -1
- package/dist/presence/index.js +2 -1
- package/dist/presence/index.js.map +1 -1
- package/dist/presence/motion.d.ts +84 -0
- package/dist/presence/motion.d.ts.map +1 -0
- package/dist/presence/motion.js +114 -0
- package/dist/presence/motion.js.map +1 -0
- package/dist/presence/preview.d.ts +25 -0
- package/dist/presence/preview.d.ts.map +1 -0
- package/dist/presence/preview.js +32 -0
- package/dist/presence/preview.js.map +1 -0
- package/package.json +1 -1
- package/src/presence/helper-script.ts +327 -87
- package/src/presence/index.ts +10 -1
- package/src/presence/motion.ts +141 -0
- package/src/presence/preview.ts +42 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3b52063: On Windows, the agent's cursor and the frame around the window it is working in look and move like part of a modern app. The cursor is a smooth green arrow with a soft shadow that stays the same size on a 150 % or 200 % display; it fades in the first time it appears and glides to each spot along a gentle curve, a little longer for a longer trip. A click makes it dip and send out a round ripple, and typing sends out a smaller, softer one. The frame is a smooth rounded outline with a soft glow inside it that breathes slowly while the agent is active and fades out with the cursor, in place of the old dotted square edge. It also stops redrawing when nothing is moving. Nothing changes in how you turn it off (`presence: false` or `NAMZU_COMPUTER_USE_PRESENCE=off`) or in what the model sees: the overlay is still left out of every screenshot.
|
|
8
|
+
|
|
3
9
|
## 4.1.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
+
export { APPEAR_MS, FADE_MS, GLIDE_MAX_MS, GLIDE_MIN_MS, HOLD_MS, RIPPLE_MS, } from './motion.js';
|
|
1
2
|
/**
|
|
2
3
|
* The Windows side of the presence overlay: one long-lived PowerShell process
|
|
3
4
|
* that owns two small windows and draws them itself.
|
|
4
5
|
*
|
|
5
|
-
* - the agent cursor, a
|
|
6
|
-
* outline,
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* - the agent cursor, a smooth anti-aliased arrow in the project's green with
|
|
7
|
+
* a dark outline, a soft highlight and a soft shadow, drawn once per display
|
|
8
|
+
* scale and composited at sub-pixel positions. It fades in on its first
|
|
9
|
+
* appearance, glides along a gentle curve to each action point (140 to
|
|
10
|
+
* 420 ms by distance), dips on a click and sends out a circular ripple (a
|
|
11
|
+
* smaller one for typing);
|
|
12
|
+
* - the presence border, a smooth rounded frame inside the operated window
|
|
13
|
+
* (a green stroke with a soft glow inward), which follows the window, breathes
|
|
14
|
+
* very gently while the cursor is active and fades out with it.
|
|
15
|
+
*
|
|
16
|
+
* Sizes are written in logical pixels and multiplied by the operated window's
|
|
17
|
+
* display scale (its DPI over 96). The numbers and the formulas are in
|
|
18
|
+
* `motion.ts`; the C# below follows them. Nothing is redrawn when nothing moves:
|
|
19
|
+
* the 16 ms timer only compares, and bitmaps are allocated once per size.
|
|
11
20
|
*
|
|
12
21
|
* Both windows are layered, click-through (`WS_EX_TRANSPARENT`), never
|
|
13
22
|
* activated (`WS_EX_NOACTIVATE`), kept out of the taskbar and alt-tab
|
|
@@ -20,12 +29,10 @@
|
|
|
20
29
|
*
|
|
21
30
|
* Like the foreground helper it is handed to PowerShell as an encoded command
|
|
22
31
|
* and speaks one JSON object per line in each direction; its input closing
|
|
23
|
-
* ends it, and its windows go with it.
|
|
32
|
+
* ends it, and its windows go with it. Besides `act`, `hide`, `info` and `quit`
|
|
33
|
+
* it answers `preview`, a development aid that draws one state of the overlay
|
|
34
|
+
* into a PNG without showing a window (see `preview.ts`).
|
|
24
35
|
*/
|
|
25
|
-
export declare const GLIDE_MS = 120;
|
|
26
|
-
/** How long the border and cursor stay after the last action, then fade. */
|
|
27
|
-
export declare const HOLD_MS = 2500;
|
|
28
|
-
export declare const FADE_MS = 600;
|
|
29
36
|
export declare const PRESENCE_HELPER_SCRIPT: string;
|
|
30
37
|
/**
|
|
31
38
|
* The script is longer than a Windows command line allows once encoded, so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper-script.d.ts","sourceRoot":"","sources":["../../src/presence/helper-script.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helper-script.d.ts","sourceRoot":"","sources":["../../src/presence/helper-script.ts"],"names":[],"mappings":"AAmBA,OAAO,EACN,SAAS,EACT,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,SAAS,GACT,MAAM,aAAa,CAAA;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,sBAAsB,QAselC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,qHACoF,CAAA;AAEnH,mFAAmF;AACnF,wBAAgB,kBAAkB,CAAC,MAAM,GAAE,MAA+B,GAAG,MAAM,CAElF"}
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
+
import { APPEAR_FROM_SCALE, APPEAR_MS, CLICK_RIPPLE, DIP_DOWN_MS, DIP_SCALE, DIP_UP_MS, FADE_MS, FRAME_PULSE_DEPTH, FRAME_PULSE_MS, GLIDE_BOW, GLIDE_MAX_MS, GLIDE_MIN_MS, GLIDE_MS_PER_PX, HOLD_MS, KEY_RIPPLE, RIPPLE_MS, } from './motion.js';
|
|
2
|
+
export { APPEAR_MS, FADE_MS, GLIDE_MAX_MS, GLIDE_MIN_MS, HOLD_MS, RIPPLE_MS, } from './motion.js';
|
|
1
3
|
/**
|
|
2
4
|
* The Windows side of the presence overlay: one long-lived PowerShell process
|
|
3
5
|
* that owns two small windows and draws them itself.
|
|
4
6
|
*
|
|
5
|
-
* - the agent cursor, a
|
|
6
|
-
* outline,
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* - the agent cursor, a smooth anti-aliased arrow in the project's green with
|
|
8
|
+
* a dark outline, a soft highlight and a soft shadow, drawn once per display
|
|
9
|
+
* scale and composited at sub-pixel positions. It fades in on its first
|
|
10
|
+
* appearance, glides along a gentle curve to each action point (140 to
|
|
11
|
+
* 420 ms by distance), dips on a click and sends out a circular ripple (a
|
|
12
|
+
* smaller one for typing);
|
|
13
|
+
* - the presence border, a smooth rounded frame inside the operated window
|
|
14
|
+
* (a green stroke with a soft glow inward), which follows the window, breathes
|
|
15
|
+
* very gently while the cursor is active and fades out with it.
|
|
16
|
+
*
|
|
17
|
+
* Sizes are written in logical pixels and multiplied by the operated window's
|
|
18
|
+
* display scale (its DPI over 96). The numbers and the formulas are in
|
|
19
|
+
* `motion.ts`; the C# below follows them. Nothing is redrawn when nothing moves:
|
|
20
|
+
* the 16 ms timer only compares, and bitmaps are allocated once per size.
|
|
11
21
|
*
|
|
12
22
|
* Both windows are layered, click-through (`WS_EX_TRANSPARENT`), never
|
|
13
23
|
* activated (`WS_EX_NOACTIVATE`), kept out of the taskbar and alt-tab
|
|
@@ -20,18 +30,16 @@
|
|
|
20
30
|
*
|
|
21
31
|
* Like the foreground helper it is handed to PowerShell as an encoded command
|
|
22
32
|
* and speaks one JSON object per line in each direction; its input closing
|
|
23
|
-
* ends it, and its windows go with it.
|
|
33
|
+
* ends it, and its windows go with it. Besides `act`, `hide`, `info` and `quit`
|
|
34
|
+
* it answers `preview`, a development aid that draws one state of the overlay
|
|
35
|
+
* into a PNG without showing a window (see `preview.ts`).
|
|
24
36
|
*/
|
|
25
|
-
export const GLIDE_MS = 120;
|
|
26
|
-
/** How long the border and cursor stay after the last action, then fade. */
|
|
27
|
-
export const HOLD_MS = 2_500;
|
|
28
|
-
export const FADE_MS = 600;
|
|
29
37
|
export const PRESENCE_HELPER_SCRIPT = String.raw `
|
|
30
38
|
$ErrorActionPreference = 'Stop'
|
|
31
39
|
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
32
40
|
[Console]::InputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
33
|
-
Add-Type -TypeDefinition @
|
|
34
|
-
using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading;
|
|
41
|
+
Add-Type -ReferencedAssemblies System.Drawing -TypeDefinition @'
|
|
42
|
+
using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Runtime.InteropServices; using System.Threading;
|
|
35
43
|
public static class NzP {
|
|
36
44
|
[StructLayout(LayoutKind.Sequential)] struct PT { public int x; public int y; }
|
|
37
45
|
[StructLayout(LayoutKind.Sequential)] struct SZ { public int cx; public int cy; }
|
|
@@ -62,6 +70,7 @@ public static class NzP {
|
|
|
62
70
|
[DllImport("user32.dll", EntryPoint="SetWindowLongPtrW", SetLastError=true)] static extern IntPtr SetWindowLongPtr64(IntPtr h, int i, IntPtr v);
|
|
63
71
|
[DllImport("user32.dll", EntryPoint="SetWindowLongW", SetLastError=true)] static extern int SetWindowLongPtr32(IntPtr h, int i, int v);
|
|
64
72
|
[DllImport("user32.dll")] static extern int GetWindowLong(IntPtr h, int i);
|
|
73
|
+
[DllImport("user32.dll")] static extern uint GetDpiForWindow(IntPtr h);
|
|
65
74
|
[DllImport("user32.dll")] static extern IntPtr GetDC(IntPtr h);
|
|
66
75
|
[DllImport("user32.dll")] static extern int ReleaseDC(IntPtr h, IntPtr dc);
|
|
67
76
|
[DllImport("user32.dll")] static extern IntPtr GetForegroundWindow();
|
|
@@ -76,14 +85,29 @@ public static class NzP {
|
|
|
76
85
|
[DllImport("kernel32.dll")] static extern IntPtr GetModuleHandle(string n);
|
|
77
86
|
|
|
78
87
|
const uint EX = 0x20 | 0x08000000 | 0x80;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
88
|
+
|
|
89
|
+
// ---- Design, in logical px; every size is multiplied by the window's display scale. ----
|
|
90
|
+
// The cursor window reaches Pad around the tip (room for the ripple and the shadow).
|
|
91
|
+
const double Pad = 32, SprMargin = 8, SprRight = 20, SprDown = 32;
|
|
92
|
+
const double ShadowDx = 1.5, ShadowDy = 2.5, ShadowBlur = 4, ShadowA = 0.32;
|
|
93
|
+
const double OutlineW = 1.25;
|
|
94
|
+
const double FrameStroke = 2, FrameGlow = 8, FrameRadius = 8, FrameStrokeA = 0.65, FrameGlowA = 0.30;
|
|
95
|
+
const int AccentR = 0x34, AccentG = 0xd3, AccentB = 0x69;
|
|
96
|
+
// The arrow: x, y (tip at 0,0) and the radius that rounds each corner.
|
|
97
|
+
static readonly float[][] Arrow = {
|
|
98
|
+
new float[]{0f, 0f, 1.1f}, new float[]{0f, 18.8f, 1.3f}, new float[]{4.5f, 15.2f, 0.9f}, new float[]{7.7f, 21.6f, 1.2f},
|
|
99
|
+
new float[]{11.2f, 20.1f, 1.2f}, new float[]{8.0f, 15.2f, 0.9f}, new float[]{14.0f, 15.2f, 1.3f}
|
|
82
100
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
101
|
+
|
|
102
|
+
// ---- Motion (the numbers and formulas are in motion.ts). ----
|
|
103
|
+
const int GlideMinMs = ${GLIDE_MIN_MS}, GlideMaxMs = ${GLIDE_MAX_MS}, AppearMs = ${APPEAR_MS}, DipDownMs = ${DIP_DOWN_MS}, DipUpMs = ${DIP_UP_MS}, RippleMs = ${RIPPLE_MS}, FramePulseMs = ${FRAME_PULSE_MS};
|
|
104
|
+
const double GlideMsPerPx = ${GLIDE_MS_PER_PX}, GlideBow = ${GLIDE_BOW}, AppearFrom = ${APPEAR_FROM_SCALE}, DipScale = ${DIP_SCALE}, PulseDepth = ${FRAME_PULSE_DEPTH};
|
|
105
|
+
const double ClickFrom = ${CLICK_RIPPLE.from}, ClickTo = ${CLICK_RIPPLE.to}, ClickA = ${CLICK_RIPPLE.alpha}, ClickW = ${CLICK_RIPPLE.stroke};
|
|
106
|
+
const double KeyFrom = ${KEY_RIPPLE.from}, KeyTo = ${KEY_RIPPLE.to}, KeyA = ${KEY_RIPPLE.alpha}, KeyW = ${KEY_RIPPLE.stroke};
|
|
107
|
+
public static int HoldMs = ${HOLD_MS}, FadeMs = ${FADE_MS};
|
|
108
|
+
|
|
109
|
+
sealed class Spr { public Bitmap Bmp; public double Tx; public double Ty; public int W; public int H; }
|
|
110
|
+
static Dictionary<int, Spr> sprites = new Dictionary<int, Spr>();
|
|
87
111
|
|
|
88
112
|
static IntPtr frm, cur, mem1, mem2, bmp1, bmp2, bits1, bits2; static WP proc;
|
|
89
113
|
static int fw, fh, lastX, lastY, lastW, lastH; static IntPtr lastPrev;
|
|
@@ -91,15 +115,45 @@ public static class NzP {
|
|
|
91
115
|
static ManualResetEvent ready = new ManualResetEvent(false);
|
|
92
116
|
static object gate = new object();
|
|
93
117
|
// Command state (written by the reader thread, read by the UI thread).
|
|
94
|
-
static IntPtr target; static double ax, ay; static bool hasPoint; static int kind; static
|
|
95
|
-
// Animation state (UI thread only).
|
|
96
|
-
static double rx, ry, fx, fy, tx, ty; static long glideAt = -
|
|
97
|
-
|
|
118
|
+
static IntPtr target; static double ax, ay; static bool hasPoint; static int kind; static bool hidden = true, pending, retarget;
|
|
119
|
+
// Animation state (UI thread only). Positions are physical pixels from the operated window's corner.
|
|
120
|
+
static double rx, ry, fx, fy, tx, ty, kx, ky; static long glideAt = -100000; static int glideDur; static long appearAt = -100000, pressAt = -100000, holdFrom; static int pressKind; static bool placed;
|
|
121
|
+
// What is drawn now, to tell whether anything changed.
|
|
122
|
+
static int lastAlpha = -1; static long lastPush = -1000; static bool borderDrawn; static IntPtr drawnFor; static double frameScale;
|
|
123
|
+
static Bitmap curBmp; static Graphics curG; static int curW, curPad; static double curScale; static bool curDirty = true;
|
|
124
|
+
static double dSx = -1e9, dSy = -1e9, dSc, dRr, dRa, dRw; static int dA = -1, dRk = -1;
|
|
125
|
+
static int[] frameBuf;
|
|
98
126
|
public static long Ticks, TickUs, MaxTickUs; static Stopwatch sw = Stopwatch.StartNew();
|
|
99
127
|
static bool timerOn; static long refuseUntil; public static int Refused;
|
|
100
|
-
public static int GlideMs = ${GLIDE_MS}, HoldMs = ${HOLD_MS}, FadeMs = ${FADE_MS};
|
|
101
128
|
|
|
102
129
|
static long Now() { return sw.ElapsedMilliseconds; }
|
|
130
|
+
static double Clamp(double v, double lo, double hi) { return v < lo ? lo : (v > hi ? hi : v); }
|
|
131
|
+
static double EaseInOut(double u) { u = Clamp(u, 0, 1); return u < 0.5 ? 4 * u * u * u : 1 - Math.Pow(-2 * u + 2, 3) / 2; }
|
|
132
|
+
static double EaseOut(double u) { u = Clamp(u, 0, 1); return 1 - Math.Pow(1 - u, 3); }
|
|
133
|
+
static int GlideDuration(double logical) { return (int)Math.Round(Clamp(GlideMinMs + logical * GlideMsPerPx, GlideMinMs, GlideMaxMs)); }
|
|
134
|
+
// The middle of the path moved sideways by GlideBow of its length, always to the same side of the line (up; right for a vertical one), whichever way it is travelled.
|
|
135
|
+
static void Control(double x0, double y0, double x1, double y1, out double cx, out double cy) {
|
|
136
|
+
double dx = x1 - x0, dy = y1 - y0, len = Math.Sqrt(dx * dx + dy * dy);
|
|
137
|
+
cx = (x0 + x1) / 2; cy = (y0 + y1) / 2; if (len < 1e-9) return;
|
|
138
|
+
double nx = -dy / len, ny = dx / len;
|
|
139
|
+
if (ny > 1e-9 || (Math.Abs(ny) <= 1e-9 && nx < 0)) { nx = -nx; ny = -ny; }
|
|
140
|
+
cx += nx * len * GlideBow; cy += ny * len * GlideBow;
|
|
141
|
+
}
|
|
142
|
+
static double Dip(double ms) {
|
|
143
|
+
if (ms < 0 || ms >= DipDownMs + DipUpMs) return 1;
|
|
144
|
+
if (ms < DipDownMs) return 1 - (1 - DipScale) * EaseOut(ms / DipDownMs);
|
|
145
|
+
return DipScale + (1 - DipScale) * EaseOut((ms - DipDownMs) / DipUpMs);
|
|
146
|
+
}
|
|
147
|
+
// The ripple k (1 click, 2 key) ms after it lands; false before it and once faded.
|
|
148
|
+
static bool Ripple(int k, double ms, out double radius, out double alpha, out double stroke) {
|
|
149
|
+
radius = 0; alpha = 0; stroke = 0;
|
|
150
|
+
if (k == 0 || ms < 0 || ms >= RippleMs) return false;
|
|
151
|
+
double p = ms / RippleMs, from = k == 2 ? KeyFrom : ClickFrom, to = k == 2 ? KeyTo : ClickTo;
|
|
152
|
+
radius = from + (to - from) * EaseOut(p); alpha = (k == 2 ? KeyA : ClickA) * (1 - p); stroke = k == 2 ? KeyW : ClickW;
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
static double ScaleOf(IntPtr h) { try { uint d = GetDpiForWindow(h); return d == 0 ? 1.0 : d / 96.0; } catch (Exception) { return 1.0; } }
|
|
156
|
+
|
|
103
157
|
static IntPtr Wnd(IntPtr h, uint m, IntPtr w, IntPtr l) {
|
|
104
158
|
if (m == 0x113) { try { Tick(); } catch (Exception e) { Err = e.Message; } return IntPtr.Zero; }
|
|
105
159
|
if (m == 0x8000) { try { Tick(); } catch (Exception e) { Err = e.Message; } return IntPtr.Zero; }
|
|
@@ -134,7 +188,6 @@ public static class NzP {
|
|
|
134
188
|
frm = Make("NzPresence", ref a1); cur = Make("NzPresence", ref a2);
|
|
135
189
|
Hwnd1 = (long)frm; Hwnd2 = (long)cur; Excluded = a1 == 0x11 && a2 == 0x11;
|
|
136
190
|
if (!Excluded) throw new Exception("capture exclusion not applied");
|
|
137
|
-
bmp2 = Dib(CW, CH, out mem2, out bits2);
|
|
138
191
|
Ready = true; ready.Set();
|
|
139
192
|
MSG m; while (GetMessage(out m, IntPtr.Zero, 0, 0) > 0) { DispatchMessage(ref m); }
|
|
140
193
|
} catch (Exception e) { Err = e.Message; ready.Set(); }
|
|
@@ -145,15 +198,14 @@ public static class NzP {
|
|
|
145
198
|
// Called from the reader thread.
|
|
146
199
|
public static void Act(long hwnd, double x, double y, bool point, int k) {
|
|
147
200
|
lock (gate) {
|
|
148
|
-
IntPtr h = (IntPtr)hwnd; if (h != target) { target = h;
|
|
149
|
-
hasPoint = point; ax = x; ay = y; kind = k;
|
|
201
|
+
IntPtr h = (IntPtr)hwnd; if (h != target) { target = h; retarget = true; }
|
|
202
|
+
hasPoint = point; ax = x; ay = y; kind = k; hidden = false; pending = true;
|
|
150
203
|
}
|
|
151
204
|
PostMessage(frm, 0x8000, IntPtr.Zero, IntPtr.Zero);
|
|
152
205
|
}
|
|
153
|
-
static bool pending;
|
|
154
206
|
public static void Hide() { lock (gate) { hidden = true; pending = true; } PostMessage(frm, 0x8000, IntPtr.Zero, IntPtr.Zero); }
|
|
155
207
|
static void HideNow() {
|
|
156
|
-
ShowWindow(frm, 0); ShowWindow(cur, 0); lastW = 0; lastH = 0; lastPrev = IntPtr.Zero; lastAlpha = -1;
|
|
208
|
+
ShowWindow(frm, 0); ShowWindow(cur, 0); lastW = 0; lastH = 0; lastPrev = IntPtr.Zero; lastAlpha = -1; curDirty = true; placed = false; pressKind = 0;
|
|
157
209
|
if (timerOn) { KillTimer(frm, (UIntPtr)1); timerOn = false; }
|
|
158
210
|
}
|
|
159
211
|
// An owned window stays directly above its owner in the z-order whatever else moves, in front of or behind other windows, without raising the owner.
|
|
@@ -166,28 +218,54 @@ public static class NzP {
|
|
|
166
218
|
// A window without a frame rectangle (a hidden application window) covers nothing.
|
|
167
219
|
static bool Overlaps(IntPtr h, RC r) { RC o; if (!Rect(h, out o)) return false; return o.l < r.r && o.r > r.l && o.t < r.b && o.b > r.t; }
|
|
168
220
|
static bool Rect(IntPtr h, out RC r) { return DwmGetWindowAttribute(h, 9, out r, 16) == 0 && r.r > r.l && r.b > r.t; }
|
|
221
|
+
|
|
222
|
+
// A new action, on the UI thread: where the pointer goes, how it gets there and when its press lands.
|
|
223
|
+
static void Begin(long now, RC r, int w, int h, double px, double py, bool hp, int k, bool retargeted, double s) {
|
|
224
|
+
long arrive = now; bool appear = !placed || retargeted;
|
|
225
|
+
if (hp) {
|
|
226
|
+
px = Clamp(px - r.l, 0, w - 1); py = Clamp(py - r.t, 0, h - 1);
|
|
227
|
+
if (appear) { fx = px; fy = py; tx = px; ty = py; rx = px; ry = py; glideDur = 0; }
|
|
228
|
+
else {
|
|
229
|
+
fx = rx; fy = ry; tx = px; ty = py;
|
|
230
|
+
double dist = Math.Sqrt((tx - fx) * (tx - fx) + (ty - fy) * (ty - fy)) / s;
|
|
231
|
+
if (dist < 0.5) glideDur = 0; else { glideDur = GlideDuration(dist); Control(fx, fy, tx, ty, out kx, out ky); }
|
|
232
|
+
glideAt = now; arrive = now + glideDur;
|
|
233
|
+
}
|
|
234
|
+
} else if (appear) { tx = w / 2.0; ty = h / 2.0; fx = tx; fy = ty; rx = tx; ry = ty; glideDur = 0; }
|
|
235
|
+
else if (glideAt + glideDur > now) arrive = glideAt + glideDur;
|
|
236
|
+
if (appear) { appearAt = now; arrive = now + AppearMs; placed = true; }
|
|
237
|
+
if (k != 0) { pressAt = arrive; pressKind = k; }
|
|
238
|
+
holdFrom = arrive;
|
|
239
|
+
}
|
|
240
|
+
|
|
169
241
|
static void Tick() {
|
|
170
|
-
long t0 = sw.ElapsedTicks; IntPtr tg; bool hid, hp, ch; double px, py; int k;
|
|
171
|
-
lock (gate) { tg = target; hid = hidden; hp = hasPoint; px = ax; py = ay; k = kind;
|
|
242
|
+
long t0 = sw.ElapsedTicks; IntPtr tg; bool hid, hp, ch, rt; double px, py; int k;
|
|
243
|
+
lock (gate) { tg = target; hid = hidden; hp = hasPoint; px = ax; py = ay; k = kind; ch = pending; rt = retarget; pending = false; retarget = false; }
|
|
172
244
|
if (hid || tg == IntPtr.Zero || !IsWindow(tg) || IsIconic(tg) || !IsWindowVisible(tg)) { HideNow(); return; }
|
|
173
245
|
RC r; if (!Rect(tg, out r)) { HideNow(); return; }
|
|
174
246
|
long now = Now(); int w = r.r - r.l, h = r.b - r.t;
|
|
175
|
-
double
|
|
247
|
+
double s = ScaleOf(tg);
|
|
248
|
+
if (ch) Begin(now, r, w, h, px, py, hp, k, rt, s);
|
|
249
|
+
double age = now - holdFrom, alpha = 1.0;
|
|
176
250
|
if (age > HoldMs) alpha = 1.0 - (age - HoldMs) / FadeMs;
|
|
177
251
|
if (alpha <= 0) { lock (gate) { hidden = true; } HideNow(); return; }
|
|
178
252
|
if (now < refuseUntil) return;
|
|
179
253
|
if (!timerOn) { SetTimer(frm, (UIntPtr)1, 16, IntPtr.Zero); timerOn = true; }
|
|
180
|
-
|
|
181
|
-
// New action point in window coordinates: relative to the window's rectangle.
|
|
182
|
-
px -= r.l; py -= r.t; fx = placed ? rx : px; fy = placed ? ry : py; tx = px; ty = py; glideAt = now; placed = true; if (k != 0) { pulseAt = now; pulseKind = k; }
|
|
183
|
-
} else if (ch) {
|
|
184
|
-
if (k != 0) { pulseAt = now; pulseKind = k; }
|
|
185
|
-
if (!placed) { tx = w / 2.0; ty = h / 2.0; fx = tx; fy = ty; rx = tx; ry = ty; placed = true; glideAt = -1000; }
|
|
186
|
-
}
|
|
254
|
+
// Where the pointer is now: along the curve, eased, in sub-pixels.
|
|
187
255
|
if (placed) {
|
|
188
|
-
double u = (now - glideAt) / (double)
|
|
189
|
-
|
|
256
|
+
double u = glideDur > 0 ? Clamp((now - glideAt) / (double)glideDur, 0, 1) : 1;
|
|
257
|
+
if (u >= 1) { rx = tx; ry = ty; }
|
|
258
|
+
else { double e = EaseInOut(u), b = 1 - e; rx = b * b * fx + 2 * b * e * kx + e * e * tx; ry = b * b * fy + 2 * b * e * ky + e * e * ty; }
|
|
190
259
|
}
|
|
260
|
+
double ap = EaseOut((now - appearAt) / (double)AppearMs);
|
|
261
|
+
double sc = AppearFrom + (1 - AppearFrom) * ap;
|
|
262
|
+
if (pressKind == 1) sc *= Dip(now - pressAt);
|
|
263
|
+
double rr, ra, rw; int rk = 0;
|
|
264
|
+
if (Ripple(pressKind, now - pressAt, out rr, out ra, out rw)) rk = pressKind;
|
|
265
|
+
double sx = Clamp(r.l + rx, r.l, r.r - 1), sy = Clamp(r.t + ry, r.t, r.b - 1);
|
|
266
|
+
int ca = (int)Math.Round(255 * alpha * ap);
|
|
267
|
+
int fa = (int)Math.Round(255 * alpha * ap * (1 - PulseDepth + PulseDepth * Math.Sin(2 * Math.PI * (now % FramePulseMs) / FramePulseMs)));
|
|
268
|
+
EnsureCursor(s);
|
|
191
269
|
// z-order: directly above the operated window, never above others.
|
|
192
270
|
IntPtr prev = GetWindow(tg, 3);
|
|
193
271
|
// Windows that are not shown (input-method helpers and the like) sit in bands of their own: ordering against them has no effect.
|
|
@@ -197,22 +275,14 @@ public static class NzP {
|
|
|
197
275
|
// The operated window can move up past the overlay (it is raised, or the window above it closes): the overlay must be right above it again.
|
|
198
276
|
bool moved = r.l != lastX || r.t != lastY || w != lastW || h != lastH || prev != lastPrev || Steps(frm, tg) < 0;
|
|
199
277
|
bool fresh = lastW == 0;
|
|
200
|
-
if (w != fw || h != fh || !borderDrawn || drawnFor != tg)
|
|
201
|
-
|
|
202
|
-
if (moved || fresh ||
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
UpdateLayeredWindow(frm, IntPtr.Zero, ref pd, ref sz, mem1, ref ps, 0, ref bf, 2);
|
|
206
|
-
lastAlpha = a;
|
|
207
|
-
}
|
|
208
|
-
// The cursor window follows the glide; its sprite tip sits at the window's (PAD,PAD).
|
|
209
|
-
double sx = r.l + rx, sy = r.t + ry;
|
|
210
|
-
if (sx < r.l) sx = r.l; if (sy < r.t) sy = r.t; if (sx > r.r - 1) sx = r.r - 1; if (sy > r.b - 1) sy = r.b - 1;
|
|
211
|
-
DrawCursor(now, (int)Math.Round(sx) - PAD, (int)Math.Round(sy) - PAD, alpha);
|
|
278
|
+
if (w != fw || h != fh || !borderDrawn || drawnFor != tg || frameScale != s) BuildFrame(w, h, s, tg);
|
|
279
|
+
// The frame's picture is whole; only its opacity breathes, so it is pushed when it moved or its opacity changed enough to see.
|
|
280
|
+
if (moved || fresh || (fa != lastAlpha && now - lastPush >= 33)) PushFrame(r, w, h, fa, now);
|
|
281
|
+
int cx = (int)Math.Floor(sx) - curPad, cy = (int)Math.Floor(sy) - curPad;
|
|
282
|
+
DrawCursor(s, sx - Math.Floor(sx), sy - Math.Floor(sy), sx, sy, sc, rk, rr, ra, rw, ca, cx, cy, fresh);
|
|
212
283
|
uint fl = 0x10 | 0x40; // NOACTIVATE | SHOWWINDOW
|
|
213
284
|
if (ownedBy != tg) { ownedBy = Own(frm, tg) && Own(cur, tg) ? tg : IntPtr.Zero; moved = true; }
|
|
214
285
|
if (moved || fresh) {
|
|
215
|
-
int cx = (int)Math.Round(sx) - PAD, cy = (int)Math.Round(sy) - PAD;
|
|
216
286
|
// Ownership keeps an owned window above its owner only when it is raised; it does not reorder
|
|
217
287
|
// windows already stacked above the owner (a target created after the overlay), so the order is
|
|
218
288
|
// set explicitly: right above the operated window, never above others.
|
|
@@ -222,7 +292,7 @@ public static class NzP {
|
|
|
222
292
|
for (int up = 0; !SetWindowPos(frm, ins, r.l, r.t, 0, 0, fl | 0x1) && ins != IntPtr.Zero && ins != (IntPtr)(-1) && up < 40; up++) ins = GetWindow(ins, 3);
|
|
223
293
|
SetWindowPos(cur, frm, cx, cy, 0, 0, fl | 0x1);
|
|
224
294
|
// A layered window shown for the first time takes its picture again.
|
|
225
|
-
if (fresh) {
|
|
295
|
+
if (fresh) { PushFrame(r, w, h, fa, now); DrawCursor(s, sx - Math.Floor(sx), sy - Math.Floor(sy), sx, sy, sc, rk, rr, ra, rw, ca, cx, cy, true); }
|
|
226
296
|
lastX = r.l; lastY = r.t; lastW = w; lastH = h; lastPrev = prev;
|
|
227
297
|
// A window the overlay cannot be ordered against gets no overlay at all: a frame hidden
|
|
228
298
|
// behind its window is worse than none.
|
|
@@ -231,52 +301,196 @@ public static class NzP {
|
|
|
231
301
|
long us = (sw.ElapsedTicks - t0) * 1000000 / Stopwatch.Frequency;
|
|
232
302
|
Ticks++; TickUs += us; if (us > MaxTickUs) MaxTickUs = us;
|
|
233
303
|
}
|
|
234
|
-
|
|
304
|
+
|
|
305
|
+
// ---- The frame: a rounded stroke with a soft glow inward, from a distance field (smooth edges, no dithering). ----
|
|
306
|
+
static void BuildFrame(int w, int h, double s, IntPtr tg) {
|
|
235
307
|
if (bmp1 != IntPtr.Zero) { SelectObject(mem1, IntPtr.Zero); DeleteObject(bmp1); DeleteDC(mem1); }
|
|
236
|
-
bmp1 = Dib(w, h, out mem1, out bits1); fw = w; fh = h; drawnFor = tg; borderDrawn = true;
|
|
237
|
-
int
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
308
|
+
bmp1 = Dib(w, h, out mem1, out bits1); fw = w; fh = h; drawnFor = tg; frameScale = s; borderDrawn = true;
|
|
309
|
+
int n = w * h; if (frameBuf == null || frameBuf.Length < n) frameBuf = new int[n]; else Array.Clear(frameBuf, 0, n);
|
|
310
|
+
FrameFill(frameBuf, w, h, s);
|
|
311
|
+
Marshal.Copy(frameBuf, 0, bits1, n); lastAlpha = -1;
|
|
312
|
+
}
|
|
313
|
+
// Fills premultiplied pixels for a w x h window: the stroke FrameStroke wide on the inside of a rounded rectangle, then the glow FrameGlow deep fading to nothing.
|
|
314
|
+
static void FrameFill(int[] px, int w, int h, double s) {
|
|
315
|
+
double rad = FrameRadius * s, sw2 = FrameStroke * s, gw = FrameGlow * s;
|
|
316
|
+
int band = (int)Math.Ceiling(sw2 + gw) + 1;
|
|
317
|
+
double cx = w / 2.0, cy = h / 2.0, ex = cx - rad, ey = cy - rad;
|
|
318
|
+
for (int y = 0; y < h; y++) {
|
|
319
|
+
bool edgeRow = y < band || y >= h - band;
|
|
320
|
+
for (int x = 0; x < w; x++) {
|
|
321
|
+
if (!edgeRow && x >= band && x < w - band) { x = w - band - 1; continue; }
|
|
322
|
+
double qx = Math.Abs(x + 0.5 - cx) - ex, qy = Math.Abs(y + 0.5 - cy) - ey;
|
|
323
|
+
double ox = Math.Max(qx, 0), oy = Math.Max(qy, 0);
|
|
324
|
+
double din = -(Math.Sqrt(ox * ox + oy * oy) + Math.Min(Math.Max(qx, qy), 0) - rad);
|
|
325
|
+
if (din < -0.5) continue;
|
|
326
|
+
double outer = Clamp(din + 0.5, 0, 1), inStroke = Clamp(sw2 - din + 0.5, 0, 1), t = Clamp((din - sw2) / gw, 0, 1);
|
|
327
|
+
double a = outer * (FrameStrokeA * inStroke + FrameGlowA * (1 - t) * (1 - t) * (1 - inStroke));
|
|
328
|
+
int ia = (int)Math.Round(a * 255); if (ia <= 0) continue;
|
|
329
|
+
px[y * w + x] = (ia << 24) | ((AccentR * ia / 255) << 16) | ((AccentG * ia / 255) << 8) | (AccentB * ia / 255);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
static void PushFrame(RC r, int w, int h, int a, long now) {
|
|
334
|
+
PT pd = new PT(); pd.x = r.l; pd.y = r.t; SZ sz = new SZ(); sz.cx = w; sz.cy = h; PT ps = new PT();
|
|
335
|
+
BF bf = new BF(); bf.op = 0; bf.fl = 0; bf.a = (byte)Math.Max(0, Math.Min(255, a)); bf.fmt = 1;
|
|
336
|
+
UpdateLayeredWindow(frm, IntPtr.Zero, ref pd, ref sz, mem1, ref ps, 0, ref bf, 2);
|
|
337
|
+
lastAlpha = a; lastPush = now;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// ---- The pointer: drawn once per display scale with its shadow baked in, then composited at sub-pixel positions. ----
|
|
341
|
+
static GraphicsPath ArrowPath() {
|
|
342
|
+
GraphicsPath gp = new GraphicsPath(); int n = Arrow.Length; PointF[] a = new PointF[n], b = new PointF[n];
|
|
343
|
+
for (int i = 0; i < n; i++) {
|
|
344
|
+
float[] v = Arrow[i], p = Arrow[(i + n - 1) % n], q = Arrow[(i + 1) % n];
|
|
345
|
+
float dp = (float)Math.Sqrt((p[0] - v[0]) * (p[0] - v[0]) + (p[1] - v[1]) * (p[1] - v[1])), dq = (float)Math.Sqrt((q[0] - v[0]) * (q[0] - v[0]) + (q[1] - v[1]) * (q[1] - v[1]));
|
|
346
|
+
float tp = Math.Min(v[2], dp / 2), tq = Math.Min(v[2], dq / 2);
|
|
347
|
+
a[i] = new PointF(v[0] + (p[0] - v[0]) / dp * tp, v[1] + (p[1] - v[1]) / dp * tp);
|
|
348
|
+
b[i] = new PointF(v[0] + (q[0] - v[0]) / dq * tq, v[1] + (q[1] - v[1]) / dq * tq);
|
|
349
|
+
}
|
|
350
|
+
PointF cur0 = b[0];
|
|
351
|
+
for (int i = 1; i <= n; i++) {
|
|
352
|
+
int j = i % n; PointF v = new PointF(Arrow[j][0], Arrow[j][1]);
|
|
353
|
+
gp.AddLine(cur0, a[j]);
|
|
354
|
+
gp.AddBezier(a[j], new PointF(a[j].X + (v.X - a[j].X) * 2f / 3f, a[j].Y + (v.Y - a[j].Y) * 2f / 3f), new PointF(b[j].X + (v.X - b[j].X) * 2f / 3f, b[j].Y + (v.Y - b[j].Y) * 2f / 3f), b[j]);
|
|
355
|
+
cur0 = b[j];
|
|
242
356
|
}
|
|
243
|
-
|
|
357
|
+
gp.CloseFigure(); return gp;
|
|
244
358
|
}
|
|
245
|
-
static void
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
359
|
+
static void BoxBlur(float[] a, int w, int h, int r) {
|
|
360
|
+
float[] t = new float[a.Length];
|
|
361
|
+
for (int pass = 0; pass < 3; pass++) {
|
|
362
|
+
for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { float sum = 0; for (int i = -r; i <= r; i++) { int xx = x + i; if (xx >= 0 && xx < w) sum += a[y * w + xx]; } t[y * w + x] = sum / (2 * r + 1); }
|
|
363
|
+
for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { float sum = 0; for (int i = -r; i <= r; i++) { int yy = y + i; if (yy >= 0 && yy < h) sum += t[yy * w + x]; } a[y * w + x] = sum / (2 * r + 1); }
|
|
364
|
+
}
|
|
249
365
|
}
|
|
250
|
-
static
|
|
251
|
-
int
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
366
|
+
static Spr MakeSprite(double s) {
|
|
367
|
+
int mg = (int)Math.Round(SprMargin * s), W = mg + (int)Math.Ceiling(SprRight * s), H = mg + (int)Math.Ceiling(SprDown * s);
|
|
368
|
+
Spr sp = new Spr(); sp.W = W; sp.H = H; sp.Tx = mg; sp.Ty = mg;
|
|
369
|
+
using (GraphicsPath gp = ArrowPath()) {
|
|
370
|
+
// The shadow: the silhouette, offset, blurred and faint.
|
|
371
|
+
float[] sh = new float[W * H];
|
|
372
|
+
using (Bitmap tmp = new Bitmap(W, H, PixelFormat.Format32bppArgb)) {
|
|
373
|
+
using (Graphics gt = Graphics.FromImage(tmp)) {
|
|
374
|
+
gt.SmoothingMode = SmoothingMode.AntiAlias; gt.TranslateTransform((float)(mg + ShadowDx * s), (float)(mg + ShadowDy * s)); gt.ScaleTransform((float)s, (float)s);
|
|
375
|
+
gt.FillPath(Brushes.Black, gp);
|
|
260
376
|
}
|
|
377
|
+
BitmapData d = tmp.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
|
378
|
+
int[] px = new int[W * H]; Marshal.Copy(d.Scan0, px, 0, W * H); tmp.UnlockBits(d);
|
|
379
|
+
for (int i = 0; i < px.Length; i++) sh[i] = ((px[i] >> 24) & 255) / 255f;
|
|
380
|
+
}
|
|
381
|
+
BoxBlur(sh, W, H, Math.Max(1, (int)Math.Round(ShadowBlur * s / 2)));
|
|
382
|
+
int[] outp = new int[W * H];
|
|
383
|
+
for (int i = 0; i < outp.Length; i++) outp[i] = ((int)Math.Round(sh[i] * ShadowA * 255)) << 24;
|
|
384
|
+
sp.Bmp = new Bitmap(W, H, PixelFormat.Format32bppPArgb);
|
|
385
|
+
BitmapData bd = sp.Bmp.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb);
|
|
386
|
+
Marshal.Copy(outp, 0, bd.Scan0, W * H); sp.Bmp.UnlockBits(bd);
|
|
387
|
+
using (Graphics g = Graphics.FromImage(sp.Bmp)) {
|
|
388
|
+
g.SmoothingMode = SmoothingMode.AntiAlias; g.CompositingQuality = CompositingQuality.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
|
389
|
+
g.TranslateTransform(mg, mg); g.ScaleTransform((float)s, (float)s);
|
|
390
|
+
RectangleF bb = gp.GetBounds();
|
|
391
|
+
using (LinearGradientBrush fill = new LinearGradientBrush(new PointF(0, bb.Top), new PointF(0, bb.Bottom), Color.FromArgb(0x8c, 0xff, 0x8c), Color.FromArgb(0x2f, 0xcb, 0x63))) g.FillPath(fill, gp);
|
|
392
|
+
// A fine highlight down the upper-left edge, fading with depth.
|
|
393
|
+
g.SetClip(gp);
|
|
394
|
+
using (LinearGradientBrush hb = new LinearGradientBrush(new PointF(0, 2f), new PointF(0, 16f), Color.FromArgb(190, 255, 255, 255), Color.FromArgb(0, 255, 255, 255)))
|
|
395
|
+
using (Pen hp = new Pen(hb, 1.0f)) { g.DrawLine(hp, 1.35f, 2.4f, 1.35f, 16f); }
|
|
396
|
+
g.ResetClip();
|
|
397
|
+
using (Pen op = new Pen(Color.FromArgb(230, 0x0b, 0x0f, 0x0c), (float)OutlineW)) { op.LineJoin = LineJoin.Round; g.DrawPath(op, gp); }
|
|
261
398
|
}
|
|
262
399
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
400
|
+
return sp;
|
|
401
|
+
}
|
|
402
|
+
static Spr Sprite(double s) {
|
|
403
|
+
int key = (int)Math.Round(s * 96);
|
|
404
|
+
lock (sprites) {
|
|
405
|
+
Spr sp; if (sprites.TryGetValue(key, out sp)) return sp;
|
|
406
|
+
sp = MakeSprite(key / 96.0); sprites[key] = sp; return sp;
|
|
267
407
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
408
|
+
}
|
|
409
|
+
// The cursor picture: the ripple, then the pointer scaled about its tip, with the tip at (pad + fracX, pad + fracY).
|
|
410
|
+
static void Compose(Graphics g, Spr sp, double s, int pad, double fracX, double fracY, double sc, double rr, double ra, double rw) {
|
|
411
|
+
g.Clear(Color.Transparent);
|
|
412
|
+
g.SmoothingMode = SmoothingMode.AntiAlias; g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.Half;
|
|
413
|
+
double tipx = pad + fracX, tipy = pad + fracY;
|
|
414
|
+
if (ra > 0.002 && rr > 0) {
|
|
415
|
+
using (Pen p = new Pen(Color.FromArgb((int)Math.Round(ra * 255), AccentR, AccentG, AccentB), (float)(rw * s))) {
|
|
416
|
+
float rd = (float)(rr * s); g.DrawEllipse(p, (float)tipx - rd, (float)tipy - rd, rd * 2, rd * 2);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
RectangleF dst = new RectangleF((float)(tipx - sp.Tx * sc), (float)(tipy - sp.Ty * sc), (float)(sp.W * sc), (float)(sp.H * sc));
|
|
420
|
+
g.DrawImage(sp.Bmp, dst, new RectangleF(0f, 0f, (float)sp.W, (float)sp.H), GraphicsUnit.Pixel);
|
|
421
|
+
}
|
|
422
|
+
// The cursor window's bitmap is allocated once per size and drawn into in place.
|
|
423
|
+
static void EnsureCursor(double s) {
|
|
424
|
+
int pad = (int)Math.Round(Pad * s);
|
|
425
|
+
if (pad * 2 != curW) {
|
|
426
|
+
if (curG != null) { curG.Dispose(); curG = null; } if (curBmp != null) { curBmp.Dispose(); curBmp = null; }
|
|
427
|
+
if (bmp2 != IntPtr.Zero) { SelectObject(mem2, IntPtr.Zero); DeleteObject(bmp2); DeleteDC(mem2); }
|
|
428
|
+
curW = pad * 2; curPad = pad; bmp2 = Dib(curW, curW, out mem2, out bits2);
|
|
429
|
+
curBmp = new Bitmap(curW, curW, curW * 4, PixelFormat.Format32bppPArgb, bits2); curG = Graphics.FromImage(curBmp); curDirty = true;
|
|
430
|
+
}
|
|
431
|
+
if (curScale != s) { curScale = s; curDirty = true; }
|
|
432
|
+
}
|
|
433
|
+
// Draws and pushes the cursor window only when something about it changed since the last time.
|
|
434
|
+
static void DrawCursor(double s, double fracX, double fracY, double sx, double sy, double sc, int rk, double rr, double ra, double rw, int ca, int cx, int cy, bool force) {
|
|
435
|
+
if (!force && !curDirty && sx == dSx && sy == dSy && sc == dSc && rr == dRr && ra == dRa && ca == dA && rk == dRk) return;
|
|
436
|
+
dSx = sx; dSy = sy; dSc = sc; dRr = rr; dRa = ra; dRw = rw; dA = ca; dRk = rk; curDirty = false;
|
|
437
|
+
Compose(curG, Sprite(s), s, curPad, fracX, fracY, sc, rr, ra, rw);
|
|
438
|
+
PT pd = new PT(); pd.x = cx; pd.y = cy; SZ sz = new SZ(); sz.cx = curW; sz.cy = curW; PT ps = new PT();
|
|
439
|
+
BF bf = new BF(); bf.op = 0; bf.fl = 0; bf.a = (byte)Math.Max(0, Math.Min(255, ca)); bf.fmt = 1;
|
|
271
440
|
UpdateLayeredWindow(cur, IntPtr.Zero, ref pd, ref sz, mem2, ref ps, 0, ref bf, 2);
|
|
272
441
|
}
|
|
273
442
|
static int Steps(IntPtr from, IntPtr to) { IntPtr w = from; for (int i = 0; i < 400 && w != IntPtr.Zero; i++) { if (w == to) return i; w = GetWindow(w, 2); } return -1; }
|
|
443
|
+
|
|
444
|
+
// ---- Development aid: one state of the overlay drawn offscreen and saved as a PNG; no window is shown. ----
|
|
445
|
+
static void Backdrop(Graphics g, int kindOf, int x0, int w, int h, double s) {
|
|
446
|
+
if (kindOf == 0) {
|
|
447
|
+
int sq = Math.Max(2, (int)Math.Round(8 * s));
|
|
448
|
+
using (SolidBrush a = new SolidBrush(Color.FromArgb(0x7d, 0x7d, 0x7d))) using (SolidBrush b = new SolidBrush(Color.FromArgb(0x93, 0x93, 0x93)))
|
|
449
|
+
for (int y = 0; y * sq < h; y++) for (int x = 0; x * sq < w; x++) g.FillRectangle(((x + y) & 1) == 0 ? a : b, x0 + x * sq, y * sq, sq, sq);
|
|
450
|
+
} else using (SolidBrush c = new SolidBrush(kindOf == 1 ? Color.FromArgb(0xf3, 0xf4, 0xf6) : Color.FromArgb(0x1b, 0x1e, 0x23))) g.FillRectangle(c, x0, 0, w, h);
|
|
451
|
+
}
|
|
452
|
+
public static string Preview(int dpi, string state, string path) {
|
|
453
|
+
if (dpi < 48 || dpi > 576) throw new Exception("dpi out of range");
|
|
454
|
+
if (state != "rest" && state != "press" && state != "ripple" && state != "frame") throw new Exception("unknown preview state");
|
|
455
|
+
if (string.IsNullOrEmpty(path)) throw new Exception("preview needs a path");
|
|
456
|
+
double s = dpi / 96.0;
|
|
457
|
+
bool frame = state == "frame";
|
|
458
|
+
int pw = (int)Math.Round((frame ? 200 : 80) * s), ph = (int)Math.Round((frame ? 130 : 80) * s);
|
|
459
|
+
using (Bitmap scene = new Bitmap(pw * 3, ph, PixelFormat.Format32bppPArgb)) {
|
|
460
|
+
using (Graphics g = Graphics.FromImage(scene)) {
|
|
461
|
+
for (int i = 0; i < 3; i++) Backdrop(g, i, i * pw, pw, ph, s);
|
|
462
|
+
g.SmoothingMode = SmoothingMode.AntiAlias; g.CompositingQuality = CompositingQuality.HighQuality;
|
|
463
|
+
if (frame) {
|
|
464
|
+
int[] px = new int[pw * ph]; FrameFill(px, pw, ph, s);
|
|
465
|
+
using (Bitmap fb = new Bitmap(pw, ph, PixelFormat.Format32bppPArgb)) {
|
|
466
|
+
BitmapData d = fb.LockBits(new Rectangle(0, 0, pw, ph), ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb);
|
|
467
|
+
Marshal.Copy(px, 0, d.Scan0, pw * ph); fb.UnlockBits(d);
|
|
468
|
+
for (int i = 0; i < 3; i++) g.DrawImageUnscaled(fb, i * pw, 0);
|
|
469
|
+
}
|
|
470
|
+
} else {
|
|
471
|
+
int pad = (int)Math.Round(Pad * s);
|
|
472
|
+
double sc = 1, rr = 0, ra = 0, rw = 0;
|
|
473
|
+
if (state == "press") { sc = DipScale; Ripple(1, 40, out rr, out ra, out rw); }
|
|
474
|
+
if (state == "ripple") Ripple(1, 200, out rr, out ra, out rw);
|
|
475
|
+
Spr sp = MakeSprite(s);
|
|
476
|
+
using (Bitmap canvas = new Bitmap(pad * 2, pad * 2, PixelFormat.Format32bppPArgb)) {
|
|
477
|
+
using (Graphics gc = Graphics.FromImage(canvas)) Compose(gc, sp, s, pad, 0.4, 0.4, sc, rr, ra, rw);
|
|
478
|
+
for (int i = 0; i < 3; i++) g.DrawImageUnscaled(canvas, i * pw + (int)Math.Round(34 * s) - pad, (int)Math.Round(28 * s) - pad);
|
|
479
|
+
}
|
|
480
|
+
sp.Bmp.Dispose();
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
scene.Save(path, ImageFormat.Png);
|
|
484
|
+
}
|
|
485
|
+
return path;
|
|
486
|
+
}
|
|
487
|
+
|
|
274
488
|
public static string Info() {
|
|
275
489
|
uint a1, a2; GetWindowDisplayAffinity(frm, out a1); GetWindowDisplayAffinity(cur, out a2);
|
|
276
490
|
return "{\"frame\":\"0x" + Hwnd1.ToString("X") + "\",\"cursor\":\"0x" + Hwnd2.ToString("X") + "\",\"affinity\":[" + a1 + "," + a2 + "],\"ex\":[" + (uint)GetWindowLong(frm, -20) + "," + (uint)GetWindowLong(cur, -20) + "],\"above\":" + (Steps(frm, target) >= 0 ? "true" : "false") + ",\"fvis\":" + (IsWindowVisible(frm) ? 1 : 0) + ",\"cvis\":" + (IsWindowVisible(cur) ? 1 : 0) + ",\"lastAlpha\":" + lastAlpha + ",\"fwh\":\"" + fw + "x" + fh + " last " + lastW + "x" + lastH + " at " + lastX + "," + lastY + "\",\"owned\":" + (ownedBy == target ? "true" : "false") + ",\"refused\":" + Refused + ",\"err\":\"" + Err.Replace("\"", "'") + "\",\"ticks\":" + Ticks + ",\"avgTickUs\":" + (Ticks == 0 ? 0 : TickUs / Ticks) + ",\"maxTickUs\":" + MaxTickUs + ",\"foreground\":\"0x" + ((long)GetForegroundWindow()).ToString("X") + "\"}";
|
|
277
491
|
}
|
|
278
492
|
}
|
|
279
|
-
|
|
493
|
+
'@
|
|
280
494
|
$ok = [NzP]::Start()
|
|
281
495
|
function Reply($o) { [Console]::Out.WriteLine((ConvertTo-Json -InputObject $o -Compress -Depth 6)) }
|
|
282
496
|
Reply @{ ok = $ok; excluded = [NzP]::Excluded; error = [NzP]::Err }
|
|
@@ -296,6 +510,7 @@ while (($line = [Console]::In.ReadLine()) -ne $null) {
|
|
|
296
510
|
}
|
|
297
511
|
'hide' { [NzP]::Hide(); $r = @{ ok = $true } }
|
|
298
512
|
'info' { $r = ([NzP]::Info() | ConvertFrom-Json) }
|
|
513
|
+
'preview' { $r = @{ path = [NzP]::Preview([int]$c.dpi, [string]$c.state, [string]$c.path) } }
|
|
299
514
|
'quit' { break }
|
|
300
515
|
default { $r = @{ error = 'unknown command' } }
|
|
301
516
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper-script.js","sourceRoot":"","sources":["../../src/presence/helper-script.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"helper-script.js","sourceRoot":"","sources":["../../src/presence/helper-script.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,WAAW,EACX,SAAS,EACT,SAAS,EACT,OAAO,EACP,iBAAiB,EACjB,cAAc,EACd,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,OAAO,EACP,UAAU,EACV,SAAS,GACT,MAAM,aAAa,CAAA;AAEpB,OAAO,EACN,SAAS,EACT,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,SAAS,GACT,MAAM,aAAa,CAAA;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAkEtB,YAAY,kBAAkB,YAAY,gBAAgB,SAAS,iBAAiB,WAAW,eAAe,SAAS,gBAAgB,SAAS,oBAAoB,cAAc;+BAC7K,eAAe,gBAAgB,SAAS,kBAAkB,iBAAiB,gBAAgB,SAAS,kBAAkB,iBAAiB;4BAC1I,YAAY,CAAC,IAAI,eAAe,YAAY,CAAC,EAAE,cAAc,YAAY,CAAC,KAAK,cAAc,YAAY,CAAC,MAAM;0BAClH,UAAU,CAAC,IAAI,aAAa,UAAU,CAAC,EAAE,YAAY,UAAU,CAAC,KAAK,YAAY,UAAU,CAAC,MAAM;8BAC9F,OAAO,cAAc,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgazD,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC9B,kHAAkH,CAAA;AAEnH,mFAAmF;AACnF,MAAM,UAAU,kBAAkB,CAAC,SAAiB,sBAAsB;IACzE,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;AACtD,CAAC"}
|
package/dist/presence/index.d.ts
CHANGED
|
@@ -2,5 +2,7 @@ export { WindowsPresence } from './presence.js';
|
|
|
2
2
|
export type { Presence, PresenceKind, PresenceMark, PresenceProcess, WindowsPresenceOptions, } from './presence.js';
|
|
3
3
|
export { PRESENCE_ENV, createWindowsPresence, presenceDisabledByEnv } from './windows.js';
|
|
4
4
|
export type { WindowsPresenceFactoryOptions } from './windows.js';
|
|
5
|
-
export { FADE_MS,
|
|
5
|
+
export { APPEAR_MS, FADE_MS, GLIDE_MAX_MS, GLIDE_MIN_MS, HOLD_MS, PRESENCE_BOOTSTRAP, PRESENCE_HELPER_SCRIPT, RIPPLE_MS, } from './helper-script.js';
|
|
6
|
+
export { PREVIEW_DPIS, PREVIEW_STATES, previewCommandLine, } from './preview.js';
|
|
7
|
+
export type { PreviewDpi, PreviewRequest, PreviewState } from './preview.js';
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/presence/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,YAAY,EACX,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,sBAAsB,GACtB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AACzF,YAAY,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAA;AACjE,OAAO,EACN,OAAO,EACP,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/presence/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,YAAY,EACX,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,sBAAsB,GACtB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AACzF,YAAY,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAA;AACjE,OAAO,EACN,SAAS,EACT,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,kBAAkB,EAClB,sBAAsB,EACtB,SAAS,GACT,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACN,YAAY,EACZ,cAAc,EACd,kBAAkB,GAClB,MAAM,cAAc,CAAA;AACrB,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA"}
|