@copylee/dsh-computer-use 0.16.0 → 0.17.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 +1 -1
- package/helper/Capture.cs +25 -0
- package/helper/Native.cs +1 -0
- package/helper/Overlay.cs +874 -34
- package/helper/Program.cs +5 -1
- package/helper/Uia.cs +38 -0
- package/lib/client.js +8 -4
- package/lib/index.js +162 -12
- package/lib/types/computer.d.ts +10 -0
- package/lib/types/overlay.d.ts +19 -1
- package/lib/types/tools.d.ts +8 -1
- package/package.json +1 -1
package/helper/Overlay.cs
CHANGED
|
@@ -395,8 +395,6 @@ namespace DshComputerUse
|
|
|
395
395
|
static DateTime markExpiresAt = DateTime.MinValue;
|
|
396
396
|
static bool markActive;
|
|
397
397
|
static bool markIsResting;
|
|
398
|
-
static LayeredForm clickRippleForm;
|
|
399
|
-
static DateTime clickRippleExpiresAt = DateTime.MinValue;
|
|
400
398
|
static float cachedMarkScale;
|
|
401
399
|
static bool cachedMarkFlipX, cachedMarkFlipY, cachedMarkRipple, cachedMarkArrow;
|
|
402
400
|
static string cachedMarkText = "";
|
|
@@ -493,7 +491,7 @@ namespace DshComputerUse
|
|
|
493
491
|
}
|
|
494
492
|
petAlpha = (byte)Math.Max(90, Math.Min(255, Args.Int(r, "petOpacity", 90) * 255 / 100));
|
|
495
493
|
string reqSize = Args.Str(r, "petSize", "");
|
|
496
|
-
if (reqSize == "compact" || reqSize == "standard" || reqSize == "detailed") petSize = reqSize;
|
|
494
|
+
if (reqSize == "bar" || reqSize == "compact" || reqSize == "standard" || reqSize == "detailed") petSize = reqSize;
|
|
497
495
|
clickTargetEnabled = Args.Bool(r, "glow", true);
|
|
498
496
|
string badgeSrc = label.Replace("正在操控你的电脑", "").Replace("正在操控", "").Trim();
|
|
499
497
|
if (badgeSrc.Length == 0 || badgeSrc.StartsWith("DeepSeek", StringComparison.OrdinalIgnoreCase) || string.Equals(badgeSrc, "DSH", StringComparison.OrdinalIgnoreCase)) cursorBadge = "DSH";
|
|
@@ -508,6 +506,8 @@ namespace DshComputerUse
|
|
|
508
506
|
petMode = Args.Bool(r, "pet", false);
|
|
509
507
|
hoveredBtn = "";
|
|
510
508
|
pressedBtn = "";
|
|
509
|
+
barMenu = false; barHover = false; hoverAnim.Clear(); tickerText = ""; tickerLag = 0; petTotal = 0;
|
|
510
|
+
petThinkingAt = DateTime.MinValue;
|
|
511
511
|
petThinking = Args.Str(r, "thinking", "");
|
|
512
512
|
petReply = "";
|
|
513
513
|
petSteps = new List<string>();
|
|
@@ -537,14 +537,17 @@ namespace DshComputerUse
|
|
|
537
537
|
string hit = "";
|
|
538
538
|
foreach (var b in buttons) if (b.Key.Contains(e.Location)) { hit = b.Value; break; }
|
|
539
539
|
pet.Cursor = hit.Length > 0 ? Cursors.Hand : Cursors.SizeAll;
|
|
540
|
+
barHover = true;
|
|
540
541
|
if (hit != hoveredBtn)
|
|
541
542
|
{
|
|
542
543
|
hoveredBtn = hit;
|
|
544
|
+
hoverSince = DateTime.UtcNow;
|
|
543
545
|
RenderPill();
|
|
544
546
|
}
|
|
545
547
|
};
|
|
546
548
|
pet.MouseLeave += delegate
|
|
547
549
|
{
|
|
550
|
+
barHover = false;
|
|
548
551
|
if (hoveredBtn.Length > 0 || pressedBtn.Length > 0)
|
|
549
552
|
{
|
|
550
553
|
hoveredBtn = "";
|
|
@@ -568,7 +571,11 @@ namespace DshComputerUse
|
|
|
568
571
|
Native.ReleaseCapture();
|
|
569
572
|
Native.SendMessage(pet.Handle, 0xA1, new IntPtr(2), IntPtr.Zero); // WM_NCLBUTTONDOWN, HTCAPTION
|
|
570
573
|
Native.RECT rc;
|
|
571
|
-
if (pet != null && Native.GetWindowRect(pet.Handle, out rc))
|
|
574
|
+
if (pet != null && Native.GetWindowRect(pet.Handle, out rc))
|
|
575
|
+
{
|
|
576
|
+
petAnchor = new Point(rc.Right - petShadow, rc.Bottom - petShadow);
|
|
577
|
+
barPos = new Point(rc.Left + petShadow, rc.Top + petShadow);
|
|
578
|
+
}
|
|
572
579
|
petDragged = true;
|
|
573
580
|
RenderPill();
|
|
574
581
|
};
|
|
@@ -756,12 +763,14 @@ namespace DshComputerUse
|
|
|
756
763
|
}
|
|
757
764
|
|
|
758
765
|
/** Latest host-provided reasoning, brief reply text, and recent operations, oldest first. */
|
|
759
|
-
public static void PetUpdate(string thinking, string reply, List<string> steps)
|
|
766
|
+
public static void PetUpdate(string thinking, string reply, List<string> steps, int total)
|
|
760
767
|
{
|
|
761
768
|
if (thread == null || !visible || !petMode || petFinished) return;
|
|
762
769
|
invoker.BeginInvoke((MethodInvoker)delegate
|
|
763
770
|
{
|
|
764
771
|
if (petFinished) return;
|
|
772
|
+
if (thinking != petThinking && thinking.Length > petThinking.Length) petThinkingAt = DateTime.UtcNow;
|
|
773
|
+
if (total > 0) petTotal = total;
|
|
765
774
|
petThinking = thinking;
|
|
766
775
|
petReply = reply ?? "";
|
|
767
776
|
if (steps.Count > 0) petSteps = steps;
|
|
@@ -843,6 +852,10 @@ namespace DshComputerUse
|
|
|
843
852
|
RestoreSystemCursor(false);
|
|
844
853
|
CloseInput(false);
|
|
845
854
|
petFinished = false;
|
|
855
|
+
barMenu = false;
|
|
856
|
+
hoverAnim.Clear();
|
|
857
|
+
tickerText = "";
|
|
858
|
+
tickerLag = 0;
|
|
846
859
|
petWaiting = false;
|
|
847
860
|
petPhase = "";
|
|
848
861
|
lastPhaseSec = -1;
|
|
@@ -1124,15 +1137,40 @@ namespace DshComputerUse
|
|
|
1124
1137
|
if (Native.GetCursorPos(out cur)) { startX = cur.X; startY = cur.Y; }
|
|
1125
1138
|
else if (hasLastMark) { startX = lastMarkX; startY = lastMarkY; }
|
|
1126
1139
|
else { startX = x; startY = y; }
|
|
1127
|
-
|
|
1140
|
+
Ensure();
|
|
1141
|
+
gliding = true;
|
|
1142
|
+
try
|
|
1128
1143
|
{
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1144
|
+
AnimatePointer(startX, startY, x, y, 0, delegate(int ix, int iy)
|
|
1145
|
+
{
|
|
1146
|
+
try { Native.SetCursorPos(ix, iy); } catch (Exception) { }
|
|
1147
|
+
// Never wait for the UI thread mid-glide: the latest point wins, older ones are dropped.
|
|
1148
|
+
glideX = ix; glideY = iy; glideText = text; glideColor = color; glideHold = holdMs;
|
|
1149
|
+
if (Interlocked.Exchange(ref glidePending, 1) == 0)
|
|
1150
|
+
{
|
|
1151
|
+
try { invoker.BeginInvoke((MethodInvoker)PlaceGlideOnUi); }
|
|
1152
|
+
catch (Exception) { Interlocked.Exchange(ref glidePending, 0); }
|
|
1153
|
+
}
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1156
|
+
finally { gliding = false; }
|
|
1132
1157
|
try { Native.SetCursorPos(x, y); } catch (Exception) { }
|
|
1133
1158
|
Mark(x, y, text, color, holdMs, false, false);
|
|
1134
1159
|
}
|
|
1135
1160
|
|
|
1161
|
+
static volatile bool gliding;
|
|
1162
|
+
static volatile int glideX, glideY, glideHold;
|
|
1163
|
+
static volatile string glideText = "";
|
|
1164
|
+
static Color glideColor;
|
|
1165
|
+
static int glidePending;
|
|
1166
|
+
|
|
1167
|
+
static void PlaceGlideOnUi()
|
|
1168
|
+
{
|
|
1169
|
+
Interlocked.Exchange(ref glidePending, 0);
|
|
1170
|
+
if (!gliding) return;
|
|
1171
|
+
PlaceMarkOnUi(glideX, glideY, glideText, glideColor, glideHold, false, false, false);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1136
1174
|
/** Glide duration for a move of `dist` pixels: short hops stay quick, long sweeps stay readable. */
|
|
1137
1175
|
public static double GlideDurationMs(double dist)
|
|
1138
1176
|
{
|
|
@@ -1199,15 +1237,45 @@ namespace DshComputerUse
|
|
|
1199
1237
|
Ui(delegate { PlaceMarkOnUi(x, y, text, color, holdMs, capturable, ripple, false); });
|
|
1200
1238
|
}
|
|
1201
1239
|
|
|
1202
|
-
|
|
1203
|
-
static
|
|
1240
|
+
// ---- Click feedback: animated on its own thread so a busy UI thread never makes it stutter. ----
|
|
1241
|
+
static Thread fxThread;
|
|
1242
|
+
static Control fxInvoker;
|
|
1243
|
+
static System.Windows.Forms.Timer fxTimer;
|
|
1244
|
+
static LayeredForm fxForm;
|
|
1245
|
+
static readonly Stopwatch fxClock = new Stopwatch();
|
|
1246
|
+
static int fxX, fxY, fxHold, fxCx, fxCy;
|
|
1247
|
+
static string fxText = "";
|
|
1248
|
+
static Color fxColor;
|
|
1249
|
+
static float fxScale = 1f;
|
|
1250
|
+
static bool fxFlipX, fxFlipY, fxHighRes;
|
|
1251
|
+
|
|
1252
|
+
static void OnFxThread(MethodInvoker action)
|
|
1204
1253
|
{
|
|
1205
|
-
if (
|
|
1254
|
+
if (fxThread == null)
|
|
1206
1255
|
{
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1256
|
+
var ready = new ManualResetEvent(false);
|
|
1257
|
+
fxThread = new Thread(delegate ()
|
|
1258
|
+
{
|
|
1259
|
+
fxInvoker = new Control();
|
|
1260
|
+
var force = fxInvoker.Handle;
|
|
1261
|
+
fxTimer = new System.Windows.Forms.Timer();
|
|
1262
|
+
fxTimer.Interval = 10;
|
|
1263
|
+
fxTimer.Tick += delegate { FxFrame(); };
|
|
1264
|
+
ready.Set();
|
|
1265
|
+
Application.Run();
|
|
1266
|
+
});
|
|
1267
|
+
fxThread.IsBackground = true;
|
|
1268
|
+
fxThread.Priority = ThreadPriority.AboveNormal;
|
|
1269
|
+
fxThread.SetApartmentState(ApartmentState.STA);
|
|
1270
|
+
fxThread.Start();
|
|
1271
|
+
ready.WaitOne();
|
|
1210
1272
|
}
|
|
1273
|
+
try { fxInvoker.BeginInvoke(action); } catch (Exception) { }
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
/** The click marker stays capturable, so the next screenshot still shows the model where it clicked. */
|
|
1277
|
+
static void ShowClickRippleOnUi(int x, int y, string text, Color color, int holdMs)
|
|
1278
|
+
{
|
|
1211
1279
|
float scale; Rectangle mon;
|
|
1212
1280
|
MonitorAt(x, y, out scale, out mon);
|
|
1213
1281
|
float s = Math.Max(0.75f, Math.Min(3f, scale));
|
|
@@ -1215,23 +1283,115 @@ namespace DshComputerUse
|
|
|
1215
1283
|
int estW = (int)((Math.Max(6, labelText.Length) * 11 + 36) * s);
|
|
1216
1284
|
bool flipX = !mon.IsEmpty && x + estW > mon.Right;
|
|
1217
1285
|
bool flipY = !mon.IsEmpty && y + (int)(52 * s) > mon.Bottom;
|
|
1218
|
-
|
|
1219
|
-
using (var bmp = DrawMark(labelText, color, scale, flipX, flipY, true, false, out cx, out cy))
|
|
1286
|
+
OnFxThread(delegate
|
|
1220
1287
|
{
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1288
|
+
if (fxForm == null)
|
|
1289
|
+
{
|
|
1290
|
+
fxForm = new LayeredForm(true);
|
|
1291
|
+
fxForm.SetCapturable(true);
|
|
1292
|
+
fxForm.Show();
|
|
1293
|
+
}
|
|
1294
|
+
fxX = x; fxY = y; fxText = labelText; fxColor = color; fxHold = Math.Max(420, holdMs);
|
|
1295
|
+
fxScale = scale; fxFlipX = flipX; fxFlipY = flipY;
|
|
1296
|
+
fxClock.Restart();
|
|
1297
|
+
if (!fxHighRes) { try { fxHighRes = Native.timeBeginPeriod(1) == 0; } catch (Exception) { } }
|
|
1298
|
+
FxFrame();
|
|
1299
|
+
fxForm.KeepOnTop();
|
|
1300
|
+
fxTimer.Start();
|
|
1301
|
+
});
|
|
1226
1302
|
}
|
|
1227
1303
|
|
|
1228
|
-
static void HideClickRipple()
|
|
1304
|
+
static void HideClickRipple() { if (fxThread != null) OnFxThread(EndFx); }
|
|
1305
|
+
|
|
1306
|
+
static void EndFx()
|
|
1307
|
+
{
|
|
1308
|
+
if (fxTimer != null) fxTimer.Stop();
|
|
1309
|
+
if (fxHighRes) { try { Native.timeEndPeriod(1); } catch (Exception) { } fxHighRes = false; }
|
|
1310
|
+
if (fxForm != null) { fxForm.Close(); fxForm = null; }
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
static void FxFrame()
|
|
1314
|
+
{
|
|
1315
|
+
if (fxForm == null) { EndFx(); return; }
|
|
1316
|
+
double ms = fxClock.Elapsed.TotalMilliseconds;
|
|
1317
|
+
if (ms >= fxHold) { EndFx(); return; }
|
|
1318
|
+
double fadeOut = Math.Min(1.0, (fxHold - ms) / 180.0);
|
|
1319
|
+
using (var bmp = DrawClickFx(fxText, fxColor, fxScale, fxFlipX, fxFlipY, ms / 1000.0, out fxCx, out fxCy))
|
|
1320
|
+
fxForm.SetBitmap(bmp, new Rectangle(fxX - fxCx, fxY - fxCy, bmp.Width, bmp.Height), (byte)(255 * fadeOut));
|
|
1321
|
+
// Once the motion settles only the fade remains: slow the timer down.
|
|
1322
|
+
fxTimer.Interval = ms < 600 ? 10 : 30;
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
static float EaseOutCubic(double t) { t = Math.Max(0, Math.Min(1, t)); return (float)(1 - Math.Pow(1 - t, 3)); }
|
|
1326
|
+
|
|
1327
|
+
/** One frame of the click feedback, `t` seconds after the click: two rings spread and fade, the dot pops, the tag slides in. */
|
|
1328
|
+
static Bitmap DrawClickFx(string text, Color color, float scale, bool flipX, bool flipY, double t, out int cx, out int cy)
|
|
1229
1329
|
{
|
|
1230
|
-
|
|
1231
|
-
|
|
1330
|
+
float s = Math.Max(0.75f, Math.Min(3f, scale));
|
|
1331
|
+
float px = 1.333f * s;
|
|
1332
|
+
float maxR = 30f * s, pad = 4f * s;
|
|
1333
|
+
using (var font = new Font("Microsoft YaHei UI", 7.8f * px, FontStyle.Bold, GraphicsUnit.Pixel))
|
|
1334
|
+
using (var fmt = new StringFormat(StringFormat.GenericTypographic))
|
|
1232
1335
|
{
|
|
1233
|
-
|
|
1234
|
-
|
|
1336
|
+
fmt.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap;
|
|
1337
|
+
SizeF textSize;
|
|
1338
|
+
using (var probe = new Bitmap(1, 1)) using (var mg = Graphics.FromImage(probe))
|
|
1339
|
+
textSize = string.IsNullOrEmpty(text) ? SizeF.Empty : mg.MeasureString(text, font, 10000, fmt);
|
|
1340
|
+
float pillW = textSize.Width > 0 ? (float)Math.Ceiling(textSize.Width + 16f * s) : 0f;
|
|
1341
|
+
float pillH = textSize.Height > 0 ? Math.Max(20f * s, (float)Math.Ceiling(textSize.Height + 7f * s)) : 0f;
|
|
1342
|
+
float tagX = flipX ? (-12f * s - pillW) : 13f * s;
|
|
1343
|
+
float tagY = flipY ? (-12f * s - pillH) : 15f * s;
|
|
1344
|
+
float minX = Math.Min(-maxR, pillW > 0 ? tagX : 0f) - pad, maxX = Math.Max(maxR, pillW > 0 ? tagX + pillW : 0f) + pad;
|
|
1345
|
+
float minY = Math.Min(-maxR, pillH > 0 ? tagY - 6f * s : 0f) - pad, maxY = Math.Max(maxR, pillH > 0 ? tagY + pillH + 8f * s : 0f) + pad;
|
|
1346
|
+
int W = Math.Max(1, (int)Math.Ceiling(maxX - minX)), H = Math.Max(1, (int)Math.Ceiling(maxY - minY));
|
|
1347
|
+
cx = (int)Math.Round(-minX); cy = (int)Math.Round(-minY);
|
|
1348
|
+
var bmp = new Bitmap(W, H, PixelFormat.Format32bppArgb);
|
|
1349
|
+
using (var g = Graphics.FromImage(bmp))
|
|
1350
|
+
{
|
|
1351
|
+
g.Clear(Color.Transparent);
|
|
1352
|
+
g.SmoothingMode = SmoothingMode.AntiAlias;
|
|
1353
|
+
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
|
1354
|
+
// A soft press shadow that blooms and fades.
|
|
1355
|
+
float pb = EaseOutCubic(t / 0.35);
|
|
1356
|
+
float fr = (5f + 13f * pb) * s;
|
|
1357
|
+
using (var b = new SolidBrush(Color.FromArgb((int)(60 * (1 - pb)), color))) g.FillEllipse(b, cx - fr, cy - fr, 2 * fr, 2 * fr);
|
|
1358
|
+
// Two rings, the second a beat later.
|
|
1359
|
+
for (int i = 0; i < 2; i++)
|
|
1360
|
+
{
|
|
1361
|
+
double p = (t - i * 0.09) / 0.52;
|
|
1362
|
+
if (p <= 0 || p >= 1) continue;
|
|
1363
|
+
float e = EaseOutCubic(p);
|
|
1364
|
+
float r = (6f + (maxR - 8f * s) / s * e) * s;
|
|
1365
|
+
int a = (int)((i == 0 ? 210 : 140) * Math.Pow(1 - p, 1.6));
|
|
1366
|
+
using (var pen = new Pen(Color.FromArgb(a, color), Math.Max(1f, (2.6f - 1.6f * e) * s))) g.DrawEllipse(pen, cx - r, cy - r, 2 * r, 2 * r);
|
|
1367
|
+
}
|
|
1368
|
+
// The dot: pops slightly past full size, then settles.
|
|
1369
|
+
double dp = t / 0.22;
|
|
1370
|
+
float pop = dp >= 1 ? 1f : dp < 0.55 ? (float)(0.35 + 0.95 * EaseOutCubic(dp / 0.55)) : (float)(1.3 - 0.3 * EaseOutCubic((dp - 0.55) / 0.45));
|
|
1371
|
+
float dr = 3.6f * s * pop;
|
|
1372
|
+
using (var halo = new SolidBrush(Color.FromArgb(240, 255, 255, 255))) g.FillEllipse(halo, cx - dr - 1.6f * s, cy - dr - 1.6f * s, 2 * (dr + 1.6f * s), 2 * (dr + 1.6f * s));
|
|
1373
|
+
using (var dot = new SolidBrush(color)) g.FillEllipse(dot, cx - dr, cy - dr, 2 * dr, 2 * dr);
|
|
1374
|
+
// The tag fades in and slides toward the point.
|
|
1375
|
+
if (pillW > 0)
|
|
1376
|
+
{
|
|
1377
|
+
float ta = EaseOutCubic((t - 0.05) / 0.18);
|
|
1378
|
+
if (ta > 0.01f)
|
|
1379
|
+
{
|
|
1380
|
+
float slide = (1 - ta) * 5f * s * (flipY ? -1 : 1);
|
|
1381
|
+
var rect = new RectangleF(cx + tagX, cy + tagY + slide, pillW, pillH);
|
|
1382
|
+
using (var sp = Rounded(new RectangleF(rect.X, rect.Y + 2f * s, rect.Width, rect.Height), pillH / 2f))
|
|
1383
|
+
using (var sb = new SolidBrush(Color.FromArgb((int)(50 * ta), 0, 0, 0))) g.FillPath(sb, sp);
|
|
1384
|
+
using (var pp = Rounded(rect, pillH / 2f))
|
|
1385
|
+
{
|
|
1386
|
+
using (var fill = new SolidBrush(Color.FromArgb((int)(242 * ta), color))) g.FillPath(fill, pp);
|
|
1387
|
+
using (var border = new Pen(Color.FromArgb((int)(200 * ta), 255, 255, 255), Math.Max(1f, s))) g.DrawPath(border, pp);
|
|
1388
|
+
}
|
|
1389
|
+
using (var fg = new SolidBrush(Color.FromArgb((int)(255 * ta), 255, 255, 255)))
|
|
1390
|
+
g.DrawString(text, font, fg, rect.X + (pillW - textSize.Width) / 2f, rect.Y + (pillH - textSize.Height) / 2f - 0.5f * s, fmt);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
return bmp;
|
|
1235
1395
|
}
|
|
1236
1396
|
}
|
|
1237
1397
|
|
|
@@ -1289,6 +1449,10 @@ namespace DshComputerUse
|
|
|
1289
1449
|
// pause / resume / stop, from Esc or the pill buttons.
|
|
1290
1450
|
static void Press(string action)
|
|
1291
1451
|
{
|
|
1452
|
+
if (action == "menu") { barMenu = !barMenu; barMenuAt = DateTime.UtcNow; barOutsideTick = Environment.TickCount; RenderPill(); return; }
|
|
1453
|
+
if (action.StartsWith("m_")) { barMenu = false; Press(action.Substring(2)); return; }
|
|
1454
|
+
barMenu = false;
|
|
1455
|
+
if (action == "open_host") { Program.EmitEvent("open_host", "button"); RenderPill(); return; }
|
|
1292
1456
|
if (action == "stop") { paused = false; petWaiting = false; SkipWaitRequested = true; RestoreSystemCursor(false); Program.EmitEvent("stop", "button"); }
|
|
1293
1457
|
else if (action == "skip_wait") { petWaiting = false; SkipWaitRequested = true; Program.EmitEvent("skip_wait", "button"); }
|
|
1294
1458
|
else if (action == "pause") { paused = true; HideMark(); RestoreSystemCursor(false); Program.EmitEvent("pause", "user"); }
|
|
@@ -1362,10 +1526,6 @@ namespace DshComputerUse
|
|
|
1362
1526
|
|
|
1363
1527
|
static void Tick()
|
|
1364
1528
|
{
|
|
1365
|
-
if (clickRippleForm != null && DateTime.UtcNow >= clickRippleExpiresAt)
|
|
1366
|
-
{
|
|
1367
|
-
HideClickRipple();
|
|
1368
|
-
}
|
|
1369
1529
|
if (markActive && DateTime.UtcNow >= markExpiresAt)
|
|
1370
1530
|
{
|
|
1371
1531
|
if (visible && clickTargetEnabled && !petFinished && !paused)
|
|
@@ -1379,7 +1539,7 @@ namespace DshComputerUse
|
|
|
1379
1539
|
}
|
|
1380
1540
|
if (!visible)
|
|
1381
1541
|
{
|
|
1382
|
-
if (!markActive
|
|
1542
|
+
if (!markActive) timer.Stop();
|
|
1383
1543
|
return;
|
|
1384
1544
|
}
|
|
1385
1545
|
if (visible && clickTargetEnabled && !petFinished && !paused && !markActive)
|
|
@@ -1393,6 +1553,16 @@ namespace DshComputerUse
|
|
|
1393
1553
|
if (Native.GetCursorPos(out cp) && (Math.Abs(cp.X - lastMarkX) > 2 || Math.Abs(cp.Y - lastMarkY) > 2))
|
|
1394
1554
|
ShowRestingMarkOnUi(cp.X, cp.Y);
|
|
1395
1555
|
}
|
|
1556
|
+
if (petMode && BarStyle() && pet != null)
|
|
1557
|
+
{
|
|
1558
|
+
if (barMenu)
|
|
1559
|
+
{
|
|
1560
|
+
Native.POINT mp; Native.GetCursorPos(out mp);
|
|
1561
|
+
if (pet.Physical.Contains(mp.X, mp.Y)) barOutsideTick = Environment.TickCount;
|
|
1562
|
+
else if (unchecked(Environment.TickCount - barOutsideTick) > 1200 || (Native.GetAsyncKeyState(0x01) & 0x8000) != 0) { barMenu = false; RenderPill(); }
|
|
1563
|
+
}
|
|
1564
|
+
if (!gliding && BarAnimating()) RenderPill();
|
|
1565
|
+
}
|
|
1396
1566
|
if (petFinished)
|
|
1397
1567
|
{
|
|
1398
1568
|
Native.POINT p; Native.GetCursorPos(out p);
|
|
@@ -1556,9 +1726,645 @@ namespace DshComputerUse
|
|
|
1556
1726
|
return "";
|
|
1557
1727
|
}
|
|
1558
1728
|
|
|
1729
|
+
// ---- The top progress bar ("bar" pet style): one pill at the top of the screen. ----
|
|
1730
|
+
static readonly Color BarBlue = Color.FromArgb(77, 107, 254); // #4D6BFE
|
|
1731
|
+
static readonly Color BarGreen = Color.FromArgb(93, 187, 122); // #5DBB7A
|
|
1732
|
+
static bool barMenu;
|
|
1733
|
+
static DateTime barMenuAt = DateTime.MinValue;
|
|
1734
|
+
static int barOutsideTick;
|
|
1735
|
+
static bool barHover;
|
|
1736
|
+
static Point barPos = Point.Empty;
|
|
1737
|
+
static DateTime barLastFrame = DateTime.UtcNow;
|
|
1738
|
+
static DateTime hoverSince = DateTime.UtcNow;
|
|
1739
|
+
static readonly Dictionary<string, float> hoverAnim = new Dictionary<string, float>();
|
|
1740
|
+
static string tickerText = "";
|
|
1741
|
+
static float tickerLag;
|
|
1742
|
+
static DateTime petThinkingAt = DateTime.MinValue;
|
|
1743
|
+
static int petTotal;
|
|
1744
|
+
|
|
1745
|
+
static bool BarStyle() { return petSize == "bar"; }
|
|
1746
|
+
|
|
1747
|
+
/** Test hook: open the menu and/or pretend the pointer rests on a button. */
|
|
1748
|
+
public static void BarDebug(bool menu, string hover)
|
|
1749
|
+
{
|
|
1750
|
+
if (thread == null) return;
|
|
1751
|
+
Ui(delegate { barMenu = menu; barMenuAt = DateTime.UtcNow.AddSeconds(-1); barOutsideTick = Environment.TickCount + 600000; hoveredBtn = hover; hoverSince = DateTime.UtcNow.AddSeconds(-1); barHover = hover.Length > 0 || menu; if (visible) RenderPill(); });
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
/** Animation clock in seconds since the bar showed. */
|
|
1755
|
+
static double BarClock() { return (DateTime.UtcNow - shownAt).TotalSeconds; }
|
|
1756
|
+
|
|
1757
|
+
/** The model is producing reasoning right now (or the request is in flight). */
|
|
1758
|
+
static bool BarThinking()
|
|
1759
|
+
{
|
|
1760
|
+
if (petFinished || paused || petWaiting || Typing()) return false;
|
|
1761
|
+
if (petReply.Length > 0) return false;
|
|
1762
|
+
if (petPhase == "llm") return true;
|
|
1763
|
+
return (DateTime.UtcNow - petThinkingAt).TotalMilliseconds < 1600;
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
/** Eased per-button hover amount, 0..1, advanced by real time. */
|
|
1767
|
+
static float HoverAmount(string act, float dt)
|
|
1768
|
+
{
|
|
1769
|
+
float cur;
|
|
1770
|
+
if (!hoverAnim.TryGetValue(act, out cur)) cur = 0;
|
|
1771
|
+
float target = hoveredBtn == act ? 1f : 0f;
|
|
1772
|
+
float k = (float)(1 - Math.Exp(-dt / 0.07));
|
|
1773
|
+
cur += (target - cur) * k;
|
|
1774
|
+
if (Math.Abs(target - cur) < 0.01f) cur = target;
|
|
1775
|
+
hoverAnim[act] = cur;
|
|
1776
|
+
return cur;
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
static bool BarAnimating()
|
|
1780
|
+
{
|
|
1781
|
+
foreach (var kv in hoverAnim)
|
|
1782
|
+
if (kv.Value > 0.001f && kv.Value < 0.999f) return true;
|
|
1783
|
+
if (tickerLag > 0.5f) return true;
|
|
1784
|
+
if (barMenu && (DateTime.UtcNow - barMenuAt).TotalMilliseconds < 220) return true;
|
|
1785
|
+
if (hoveredBtn.Length > 0 && (DateTime.UtcNow - hoverSince).TotalMilliseconds < 450) return true;
|
|
1786
|
+
return !petFinished; // the pulsing dot, the thinking bubble and the shimmer
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
static Color Mix(Color a, Color b, float t)
|
|
1790
|
+
{
|
|
1791
|
+
t = Math.Max(0, Math.Min(1, t));
|
|
1792
|
+
return Color.FromArgb((int)(a.A + (b.A - a.A) * t), (int)(a.R + (b.R - a.R) * t), (int)(a.G + (b.G - a.G) * t), (int)(a.B + (b.B - a.B) * t));
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
static string Elapsed(TimeSpan span)
|
|
1796
|
+
{
|
|
1797
|
+
int sec = (int)Math.Max(0, span.TotalSeconds);
|
|
1798
|
+
if (sec < 60) return sec + " 秒";
|
|
1799
|
+
return (sec / 60) + " 分 " + (sec % 60) + " 秒";
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
/** Fade the first `fade` columns of a transparent text strip to nothing (newest text stays on the right). */
|
|
1803
|
+
static void FadeLeft(Bitmap strip, int fade)
|
|
1804
|
+
{
|
|
1805
|
+
fade = Math.Min(fade, strip.Width);
|
|
1806
|
+
if (fade <= 0) return;
|
|
1807
|
+
var data = strip.LockBits(new Rectangle(0, 0, fade, strip.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
|
1808
|
+
try
|
|
1809
|
+
{
|
|
1810
|
+
var row = new byte[fade * 4];
|
|
1811
|
+
for (int y = 0; y < strip.Height; y++)
|
|
1812
|
+
{
|
|
1813
|
+
IntPtr p = new IntPtr(data.Scan0.ToInt64() + (long)y * data.Stride);
|
|
1814
|
+
Marshal.Copy(p, row, 0, row.Length);
|
|
1815
|
+
for (int x = 0; x < fade; x++)
|
|
1816
|
+
{
|
|
1817
|
+
double f = (double)x / fade;
|
|
1818
|
+
row[x * 4 + 3] = (byte)(row[x * 4 + 3] * f * f);
|
|
1819
|
+
}
|
|
1820
|
+
Marshal.Copy(row, 0, p, row.Length);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
finally { strip.UnlockBits(data); }
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
/** A round icon button with eased hover (lift + brighten + halo) and press (shrink) feedback. */
|
|
1827
|
+
static void BarButton(Graphics g, string act, RectangleF hit, string glyph, string fallback, Font fGlyph, bool primary, bool dark, Color ink, float s, float dt)
|
|
1828
|
+
{
|
|
1829
|
+
float h = HoverAmount(act, dt);
|
|
1830
|
+
bool press = pressedBtn == act;
|
|
1831
|
+
float scale = press ? 0.88f : 1f + 0.04f * h;
|
|
1832
|
+
float lift = press ? 0 : -1f * s * h;
|
|
1833
|
+
var c = new PointF(hit.X + hit.Width / 2f, hit.Y + hit.Height / 2f + lift);
|
|
1834
|
+
float r = hit.Width / 2f * scale;
|
|
1835
|
+
var circle = new RectangleF(c.X - r, c.Y - r, 2 * r, 2 * r);
|
|
1836
|
+
if (primary)
|
|
1837
|
+
{
|
|
1838
|
+
if (h > 0.01f)
|
|
1839
|
+
using (var halo = new SolidBrush(Color.FromArgb((int)(72 * h), Accent)))
|
|
1840
|
+
g.FillEllipse(halo, RectangleF.Inflate(circle, 4 * s * h, 4 * s * h));
|
|
1841
|
+
Color fill = press ? Color.FromArgb(192, 96, 63) : Mix(Accent, Color.FromArgb(232, 135, 95), h);
|
|
1842
|
+
using (var b = new SolidBrush(fill)) g.FillEllipse(b, circle);
|
|
1843
|
+
// The stop sign: a small white rounded square.
|
|
1844
|
+
float q = 10 * s * scale;
|
|
1845
|
+
using (var path = Rounded(new RectangleF(c.X - q / 2f, c.Y - q / 2f, q, q), 2.4f * s))
|
|
1846
|
+
using (var b = new SolidBrush(Color.White)) g.FillPath(b, path);
|
|
1847
|
+
}
|
|
1848
|
+
else
|
|
1849
|
+
{
|
|
1850
|
+
Color idle = dark ? Color.FromArgb(0, 255, 255, 255) : Color.FromArgb(0, 0, 0, 0);
|
|
1851
|
+
Color hot = dark ? Color.FromArgb(press ? 46 : 30, 255, 255, 255) : Color.FromArgb(press ? 26 : 16, 0, 0, 0);
|
|
1852
|
+
bool on = act == "menu" && barMenu;
|
|
1853
|
+
Color fill = on ? hot : Mix(idle, hot, h);
|
|
1854
|
+
if (fill.A > 0) using (var b = new SolidBrush(fill)) g.FillEllipse(b, circle);
|
|
1855
|
+
var center = new StringFormat(); center.Alignment = StringAlignment.Center; center.LineAlignment = StringAlignment.Center;
|
|
1856
|
+
Color gc = Mix(Color.FromArgb(dark ? 200 : 170, ink), ink, Math.Max(h, on ? 1f : 0f));
|
|
1857
|
+
using (var b = new SolidBrush(gc)) g.DrawString(IconFont().Length > 0 ? glyph : fallback, fGlyph, b, circle, center);
|
|
1858
|
+
}
|
|
1859
|
+
buttons.Add(new KeyValuePair<Rectangle, string>(Rectangle.Round(hit), act));
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
/** A small pill button inside the text area ("跳过等待", "继续"). */
|
|
1863
|
+
static void BarChip(Graphics g, string act, RectangleF hit, string text, Font font, float s, float dt)
|
|
1864
|
+
{
|
|
1865
|
+
float h = HoverAmount(act, dt);
|
|
1866
|
+
bool press = pressedBtn == act;
|
|
1867
|
+
var r = press ? RectangleF.Inflate(hit, -1.2f * s, -1.2f * s) : new RectangleF(hit.X, hit.Y - 1f * s * h, hit.Width, hit.Height);
|
|
1868
|
+
using (var path = Rounded(r, r.Height / 2f))
|
|
1869
|
+
{
|
|
1870
|
+
using (var b = new SolidBrush(Color.FromArgb((int)(40 + 50 * h + (press ? 40 : 0)), Accent))) g.FillPath(b, path);
|
|
1871
|
+
using (var pen = new Pen(Color.FromArgb((int)(150 + 90 * h), Accent), Math.Max(1f, s))) g.DrawPath(pen, path);
|
|
1872
|
+
}
|
|
1873
|
+
var center = new StringFormat(); center.Alignment = StringAlignment.Center; center.LineAlignment = StringAlignment.Center;
|
|
1874
|
+
using (var b = new SolidBrush(Mix(AccentHi, Color.White, h))) g.DrawString(text, font, b, r, center);
|
|
1875
|
+
buttons.Add(new KeyValuePair<Rectangle, string>(Rectangle.Round(hit), act));
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
static void RenderBar()
|
|
1879
|
+
{
|
|
1880
|
+
if (pet == null) return;
|
|
1881
|
+
Rectangle work = Rectangle.Empty; float scale = 1f;
|
|
1882
|
+
foreach (Dictionary<string, object> dd in Screen2.Displays())
|
|
1883
|
+
{
|
|
1884
|
+
if (work.IsEmpty || (bool)dd["primary"])
|
|
1885
|
+
{
|
|
1886
|
+
work = new Rectangle((int)dd["workX"], (int)dd["workY"], (int)dd["workWidth"], (int)dd["workHeight"]);
|
|
1887
|
+
scale = (int)dd["dpi"] / 96f;
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
rendered = Key();
|
|
1891
|
+
var now = DateTime.UtcNow;
|
|
1892
|
+
float dt = (float)Math.Max(0.0, Math.Min(0.2, (now - barLastFrame).TotalSeconds));
|
|
1893
|
+
barLastFrame = now;
|
|
1894
|
+
double clock = BarClock();
|
|
1895
|
+
bool dark = DarkTheme();
|
|
1896
|
+
float s = scale, px = 1.333f * scale;
|
|
1897
|
+
byte bgA = (byte)(barHover || barMenu || input != null ? 252 : Math.Max(petAlpha, (byte)242));
|
|
1898
|
+
Color bg = dark ? Color.FromArgb(bgA, 26, 25, 24) : Color.FromArgb(bgA, 252, 252, 251);
|
|
1899
|
+
Color ink = dark ? Color.FromArgb(244, 243, 241) : Color.FromArgb(31, 30, 29);
|
|
1900
|
+
Color muted = dark ? Color.FromArgb(150, 147, 142) : Color.FromArgb(120, 117, 112);
|
|
1901
|
+
Color faint = dark ? Color.FromArgb(26, 255, 255, 255) : Color.FromArgb(20, 0, 0, 0);
|
|
1902
|
+
Color menuBg = dark ? Color.FromArgb(250, 36, 35, 33) : Color.FromArgb(252, 255, 255, 255);
|
|
1903
|
+
|
|
1904
|
+
bool typing = !petFinished && !paused && Typing();
|
|
1905
|
+
bool waiting = !petFinished && !paused && !typing && petWaiting;
|
|
1906
|
+
bool hasReply = !petFinished && petReply.Length > 0;
|
|
1907
|
+
bool llmWait = !petFinished && !paused && !typing && !waiting && petPhase == "llm" && !hasReply && petThinking.Length == 0;
|
|
1908
|
+
bool thinkingNow = BarThinking();
|
|
1909
|
+
int waitSec = (int)Math.Max(0, Math.Floor((now - petWaitingSince).TotalSeconds));
|
|
1910
|
+
int llmSec = (int)Math.Max(0, Math.Floor((now - petPhaseSince).TotalSeconds));
|
|
1911
|
+
|
|
1912
|
+
const float shadowPad = 18f;
|
|
1913
|
+
int sh = (int)(shadowPad * s);
|
|
1914
|
+
float bodyW = Math.Min(660f * s, work.Width - 40f * s);
|
|
1915
|
+
float headH = 44f * s;
|
|
1916
|
+
float textW = bodyW - 32f * s;
|
|
1917
|
+
|
|
1918
|
+
// Expanded: the full reasoning (or reply) and the step list under the header.
|
|
1919
|
+
string fullText = hasReply ? petReply : petThinking;
|
|
1920
|
+
float expandTextH = 0, expandListH = 0;
|
|
1921
|
+
int listRows = 0;
|
|
1922
|
+
if (petExpanded)
|
|
1923
|
+
{
|
|
1924
|
+
using (var probe = new Bitmap(1, 1))
|
|
1925
|
+
using (var pg = Graphics.FromImage(probe))
|
|
1926
|
+
using (var pf = new Font("Microsoft YaHei UI", 9.5f * px, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
1927
|
+
{
|
|
1928
|
+
string t = fullText.Length > 0 ? fullText : "还没有思考内容";
|
|
1929
|
+
float need = pg.MeasureString(t, pf, new SizeF(textW, 100000), new StringFormat(StringFormat.GenericTypographic)).Height + 6 * s;
|
|
1930
|
+
expandTextH = Math.Max(24f * s, Math.Min(118f * s, need));
|
|
1931
|
+
}
|
|
1932
|
+
listRows = Math.Min(6, Math.Max(1, petSteps.Count));
|
|
1933
|
+
expandListH = 12f * s + listRows * 24f * s;
|
|
1934
|
+
}
|
|
1935
|
+
float inputH = input != null ? 48f * s : 0;
|
|
1936
|
+
float bodyH = headH + (petExpanded ? expandTextH + expandListH + 14f * s : 0) + inputH;
|
|
1937
|
+
|
|
1938
|
+
// Menu and tooltip hang under the bar inside the same layered window.
|
|
1939
|
+
var menuItems = new List<string[]>(); // act, glyph, fallback, label, hint
|
|
1940
|
+
if (barMenu && !petFinished)
|
|
1941
|
+
{
|
|
1942
|
+
if (paused) menuItems.Add(new[] { "resume", "", "▶", "继续操控", "Esc" });
|
|
1943
|
+
else menuItems.Add(new[] { "pause", "", "❚❚", "暂停操控", "Esc" });
|
|
1944
|
+
if (petWaiting && !paused) menuItems.Add(new[] { "skip_wait", "", "⏭", "跳过等待", "" });
|
|
1945
|
+
menuItems.Add(new[] { "expand", petExpanded ? "" : "", petExpanded ? "˄" : "˅", petExpanded ? "收起思考与步骤" : "展开思考与步骤", "" });
|
|
1946
|
+
menuItems.Add(new[] { "input", "", "✎", input != null ? "关闭输入框" : "输入新指令", "" });
|
|
1947
|
+
menuItems.Add(new[] { "open_host", "", "↗", "打开 DeepSeek Harness 窗口", "" });
|
|
1948
|
+
menuItems.Add(new[] { "-", "", "", "", "" });
|
|
1949
|
+
menuItems.Add(new[] { "stop", "", "■", "停止控制并回到 DSH", "" });
|
|
1950
|
+
}
|
|
1951
|
+
float itemH = 34f * s, menuPad = 6f * s;
|
|
1952
|
+
float menuW = 236f * s;
|
|
1953
|
+
float menuH = 0;
|
|
1954
|
+
foreach (var it in menuItems) menuH += it[0] == "-" ? 9f * s : itemH;
|
|
1955
|
+
if (menuH > 0) menuH += 2 * menuPad;
|
|
1956
|
+
string tip = barMenu ? "" : ButtonTip(hoveredBtn);
|
|
1957
|
+
bool showTip = tip.Length > 0 && (now - hoverSince).TotalMilliseconds >= 250 && hoveredBtn != "send";
|
|
1958
|
+
float below = Math.Max(menuH > 0 ? menuH + 8f * s : 0, showTip ? 34f * s : 0);
|
|
1959
|
+
|
|
1960
|
+
int W = (int)Math.Ceiling(bodyW) + 2 * sh;
|
|
1961
|
+
int H = (int)Math.Ceiling(bodyH + below) + 2 * sh;
|
|
1962
|
+
if (barPos.IsEmpty) barPos = new Point(work.X + (int)((work.Width - bodyW) / 2), work.Y + (int)(14 * s));
|
|
1963
|
+
int x = Math.Max(work.X - sh, Math.Min(work.Right - W + sh, barPos.X - sh));
|
|
1964
|
+
int y = Math.Max(work.Y - sh, Math.Min(work.Bottom - (int)bodyH - sh, barPos.Y - sh));
|
|
1965
|
+
petBody = new Rectangle(x + sh, y + sh, (int)bodyW, (int)bodyH);
|
|
1966
|
+
petShadow = sh;
|
|
1967
|
+
|
|
1968
|
+
string glyphFont = IconFont();
|
|
1969
|
+
using (var fText = new Font("Microsoft YaHei UI", 9.6f * px, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
1970
|
+
using (var fSmall = new Font("Microsoft YaHei UI", 8.8f * px, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
1971
|
+
using (var fMenu = new Font("Microsoft YaHei UI", 9.2f * px, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
1972
|
+
using (var fGlyph = new Font(glyphFont.Length > 0 ? glyphFont : "Segoe UI Symbol", 9f * px, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
1973
|
+
using (var fGlyphSmall = new Font(glyphFont.Length > 0 ? glyphFont : "Segoe UI Symbol", 7f * px, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
1974
|
+
using (var bmp = new Bitmap(W, H, PixelFormat.Format32bppArgb))
|
|
1975
|
+
using (var g = Graphics.FromImage(bmp))
|
|
1976
|
+
{
|
|
1977
|
+
g.Clear(Color.Transparent);
|
|
1978
|
+
g.SmoothingMode = SmoothingMode.AntiAlias;
|
|
1979
|
+
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
1980
|
+
g.TextRenderingHint = TextRenderingHint.AntiAlias;
|
|
1981
|
+
var fmt = new StringFormat(StringFormat.GenericTypographic);
|
|
1982
|
+
fmt.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap;
|
|
1983
|
+
var wrap = new StringFormat(StringFormat.GenericTypographic);
|
|
1984
|
+
var center = new StringFormat(); center.Alignment = StringAlignment.Center; center.LineAlignment = StringAlignment.Center;
|
|
1985
|
+
buttons.Clear();
|
|
1986
|
+
|
|
1987
|
+
var body = new RectangleF(sh, sh, bodyW, bodyH);
|
|
1988
|
+
float radius = petExpanded || input != null ? 20f * s : bodyH / 2f;
|
|
1989
|
+
// Soft drop shadow (0 8px 28px).
|
|
1990
|
+
for (int i = sh; i > 0; i -= Math.Max(1, (int)s))
|
|
1991
|
+
{
|
|
1992
|
+
double f = 1.0 - (double)i / sh;
|
|
1993
|
+
using (var path = Rounded(new RectangleF(body.X - i * 0.6f, body.Y - i * 0.35f + 6f * s, body.Width + i * 1.2f, body.Height + i * 0.9f), radius + i * 0.6f))
|
|
1994
|
+
using (var brush = new SolidBrush(Color.FromArgb((int)((dark ? 20 : 12) * f * f), 0, 0, 0))) g.FillPath(brush, path);
|
|
1995
|
+
}
|
|
1996
|
+
Color border = petFinished ? Color.FromArgb(180, BarGreen)
|
|
1997
|
+
: (typing || paused) ? Color.FromArgb(190, Accent)
|
|
1998
|
+
: dark ? Color.FromArgb(28, 255, 255, 255) : Color.FromArgb(22, 0, 0, 0);
|
|
1999
|
+
using (var path = Rounded(body, radius))
|
|
2000
|
+
{
|
|
2001
|
+
using (var brush = new SolidBrush(bg)) g.FillPath(brush, path);
|
|
2002
|
+
using (var pen = new Pen(border, Math.Max(1f, (petFinished || typing || paused ? 1.3f : 1f) * s))) g.DrawPath(pen, path);
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
float cy = body.Y + headH / 2f;
|
|
2006
|
+
// Logo: the whale on a blue disc; a green check when done; dimmed while the user has the computer.
|
|
2007
|
+
float logoD = 30f * s;
|
|
2008
|
+
var logo = new RectangleF(body.X + 7f * s, cy - logoD / 2f, logoD, logoD);
|
|
2009
|
+
if (petFinished)
|
|
2010
|
+
{
|
|
2011
|
+
using (var b = new SolidBrush(BarGreen)) g.FillEllipse(b, logo);
|
|
2012
|
+
using (var b = new SolidBrush(Color.White)) g.DrawString(glyphFont.Length > 0 ? "" : "✓", fGlyph, b, logo, center);
|
|
2013
|
+
}
|
|
2014
|
+
else
|
|
2015
|
+
{
|
|
2016
|
+
int la = typing || paused ? 110 : 255;
|
|
2017
|
+
using (var b = new SolidBrush(Color.FromArgb(la, BarBlue))) g.FillEllipse(b, logo);
|
|
2018
|
+
if (icon != null)
|
|
2019
|
+
{
|
|
2020
|
+
var ir = RectangleF.Inflate(logo, -6f * s, -6f * s);
|
|
2021
|
+
var cm = new ColorMatrix(); cm.Matrix33 = la / 255f;
|
|
2022
|
+
using (var ia = new ImageAttributes())
|
|
2023
|
+
{
|
|
2024
|
+
ia.SetColorMatrix(cm);
|
|
2025
|
+
g.DrawImage(icon, Rectangle.Round(ir), 0, 0, icon.Width, icon.Height, GraphicsUnit.Pixel, ia);
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
// Right side, right to left: stop (or close), menu, then the last two steps.
|
|
2031
|
+
float bx = body.Right - 6f * s;
|
|
2032
|
+
float btnD = 32f * s;
|
|
2033
|
+
if (petFinished)
|
|
2034
|
+
{
|
|
2035
|
+
bx -= btnD;
|
|
2036
|
+
BarButton(g, "close", new RectangleF(bx, cy - btnD / 2f, btnD, btnD), "", "✕", fGlyph, false, dark, ink, s, dt);
|
|
2037
|
+
}
|
|
2038
|
+
else
|
|
2039
|
+
{
|
|
2040
|
+
bx -= btnD;
|
|
2041
|
+
BarButton(g, "stop", new RectangleF(bx, cy - btnD / 2f, btnD, btnD), "", "", fGlyph, true, dark, ink, s, dt);
|
|
2042
|
+
bx -= 4f * s + btnD;
|
|
2043
|
+
BarButton(g, "menu", new RectangleF(bx, cy - btnD / 2f, btnD, btnD), "", "⋯", fGlyph, false, dark, ink, s, dt);
|
|
2044
|
+
}
|
|
2045
|
+
bx -= 10f * s;
|
|
2046
|
+
|
|
2047
|
+
// Steps: ✓ previous › ● current.
|
|
2048
|
+
string cur = petSteps.Count > 0 ? petSteps[petSteps.Count - 1] : (petFinished ? "" : "准备操作…");
|
|
2049
|
+
string prev = petSteps.Count > 1 ? petSteps[petSteps.Count - 2] : "";
|
|
2050
|
+
float curMax = 150f * s, prevMax = 92f * s;
|
|
2051
|
+
string curShown = cur.Length > 0 ? Ellipsize(g, cur, fSmall, curMax, fmt) : "";
|
|
2052
|
+
string prevShown = prev.Length > 0 && !petFinished ? Ellipsize(g, prev, fSmall, prevMax, fmt) : "";
|
|
2053
|
+
float curW = curShown.Length > 0 ? g.MeasureString(curShown, fSmall, 100000, fmt).Width : 0;
|
|
2054
|
+
float prevW = prevShown.Length > 0 ? g.MeasureString(prevShown, fSmall, 100000, fmt).Width : 0;
|
|
2055
|
+
float dotW = 14f * s, chevW = 16f * s, checkW = 14f * s;
|
|
2056
|
+
float stepsW = curShown.Length > 0 ? dotW + curW : 0;
|
|
2057
|
+
if (prevShown.Length > 0) stepsW += checkW + prevW + chevW;
|
|
2058
|
+
float sx = bx - stepsW;
|
|
2059
|
+
if (stepsW > 0)
|
|
2060
|
+
{
|
|
2061
|
+
float ty = cy - g.MeasureString("国", fSmall, 100000, fmt).Height / 2f;
|
|
2062
|
+
if (prevShown.Length > 0)
|
|
2063
|
+
{
|
|
2064
|
+
using (var b = new SolidBrush(BarGreen)) g.DrawString(glyphFont.Length > 0 ? "" : "✓", fGlyphSmall, b, new RectangleF(sx, cy - 8 * s, checkW - 2 * s, 16 * s), center);
|
|
2065
|
+
using (var b = new SolidBrush(muted)) g.DrawString(prevShown, fSmall, b, sx + checkW, ty, fmt);
|
|
2066
|
+
using (var b = new SolidBrush(Color.FromArgb(120, muted))) g.DrawString(glyphFont.Length > 0 ? "" : "›", fGlyphSmall, b, new RectangleF(sx + checkW + prevW, cy - 8 * s, chevW, 16 * s), center);
|
|
2067
|
+
sx += checkW + prevW + chevW;
|
|
2068
|
+
}
|
|
2069
|
+
if (curShown.Length > 0)
|
|
2070
|
+
{
|
|
2071
|
+
var dc = new PointF(sx + 5f * s, cy);
|
|
2072
|
+
if (petFinished)
|
|
2073
|
+
using (var b = new SolidBrush(BarGreen)) g.FillEllipse(b, dc.X - 3f * s, dc.Y - 3f * s, 6f * s, 6f * s);
|
|
2074
|
+
else
|
|
2075
|
+
{
|
|
2076
|
+
double pulse = 0.5 + 0.5 * Math.Sin(clock * Math.PI * 2 / 1.4);
|
|
2077
|
+
float hr = (4f + 3.5f * (float)pulse) * s;
|
|
2078
|
+
using (var b = new SolidBrush(Color.FromArgb((int)(70 * (1 - pulse) + 20), Accent))) g.FillEllipse(b, dc.X - hr, dc.Y - hr, 2 * hr, 2 * hr);
|
|
2079
|
+
using (var b = new SolidBrush(Accent)) g.FillEllipse(b, dc.X - 3.2f * s, dc.Y - 3.2f * s, 6.4f * s, 6.4f * s);
|
|
2080
|
+
}
|
|
2081
|
+
using (var b = new SolidBrush(ink)) g.DrawString(curShown, fSmall, b, sx + dotW, ty, fmt);
|
|
2082
|
+
}
|
|
2083
|
+
float divX = bx - stepsW - 12f * s;
|
|
2084
|
+
using (var pen = new Pen(faint, Math.Max(1f, s))) g.DrawLine(pen, divX, cy - 9f * s, divX, cy + 9f * s);
|
|
2085
|
+
bx = divX - 12f * s;
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
// The middle: one scrolling line of reasoning, or what the bar is waiting for.
|
|
2089
|
+
float tx = logo.Right + 10f * s;
|
|
2090
|
+
float avail = Math.Max(20f * s, bx - tx);
|
|
2091
|
+
string prefix = "", line = "", chipAct = "", chipText = "";
|
|
2092
|
+
bool shimmer = false;
|
|
2093
|
+
Color lineColor = ink;
|
|
2094
|
+
if (petFinished)
|
|
2095
|
+
{
|
|
2096
|
+
int steps = Math.Max(petTotal, petSteps.Count);
|
|
2097
|
+
line = "已交还电脑控制 · 共 " + steps + " 步,用时 " + Elapsed(finishedAt - shownAt);
|
|
2098
|
+
}
|
|
2099
|
+
else if (paused) { line = input != null ? "正在输入新指令…" : "已暂停 · 按 Esc 继续"; lineColor = AccentHi; if (input == null) { chipAct = "resume"; chipText = "▶ 继续"; } }
|
|
2100
|
+
else if (typing) { line = "你正在操作,已暂停"; lineColor = AccentHi; }
|
|
2101
|
+
else if (waiting) { line = "等待页面加载完成 · " + waitSec + "s"; shimmer = true; chipAct = "skip_wait"; chipText = "跳过"; }
|
|
2102
|
+
else if (llmWait) { line = "等待模型响应 · " + llmSec + "s"; shimmer = true; }
|
|
2103
|
+
else if (hasReply) { prefix = "回复 · "; line = petReply; }
|
|
2104
|
+
else if (petThinking.Length > 0) { prefix = "思考 · "; line = petThinking; }
|
|
2105
|
+
else { line = "正在操作…"; lineColor = muted; }
|
|
2106
|
+
|
|
2107
|
+
if (chipAct.Length > 0)
|
|
2108
|
+
{
|
|
2109
|
+
float cw = g.MeasureString(chipText, fSmall, 100000, fmt).Width + 20f * s;
|
|
2110
|
+
var chip = new RectangleF(bx - cw, cy - 12f * s, cw, 24f * s);
|
|
2111
|
+
BarChip(g, chipAct, chip, chipText, fSmall, s, dt);
|
|
2112
|
+
avail = Math.Max(20f * s, chip.X - 8f * s - tx);
|
|
2113
|
+
}
|
|
2114
|
+
float lineH = g.MeasureString("国", fText, 100000, fmt).Height;
|
|
2115
|
+
float ly = cy - lineH / 2f;
|
|
2116
|
+
if (prefix.Length > 0)
|
|
2117
|
+
{
|
|
2118
|
+
using (var b = new SolidBrush(muted)) g.DrawString(prefix, fText, b, tx, ly, fmt);
|
|
2119
|
+
float pw = g.MeasureString(prefix, fText, 100000, fmt).Width;
|
|
2120
|
+
tx += pw; avail -= pw;
|
|
2121
|
+
}
|
|
2122
|
+
// Ticker: newest text on the right, sliding in smoothly as it streams; older text fades out on the left.
|
|
2123
|
+
string key = prefix + line;
|
|
2124
|
+
if (key != tickerText)
|
|
2125
|
+
{
|
|
2126
|
+
string old = tickerText;
|
|
2127
|
+
tickerText = key;
|
|
2128
|
+
float add = 0;
|
|
2129
|
+
if (!shimmer && old.Length >= 6)
|
|
2130
|
+
{
|
|
2131
|
+
string tail = old.Substring(old.Length - 6);
|
|
2132
|
+
int at = key.LastIndexOf(tail, StringComparison.Ordinal);
|
|
2133
|
+
if (at >= 0 && at + 6 < key.Length) add = g.MeasureString(key.Substring(at + 6), fText, 100000, fmt).Width;
|
|
2134
|
+
}
|
|
2135
|
+
tickerLag = Math.Min(avail, tickerLag + add);
|
|
2136
|
+
}
|
|
2137
|
+
tickerLag *= (float)Math.Exp(-dt / 0.09);
|
|
2138
|
+
if (tickerLag < 0.5f) tickerLag = 0;
|
|
2139
|
+
int stripW = (int)Math.Max(1, Math.Ceiling(avail)), stripH = (int)Math.Ceiling(lineH + 4 * s);
|
|
2140
|
+
using (var strip = new Bitmap(stripW, stripH, PixelFormat.Format32bppArgb))
|
|
2141
|
+
{
|
|
2142
|
+
using (var sg = Graphics.FromImage(strip))
|
|
2143
|
+
{
|
|
2144
|
+
sg.Clear(Color.Transparent);
|
|
2145
|
+
sg.TextRenderingHint = TextRenderingHint.AntiAlias;
|
|
2146
|
+
string shown = Tail(sg, line, fText, avail * 1.6f + 40 * s, fmt);
|
|
2147
|
+
float w = sg.MeasureString(shown, fText, 100000, fmt).Width;
|
|
2148
|
+
float dx = w <= avail ? 0 : avail - w + tickerLag;
|
|
2149
|
+
if (shimmer)
|
|
2150
|
+
{
|
|
2151
|
+
double phase = (clock % 1.6) / 1.6;
|
|
2152
|
+
float band = 70f * s, cxs = (float)(-band + (w + 2 * band) * phase);
|
|
2153
|
+
using (var b = new SolidBrush(muted)) sg.DrawString(shown, fText, b, dx, 2 * s, fmt);
|
|
2154
|
+
var rect = new RectangleF(cxs - band, 0, band * 2, stripH);
|
|
2155
|
+
using (var lg = new LinearGradientBrush(new RectangleF(rect.X - 1, 0, rect.Width + 2, stripH), Color.FromArgb(0, ink), Color.FromArgb(0, ink), LinearGradientMode.Horizontal))
|
|
2156
|
+
{
|
|
2157
|
+
var blend = new ColorBlend(3);
|
|
2158
|
+
blend.Colors = new[] { Color.FromArgb(0, ink), Color.FromArgb(235, ink), Color.FromArgb(0, ink) };
|
|
2159
|
+
blend.Positions = new[] { 0f, 0.5f, 1f };
|
|
2160
|
+
lg.InterpolationColors = blend;
|
|
2161
|
+
sg.SetClip(rect);
|
|
2162
|
+
sg.DrawString(shown, fText, lg, dx, 2 * s, fmt);
|
|
2163
|
+
sg.ResetClip();
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
else using (var b = new SolidBrush(lineColor)) sg.DrawString(shown, fText, b, dx, 2 * s, fmt);
|
|
2167
|
+
if (dx < 0) { sg.Flush(); }
|
|
2168
|
+
}
|
|
2169
|
+
if (strip.Width > 0 && tickerText.Length > 0)
|
|
2170
|
+
{
|
|
2171
|
+
using (var probe = Graphics.FromImage(strip))
|
|
2172
|
+
{
|
|
2173
|
+
float full = probe.MeasureString(line, fText, 100000, fmt).Width;
|
|
2174
|
+
if (full > avail) FadeLeft(strip, (int)(28 * s));
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
g.DrawImageUnscaled(strip, (int)Math.Round(tx), (int)Math.Round(ly - 2 * s));
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
// The "…" thought bubble on the logo while the model is thinking (so the line reads as reasoning, not a reply).
|
|
2181
|
+
if (thinkingNow)
|
|
2182
|
+
{
|
|
2183
|
+
var bub = new RectangleF(logo.Right - 11f * s, logo.Y - 6f * s, 19f * s, 12f * s);
|
|
2184
|
+
Color bubBg = dark ? Color.FromArgb(250, 248, 247) : Color.FromArgb(31, 30, 29);
|
|
2185
|
+
Color bubInk = dark ? Color.FromArgb(31, 30, 29) : Color.White;
|
|
2186
|
+
using (var path = Rounded(bub, 6f * s))
|
|
2187
|
+
{
|
|
2188
|
+
using (var b = new SolidBrush(bubBg)) g.FillPath(b, path);
|
|
2189
|
+
using (var pen = new Pen(bg.A > 0 ? Color.FromArgb(255, bg) : Color.Black, Math.Max(1f, 1.2f * s))) g.DrawPath(pen, path);
|
|
2190
|
+
}
|
|
2191
|
+
using (var b = new SolidBrush(bubBg)) g.FillEllipse(b, bub.X + 1.5f * s, bub.Bottom - 0.5f * s, 3.4f * s, 3.4f * s);
|
|
2192
|
+
for (int i = 0; i < 3; i++)
|
|
2193
|
+
{
|
|
2194
|
+
double ph = clock * Math.PI * 2 / 1.1 - i * 0.9;
|
|
2195
|
+
float up = (float)Math.Max(0, Math.Sin(ph)) * 1.4f * s;
|
|
2196
|
+
int a = (int)(140 + 115 * Math.Max(0, Math.Sin(ph)));
|
|
2197
|
+
using (var b = new SolidBrush(Color.FromArgb(a, bubInk)))
|
|
2198
|
+
g.FillEllipse(b, bub.X + 4.4f * s + i * 4f * s - 1.3f * s, bub.Y + bub.Height / 2f - 1.3f * s - up, 2.6f * s, 2.6f * s);
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
|
|
2202
|
+
// Expanded: full text, then the step list.
|
|
2203
|
+
float ey = body.Y + headH;
|
|
2204
|
+
if (petExpanded)
|
|
2205
|
+
{
|
|
2206
|
+
using (var pen = new Pen(faint, Math.Max(1f, s))) g.DrawLine(pen, body.X + 16f * s, ey, body.Right - 16f * s, ey);
|
|
2207
|
+
ey += 8f * s;
|
|
2208
|
+
string t = fullText.Length > 0 ? (hasReply ? "回复 · " : "思考 · ") + fullText : "还没有思考内容";
|
|
2209
|
+
using (var b = new SolidBrush(fullText.Length > 0 ? ink : muted))
|
|
2210
|
+
g.DrawString(TailWrapped(g, t, fText, textW, expandTextH, wrap), fText, b, new RectangleF(body.X + 16f * s, ey, textW, expandTextH), wrap);
|
|
2211
|
+
ey += expandTextH + 4f * s;
|
|
2212
|
+
using (var pen = new Pen(faint, Math.Max(1f, s))) g.DrawLine(pen, body.X + 16f * s, ey, body.Right - 16f * s, ey);
|
|
2213
|
+
ey += 6f * s;
|
|
2214
|
+
int first = Math.Max(0, petSteps.Count - listRows);
|
|
2215
|
+
for (int i = first; i < petSteps.Count; i++)
|
|
2216
|
+
{
|
|
2217
|
+
bool isCur = i == petSteps.Count - 1 && !petFinished;
|
|
2218
|
+
float rcy = ey + 12f * s;
|
|
2219
|
+
if (isCur) using (var b = new SolidBrush(Accent)) g.FillEllipse(b, body.X + 19f * s, rcy - 3f * s, 6f * s, 6f * s);
|
|
2220
|
+
else using (var b = new SolidBrush(BarGreen)) g.DrawString(glyphFont.Length > 0 ? "" : "✓", fGlyphSmall, b, new RectangleF(body.X + 14f * s, rcy - 8f * s, 16f * s, 16f * s), center);
|
|
2221
|
+
string st = Ellipsize(g, petSteps[i], fSmall, textW - 20f * s, fmt);
|
|
2222
|
+
float sty = rcy - g.MeasureString("国", fSmall, 100000, fmt).Height / 2f;
|
|
2223
|
+
using (var b = new SolidBrush(isCur ? ink : muted)) g.DrawString(st, fSmall, b, body.X + 34f * s, sty, fmt);
|
|
2224
|
+
ey += 24f * s;
|
|
2225
|
+
}
|
|
2226
|
+
ey += 6f * s;
|
|
2227
|
+
}
|
|
2228
|
+
|
|
2229
|
+
// The instruction field: framed here, a real text box sits on top.
|
|
2230
|
+
if (input != null)
|
|
2231
|
+
{
|
|
2232
|
+
float fy = body.Bottom - inputH + 6f * s;
|
|
2233
|
+
float sendD = 32f * s;
|
|
2234
|
+
var fieldRect = new RectangleF(body.X + 12f * s, fy, bodyW - 24f * s - sendD - 8f * s, 34f * s);
|
|
2235
|
+
using (var path = Rounded(fieldRect, 17f * s))
|
|
2236
|
+
{
|
|
2237
|
+
using (var b = new SolidBrush(dark ? Color.FromArgb(52, 51, 49) : Color.White)) g.FillPath(b, path);
|
|
2238
|
+
using (var pen = new Pen(Color.FromArgb(160, Accent), Math.Max(1f, 1.2f * s))) g.DrawPath(pen, path);
|
|
2239
|
+
}
|
|
2240
|
+
var sendHit = new RectangleF(body.Right - 12f * s - sendD, fy + (34f * s - sendD) / 2f, sendD, sendD);
|
|
2241
|
+
float sh2 = HoverAmount("send", dt);
|
|
2242
|
+
var send = pressedBtn == "send" ? RectangleF.Inflate(sendHit, -2f * s, -2f * s) : new RectangleF(sendHit.X, sendHit.Y - sh2 * s, sendHit.Width, sendHit.Height);
|
|
2243
|
+
if (sh2 > 0.01f) using (var halo = new SolidBrush(Color.FromArgb((int)(70 * sh2), Accent))) g.FillEllipse(halo, RectangleF.Inflate(send, 3f * s * sh2, 3f * s * sh2));
|
|
2244
|
+
using (var b = new SolidBrush(pressedBtn == "send" ? Color.FromArgb(192, 96, 63) : Mix(Accent, Color.FromArgb(232, 135, 95), sh2))) g.FillEllipse(b, send);
|
|
2245
|
+
using (var b = new SolidBrush(Color.White)) g.DrawString(glyphFont.Length > 0 ? "" : "➤", fGlyph, b, send, center);
|
|
2246
|
+
buttons.Add(new KeyValuePair<Rectangle, string>(Rectangle.Round(sendHit), "send"));
|
|
2247
|
+
var boxRect = new Rectangle(x + (int)(fieldRect.X + 14f * s), y + (int)(fieldRect.Y + 4f * s), (int)(fieldRect.Width - 28f * s), (int)(fieldRect.Height - 8f * s));
|
|
2248
|
+
if (boxRect != inputBounds) { inputBounds = boxRect; input.Place(boxRect); }
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
// The menu drops from under the ⋯ button.
|
|
2252
|
+
if (menuH > 0)
|
|
2253
|
+
{
|
|
2254
|
+
double age = (now - barMenuAt).TotalMilliseconds;
|
|
2255
|
+
float t = (float)Math.Min(1.0, age / 160.0);
|
|
2256
|
+
float ease = 1 - (1 - t) * (1 - t) * (1 - t);
|
|
2257
|
+
float mx = body.Right - 6f * s - menuW;
|
|
2258
|
+
float my = body.Bottom + 8f * s - (1 - ease) * 6f * s;
|
|
2259
|
+
var menuRect = new RectangleF(mx, my, menuW, menuH);
|
|
2260
|
+
int mw = (int)Math.Ceiling(menuW) + 2, mh = (int)Math.Ceiling(menuH) + 2;
|
|
2261
|
+
using (var mb = new Bitmap(mw, mh, PixelFormat.Format32bppArgb))
|
|
2262
|
+
{
|
|
2263
|
+
using (var mg = Graphics.FromImage(mb))
|
|
2264
|
+
{
|
|
2265
|
+
mg.Clear(Color.Transparent);
|
|
2266
|
+
mg.SmoothingMode = SmoothingMode.AntiAlias;
|
|
2267
|
+
mg.TextRenderingHint = TextRenderingHint.AntiAlias;
|
|
2268
|
+
var local = new RectangleF(0.5f, 0.5f, menuW, menuH);
|
|
2269
|
+
using (var path = Rounded(local, 14f * s))
|
|
2270
|
+
{
|
|
2271
|
+
using (var b = new SolidBrush(menuBg)) mg.FillPath(b, path);
|
|
2272
|
+
using (var pen = new Pen(dark ? Color.FromArgb(30, 255, 255, 255) : Color.FromArgb(26, 0, 0, 0), Math.Max(1f, s))) mg.DrawPath(pen, path);
|
|
2273
|
+
}
|
|
2274
|
+
float iy = menuPad;
|
|
2275
|
+
foreach (var it in menuItems)
|
|
2276
|
+
{
|
|
2277
|
+
if (it[0] == "-")
|
|
2278
|
+
{
|
|
2279
|
+
using (var pen = new Pen(faint, Math.Max(1f, s))) mg.DrawLine(pen, 12f * s, iy + 4.5f * s, menuW - 12f * s, iy + 4.5f * s);
|
|
2280
|
+
iy += 9f * s;
|
|
2281
|
+
continue;
|
|
2282
|
+
}
|
|
2283
|
+
string act = it[0];
|
|
2284
|
+
float h = HoverAmount("m_" + act, dt);
|
|
2285
|
+
bool danger = act == "stop";
|
|
2286
|
+
var row = new RectangleF(menuPad, iy, menuW - 2 * menuPad, itemH);
|
|
2287
|
+
if (h > 0.01f || pressedBtn == "m_" + act)
|
|
2288
|
+
{
|
|
2289
|
+
Color hot = danger ? Color.FromArgb((int)((pressedBtn == "m_" + act ? 60 : 36) * Math.Max(h, 0.5f)), Accent)
|
|
2290
|
+
: dark ? Color.FromArgb((int)((pressedBtn == "m_" + act ? 34 : 20) * h), 255, 255, 255) : Color.FromArgb((int)((pressedBtn == "m_" + act ? 22 : 12) * h), 0, 0, 0);
|
|
2291
|
+
using (var path = Rounded(row, 9f * s)) using (var b = new SolidBrush(hot)) mg.FillPath(b, path);
|
|
2292
|
+
}
|
|
2293
|
+
Color rowInk = danger ? Mix(Accent, AccentHi, h) : ink;
|
|
2294
|
+
using (var b = new SolidBrush(danger ? rowInk : Color.FromArgb(dark ? 210 : 180, ink)))
|
|
2295
|
+
mg.DrawString(glyphFont.Length > 0 ? it[1] : it[2], fGlyph, b, new RectangleF(row.X + 6f * s + h * 1.5f * s, row.Y, 22f * s, itemH), center);
|
|
2296
|
+
float lty = row.Y + (itemH - mg.MeasureString("国", fMenu, 100000, fmt).Height) / 2f;
|
|
2297
|
+
using (var b = new SolidBrush(rowInk)) mg.DrawString(it[3], fMenu, b, row.X + 36f * s + h * 1.5f * s, lty, fmt);
|
|
2298
|
+
if (it[4].Length > 0)
|
|
2299
|
+
{
|
|
2300
|
+
float hw = mg.MeasureString(it[4], fSmall, 100000, fmt).Width;
|
|
2301
|
+
var kb = new RectangleF(row.Right - hw - 16f * s, row.Y + 8f * s, hw + 10f * s, itemH - 16f * s);
|
|
2302
|
+
using (var path = Rounded(kb, 4f * s)) using (var pen = new Pen(Color.FromArgb(90, muted), Math.Max(1f, s))) mg.DrawPath(pen, path);
|
|
2303
|
+
using (var b = new SolidBrush(muted)) mg.DrawString(it[4], fSmall, b, kb, center);
|
|
2304
|
+
}
|
|
2305
|
+
buttons.Add(new KeyValuePair<Rectangle, string>(Rectangle.Round(new RectangleF(row.X + mx, row.Y + my, row.Width, row.Height)), "m_" + act));
|
|
2306
|
+
iy += itemH;
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
var cm = new ColorMatrix(); cm.Matrix33 = ease;
|
|
2310
|
+
using (var ia = new ImageAttributes())
|
|
2311
|
+
{
|
|
2312
|
+
ia.SetColorMatrix(cm);
|
|
2313
|
+
// Shadow under the menu, then the menu itself.
|
|
2314
|
+
for (int i = (int)(12 * s); i > 0; i -= Math.Max(1, (int)s))
|
|
2315
|
+
{
|
|
2316
|
+
double f = 1.0 - i / (12.0 * s);
|
|
2317
|
+
using (var path = Rounded(RectangleF.Inflate(new RectangleF(mx, my + 4f * s, menuW, menuH), i * 0.6f, i * 0.6f), 14f * s + i * 0.6f))
|
|
2318
|
+
using (var b = new SolidBrush(Color.FromArgb((int)(16 * f * f * ease), 0, 0, 0))) g.FillPath(b, path);
|
|
2319
|
+
}
|
|
2320
|
+
g.DrawImage(mb, new Rectangle((int)mx, (int)my, mw, mh), 0, 0, mw, mh, GraphicsUnit.Pixel, ia);
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
else if (showTip)
|
|
2325
|
+
{
|
|
2326
|
+
// Tooltip under the hovered button.
|
|
2327
|
+
Rectangle hitR = Rectangle.Empty;
|
|
2328
|
+
foreach (var b in buttons) if (b.Value == hoveredBtn) { hitR = b.Key; break; }
|
|
2329
|
+
if (!hitR.IsEmpty)
|
|
2330
|
+
{
|
|
2331
|
+
float tw = g.MeasureString(tip, fSmall, 100000, fmt).Width + 18f * s;
|
|
2332
|
+
float th = 24f * s;
|
|
2333
|
+
float tipX = Math.Max(4f * s, Math.Min(W - tw - 4f * s, hitR.X + hitR.Width / 2f - tw / 2f));
|
|
2334
|
+
float tipY = body.Bottom + 6f * s;
|
|
2335
|
+
float age = (float)Math.Min(1.0, ((now - hoverSince).TotalMilliseconds - 250) / 120.0);
|
|
2336
|
+
var tr = new RectangleF(tipX, tipY + (1 - age) * 3f * s, tw, th);
|
|
2337
|
+
using (var path = Rounded(tr, 7f * s))
|
|
2338
|
+
using (var b = new SolidBrush(Color.FromArgb((int)(235 * age), dark ? Color.FromArgb(58, 56, 53) : Color.FromArgb(31, 30, 29))))
|
|
2339
|
+
g.FillPath(b, path);
|
|
2340
|
+
using (var b = new SolidBrush(Color.FromArgb((int)(255 * age), 244, 243, 241))) g.DrawString(tip, fSmall, b, tr, center);
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
pet.SetBitmap(bmp, new Rectangle(x, y, W, H), 255);
|
|
2345
|
+
}
|
|
2346
|
+
pet.KeepOnTop();
|
|
2347
|
+
if (input != null) Native.SetWindowPos(input.Handle, new IntPtr(-1), 0, 0, 0, 0, 0x0001 | 0x0002 | 0x0010);
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
/** `s` cut to `width` with a trailing "…". */
|
|
2351
|
+
static string Ellipsize(Graphics g, string s, Font font, float width, StringFormat fmt)
|
|
2352
|
+
{
|
|
2353
|
+
if (s.Length == 0 || g.MeasureString(s, font, 100000, fmt).Width <= width) return s;
|
|
2354
|
+
int lo = 0, hi = s.Length;
|
|
2355
|
+
while (lo < hi)
|
|
2356
|
+
{
|
|
2357
|
+
int mid = (lo + hi + 1) / 2;
|
|
2358
|
+
if (g.MeasureString(s.Substring(0, mid) + "…", font, 100000, fmt).Width <= width) lo = mid; else hi = mid - 1;
|
|
2359
|
+
}
|
|
2360
|
+
if (lo > 0 && char.IsHighSurrogate(s[lo - 1])) lo--;
|
|
2361
|
+
return s.Substring(0, lo) + "…";
|
|
2362
|
+
}
|
|
2363
|
+
|
|
1559
2364
|
static void RenderPet()
|
|
1560
2365
|
{
|
|
1561
2366
|
if (pet == null) return;
|
|
2367
|
+
if (BarStyle()) { RenderBar(); return; }
|
|
1562
2368
|
Rectangle work = Rectangle.Empty; float scale = 1f;
|
|
1563
2369
|
foreach (Dictionary<string, object> d in Screen2.Displays())
|
|
1564
2370
|
{
|
|
@@ -1918,7 +2724,41 @@ namespace DshComputerUse
|
|
|
1918
2724
|
pill.KeepOnTop();
|
|
1919
2725
|
}
|
|
1920
2726
|
|
|
1921
|
-
static
|
|
2727
|
+
static Thread hookThread;
|
|
2728
|
+
static Control hookInvoker;
|
|
2729
|
+
|
|
2730
|
+
/**
|
|
2731
|
+
* Low-level hooks get their own thread and message loop: Windows waits for
|
|
2732
|
+
* the hook callback on every physical mouse move and key press, so a hook on
|
|
2733
|
+
* the busy UI thread (drawing the card, the glow) would make the whole
|
|
2734
|
+
* system's pointer stutter.
|
|
2735
|
+
*/
|
|
2736
|
+
static void OnHookThread(MethodInvoker action)
|
|
2737
|
+
{
|
|
2738
|
+
if (hookThread == null)
|
|
2739
|
+
{
|
|
2740
|
+
var ready = new ManualResetEvent(false);
|
|
2741
|
+
hookThread = new Thread(delegate ()
|
|
2742
|
+
{
|
|
2743
|
+
hookInvoker = new Control();
|
|
2744
|
+
var force = hookInvoker.Handle;
|
|
2745
|
+
ready.Set();
|
|
2746
|
+
Application.Run();
|
|
2747
|
+
});
|
|
2748
|
+
hookThread.IsBackground = true;
|
|
2749
|
+
hookThread.Priority = ThreadPriority.Highest;
|
|
2750
|
+
hookThread.SetApartmentState(ApartmentState.STA);
|
|
2751
|
+
hookThread.Start();
|
|
2752
|
+
ready.WaitOne();
|
|
2753
|
+
}
|
|
2754
|
+
try { hookInvoker.BeginInvoke(action); } catch (Exception) { }
|
|
2755
|
+
}
|
|
2756
|
+
|
|
2757
|
+
static void InstallHook() { OnHookThread(InstallHookCore); }
|
|
2758
|
+
|
|
2759
|
+
static void RemoveHook() { OnHookThread(RemoveHookCore); }
|
|
2760
|
+
|
|
2761
|
+
static void InstallHookCore()
|
|
1922
2762
|
{
|
|
1923
2763
|
if (hook == IntPtr.Zero)
|
|
1924
2764
|
{
|
|
@@ -1932,7 +2772,7 @@ namespace DshComputerUse
|
|
|
1932
2772
|
}
|
|
1933
2773
|
}
|
|
1934
2774
|
|
|
1935
|
-
static void
|
|
2775
|
+
static void RemoveHookCore()
|
|
1936
2776
|
{
|
|
1937
2777
|
if (hook != IntPtr.Zero)
|
|
1938
2778
|
{
|