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