ai-battery 0.2.0 → 0.2.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.
Files changed (45) hide show
  1. package/README.md +30 -14
  2. package/bin/ai-battery-macos-status.applescript +5 -12
  3. package/bin/ai-battery-run +701 -31
  4. package/bin/ai-battery-tmux.js +17 -0
  5. package/bin/terminal-compositor.js +111 -0
  6. package/docs/REFERENCE.md +23 -3
  7. package/docs/RELEASING.md +24 -7
  8. package/docs/WINDOWS-TERMINAL-SHARED-BAR.md +74 -0
  9. package/docs/hud-preview.svg +43 -20
  10. package/docs/terminal-vertical-preview.svg +73 -0
  11. package/lib/cli.js +945 -219
  12. package/lib/core/atomic-rename.js +18 -0
  13. package/lib/core/cli-help.js +35 -7
  14. package/lib/core/cli-messages.js +45 -1
  15. package/lib/core/cli-output.js +277 -72
  16. package/lib/core/cli-wrappers.js +410 -0
  17. package/lib/core/config-editor.js +177 -29
  18. package/lib/core/display-config.js +45 -0
  19. package/lib/core/integration-files.js +32 -3
  20. package/lib/core/shared-bar.js +603 -0
  21. package/lib/core/statusline-git.js +179 -15
  22. package/lib/core/terminal.js +25 -7
  23. package/lib/core/tmux-status.js +172 -0
  24. package/lib/core/uninstall.js +20 -7
  25. package/lib/core/usage-store.js +85 -0
  26. package/lib/hud/launcher.js +29 -31
  27. package/lib/platforms/linux/hud.js +1 -1
  28. package/lib/platforms/linux/panel.js +1 -1
  29. package/lib/platforms/macos/hud.js +5 -5
  30. package/lib/platforms/process-scanner.js +77 -29
  31. package/lib/platforms/windows/autostart-cleanup.js +1 -1
  32. package/lib/platforms/windows/codex-runner.js +178 -21
  33. package/lib/platforms/windows/hud/controls.ps1 +44 -10
  34. package/lib/platforms/windows/hud/main.ps1 +350 -43
  35. package/lib/platforms/windows/hud/rendering.ps1 +1227 -1
  36. package/lib/platforms/windows/hud/snapshot.ps1 +26 -46
  37. package/lib/platforms/windows/hud-launcher.js +153 -79
  38. package/lib/platforms/windows/shared-bar-platform.js +972 -0
  39. package/lib/platforms/windows/terminal-compositor.js +210 -25
  40. package/lib/platforms/windows/wt-bar.js +729 -0
  41. package/lib/platforms/windows/wt-fragment.js +665 -0
  42. package/lib/platforms/windows/wt-keybinding.js +300 -0
  43. package/lib/providers/antigravity.js +155 -8
  44. package/package.json +5 -2
  45. package/vendor/PaneContext.cs +875 -0
@@ -1,4 +1,4 @@
1
- function Enable-HudDoubleBuffering($Control) {
1
+ function Enable-HudDoubleBuffering($Control) {
2
2
  $property = [System.Windows.Forms.Control].GetProperty("DoubleBuffered", [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic)
3
3
  $property.SetValue($Control, $true, $null)
4
4
  }
@@ -396,3 +396,1229 @@ function Dispose-StatusMenuRow($Row) {
396
396
  $Row.Icon.Image = $null
397
397
  }
398
398
  }
399
+
400
+ $script:brandSvgRendererReady = $false
401
+
402
+ function Initialize-BrandSvgRenderer {
403
+ if ($script:brandSvgRendererReady) { return $true }
404
+ if ("AiBatterySvgIcons" -as [type]) {
405
+ $script:brandSvgRendererReady = $true
406
+ return $true
407
+ }
408
+
409
+ $svgCode = @'
410
+ using System;
411
+ using System.Collections.Generic;
412
+ using System.Drawing;
413
+ using System.Drawing.Drawing2D;
414
+ using System.Drawing.Imaging;
415
+ using System.Globalization;
416
+ using System.Runtime.InteropServices;
417
+
418
+ public static class AiBatterySvgIcons {
419
+ // Exact SVG paths matching lib/cli.js MENU_BAR_BRAND_ICONS and docs/antigravity-icon.svg.
420
+ public const string CodexSvgPath = "m297.06 130.97c7.26-21.79 4.76-45.66-6.85-65.48-17.46-30.4-52.56-46.04-86.84-38.68-15.25-17.18-37.16-26.95-60.13-26.81-35.04-.08-66.13 22.48-76.91 55.82-22.51 4.61-41.94 18.7-53.31 38.67-17.59 30.32-13.58 68.54 9.92 94.54-7.26 21.79-4.76 45.66 6.85 65.48 17.46 30.4 52.56 46.04 86.84 38.68 15.24 17.18 37.16 26.95 60.13 26.8 35.06.09 66.16-22.49 76.94-55.86 22.51-4.61 41.94-18.7 53.31-38.67 17.57-30.32 13.55-68.51-9.94-94.51zm-120.28 168.11c-14.03.02-27.62-4.89-38.39-13.88.49-.26 1.34-.73 1.89-1.07l63.72-36.8c3.26-1.85 5.26-5.32 5.24-9.07v-89.83l26.93 15.55c.29.14.48.42.52.74v74.39c-.04 33.08-26.83 59.9-59.91 59.97zm-128.84-55.03c-7.03-12.14-9.56-26.37-7.15-40.18.47.28 1.3.79 1.89 1.13l63.72 36.8c3.23 1.89 7.23 1.89 10.47 0l77.79-44.92v31.1c.02.32-.13.63-.38.83l-64.41 37.19c-28.69 16.52-65.33 6.7-81.92-21.95zm-16.77-139.09c7-12.16 18.05-21.46 31.21-26.29 0 .55-.03 1.52-.03 2.2v73.61c-.02 3.74 1.98 7.21 5.23 9.06l77.79 44.91-26.93 15.55c-.27.18-.61.21-.91.08l-64.42-37.22c-28.63-16.58-38.45-53.21-21.95-81.89zm221.26 51.49-77.79-44.92 26.93-15.54c.27-.18.61-.21.91-.08l64.42 37.19c28.68 16.57 38.51 53.26 21.94 81.94-7.01 12.14-18.05 21.44-31.2 26.28v-75.81c.03-3.74-1.96-7.2-5.2-9.06zm26.8-40.34c-.47-.29-1.3-.79-1.89-1.13l-63.72-36.8c-3.23-1.89-7.23-1.89-10.47 0l-77.79 44.92v-31.1c-.02-.32.13-.63.38-.83l64.41-37.16c28.69-16.55 65.37-6.7 81.91 22 6.99 12.12 9.52 26.31 7.15 40.1zm-168.51 55.43-26.94-15.55c-.29-.14-.48-.42-.52-.74v-74.39c.02-33.12 26.89-59.96 60.01-59.94 14.01 0 27.57 4.92 38.34 13.88-.49.26-1.33.73-1.89 1.07l-63.72 36.8c-3.26 1.85-5.26 5.31-5.24 9.06l-.04 89.79zm14.63-31.54 34.65-20.01 34.65 20v40.01l-34.65 20-34.65-20z";
421
+
422
+ public const string ClaudeSvgPath = "m4.7144 15.9555 4.7174-2.6471.079-.2307-.079-.1275h-.2307l-.7893-.0486-2.6956-.0729-2.3375-.0971-2.2646-.1214-.5707-.1215-.5343-.7042.0546-.3522.4797-.3218.686.0608 1.5179.1032 2.2767.1578 1.6514.0972 2.4468.255h.3886l.0546-.1579-.1336-.0971-.1032-.0972L6.973 9.8356l-2.55-1.6879-1.3356-.9714-.7225-.4918-.3643-.4614-.1578-1.0078.6557-.7225.8803.0607.2246.0607.8925.686 1.9064 1.4754 2.4893 1.8336.3643.3035.1457-.1032.0182-.0728-.164-.2733-1.3539-2.4467-1.445-2.4893-.6435-1.032-.17-.6194c-.0607-.255-.1032-.4674-.1032-.7285L6.287.1335 6.6997 0l.9957.1336.419.3642.6192 1.4147 1.0018 2.2282 1.5543 3.0296.4553.8985.2429.8318.091.255h.1579v-.1457l.1275-1.706.2368-2.0947.2307-2.6957.0789-.7589.3764-.9107.7468-.4918.5828.2793.4797.686-.0668.4433-.2853 1.8517-.5586 2.9021-.3643 1.9429h.2125l.2429-.2429.9835-1.3053 1.6514-2.0643.7286-.8196.85-.9046.5464-.4311h1.0321l.759 1.1293-.34 1.1657-1.0625 1.3478-.8804 1.1414-1.2628 1.7-.7893 1.36.0729.1093.1882-.0183 2.8535-.607 1.5421-.2794 1.8396-.3157.8318.3886.091.3946-.3278.8075-1.967.4857-2.3072.4614-3.4364.8136-.0425.0304.0486.0607 1.5482.1457.6618.0364h1.621l3.0175.2247.7892.522.4736.6376-.079.4857-1.2142.6193-1.6393-.3886-3.825-.9107-1.3113-.3279h-.1822v.1093l1.0929 1.0686 2.0035 1.8092 2.5075 2.3314.1275.5768-.3218.4554-.34-.0486-2.2039-1.6575-.85-.7468-1.9246-1.621h-.1275v.17l.4432.6496 2.3436 3.5214.1214 1.0807-.17.3521-.6071.2125-.6679-.1214-1.3721-1.9246L14.38 17.959l-1.1414-1.9428-.1397.079-.674 7.2552-.3156.3703-.7286.2793-.6071-.4614-.3218-.7468.3218-1.4753.3886-1.9246.3157-1.53.2853-1.9004.17-.6314-.0121-.0425-.1397.0182-1.4328 1.9672-2.1796 2.9446-1.7243 1.8456-.4128.164-.7164-.3704.0667-.6618.4008-.5889 2.386-3.0357 1.4389-1.882.929-1.0868-.0062-.1579h-.0546l-6.3385 4.1164-1.1293.1457-.4857-.4554.0608-.7467.2307-.2429 1.9064-1.3114Z";
423
+
424
+ public const string AntigravitySilhouettePath = "M144.248 149.062C151.748 154.688 162.998 150.938 152.685 140.625C121.748 110.625 128.31 28.125 89.8727 28.125C51.4352 28.125 57.9977 110.625 27.0602 140.625C15.8102 151.875 27.9977 154.688 35.4977 149.062C64.5602 129.375 62.6852 94.6875 89.8727 94.6875C117.06 94.6875 115.185 129.375 144.248 149.062Z";
425
+
426
+ private const string AntigravityPath7 = "M4.21557 239.063C-25.3231 227.467 25.1577 132.061 37.7105 100.085C50.2634 68.1097 84.3853 51.5888 113.924 63.1848C143.463 74.7809 178.474 138.65 165.921 170.626C153.368 202.601 33.7543 250.659 4.21557 239.063Z";
427
+ private const string AntigravityPath8 = "M183.197 120.315C175.289 129.545 154.652 124.839 137.102 109.803C119.553 94.7668 111.738 75.0955 119.646 65.8656C127.554 56.6357 148.191 61.3423 165.74 76.3782C183.289 91.414 191.105 111.085 183.197 120.315Z";
428
+
429
+ private static readonly Dictionary<string, Bitmap> Cache = new Dictionary<string, Bitmap>();
430
+ private static Bitmap AntigravityFieldCache = null;
431
+
432
+ public static GraphicsPath ParseSvgPath(string d, FillMode fillMode) {
433
+ var path = new GraphicsPath(fillMode);
434
+ if (string.IsNullOrEmpty(d)) return path;
435
+
436
+ int i = 0;
437
+ int len = d.Length;
438
+ char cmd = '\0';
439
+ char prevCmd = '\0';
440
+ float cx = 0f, cy = 0f, sx = 0f, sy = 0f;
441
+ float lastC2X = 0f, lastC2Y = 0f;
442
+ float lastQ1X = 0f, lastQ1Y = 0f;
443
+
444
+ while (i < len) {
445
+ SkipSeparators(d, ref i);
446
+ if (i >= len) break;
447
+
448
+ char ch = d[i];
449
+ if (IsCommandChar(ch)) {
450
+ cmd = ch;
451
+ i++;
452
+ } else if (cmd == '\0') {
453
+ break;
454
+ }
455
+
456
+ if (cmd == 'Z' || cmd == 'z') {
457
+ path.CloseFigure();
458
+ cx = sx;
459
+ cy = sy;
460
+ prevCmd = cmd;
461
+ cmd = '\0';
462
+ continue;
463
+ }
464
+
465
+ switch (cmd) {
466
+ case 'M':
467
+ case 'm': {
468
+ float x = ReadNumber(d, ref i);
469
+ float y = ReadNumber(d, ref i);
470
+ if (cmd == 'm') { x += cx; y += cy; }
471
+ path.StartFigure();
472
+ cx = sx = x;
473
+ cy = sy = y;
474
+ prevCmd = cmd;
475
+ cmd = (cmd == 'm') ? 'l' : 'L';
476
+ break;
477
+ }
478
+ case 'L':
479
+ case 'l': {
480
+ float x = ReadNumber(d, ref i);
481
+ float y = ReadNumber(d, ref i);
482
+ if (cmd == 'l') { x += cx; y += cy; }
483
+ path.AddLine(cx, cy, x, y);
484
+ cx = x; cy = y;
485
+ prevCmd = cmd;
486
+ break;
487
+ }
488
+ case 'H':
489
+ case 'h': {
490
+ float x = ReadNumber(d, ref i);
491
+ if (cmd == 'h') x += cx;
492
+ path.AddLine(cx, cy, x, cy);
493
+ cx = x;
494
+ prevCmd = cmd;
495
+ break;
496
+ }
497
+ case 'V':
498
+ case 'v': {
499
+ float y = ReadNumber(d, ref i);
500
+ if (cmd == 'v') y += cy;
501
+ path.AddLine(cx, cy, cx, y);
502
+ cy = y;
503
+ prevCmd = cmd;
504
+ break;
505
+ }
506
+ case 'C':
507
+ case 'c': {
508
+ float x1 = ReadNumber(d, ref i);
509
+ float y1 = ReadNumber(d, ref i);
510
+ float x2 = ReadNumber(d, ref i);
511
+ float y2 = ReadNumber(d, ref i);
512
+ float x = ReadNumber(d, ref i);
513
+ float y = ReadNumber(d, ref i);
514
+ if (cmd == 'c') {
515
+ x1 += cx; y1 += cy;
516
+ x2 += cx; y2 += cy;
517
+ x += cx; y += cy;
518
+ }
519
+ path.AddBezier(cx, cy, x1, y1, x2, y2, x, y);
520
+ lastC2X = x2; lastC2Y = y2;
521
+ cx = x; cy = y;
522
+ prevCmd = cmd;
523
+ break;
524
+ }
525
+ case 'S':
526
+ case 's': {
527
+ float x1 = (prevCmd == 'C' || prevCmd == 'c' || prevCmd == 'S' || prevCmd == 's') ? (2f * cx - lastC2X) : cx;
528
+ float y1 = (prevCmd == 'C' || prevCmd == 'c' || prevCmd == 'S' || prevCmd == 's') ? (2f * cy - lastC2Y) : cy;
529
+ float x2 = ReadNumber(d, ref i);
530
+ float y2 = ReadNumber(d, ref i);
531
+ float x = ReadNumber(d, ref i);
532
+ float y = ReadNumber(d, ref i);
533
+ if (cmd == 's') {
534
+ x2 += cx; y2 += cy;
535
+ x += cx; y += cy;
536
+ }
537
+ path.AddBezier(cx, cy, x1, y1, x2, y2, x, y);
538
+ lastC2X = x2; lastC2Y = y2;
539
+ cx = x; cy = y;
540
+ prevCmd = cmd;
541
+ break;
542
+ }
543
+ case 'Q':
544
+ case 'q': {
545
+ float qx = ReadNumber(d, ref i);
546
+ float qy = ReadNumber(d, ref i);
547
+ float x = ReadNumber(d, ref i);
548
+ float y = ReadNumber(d, ref i);
549
+ if (cmd == 'q') {
550
+ qx += cx; qy += cy;
551
+ x += cx; y += cy;
552
+ }
553
+ float c1x = cx + (2f / 3f) * (qx - cx);
554
+ float c1y = cy + (2f / 3f) * (qy - cy);
555
+ float c2x = x + (2f / 3f) * (qx - x);
556
+ float c2y = y + (2f / 3f) * (qy - y);
557
+ path.AddBezier(cx, cy, c1x, c1y, c2x, c2y, x, y);
558
+ lastQ1X = qx; lastQ1Y = qy;
559
+ cx = x; cy = y;
560
+ prevCmd = cmd;
561
+ break;
562
+ }
563
+ default:
564
+ i++;
565
+ break;
566
+ }
567
+ }
568
+ return path;
569
+ }
570
+
571
+ private static bool IsCommandChar(char c) {
572
+ return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
573
+ }
574
+
575
+ private static void SkipSeparators(string s, ref int i) {
576
+ while (i < s.Length) {
577
+ char c = s[i];
578
+ if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == ',') i++;
579
+ else break;
580
+ }
581
+ }
582
+
583
+ private static float ReadNumber(string s, ref int i) {
584
+ SkipSeparators(s, ref i);
585
+ int start = i;
586
+ if (i < s.Length && (s[i] == '+' || s[i] == '-')) i++;
587
+ bool hasDot = false;
588
+ while (i < s.Length) {
589
+ char c = s[i];
590
+ if (c >= '0' && c <= '9') {
591
+ i++;
592
+ } else if (c == '.' && !hasDot) {
593
+ hasDot = true;
594
+ i++;
595
+ } else {
596
+ break;
597
+ }
598
+ }
599
+ if (i < s.Length && (s[i] == 'e' || s[i] == 'E')) {
600
+ int expStart = i;
601
+ i++;
602
+ if (i < s.Length && (s[i] == '+' || s[i] == '-')) i++;
603
+ int digitStart = i;
604
+ while (i < s.Length && s[i] >= '0' && s[i] <= '9') i++;
605
+ if (i == digitStart) i = expStart;
606
+ }
607
+ if (i == start) return 0f;
608
+ float value;
609
+ if (float.TryParse(s.Substring(start, i - start), NumberStyles.Float, CultureInfo.InvariantCulture, out value)) {
610
+ return value;
611
+ }
612
+ return 0f;
613
+ }
614
+
615
+ private static void GaussianBlurPArgb(float[] src, int w, int h, float sigma) {
616
+ if (sigma <= 0.1f) return;
617
+ int radius = Math.Max(1, Math.Min(64, (int)Math.Ceiling(sigma * 3.0f)));
618
+ float[] kernel = new float[radius * 2 + 1];
619
+ float sum = 0f;
620
+ float invTwoSigmaSq = 1.0f / (2.0f * sigma * sigma);
621
+ for (int k = -radius; k <= radius; k++) {
622
+ float v = (float)Math.Exp(-(k * k) * invTwoSigmaSq);
623
+ kernel[k + radius] = v;
624
+ sum += v;
625
+ }
626
+ for (int k = 0; k < kernel.Length; k++) kernel[k] /= sum;
627
+
628
+ float[] tmp = new float[src.Length];
629
+ // Horizontal pass
630
+ for (int y = 0; y < h; y++) {
631
+ int rowOff = y * w;
632
+ for (int x = 0; x < w; x++) {
633
+ float b = 0f, g = 0f, r = 0f, a = 0f;
634
+ for (int k = -radius; k <= radius; k++) {
635
+ int sx = x + k;
636
+ if (sx < 0 || sx >= w) continue;
637
+ int idx = (rowOff + sx) * 4;
638
+ float wt = kernel[k + radius];
639
+ b += src[idx] * wt;
640
+ g += src[idx + 1] * wt;
641
+ r += src[idx + 2] * wt;
642
+ a += src[idx + 3] * wt;
643
+ }
644
+ int dstIdx = (rowOff + x) * 4;
645
+ tmp[dstIdx] = b;
646
+ tmp[dstIdx + 1] = g;
647
+ tmp[dstIdx + 2] = r;
648
+ tmp[dstIdx + 3] = a;
649
+ }
650
+ }
651
+ // Vertical pass
652
+ for (int y = 0; y < h; y++) {
653
+ int rowOff = y * w;
654
+ for (int x = 0; x < w; x++) {
655
+ float b = 0f, g = 0f, r = 0f, a = 0f;
656
+ for (int k = -radius; k <= radius; k++) {
657
+ int sy = y + k;
658
+ if (sy < 0 || sy >= h) continue;
659
+ int idx = (sy * w + x) * 4;
660
+ float wt = kernel[k + radius];
661
+ b += tmp[idx] * wt;
662
+ g += tmp[idx + 1] * wt;
663
+ r += tmp[idx + 2] * wt;
664
+ a += tmp[idx + 3] * wt;
665
+ }
666
+ int dstIdx = (rowOff + x) * 4;
667
+ src[dstIdx] = b;
668
+ src[dstIdx + 1] = g;
669
+ src[dstIdx + 2] = r;
670
+ src[dstIdx + 3] = a;
671
+ }
672
+ }
673
+ }
674
+
675
+ private static void CompositeBlurredLayer(float[] accum, int bufSize, float scale, float pad, float stdDev, Action<Graphics> drawAction) {
676
+ using (var bmp = new Bitmap(bufSize, bufSize, PixelFormat.Format32bppPArgb)) {
677
+ using (var g = Graphics.FromImage(bmp)) {
678
+ g.Clear(Color.Transparent);
679
+ g.SmoothingMode = SmoothingMode.AntiAlias;
680
+ g.ScaleTransform(scale, scale);
681
+ g.TranslateTransform(pad, pad);
682
+ drawAction(g);
683
+ }
684
+ var rect = new Rectangle(0, 0, bufSize, bufSize);
685
+ var data = bmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb);
686
+ byte[] bytes = new byte[bufSize * bufSize * 4];
687
+ Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
688
+ bmp.UnlockBits(data);
689
+
690
+ float[] layer = new float[bytes.Length];
691
+ for (int i = 0; i < bytes.Length; i++) layer[i] = bytes[i] / 255.0f;
692
+
693
+ GaussianBlurPArgb(layer, bufSize, bufSize, stdDev * scale);
694
+
695
+ for (int i = 0; i < accum.Length; i += 4) {
696
+ float sa = layer[i + 3];
697
+ if (sa <= 0.0001f) continue;
698
+ float invSa = 1.0f - sa;
699
+ accum[i] = layer[i] + accum[i] * invSa;
700
+ accum[i + 1] = layer[i + 1] + accum[i + 1] * invSa;
701
+ accum[i + 2] = layer[i + 2] + accum[i + 2] * invSa;
702
+ accum[i + 3] = sa + accum[i + 3] * invSa;
703
+ }
704
+ }
705
+ }
706
+
707
+ private static void DrawRotatedEllipse(Graphics g, float cx, float cy, float rx, float ry, float angle, Color fill) {
708
+ var st = g.Save();
709
+ g.TranslateTransform(cx, cy);
710
+ g.RotateTransform(angle);
711
+ g.TranslateTransform(-cx, -cy);
712
+ using (var brush = new SolidBrush(fill)) {
713
+ g.FillEllipse(brush, cx - rx, cy - ry, rx * 2f, ry * 2f);
714
+ }
715
+ g.Restore(st);
716
+ }
717
+
718
+ private static void DrawMatrixEllipse(Graphics g, float cx, float cy, float rx, float ry, float m11, float m12, float m21, float m22, float dx, float dy, Color fill) {
719
+ var st = g.Save();
720
+ using (var m = new Matrix(m11, m12, m21, m22, dx, dy)) {
721
+ g.MultiplyTransform(m, MatrixOrder.Prepend);
722
+ }
723
+ using (var brush = new SolidBrush(fill)) {
724
+ g.FillEllipse(brush, cx - rx, cy - ry, rx * 2f, ry * 2f);
725
+ }
726
+ g.Restore(st);
727
+ }
728
+
729
+ private static Bitmap GetAntigravityColorField() {
730
+ if (AntigravityFieldCache != null) return AntigravityFieldCache;
731
+ // Covers SVG [-60..240] at scale 0.4 -> 120x120 buffer, cropped to [0..180] = 72x72.
732
+ const float pad = 60f;
733
+ const float scale = 0.4f;
734
+ const int bufSize = 120;
735
+ const int cropOffset = 24;
736
+ const int cropSize = 72;
737
+
738
+ float[] accum = new float[bufSize * bufSize * 4];
739
+ // Base fill #3186FF
740
+ float baseB = 0xFF / 255.0f, baseG = 0x86 / 255.0f, baseR = 0x31 / 255.0f;
741
+ for (int i = 0; i < accum.Length; i += 4) {
742
+ accum[i] = baseB;
743
+ accum[i + 1] = baseG;
744
+ accum[i + 2] = baseR;
745
+ accum[i + 3] = 1.0f;
746
+ }
747
+
748
+ CompositeBlurredLayer(accum, bufSize, scale, pad, 6.25234f, g => DrawMatrixEllipse(g, 36.6225f, 43.0872f, 36.6225f, 43.0872f, -0.112784f, 0.99362f, -0.99362f, -0.112781f, 106.557f, -26.4847f, Color.FromArgb(0xFF, 0xE4, 0x32)));
749
+ CompositeBlurredLayer(accum, bufSize, scale, pad, 30.2268f, g => DrawRotatedEllipse(g, 155.163f, 54.9292f, 47.4118f, 48.4541f, 76.9243f, Color.FromArgb(0xFC, 0x41, 0x3D)));
750
+ CompositeBlurredLayer(accum, bufSize, scale, pad, 25.6957f, g => DrawRotatedEllipse(g, 14.6006f, 65.4425f, 49.5515f, 64.192f, 74.1257f, Color.FromArgb(0x00, 0xB9, 0x5C)));
751
+ CompositeBlurredLayer(accum, bufSize, scale, pad, 25.6957f, g => DrawRotatedEllipse(g, 14.6006f, 65.4425f, 49.5515f, 64.192f, 74.1257f, Color.FromArgb(0x00, 0xB9, 0x5C)));
752
+ CompositeBlurredLayer(accum, bufSize, scale, pad, 25.6957f, g => DrawRotatedEllipse(g, 18.1226f, 67.414f, 48.5679f, 53.4688f, 45.6065f, Color.FromArgb(0x00, 0xB9, 0x5C)));
753
+ CompositeBlurredLayer(accum, bufSize, scale, pad, 24.4184f, g => DrawRotatedEllipse(g, 121.837f, 166.945f, 46.6356f, 44.9084f, 76.9243f, Color.FromArgb(0x31, 0x86, 0xFF)));
754
+ CompositeBlurredLayer(accum, bufSize, scale, pad, 22.1301f, g => DrawMatrixEllipse(g, 53.9456f, 56.8997f, 53.9456f, 56.8997f, -0.409539f, 0.912293f, -0.912294f, -0.409537f, 162.811f, -25.895f, Color.FromArgb(0xFB, 0xBC, 0x04)));
755
+ CompositeBlurredLayer(accum, bufSize, scale, pad, 19.7631f, g => {
756
+ using (var p = ParseSvgPath(AntigravityPath7, FillMode.Winding))
757
+ using (var br = new SolidBrush(Color.FromArgb(0x31, 0x86, 0xFF))) {
758
+ g.FillPath(br, p);
759
+ }
760
+ });
761
+ CompositeBlurredLayer(accum, bufSize, scale, pad, 17.6843f, g => {
762
+ using (var p = ParseSvgPath(AntigravityPath8, FillMode.Winding))
763
+ using (var br = new SolidBrush(Color.FromArgb(0x74, 0x9B, 0xFF))) {
764
+ g.FillPath(br, p);
765
+ }
766
+ });
767
+ CompositeBlurredLayer(accum, bufSize, scale, pad, 14.9365f, g => DrawRotatedEllipse(g, 148.928f, 36.7252f, 71.1018f, 44.199f, 34.0763f, Color.FromArgb(0xFC, 0x41, 0x3D)));
768
+ CompositeBlurredLayer(accum, bufSize, scale, pad, 18.4865f, g => DrawRotatedEllipse(g, 37.848f, 46.0346f, 38.1008f, 22.1575f, 112.516f, Color.FromArgb(0xFF, 0xEE, 0x48)));
769
+
770
+ var field = new Bitmap(cropSize, cropSize, PixelFormat.Format32bppArgb);
771
+ var rect = new Rectangle(0, 0, cropSize, cropSize);
772
+ var outData = field.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
773
+ byte[] outBytes = new byte[cropSize * cropSize * 4];
774
+ for (int y = 0; y < cropSize; y++) {
775
+ for (int x = 0; x < cropSize; x++) {
776
+ int si = ((y + cropOffset) * bufSize + (x + cropOffset)) * 4;
777
+ int di = (y * cropSize + x) * 4;
778
+ float a = Math.Max(0.0001f, Math.Min(1.0f, accum[si + 3]));
779
+ outBytes[di] = (byte)Math.Max(0, Math.Min(255, (int)Math.Round((accum[si] / a) * 255.0f)));
780
+ outBytes[di + 1] = (byte)Math.Max(0, Math.Min(255, (int)Math.Round((accum[si + 1] / a) * 255.0f)));
781
+ outBytes[di + 2] = (byte)Math.Max(0, Math.Min(255, (int)Math.Round((accum[si + 2] / a) * 255.0f)));
782
+ outBytes[di + 3] = 255;
783
+ }
784
+ }
785
+ Marshal.Copy(outBytes, 0, outData.Scan0, outBytes.Length);
786
+ field.UnlockBits(outData);
787
+ AntigravityFieldCache = field;
788
+ return field;
789
+ }
790
+
791
+ private static Bitmap RenderMonoSvg(string svgPath, float viewBox, int pixelSize, Color color) {
792
+ int ss = Math.Max(pixelSize * 2, 32);
793
+ using (var hi = new Bitmap(ss, ss, PixelFormat.Format32bppArgb)) {
794
+ using (var g = Graphics.FromImage(hi)) {
795
+ g.Clear(Color.Transparent);
796
+ g.SmoothingMode = SmoothingMode.HighQuality;
797
+ g.PixelOffsetMode = PixelOffsetMode.HighQuality;
798
+ float s = ss / viewBox;
799
+ g.ScaleTransform(s, s);
800
+ using (var path = ParseSvgPath(svgPath, FillMode.Winding))
801
+ using (var brush = new SolidBrush(color)) {
802
+ g.FillPath(brush, path);
803
+ }
804
+ }
805
+ var dst = new Bitmap(pixelSize, pixelSize, PixelFormat.Format32bppArgb);
806
+ using (var g = Graphics.FromImage(dst)) {
807
+ g.Clear(Color.Transparent);
808
+ g.InterpolationMode = InterpolationMode.HighQualityBicubic;
809
+ g.SmoothingMode = SmoothingMode.HighQuality;
810
+ g.PixelOffsetMode = PixelOffsetMode.HighQuality;
811
+ g.DrawImage(hi, new Rectangle(0, 0, pixelSize, pixelSize));
812
+ }
813
+ return dst;
814
+ }
815
+ }
816
+
817
+ private static Bitmap RenderAntigravitySvg(int pixelSize, float opacity) {
818
+ int ss = Math.Max(pixelSize * 2, 36);
819
+ var field = GetAntigravityColorField();
820
+ using (var hiColor = new Bitmap(ss, ss, PixelFormat.Format32bppArgb))
821
+ using (var hiMask = new Bitmap(ss, ss, PixelFormat.Format32bppArgb)) {
822
+ using (var gc = Graphics.FromImage(hiColor)) {
823
+ gc.InterpolationMode = InterpolationMode.HighQualityBicubic;
824
+ gc.PixelOffsetMode = PixelOffsetMode.HighQuality;
825
+ gc.DrawImage(field, new Rectangle(0, 0, ss, ss));
826
+ }
827
+ using (var gm = Graphics.FromImage(hiMask)) {
828
+ gm.Clear(Color.Transparent);
829
+ gm.SmoothingMode = SmoothingMode.HighQuality;
830
+ gm.PixelOffsetMode = PixelOffsetMode.HighQuality;
831
+ float s = ss / 180.0f;
832
+ gm.ScaleTransform(s, s);
833
+ using (var path = ParseSvgPath(AntigravitySilhouettePath, FillMode.Winding))
834
+ using (var brush = new SolidBrush(Color.White)) {
835
+ gm.FillPath(brush, path);
836
+ }
837
+ }
838
+
839
+ var rect = new Rectangle(0, 0, ss, ss);
840
+ var cData = hiColor.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
841
+ var mData = hiMask.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
842
+ int byteLen = ss * ss * 4;
843
+ byte[] cBytes = new byte[byteLen];
844
+ byte[] mBytes = new byte[byteLen];
845
+ Marshal.Copy(cData.Scan0, cBytes, 0, byteLen);
846
+ Marshal.Copy(mData.Scan0, mBytes, 0, byteLen);
847
+ for (int i = 0; i < byteLen; i += 4) {
848
+ cBytes[i + 3] = (byte)Math.Max(0, Math.Min(255, (int)Math.Round(mBytes[i + 3] * opacity)));
849
+ }
850
+ Marshal.Copy(cBytes, 0, cData.Scan0, byteLen);
851
+ hiColor.UnlockBits(cData);
852
+ hiMask.UnlockBits(mData);
853
+
854
+ var dst = new Bitmap(pixelSize, pixelSize, PixelFormat.Format32bppArgb);
855
+ using (var g = Graphics.FromImage(dst)) {
856
+ g.Clear(Color.Transparent);
857
+ g.InterpolationMode = InterpolationMode.HighQualityBicubic;
858
+ g.SmoothingMode = SmoothingMode.HighQuality;
859
+ g.PixelOffsetMode = PixelOffsetMode.HighQuality;
860
+ g.DrawImage(hiColor, new Rectangle(0, 0, pixelSize, pixelSize));
861
+ }
862
+ return dst;
863
+ }
864
+ }
865
+
866
+ public static Bitmap GetBrandIcon(string provider, int pixelSize, bool running, bool darkText) {
867
+ int size = Math.Max(8, pixelSize);
868
+ string p = (provider ?? "codex").Trim().ToLowerInvariant();
869
+ string key = p + "|" + size + "|" + (running ? "1" : "0") + "|" + (darkText ? "1" : "0");
870
+ Bitmap cached;
871
+ if (Cache.TryGetValue(key, out cached)) return cached;
872
+
873
+ if (Cache.Count >= 64) {
874
+ foreach (var item in Cache.Values) item.Dispose();
875
+ Cache.Clear();
876
+ }
877
+
878
+ Bitmap rendered;
879
+ if (p == "claude") {
880
+ Color c = running ? Color.FromArgb(255, 217, 119, 6) : Color.FromArgb(184, 217, 119, 6);
881
+ rendered = RenderMonoSvg(ClaudeSvgPath, 24.0f, size, c);
882
+ } else if (p == "antigravity" || p == "gemini") {
883
+ rendered = RenderAntigravitySvg(size, running ? 1.0f : 0.72f);
884
+ } else {
885
+ Color c = running
886
+ ? (darkText ? Color.FromArgb(255, 17, 17, 17) : Color.FromArgb(255, 245, 245, 247))
887
+ : (darkText ? Color.FromArgb(184, 96, 96, 102) : Color.FromArgb(184, 161, 161, 170));
888
+ rendered = RenderMonoSvg(CodexSvgPath, 320.0f, size, c);
889
+ }
890
+ Cache[key] = rendered;
891
+ return rendered;
892
+ }
893
+ }
894
+ '@
895
+
896
+ Add-Type -TypeDefinition $svgCode -ReferencedAssemblies @("System.Drawing")
897
+ $script:brandSvgRendererReady = $true
898
+ return $true
899
+ }
900
+
901
+ function Draw-BrandIcon($Graphics, [string]$Provider, [single]$X, [single]$Y, [single]$Size, [bool]$Running = $true) {
902
+ $pixelSize = [math]::Max(8, [int][math]::Round($Size))
903
+ if (Initialize-BrandSvgRenderer) {
904
+ $iconBitmap = [AiBatterySvgIcons]::GetBrandIcon($Provider, $pixelSize, $Running, [bool]$script:hudDarkText)
905
+ if ($iconBitmap) {
906
+ $state = $Graphics.Save()
907
+ try {
908
+ $Graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
909
+ $Graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
910
+ $Graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
911
+ $Graphics.DrawImage($iconBitmap, [System.Drawing.RectangleF]::new($X, $Y, $Size, $Size))
912
+ } finally {
913
+ $Graphics.Restore($state)
914
+ }
915
+ return
916
+ }
917
+ }
918
+ }
919
+
920
+ function New-RoundedRectPath([single]$X, [single]$Y, [single]$Width, [single]$Height, [single]$Radius) {
921
+ $path = [System.Drawing.Drawing2D.GraphicsPath]::new()
922
+ $r = [single][math]::Max(0.1, [math]::Min($Radius, [math]::Min($Width / 2.0, $Height / 2.0)))
923
+ $d = [single]($r * 2.0)
924
+ $path.AddArc($X, $Y, $d, $d, 180, 90)
925
+ $path.AddArc(($X + $Width - $d), $Y, $d, $d, 270, 90)
926
+ $path.AddArc(($X + $Width - $d), ($Y + $Height - $d), $d, $d, 0, 90)
927
+ $path.AddArc($X, ($Y + $Height - $d), $d, $d, 90, 90)
928
+ $path.CloseFigure()
929
+ return $path
930
+ }
931
+
932
+ function Get-MenuBatteryFillColor([Nullable[int]]$Percent, [bool]$Running = $true) {
933
+ if (-not $Running) {
934
+ return $(if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(113, 113, 122) } else { [System.Drawing.Color]::FromArgb(161, 161, 170) })
935
+ }
936
+ if ($null -eq $Percent) {
937
+ return $(if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(24, 24, 24) } else { [System.Drawing.Color]::FromArgb(255, 255, 255) })
938
+ }
939
+ if ($Percent -le 20) { return [System.Drawing.Color]::FromArgb(255, 69, 58) }
940
+ if ($Percent -le 40) { return [System.Drawing.Color]::FromArgb(255, 159, 10) }
941
+ return [System.Drawing.Color]::FromArgb(48, 209, 88)
942
+ }
943
+
944
+ function Get-HorizontalHudUnit {
945
+ return [double]($script:hudScale * 1.18)
946
+ }
947
+
948
+ function Get-HorizontalProviderDetailText($Parts) {
949
+ $segments = @()
950
+ if ($Parts.ResetValue) { $segments += [string]$Parts.ResetValue }
951
+ if ($Parts.WeekValue) { $segments += [string]$Parts.WeekValue }
952
+ if (-not $segments.Count -and $Parts.ExtraText) { $segments += [string]$Parts.ExtraText }
953
+ return ($segments -join " · ")
954
+ }
955
+
956
+ function Measure-HorizontalBrandHudWidth($Texts, $DrawFont) {
957
+ $padX = Scale-HudValue 10
958
+ if (-not $Texts -or -not $Texts.Rows -or $Texts.Rows.Count -eq 0) {
959
+ return Scale-HudValue 150
960
+ }
961
+ $count = $Texts.Rows.Count
962
+ $slotStep = Scale-HudValue 64
963
+ $slotContent = Scale-HudValue 56
964
+ $contentW = (($count - 1) * $slotStep) + $slotContent
965
+ return [math]::Max((Scale-HudValue 80), ($contentW + ($padX * 2)))
966
+ }
967
+
968
+ function Draw-HorizontalBrandHud($Graphics, [int]$Width, [int]$Height, $Texts, $DrawFont) {
969
+ $Graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
970
+ $Graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::Default
971
+
972
+ if ($script:hudContrastBackdrop -or (-not $script:hudTransparentSurface)) {
973
+ $radius = [single][math]::Min((Scale-HudValue 8), [math]::Floor(($Height - 2) / 2))
974
+ $bgPath = New-RoundedRectPath ([single]0.5) ([single]0.5) ([single]($Width - 1)) ([single]($Height - 1)) $radius
975
+ $bgColor = if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(244, 244, 248) } else { [System.Drawing.Color]::FromArgb(28, 28, 32) }
976
+ $borderColor = if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(196, 196, 204) } else { [System.Drawing.Color]::FromArgb(68, 68, 74) }
977
+ $bgBrush = [System.Drawing.SolidBrush]::new($bgColor)
978
+ $borderPen = [System.Drawing.Pen]::new($borderColor, 1.0)
979
+ try {
980
+ $Graphics.FillPath($bgBrush, $bgPath)
981
+ $Graphics.DrawPath($borderPen, $bgPath)
982
+ } finally {
983
+ $bgBrush.Dispose()
984
+ $borderPen.Dispose()
985
+ $bgPath.Dispose()
986
+ }
987
+ }
988
+
989
+ $flags = [System.Windows.Forms.TextFormatFlags]::NoPadding -bor [System.Windows.Forms.TextFormatFlags]::SingleLine -bor [System.Windows.Forms.TextFormatFlags]::NoPrefix
990
+ if (-not $Texts -or -not $Texts.Rows -or $Texts.Rows.Count -eq 0) {
991
+ $msg = if ($script:hudHorizontalMessage) { $script:hudHorizontalMessage } else { "AI --" }
992
+ $msgY = [math]::Max(0, [int][math]::Floor(($Height - $DrawFont.Height) / 2))
993
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $msg, $DrawFont, [System.Drawing.Point]::new((Scale-HudValue 8), $msgY), (Get-HudMutedTextColor), $flags)
994
+ return
995
+ }
996
+
997
+ # Crisp integer pixel layout matching macOS / Linux horizontal menu bar:
998
+ # [Real Brand SVG Icon] + right column: [Solid crisp pill bar] above [hinted GDI bold %].
999
+ $padX = Scale-HudValue 10
1000
+ $slotStep = Scale-HudValue 64
1001
+ $meterOffsetX = Scale-HudValue 24
1002
+ $meterW = Scale-HudValue 30
1003
+ $meterH = [math]::Max(6, (Scale-HudValue 6))
1004
+ if (($meterH % 2) -ne 0) { $meterH += 1 }
1005
+ $contentH = Scale-HudValue 26
1006
+ $originY = [int][math]::Floor(($Height - $contentH) / 2)
1007
+ $pctFontSize = [single][math]::Max(10, (Scale-HudValue 11))
1008
+ $pctFont = [System.Drawing.Font]::new("Segoe UI", $pctFontSize, [System.Drawing.FontStyle]::Bold, [System.Drawing.GraphicsUnit]::Pixel)
1009
+ $pctFlags = [System.Windows.Forms.TextFormatFlags]::HorizontalCenter -bor [System.Windows.Forms.TextFormatFlags]::VerticalCenter -bor [System.Windows.Forms.TextFormatFlags]::SingleLine -bor [System.Windows.Forms.TextFormatFlags]::NoPadding -bor [System.Windows.Forms.TextFormatFlags]::NoPrefix
1010
+
1011
+ try {
1012
+ $index = 0
1013
+ foreach ($row in $Texts.Rows) {
1014
+ $slotX = $padX + ($index * $slotStep)
1015
+ $provider = [string]$row.Provider
1016
+ $parts = $row.Parts
1017
+ $running = [bool]$parts.Running
1018
+ $percent = $parts.Percent
1019
+
1020
+ $iconDim = if ($provider -eq "claude") { Scale-HudValue 19 } else { Scale-HudValue 21 }
1021
+ $iconY = [int][math]::Floor(($Height - $iconDim) / 2)
1022
+ Draw-BrandIcon $Graphics $provider ([single]$slotX) ([single]$iconY) ([single]$iconDim) $running
1023
+
1024
+ # Integer-snapped opaque pill bar (zero TransparencyKey fringe or subpixel blur)
1025
+ $meterX = $slotX + $meterOffsetX
1026
+ $meterY = $originY + (Scale-HudValue 3)
1027
+ $pillRadius = [single]([math]::Floor($meterH / 2))
1028
+ $trackFillColor = if ($script:hudDarkText) {
1029
+ [System.Drawing.Color]::FromArgb(232, 232, 238)
1030
+ } else {
1031
+ [System.Drawing.Color]::FromArgb(38, 38, 44)
1032
+ }
1033
+ $outlineColor = if ($script:hudDarkText) {
1034
+ if ($running) { [System.Drawing.Color]::FromArgb(72, 72, 80) } else { [System.Drawing.Color]::FromArgb(148, 148, 158) }
1035
+ } else {
1036
+ if ($running) { [System.Drawing.Color]::FromArgb(148, 148, 158) } else { [System.Drawing.Color]::FromArgb(92, 92, 102) }
1037
+ }
1038
+ $trackPath = New-RoundedRectPath ([single]$meterX) ([single]$meterY) ([single]$meterW) ([single]$meterH) $pillRadius
1039
+ $trackBrush = [System.Drawing.SolidBrush]::new($trackFillColor)
1040
+ $outlinePen = [System.Drawing.Pen]::new($outlineColor, 1.0)
1041
+ try {
1042
+ $Graphics.FillPath($trackBrush, $trackPath)
1043
+ $Graphics.DrawPath($outlinePen, $trackPath)
1044
+ } finally {
1045
+ $trackBrush.Dispose()
1046
+ $outlinePen.Dispose()
1047
+ $trackPath.Dispose()
1048
+ }
1049
+
1050
+ if ($null -ne $percent) {
1051
+ $clamped = [math]::Max(0, [math]::Min(100, [int]$percent))
1052
+ $inset = [math]::Max(2, (Scale-HudValue 2))
1053
+ $innerW = [math]::Max(2, $meterW - ($inset * 2))
1054
+ $innerH = [math]::Max(2, $meterH - ($inset * 2))
1055
+ $fillW = [int][math]::Round(($clamped / 100.0) * $innerW)
1056
+ if ($clamped -gt 0 -and $fillW -lt 2) { $fillW = 2 }
1057
+ if ($fillW -gt 0) {
1058
+ $innerX = $meterX + $inset
1059
+ $innerY = $meterY + $inset
1060
+ $fillBrush = [System.Drawing.SolidBrush]::new((Get-MenuBatteryFillColor $percent $running))
1061
+ try {
1062
+ if ($innerH -le 2) {
1063
+ $Graphics.FillRectangle($fillBrush, $innerX, $innerY, $fillW, $innerH)
1064
+ } else {
1065
+ $fillPath = New-RoundedRectPath ([single]$innerX) ([single]$innerY) ([single]$fillW) ([single]$innerH) ([single]($innerH / 2.0))
1066
+ try {
1067
+ $Graphics.FillPath($fillBrush, $fillPath)
1068
+ } finally {
1069
+ $fillPath.Dispose()
1070
+ }
1071
+ }
1072
+ } finally {
1073
+ $fillBrush.Dispose()
1074
+ }
1075
+ }
1076
+ }
1077
+
1078
+ # Crisp native Win32 hinted percentage text centered under pill bar
1079
+ $pctText = if ($null -eq $percent) { "--" } else { "$([int]$percent)%" }
1080
+ $pctColor = if ($running) {
1081
+ if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(20, 20, 24) } else { [System.Drawing.Color]::FromArgb(255, 255, 255) }
1082
+ } else {
1083
+ if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(108, 108, 116) } else { [System.Drawing.Color]::FromArgb(164, 164, 174) }
1084
+ }
1085
+ $pctRect = [System.Drawing.Rectangle]::new(
1086
+ ($meterX - (Scale-HudValue 4)),
1087
+ ($meterY + $meterH + (Scale-HudValue 2)),
1088
+ ($meterW + (Scale-HudValue 8)),
1089
+ (Scale-HudValue 15)
1090
+ )
1091
+ $pctBackColor = if ($script:hudContrastBackdrop -or (-not $script:hudTransparentSurface)) {
1092
+ [System.Drawing.Color]::FromArgb(28, 28, 32)
1093
+ } elseif ($script:hudDarkText) {
1094
+ [System.Drawing.Color]::FromArgb(254, 254, 254)
1095
+ } else {
1096
+ [System.Drawing.Color]::FromArgb(18, 18, 18)
1097
+ }
1098
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $pctText, $pctFont, $pctRect, $pctColor, $pctBackColor, $pctFlags)
1099
+ $index += 1
1100
+ }
1101
+ } finally {
1102
+ $pctFont.Dispose()
1103
+ }
1104
+ }
1105
+
1106
+ function Get-VerticalRailProviderTag([string]$Provider) {
1107
+ switch ($Provider) {
1108
+ "codex" { return "CDX" }
1109
+ "claude" { return "CLD" }
1110
+ "antigravity" { return "AGY" }
1111
+ default { return "AI" }
1112
+ }
1113
+ }
1114
+
1115
+ function Get-VerticalRailTagColor([string]$Provider, [bool]$Running = $true) {
1116
+ switch ($Provider) {
1117
+ "antigravity" {
1118
+ if ($script:hudDarkText) {
1119
+ return $(if ($Running) { [System.Drawing.Color]::FromArgb(37, 99, 235) } else { [System.Drawing.Color]::FromArgb(75, 118, 200) })
1120
+ }
1121
+ return $(if ($Running) { [System.Drawing.Color]::FromArgb(96, 165, 250) } else { [System.Drawing.Color]::FromArgb(76, 132, 204) })
1122
+ }
1123
+ "claude" {
1124
+ if ($script:hudDarkText) {
1125
+ return $(if ($Running) { [System.Drawing.Color]::FromArgb(217, 119, 6) } else { [System.Drawing.Color]::FromArgb(180, 112, 48) })
1126
+ }
1127
+ return $(if ($Running) { [System.Drawing.Color]::FromArgb(249, 115, 22) } else { [System.Drawing.Color]::FromArgb(204, 110, 42) })
1128
+ }
1129
+ default {
1130
+ if ($script:hudDarkText) {
1131
+ return $(if ($Running) { [System.Drawing.Color]::FromArgb(20, 20, 24) } else { [System.Drawing.Color]::FromArgb(92, 92, 102) })
1132
+ }
1133
+ return $(if ($Running) { [System.Drawing.Color]::FromArgb(255, 255, 255) } else { [System.Drawing.Color]::FromArgb(204, 204, 212) })
1134
+ }
1135
+ }
1136
+ }
1137
+
1138
+ function Get-VerticalRailMetrics {
1139
+ $padY = Scale-HudValue 8
1140
+ $tagH = Scale-HudValue 14
1141
+ $tagGap = Scale-HudValue 3
1142
+ $batH = Scale-HudValue 30
1143
+ $batGap = Scale-HudValue 3
1144
+ $pctH = Scale-HudValue 14
1145
+ $pctGap = Scale-HudValue 2
1146
+ $valH = Scale-HudValue 12
1147
+ $lblH = Scale-HudValue 10
1148
+ $pairGap = Scale-HudValue 3
1149
+ $divGap = Scale-HudValue 11
1150
+ $blockH = ($tagH + $tagGap) + ($batH + $batGap) + ($pctH + $pctGap) + ($valH + $lblH + $pairGap) + ($valH + $lblH)
1151
+ return [PSCustomObject]@{
1152
+ Width = Scale-HudValue 38
1153
+ PadX = Scale-HudValue 3
1154
+ PadY = $padY
1155
+ TagH = $tagH
1156
+ TagGap = $tagGap
1157
+ BatH = $batH
1158
+ BatGap = $batGap
1159
+ PctH = $pctH
1160
+ PctGap = $pctGap
1161
+ ValH = $valH
1162
+ LblH = $lblH
1163
+ PairGap = $pairGap
1164
+ DivGap = $divGap
1165
+ BlockH = $blockH
1166
+ }
1167
+ }
1168
+
1169
+ function Get-VerticalRailRowStrings($Row) {
1170
+ $parts = $Row.Parts
1171
+ $percent = $parts.Percent
1172
+ $tag = Get-VerticalRailProviderTag ([string]$Row.Provider)
1173
+ $pctText = if ($null -eq $percent) { "--%" } else { "$([int]$percent)%" }
1174
+ $primaryLbl = "5h"
1175
+ $resetVal = "--:--"
1176
+ if ($parts.ResetValue) {
1177
+ $rawReset = [string]$parts.ResetValue
1178
+ if ($rawReset -match '^(\S+)\s+(.+)$') {
1179
+ $primaryLbl = $Matches[1]
1180
+ $resetVal = $Matches[2]
1181
+ } else {
1182
+ $resetVal = $rawReset
1183
+ }
1184
+ }
1185
+ $weekLbl = "7d"
1186
+ $weekVal = "--%"
1187
+ if ($parts.WeekValue) {
1188
+ $rawWeek = [string]$parts.WeekValue
1189
+ if ($rawWeek -match '^(\S+)\s+(.+)$') {
1190
+ $weekLbl = $Matches[1]
1191
+ $weekVal = $Matches[2]
1192
+ } else {
1193
+ $weekVal = $rawWeek
1194
+ }
1195
+ }
1196
+ return [PSCustomObject]@{
1197
+ Tag = $tag
1198
+ PctText = $pctText
1199
+ PrimaryLbl = $primaryLbl
1200
+ ResetVal = $resetVal
1201
+ WeekLbl = $weekLbl
1202
+ WeekVal = $weekVal
1203
+ }
1204
+ }
1205
+
1206
+ function Measure-VerticalRailHudSize($Texts) {
1207
+ $m = Get-VerticalRailMetrics
1208
+ $rows = if ($Texts -and $Texts.Rows -and $Texts.Rows.Count -gt 0) { $Texts.Rows } else { @() }
1209
+ $count = [math]::Max(1, $rows.Count)
1210
+ $h = ($m.PadY * 2) + ($count * $m.BlockH) + ([math]::Max(0, $count - 1) * $m.DivGap)
1211
+
1212
+ $flags = [System.Windows.Forms.TextFormatFlags]::SingleLine -bor [System.Windows.Forms.TextFormatFlags]::NoPadding -bor [System.Windows.Forms.TextFormatFlags]::NoPrefix
1213
+ $bounds = [System.Drawing.Size]::new(256, 64)
1214
+ $maxContentW = [math]::Max(6, (Scale-HudValue 8))
1215
+
1216
+ $tagFont = [System.Drawing.Font]::new("Cascadia Mono", [single](Scale-HudValue 12), [System.Drawing.FontStyle]::Bold, [System.Drawing.GraphicsUnit]::Pixel)
1217
+ $pctFont = [System.Drawing.Font]::new("Segoe UI", [single](Scale-HudValue 11), [System.Drawing.FontStyle]::Bold, [System.Drawing.GraphicsUnit]::Pixel)
1218
+ $lblFont = [System.Drawing.Font]::new("Segoe UI", [single](Scale-HudValue 8.5), [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Pixel)
1219
+ $valFont = [System.Drawing.Font]::new("Cascadia Mono", [single](Scale-HudValue 10), [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Pixel)
1220
+ try {
1221
+ if ($rows.Count -eq 0) {
1222
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText("AI--", $valFont, $bounds, $flags).Width)
1223
+ } else {
1224
+ foreach ($row in $rows) {
1225
+ $items = Get-VerticalRailRowStrings $row
1226
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText($items.Tag, $tagFont, $bounds, $flags).Width)
1227
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText($items.PctText, $pctFont, $bounds, $flags).Width)
1228
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText($items.PrimaryLbl, $lblFont, $bounds, $flags).Width)
1229
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText($items.ResetVal, $valFont, $bounds, $flags).Width)
1230
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText($items.WeekLbl, $lblFont, $bounds, $flags).Width)
1231
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText($items.WeekVal, $valFont, $bounds, $flags).Width)
1232
+ }
1233
+ }
1234
+ } finally {
1235
+ $tagFont.Dispose()
1236
+ $pctFont.Dispose()
1237
+ $lblFont.Dispose()
1238
+ $valFont.Dispose()
1239
+ }
1240
+
1241
+ # Allocate only the measured content width plus minimal side padding.
1242
+ $w = $maxContentW + ($m.PadX * 2) + (Scale-HudValue 2)
1243
+ $w = [math]::Max((Scale-HudValue 32), [math]::Min((Scale-HudValue 56), $w))
1244
+ return [System.Drawing.Size]::new([int]$w, [int]$h)
1245
+ }
1246
+
1247
+ function Draw-FittedRailText($Graphics, [string]$Text, [string]$Family, [single]$StartPx, [System.Drawing.FontStyle]$Style, [System.Drawing.Rectangle]$Rect, [System.Drawing.Color]$Color, [System.Drawing.Color]$BackColor, [int]$FitMaxWidth = 0) {
1248
+ if ([string]::IsNullOrEmpty($Text)) { return }
1249
+ $measureFlags = [System.Windows.Forms.TextFormatFlags]::HorizontalCenter -bor [System.Windows.Forms.TextFormatFlags]::VerticalCenter -bor [System.Windows.Forms.TextFormatFlags]::SingleLine -bor [System.Windows.Forms.TextFormatFlags]::NoPadding -bor [System.Windows.Forms.TextFormatFlags]::NoPrefix
1250
+ $drawFlags = [System.Windows.Forms.TextFormatFlags]::HorizontalCenter -bor [System.Windows.Forms.TextFormatFlags]::VerticalCenter -bor [System.Windows.Forms.TextFormatFlags]::SingleLine -bor [System.Windows.Forms.TextFormatFlags]::NoPadding -bor [System.Windows.Forms.TextFormatFlags]::NoPrefix -bor [System.Windows.Forms.TextFormatFlags]::PreserveGraphicsTranslateTransform
1251
+ $fitLimit = if ($FitMaxWidth -gt 0) { $FitMaxWidth } else { [math]::Max(10, $Rect.Width - 6) }
1252
+ $px = $StartPx
1253
+ $minPx = [single][math]::Max(7.0, (Scale-HudValue 7))
1254
+ $drawFont = $null
1255
+ try {
1256
+ while ($true) {
1257
+ if ($drawFont) { $drawFont.Dispose() }
1258
+ $drawFont = [System.Drawing.Font]::new($Family, $px, $Style, [System.Drawing.GraphicsUnit]::Pixel)
1259
+ $sz = [System.Windows.Forms.TextRenderer]::MeasureText($Text, $drawFont, [System.Drawing.Size]::new(256, 64), $measureFlags)
1260
+ if ($sz.Width -le $fitLimit -or $px -le $minPx) { break }
1261
+ $px = [single][math]::Max($minPx, $px - 0.5)
1262
+ }
1263
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $Text, $drawFont, $Rect, $Color, $BackColor, $drawFlags)
1264
+ } finally {
1265
+ if ($drawFont) { $drawFont.Dispose() }
1266
+ }
1267
+ }
1268
+
1269
+ function Draw-VerticalRailHud($Graphics, [int]$Width, [int]$Height, $Texts, $CustomBackColor = $null, $CustomBorderColor = $null) {
1270
+ $Graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
1271
+ $Graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::Default
1272
+
1273
+ $backColor = if ($null -ne $CustomBackColor) {
1274
+ $CustomBackColor
1275
+ } elseif ($script:hudContrastBackdrop -or (-not $script:hudTransparentSurface)) {
1276
+ if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(244, 244, 248) } else { [System.Drawing.Color]::FromArgb(28, 28, 32) }
1277
+ } elseif ($script:hudDarkText) {
1278
+ [System.Drawing.Color]::FromArgb(254, 254, 254)
1279
+ } else {
1280
+ [System.Drawing.Color]::FromArgb(18, 18, 18)
1281
+ }
1282
+
1283
+ if ($null -ne $CustomBackColor -or $script:hudContrastBackdrop -or (-not $script:hudTransparentSurface)) {
1284
+ $radius = [single][math]::Min((Scale-HudValue 6), [math]::Floor(($Width - 2) / 2))
1285
+ $bgPath = New-RoundedRectPath ([single]0.5) ([single]0.5) ([single]($Width - 1)) ([single]($Height - 1)) $radius
1286
+ $bgBrush = [System.Drawing.SolidBrush]::new($backColor)
1287
+ $borderColor = if ($null -ne $CustomBorderColor) {
1288
+ $CustomBorderColor
1289
+ } elseif ($script:hudDarkText) {
1290
+ [System.Drawing.Color]::FromArgb(196, 196, 204)
1291
+ } else {
1292
+ [System.Drawing.Color]::FromArgb(68, 68, 74)
1293
+ }
1294
+ $borderPen = [System.Drawing.Pen]::new($borderColor, 1.0)
1295
+ try {
1296
+ $Graphics.FillPath($bgBrush, $bgPath)
1297
+ $Graphics.DrawPath($borderPen, $bgPath)
1298
+ } finally {
1299
+ $bgBrush.Dispose()
1300
+ $borderPen.Dispose()
1301
+ $bgPath.Dispose()
1302
+ }
1303
+ }
1304
+
1305
+ $rows = if ($Texts -and $Texts.Rows -and $Texts.Rows.Count -gt 0) { $Texts.Rows } else { @() }
1306
+ if ($rows.Count -eq 0) {
1307
+ $msgRect = [System.Drawing.Rectangle]::new(2, [int][math]::Floor($Height / 2) - (Scale-HudValue 8), ($Width - 4), (Scale-HudValue 16))
1308
+ Draw-FittedRailText $Graphics "AI--" "Cascadia Mono" ([single](Scale-HudValue 10)) ([System.Drawing.FontStyle]::Bold) $msgRect (Get-HudMutedTextColor) $backColor
1309
+ return
1310
+ }
1311
+
1312
+ $m = Get-VerticalRailMetrics
1313
+ $padX = $m.PadX
1314
+ $innerW = [math]::Max(12, $Width - ($padX * 2))
1315
+ $divInset = [math]::Min([int][math]::Floor($Width / 4), $padX + (Scale-HudValue 1))
1316
+ $y = $m.PadY
1317
+ $tagH = $m.TagH
1318
+ $batH = $m.BatH
1319
+ $pctH = $m.PctH
1320
+ $valH = $m.ValH
1321
+ $lblH = $m.LblH
1322
+ $divGap = $m.DivGap
1323
+ $divColor = if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(170, 170, 180) } else { [System.Drawing.Color]::FromArgb(74, 74, 84) }
1324
+ $divPen = [System.Drawing.Pen]::new($divColor, 1.0)
1325
+
1326
+ try {
1327
+ $idx = 0
1328
+ foreach ($row in $rows) {
1329
+ if ($idx -gt 0) {
1330
+ $divY = $y + [int][math]::Floor($divGap / 2)
1331
+ $Graphics.DrawLine($divPen, $divInset, $divY, ($Width - $divInset), $divY)
1332
+ $y += $divGap
1333
+ }
1334
+ $parts = $row.Parts
1335
+ $items = Get-VerticalRailRowStrings $row
1336
+ $running = [bool]$parts.Running
1337
+ $percent = $parts.Percent
1338
+ $primaryColor = if ($running) {
1339
+ if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(20, 20, 24) } else { [System.Drawing.Color]::FromArgb(245, 245, 247) }
1340
+ } else {
1341
+ if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(108, 108, 116) } else { [System.Drawing.Color]::FromArgb(154, 154, 164) }
1342
+ }
1343
+ $mutedColor = if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(120, 120, 128) } else { [System.Drawing.Color]::FromArgb(128, 128, 138) }
1344
+
1345
+ # 1. AGY (blue) / CDX (white) / CLD (orange)
1346
+ $tagColor = Get-VerticalRailTagColor ([string]$row.Provider) $running
1347
+ $tagRect = [System.Drawing.Rectangle]::new(0, $y, $Width, $tagH)
1348
+ Draw-FittedRailText $Graphics $items.Tag "Cascadia Mono" ([single](Scale-HudValue 12)) ([System.Drawing.FontStyle]::Bold) $tagRect $tagColor $backColor $innerW
1349
+ $y += $tagH + $m.TagGap
1350
+
1351
+ # 2. Vertical battery gauge (centered slim rail + bottom-to-top fill)
1352
+ $cx = [int][math]::Floor($Width / 2)
1353
+ $railW = [math]::Max(2, (Scale-HudValue 2))
1354
+ $barW = [math]::Max(6, (Scale-HudValue 8))
1355
+ $railBrush = [System.Drawing.SolidBrush]::new($(if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(180, 180, 188) } else { [System.Drawing.Color]::FromArgb(84, 84, 94) }))
1356
+ try {
1357
+ $Graphics.FillRectangle($railBrush, [int]($cx - [math]::Floor($railW / 2)), $y, $railW, $batH)
1358
+ } finally {
1359
+ $railBrush.Dispose()
1360
+ }
1361
+ if ($null -ne $percent) {
1362
+ $clamped = [math]::Max(0, [math]::Min(100, [int]$percent))
1363
+ $fillH = [int][math]::Round(($clamped / 100.0) * $batH)
1364
+ if ($clamped -gt 0 -and $fillH -lt 2) { $fillH = 2 }
1365
+ if ($fillH -gt 0) {
1366
+ $fillColor = Get-MenuBatteryFillColor $percent $running
1367
+ $fillBrush = [System.Drawing.SolidBrush]::new($fillColor)
1368
+ try {
1369
+ $Graphics.FillRectangle($fillBrush, [int]($cx - [math]::Floor($barW / 2)), ($y + $batH - $fillH), $barW, $fillH)
1370
+ } finally {
1371
+ $fillBrush.Dispose()
1372
+ }
1373
+ }
1374
+ }
1375
+ $y += $batH + $m.BatGap
1376
+
1377
+ # 3. Percent directly below battery
1378
+ $pctColor = if ($running) { Get-MenuBatteryFillColor $percent $true } else { $primaryColor }
1379
+ $pctRect = [System.Drawing.Rectangle]::new(0, $y, $Width, $pctH)
1380
+ Draw-FittedRailText $Graphics $items.PctText "Segoe UI" ([single](Scale-HudValue 11)) ([System.Drawing.FontStyle]::Bold) $pctRect $pctColor $backColor $innerW
1381
+ $y += $pctH + $m.PctGap
1382
+
1383
+ # 4. Primary window label (e.g. "5h") + reset time beneath
1384
+ $fiveLblRect = [System.Drawing.Rectangle]::new(0, $y, $Width, $lblH)
1385
+ Draw-FittedRailText $Graphics $items.PrimaryLbl "Segoe UI" ([single](Scale-HudValue 8.5)) ([System.Drawing.FontStyle]::Regular) $fiveLblRect $mutedColor $backColor $innerW
1386
+ $y += $lblH
1387
+ $resetRect = [System.Drawing.Rectangle]::new(0, $y, $Width, $valH)
1388
+ Draw-FittedRailText $Graphics $items.ResetVal "Cascadia Mono" ([single](Scale-HudValue 10)) ([System.Drawing.FontStyle]::Regular) $resetRect $primaryColor $backColor $innerW
1389
+ $y += $valH + $m.PairGap
1390
+
1391
+ # 5. Secondary window label (e.g. "7d") + weekly % beneath
1392
+ $weekLblRect = [System.Drawing.Rectangle]::new(0, $y, $Width, $lblH)
1393
+ Draw-FittedRailText $Graphics $items.WeekLbl "Segoe UI" ([single](Scale-HudValue 8.5)) ([System.Drawing.FontStyle]::Regular) $weekLblRect $mutedColor $backColor $innerW
1394
+ $y += $lblH
1395
+ $weekRect = [System.Drawing.Rectangle]::new(0, $y, $Width, $valH)
1396
+ Draw-FittedRailText $Graphics $items.WeekVal "Cascadia Mono" ([single](Scale-HudValue 10)) ([System.Drawing.FontStyle]::Regular) $weekRect $primaryColor $backColor $innerW
1397
+ $y += $valH
1398
+ $idx += 1
1399
+ }
1400
+ } finally {
1401
+ $divPen.Dispose()
1402
+ }
1403
+ }
1404
+
1405
+ function Format-DetailResetText([string]$Value) {
1406
+ if ([string]::IsNullOrWhiteSpace($Value)) { return "" }
1407
+ # Widen the space between the window label (e.g. "5h") and time ("18:34" / "--:--").
1408
+ return ($Value -replace '^(\S+)\s+(.+)$', '$1 $2')
1409
+ }
1410
+
1411
+ function Get-HorizontalDetailCardLayout($Texts) {
1412
+ $rows = if ($Texts -and $Texts.Rows -and $Texts.Rows.Count -gt 0) { $Texts.Rows } else { @() }
1413
+ $rowCount = [math]::Max(1, $rows.Count)
1414
+ $padX = Scale-HudValue 14
1415
+ $padY = Scale-HudValue 8
1416
+ $rowH = Scale-HudValue 36
1417
+ $footerH = Scale-HudValue 34
1418
+ $nameW = Scale-HudValue 52
1419
+ $barX = $padX + $nameW + (Scale-HudValue 12)
1420
+ $barW = Scale-HudValue 116
1421
+ $barH = Scale-HudValue 8
1422
+ $pctX = $barX + $barW + (Scale-HudValue 10)
1423
+ $pctW = Scale-HudValue 40
1424
+ $resetX = $pctX + $pctW + (Scale-HudValue 14)
1425
+
1426
+ $metaFont = [System.Drawing.Font]::new("Segoe UI", [single](Scale-HudValue 12), [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Pixel)
1427
+ $flags = [System.Windows.Forms.TextFormatFlags]::NoPadding -bor [System.Windows.Forms.TextFormatFlags]::SingleLine -bor [System.Windows.Forms.TextFormatFlags]::NoPrefix
1428
+ $resetW = Scale-HudValue 48
1429
+ $weekW = Scale-HudValue 46
1430
+ $extraW = 0
1431
+ $hasWeek = $false
1432
+ try {
1433
+ foreach ($row in $rows) {
1434
+ $p = $row.Parts
1435
+ if ($p.ResetValue) {
1436
+ $resetDisplay = Format-DetailResetText ([string]$p.ResetValue)
1437
+ $sz = [System.Windows.Forms.TextRenderer]::MeasureText($resetDisplay, $metaFont, [System.Drawing.Size]::new(512, 64), $flags)
1438
+ $resetW = [math]::Max($resetW, [int]$sz.Width + (Scale-HudValue 2))
1439
+ }
1440
+ if ($p.WeekValue) {
1441
+ $hasWeek = $true
1442
+ $sz = [System.Windows.Forms.TextRenderer]::MeasureText([string]$p.WeekValue, $metaFont, [System.Drawing.Size]::new(512, 64), $flags)
1443
+ $weekW = [math]::Max($weekW, [int]$sz.Width + (Scale-HudValue 2))
1444
+ }
1445
+ if (-not $p.ResetValue -and -not $p.WeekValue -and $p.ExtraText) {
1446
+ $sz = [System.Windows.Forms.TextRenderer]::MeasureText([string]$p.ExtraText, $metaFont, [System.Drawing.Size]::new(512, 64), $flags)
1447
+ $extraW = [math]::Max($extraW, [int]$sz.Width + (Scale-HudValue 2))
1448
+ }
1449
+ }
1450
+ } finally {
1451
+ $metaFont.Dispose()
1452
+ }
1453
+
1454
+ $metaGap = Scale-HudValue 14
1455
+ $weekX = $resetX + $resetW + $metaGap
1456
+ $metaRight = if ($hasWeek) { $weekX + $weekW } else { $resetX + [math]::Max($resetW, $extraW) }
1457
+ $metaRight = [math]::Max($metaRight, ($resetX + $extraW))
1458
+ $width = [math]::Max((Scale-HudValue 400), ($metaRight + $padX))
1459
+ # Shift week/reset right if card hit minimum width so right edge stays balanced.
1460
+ $extraShift = ($width - $padX) - $metaRight
1461
+ if ($extraShift -gt 0) {
1462
+ $resetX += $extraShift
1463
+ $weekX += $extraShift
1464
+ }
1465
+ $height = ($rowCount * $rowH) + ($padY * 2) + $footerH
1466
+
1467
+ return @{
1468
+ Width = [int]$width
1469
+ Height = [int]$height
1470
+ PadX = [int]$padX
1471
+ PadY = [int]$padY
1472
+ RowH = [int]$rowH
1473
+ FooterH = [int]$footerH
1474
+ NameX = [int]$padX
1475
+ NameW = [int]$nameW
1476
+ BarX = [int]$barX
1477
+ BarW = [int]$barW
1478
+ BarH = [int]$barH
1479
+ PctX = [int]$pctX
1480
+ PctW = [int]$pctW
1481
+ ResetX = [int]$resetX
1482
+ ResetW = [int]$resetW
1483
+ WeekX = [int]$weekX
1484
+ WeekW = [int]$weekW
1485
+ }
1486
+ }
1487
+
1488
+ function Get-HorizontalDetailCardSize($Texts) {
1489
+ $layout = Get-HorizontalDetailCardLayout $Texts
1490
+ return [System.Drawing.Size]::new($layout.Width, $layout.Height)
1491
+ }
1492
+
1493
+ function Get-HorizontalDetailFooterRects([int]$Width, [int]$Height) {
1494
+ $footerH = Scale-HudValue 34
1495
+ $y = $Height - $footerH
1496
+ $btnW = Scale-HudValue 86
1497
+ return @{
1498
+ Refresh = [System.Drawing.Rectangle]::new((Scale-HudValue 14), $y, $btnW, $footerH)
1499
+ Quit = [System.Drawing.Rectangle]::new(($Width - $btnW - (Scale-HudValue 14)), $y, $btnW, $footerH)
1500
+ }
1501
+ }
1502
+
1503
+ function Draw-HorizontalDetailCard($Graphics, [int]$Width, [int]$Height, $Texts) {
1504
+ $Graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
1505
+ $Graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
1506
+ $Graphics.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::ClearTypeGridFit
1507
+
1508
+ $bgPath = New-RoundedRectPath ([single]0.5) ([single]0.5) ([single]($Width - 1)) ([single]($Height - 1)) ([single](Scale-HudValue 10))
1509
+ $bgBrush = [System.Drawing.SolidBrush]::new([System.Drawing.Color]::FromArgb(38, 38, 43))
1510
+ $borderPen = [System.Drawing.Pen]::new([System.Drawing.Color]::FromArgb(72, 72, 78), 1.0)
1511
+ try {
1512
+ $Graphics.FillPath($bgBrush, $bgPath)
1513
+ $Graphics.DrawPath($borderPen, $bgPath)
1514
+ } finally {
1515
+ $bgBrush.Dispose()
1516
+ $borderPen.Dispose()
1517
+ $bgPath.Dispose()
1518
+ }
1519
+
1520
+ $layout = Get-HorizontalDetailCardLayout $Texts
1521
+ $nameFont = [System.Drawing.Font]::new("Segoe UI", [single](Scale-HudValue 13), [System.Drawing.FontStyle]::Bold, [System.Drawing.GraphicsUnit]::Pixel)
1522
+ $metaFont = [System.Drawing.Font]::new("Segoe UI", [single](Scale-HudValue 12), [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Pixel)
1523
+ $footerFont = [System.Drawing.Font]::new("Segoe UI", [single](Scale-HudValue 12), [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Pixel)
1524
+ $leftFlags = [System.Windows.Forms.TextFormatFlags]::Left -bor [System.Windows.Forms.TextFormatFlags]::VerticalCenter -bor [System.Windows.Forms.TextFormatFlags]::SingleLine -bor [System.Windows.Forms.TextFormatFlags]::NoPadding -bor [System.Windows.Forms.TextFormatFlags]::NoPrefix
1525
+ $rightFlags = [System.Windows.Forms.TextFormatFlags]::Right -bor [System.Windows.Forms.TextFormatFlags]::VerticalCenter -bor [System.Windows.Forms.TextFormatFlags]::SingleLine -bor [System.Windows.Forms.TextFormatFlags]::NoPadding -bor [System.Windows.Forms.TextFormatFlags]::NoPrefix
1526
+ $centerFlags = [System.Windows.Forms.TextFormatFlags]::HorizontalCenter -bor [System.Windows.Forms.TextFormatFlags]::VerticalCenter -bor [System.Windows.Forms.TextFormatFlags]::SingleLine -bor [System.Windows.Forms.TextFormatFlags]::NoPadding -bor [System.Windows.Forms.TextFormatFlags]::NoPrefix
1527
+
1528
+ try {
1529
+ $rows = if ($Texts -and $Texts.Rows -and $Texts.Rows.Count -gt 0) { $Texts.Rows } else { @() }
1530
+ $idx = 0
1531
+ foreach ($row in $rows) {
1532
+ $y = $layout.PadY + ($idx * $layout.RowH)
1533
+ $parts = $row.Parts
1534
+ $running = [bool]$parts.Running
1535
+ $percent = $parts.Percent
1536
+ $primaryColor = if ($running) { [System.Drawing.Color]::FromArgb(245, 245, 247) } else { [System.Drawing.Color]::FromArgb(161, 161, 170) }
1537
+ $metaColor = if ($running) { [System.Drawing.Color]::FromArgb(161, 161, 170) } else { [System.Drawing.Color]::FromArgb(142, 142, 147) }
1538
+
1539
+ $label = switch ([string]$row.Provider) {
1540
+ "claude" { "Claude" }
1541
+ "antigravity" { "Gemini" }
1542
+ default { "Codex" }
1543
+ }
1544
+ $nameRect = [System.Drawing.Rectangle]::new($layout.NameX, $y, $layout.NameW, $layout.RowH)
1545
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $label, $nameFont, $nameRect, $primaryColor, $leftFlags)
1546
+
1547
+ $barY = [single]($y + (($layout.RowH - $layout.BarH) / 2.0))
1548
+ $trackPath = New-RoundedRectPath ([single]$layout.BarX) $barY ([single]$layout.BarW) ([single]$layout.BarH) ([single]($layout.BarH / 2.0))
1549
+ $trackBrush = [System.Drawing.SolidBrush]::new([System.Drawing.Color]::FromArgb($(if ($running) { 26 } else { 15 }), 255, 255, 255))
1550
+ $trackPen = [System.Drawing.Pen]::new([System.Drawing.Color]::FromArgb($(if ($running) { 36 } else { 61 }), 255, 255, 255), 1.0)
1551
+ try {
1552
+ $Graphics.FillPath($trackBrush, $trackPath)
1553
+ $Graphics.DrawPath($trackPen, $trackPath)
1554
+ } finally {
1555
+ $trackBrush.Dispose()
1556
+ $trackPen.Dispose()
1557
+ $trackPath.Dispose()
1558
+ }
1559
+
1560
+ if ($null -ne $percent) {
1561
+ $clamped = [math]::Max(0, [math]::Min(100, [int]$percent))
1562
+ $fillW = [single](($clamped / 100.0) * $layout.BarW)
1563
+ if ($clamped -gt 0 -and $fillW -lt (Scale-HudValue 4)) { $fillW = [single](Scale-HudValue 4) }
1564
+ if ($fillW -gt 0.5) {
1565
+ $fillPath = New-RoundedRectPath ([single]$layout.BarX) $barY $fillW ([single]$layout.BarH) ([single]($layout.BarH / 2.0))
1566
+ $fillColor = if (-not $running) {
1567
+ [System.Drawing.Color]::FromArgb(161, 161, 170)
1568
+ } elseif ($clamped -le 20) {
1569
+ [System.Drawing.Color]::FromArgb(255, 69, 58)
1570
+ } elseif ($clamped -le 40) {
1571
+ [System.Drawing.Color]::FromArgb(255, 159, 10)
1572
+ } else {
1573
+ [System.Drawing.Color]::FromArgb(48, 209, 88)
1574
+ }
1575
+ $fillBrush = [System.Drawing.SolidBrush]::new($fillColor)
1576
+ try {
1577
+ $Graphics.FillPath($fillBrush, $fillPath)
1578
+ } finally {
1579
+ $fillBrush.Dispose()
1580
+ $fillPath.Dispose()
1581
+ }
1582
+ }
1583
+ }
1584
+
1585
+ $pctText = if ($null -eq $percent) { "--%" } else { "$([int]$percent)%" }
1586
+ $pctRect = [System.Drawing.Rectangle]::new($layout.PctX, $y, $layout.PctW, $layout.RowH)
1587
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $pctText, $nameFont, $pctRect, $primaryColor, $rightFlags)
1588
+
1589
+ if ($parts.ResetValue -or $parts.WeekValue) {
1590
+ if ($parts.ResetValue) {
1591
+ $resetRect = [System.Drawing.Rectangle]::new($layout.ResetX, $y, $layout.ResetW, $layout.RowH)
1592
+ $resetDisplay = Format-DetailResetText ([string]$parts.ResetValue)
1593
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $resetDisplay, $metaFont, $resetRect, $metaColor, $leftFlags)
1594
+ }
1595
+ if ($parts.WeekValue) {
1596
+ $weekRect = [System.Drawing.Rectangle]::new($layout.WeekX, $y, $layout.WeekW, $layout.RowH)
1597
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, [string]$parts.WeekValue, $metaFont, $weekRect, $metaColor, $leftFlags)
1598
+ }
1599
+ } elseif ($parts.ExtraText) {
1600
+ $extraW = [math]::Max(1, ($Width - $layout.PadX) - $layout.ResetX)
1601
+ $extraRect = [System.Drawing.Rectangle]::new($layout.ResetX, $y, $extraW, $layout.RowH)
1602
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, [string]$parts.ExtraText, $metaFont, $extraRect, $metaColor, $rightFlags)
1603
+ }
1604
+ $idx += 1
1605
+ }
1606
+
1607
+ $divY = $Height - $layout.FooterH
1608
+ $divPen = [System.Drawing.Pen]::new([System.Drawing.Color]::FromArgb(62, 62, 68), 1.0)
1609
+ try {
1610
+ $Graphics.DrawLine($divPen, $layout.PadX, $divY, ($Width - $layout.PadX), $divY)
1611
+ } finally {
1612
+ $divPen.Dispose()
1613
+ }
1614
+
1615
+ $rects = Get-HorizontalDetailFooterRects $Width $Height
1616
+ $footerColor = [System.Drawing.Color]::FromArgb(200, 200, 206)
1617
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, "Refresh", $footerFont, $rects.Refresh, $footerColor, $leftFlags)
1618
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, "Quit", $footerFont, $rects.Quit, $footerColor, $rightFlags)
1619
+ } finally {
1620
+ $nameFont.Dispose()
1621
+ $metaFont.Dispose()
1622
+ $footerFont.Dispose()
1623
+ }
1624
+ }