ai-battery 0.2.0 → 0.2.2

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 (48) hide show
  1. package/README.md +30 -14
  2. package/bin/ai-battery-macos-rail.applescript +227 -0
  3. package/bin/ai-battery-macos-status.applescript +5 -12
  4. package/bin/ai-battery-run +701 -31
  5. package/bin/ai-battery-tmux.js +17 -0
  6. package/bin/terminal-compositor.js +111 -0
  7. package/docs/REFERENCE.md +23 -3
  8. package/docs/RELEASING.md +30 -7
  9. package/docs/WINDOWS-TERMINAL-SHARED-BAR.md +74 -0
  10. package/docs/hud-preview.svg +75 -20
  11. package/docs/terminal-vertical-preview.svg +73 -0
  12. package/lib/cli.js +1148 -240
  13. package/lib/core/atomic-rename.js +18 -0
  14. package/lib/core/cli-help.js +57 -12
  15. package/lib/core/cli-messages.js +45 -1
  16. package/lib/core/cli-output.js +277 -72
  17. package/lib/core/cli-wrappers.js +410 -0
  18. package/lib/core/config-editor.js +194 -29
  19. package/lib/core/display-config.js +45 -0
  20. package/lib/core/integration-files.js +32 -3
  21. package/lib/core/shared-bar.js +603 -0
  22. package/lib/core/statusline-git.js +179 -15
  23. package/lib/core/terminal.js +25 -7
  24. package/lib/core/tmux-status.js +172 -0
  25. package/lib/core/uninstall.js +20 -7
  26. package/lib/core/usage-store.js +85 -0
  27. package/lib/hud/launcher.js +32 -33
  28. package/lib/platforms/linux/gnome-extension/extension.js +7 -6
  29. package/lib/platforms/linux/hud.js +157 -42
  30. package/lib/platforms/linux/panel.js +16 -3
  31. package/lib/platforms/linux/rail.js +412 -0
  32. package/lib/platforms/macos/hud.js +152 -44
  33. package/lib/platforms/process-scanner.js +77 -29
  34. package/lib/platforms/windows/autostart-cleanup.js +1 -1
  35. package/lib/platforms/windows/codex-runner.js +178 -21
  36. package/lib/platforms/windows/hud/controls.ps1 +65 -15
  37. package/lib/platforms/windows/hud/main.ps1 +715 -54
  38. package/lib/platforms/windows/hud/rendering.ps1 +1284 -2
  39. package/lib/platforms/windows/hud/snapshot.ps1 +26 -46
  40. package/lib/platforms/windows/hud-launcher.js +234 -81
  41. package/lib/platforms/windows/shared-bar-platform.js +972 -0
  42. package/lib/platforms/windows/terminal-compositor.js +210 -25
  43. package/lib/platforms/windows/wt-bar.js +729 -0
  44. package/lib/platforms/windows/wt-fragment.js +665 -0
  45. package/lib/platforms/windows/wt-keybinding.js +300 -0
  46. package/lib/providers/antigravity.js +155 -8
  47. package/package.json +6 -2
  48. 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
  }
@@ -35,10 +35,23 @@ function Get-HudDpi {
35
35
  return 96
36
36
  }
37
37
 
38
+ function Clamp-HudUserScale([double]$Value) {
39
+ if ([double]::IsNaN($Value) -or [double]::IsInfinity($Value) -or $Value -le 0) { return 1.0 }
40
+ return [math]::Round([math]::Max(0.5, [math]::Min(3.0, $Value)), 2)
41
+ }
42
+
38
43
  function Update-HudDpiScale {
39
44
  $dpi = [math]::Max(96, (Get-HudDpi))
40
45
  $script:hudDpi = [int]$dpi
41
- $script:hudScale = [double]$script:hudDpi / 96.0
46
+ $script:hudDpiScale = [double]$script:hudDpi / 96.0
47
+ $userScale = if ($DockWindowHandle -ne 0) {
48
+ 1.0
49
+ } elseif ($null -ne $script:hudUserScale -and $script:hudUserScale -gt 0) {
50
+ Clamp-HudUserScale $script:hudUserScale
51
+ } else {
52
+ 1.0
53
+ }
54
+ $script:hudScale = $script:hudDpiScale * $userScale
42
55
  }
43
56
 
44
57
  function Scale-HudValue([double]$Value) {
@@ -48,6 +61,18 @@ function Scale-HudValue([double]$Value) {
48
61
  return $scaled
49
62
  }
50
63
 
64
+ function Scale-HudDpiValue([double]$Value) {
65
+ if ($Value -eq 0) { return 0 }
66
+ $baseScale = if ($null -ne $script:hudDpiScale -and $script:hudDpiScale -gt 0) {
67
+ [double]$script:hudDpiScale
68
+ } else {
69
+ [double]$script:hudScale
70
+ }
71
+ $scaled = [int][math]::Round($Value * $baseScale)
72
+ if ($Value -gt 0) { return [math]::Max(1, $scaled) }
73
+ return $scaled
74
+ }
75
+
51
76
  function New-HudPadding([int]$Left, [int]$Top, [int]$Right, [int]$Bottom) {
52
77
  return [System.Windows.Forms.Padding]::new(
53
78
  (Scale-HudValue $Left),
@@ -396,3 +421,1260 @@ function Dispose-StatusMenuRow($Row) {
396
421
  $Row.Icon.Image = $null
397
422
  }
398
423
  }
424
+
425
+ $script:brandSvgRendererReady = $false
426
+
427
+ function Initialize-BrandSvgRenderer {
428
+ if ($script:brandSvgRendererReady) { return $true }
429
+ if ("AiBatterySvgIcons" -as [type]) {
430
+ $script:brandSvgRendererReady = $true
431
+ return $true
432
+ }
433
+
434
+ $svgCode = @'
435
+ using System;
436
+ using System.Collections.Generic;
437
+ using System.Drawing;
438
+ using System.Drawing.Drawing2D;
439
+ using System.Drawing.Imaging;
440
+ using System.Globalization;
441
+ using System.Runtime.InteropServices;
442
+
443
+ public static class AiBatterySvgIcons {
444
+ // Exact SVG paths matching lib/cli.js MENU_BAR_BRAND_ICONS and docs/antigravity-icon.svg.
445
+ 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";
446
+
447
+ 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";
448
+
449
+ 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";
450
+
451
+ 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";
452
+ 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";
453
+
454
+ private static readonly Dictionary<string, Bitmap> Cache = new Dictionary<string, Bitmap>();
455
+ private static Bitmap AntigravityFieldCache = null;
456
+
457
+ public static GraphicsPath ParseSvgPath(string d, FillMode fillMode) {
458
+ var path = new GraphicsPath(fillMode);
459
+ if (string.IsNullOrEmpty(d)) return path;
460
+
461
+ int i = 0;
462
+ int len = d.Length;
463
+ char cmd = '\0';
464
+ char prevCmd = '\0';
465
+ float cx = 0f, cy = 0f, sx = 0f, sy = 0f;
466
+ float lastC2X = 0f, lastC2Y = 0f;
467
+ float lastQ1X = 0f, lastQ1Y = 0f;
468
+
469
+ while (i < len) {
470
+ SkipSeparators(d, ref i);
471
+ if (i >= len) break;
472
+
473
+ char ch = d[i];
474
+ if (IsCommandChar(ch)) {
475
+ cmd = ch;
476
+ i++;
477
+ } else if (cmd == '\0') {
478
+ break;
479
+ }
480
+
481
+ if (cmd == 'Z' || cmd == 'z') {
482
+ path.CloseFigure();
483
+ cx = sx;
484
+ cy = sy;
485
+ prevCmd = cmd;
486
+ cmd = '\0';
487
+ continue;
488
+ }
489
+
490
+ switch (cmd) {
491
+ case 'M':
492
+ case 'm': {
493
+ float x = ReadNumber(d, ref i);
494
+ float y = ReadNumber(d, ref i);
495
+ if (cmd == 'm') { x += cx; y += cy; }
496
+ path.StartFigure();
497
+ cx = sx = x;
498
+ cy = sy = y;
499
+ prevCmd = cmd;
500
+ cmd = (cmd == 'm') ? 'l' : 'L';
501
+ break;
502
+ }
503
+ case 'L':
504
+ case 'l': {
505
+ float x = ReadNumber(d, ref i);
506
+ float y = ReadNumber(d, ref i);
507
+ if (cmd == 'l') { x += cx; y += cy; }
508
+ path.AddLine(cx, cy, x, y);
509
+ cx = x; cy = y;
510
+ prevCmd = cmd;
511
+ break;
512
+ }
513
+ case 'H':
514
+ case 'h': {
515
+ float x = ReadNumber(d, ref i);
516
+ if (cmd == 'h') x += cx;
517
+ path.AddLine(cx, cy, x, cy);
518
+ cx = x;
519
+ prevCmd = cmd;
520
+ break;
521
+ }
522
+ case 'V':
523
+ case 'v': {
524
+ float y = ReadNumber(d, ref i);
525
+ if (cmd == 'v') y += cy;
526
+ path.AddLine(cx, cy, cx, y);
527
+ cy = y;
528
+ prevCmd = cmd;
529
+ break;
530
+ }
531
+ case 'C':
532
+ case 'c': {
533
+ float x1 = ReadNumber(d, ref i);
534
+ float y1 = ReadNumber(d, ref i);
535
+ float x2 = ReadNumber(d, ref i);
536
+ float y2 = ReadNumber(d, ref i);
537
+ float x = ReadNumber(d, ref i);
538
+ float y = ReadNumber(d, ref i);
539
+ if (cmd == 'c') {
540
+ x1 += cx; y1 += cy;
541
+ x2 += cx; y2 += cy;
542
+ x += cx; y += cy;
543
+ }
544
+ path.AddBezier(cx, cy, x1, y1, x2, y2, x, y);
545
+ lastC2X = x2; lastC2Y = y2;
546
+ cx = x; cy = y;
547
+ prevCmd = cmd;
548
+ break;
549
+ }
550
+ case 'S':
551
+ case 's': {
552
+ float x1 = (prevCmd == 'C' || prevCmd == 'c' || prevCmd == 'S' || prevCmd == 's') ? (2f * cx - lastC2X) : cx;
553
+ float y1 = (prevCmd == 'C' || prevCmd == 'c' || prevCmd == 'S' || prevCmd == 's') ? (2f * cy - lastC2Y) : cy;
554
+ float x2 = ReadNumber(d, ref i);
555
+ float y2 = ReadNumber(d, ref i);
556
+ float x = ReadNumber(d, ref i);
557
+ float y = ReadNumber(d, ref i);
558
+ if (cmd == 's') {
559
+ x2 += cx; y2 += cy;
560
+ x += cx; y += cy;
561
+ }
562
+ path.AddBezier(cx, cy, x1, y1, x2, y2, x, y);
563
+ lastC2X = x2; lastC2Y = y2;
564
+ cx = x; cy = y;
565
+ prevCmd = cmd;
566
+ break;
567
+ }
568
+ case 'Q':
569
+ case 'q': {
570
+ float qx = ReadNumber(d, ref i);
571
+ float qy = ReadNumber(d, ref i);
572
+ float x = ReadNumber(d, ref i);
573
+ float y = ReadNumber(d, ref i);
574
+ if (cmd == 'q') {
575
+ qx += cx; qy += cy;
576
+ x += cx; y += cy;
577
+ }
578
+ float c1x = cx + (2f / 3f) * (qx - cx);
579
+ float c1y = cy + (2f / 3f) * (qy - cy);
580
+ float c2x = x + (2f / 3f) * (qx - x);
581
+ float c2y = y + (2f / 3f) * (qy - y);
582
+ path.AddBezier(cx, cy, c1x, c1y, c2x, c2y, x, y);
583
+ lastQ1X = qx; lastQ1Y = qy;
584
+ cx = x; cy = y;
585
+ prevCmd = cmd;
586
+ break;
587
+ }
588
+ default:
589
+ i++;
590
+ break;
591
+ }
592
+ }
593
+ return path;
594
+ }
595
+
596
+ private static bool IsCommandChar(char c) {
597
+ return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
598
+ }
599
+
600
+ private static void SkipSeparators(string s, ref int i) {
601
+ while (i < s.Length) {
602
+ char c = s[i];
603
+ if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == ',') i++;
604
+ else break;
605
+ }
606
+ }
607
+
608
+ private static float ReadNumber(string s, ref int i) {
609
+ SkipSeparators(s, ref i);
610
+ int start = i;
611
+ if (i < s.Length && (s[i] == '+' || s[i] == '-')) i++;
612
+ bool hasDot = false;
613
+ while (i < s.Length) {
614
+ char c = s[i];
615
+ if (c >= '0' && c <= '9') {
616
+ i++;
617
+ } else if (c == '.' && !hasDot) {
618
+ hasDot = true;
619
+ i++;
620
+ } else {
621
+ break;
622
+ }
623
+ }
624
+ if (i < s.Length && (s[i] == 'e' || s[i] == 'E')) {
625
+ int expStart = i;
626
+ i++;
627
+ if (i < s.Length && (s[i] == '+' || s[i] == '-')) i++;
628
+ int digitStart = i;
629
+ while (i < s.Length && s[i] >= '0' && s[i] <= '9') i++;
630
+ if (i == digitStart) i = expStart;
631
+ }
632
+ if (i == start) return 0f;
633
+ float value;
634
+ if (float.TryParse(s.Substring(start, i - start), NumberStyles.Float, CultureInfo.InvariantCulture, out value)) {
635
+ return value;
636
+ }
637
+ return 0f;
638
+ }
639
+
640
+ private static void GaussianBlurPArgb(float[] src, int w, int h, float sigma) {
641
+ if (sigma <= 0.1f) return;
642
+ int radius = Math.Max(1, Math.Min(64, (int)Math.Ceiling(sigma * 3.0f)));
643
+ float[] kernel = new float[radius * 2 + 1];
644
+ float sum = 0f;
645
+ float invTwoSigmaSq = 1.0f / (2.0f * sigma * sigma);
646
+ for (int k = -radius; k <= radius; k++) {
647
+ float v = (float)Math.Exp(-(k * k) * invTwoSigmaSq);
648
+ kernel[k + radius] = v;
649
+ sum += v;
650
+ }
651
+ for (int k = 0; k < kernel.Length; k++) kernel[k] /= sum;
652
+
653
+ float[] tmp = new float[src.Length];
654
+ // Horizontal pass
655
+ for (int y = 0; y < h; y++) {
656
+ int rowOff = y * w;
657
+ for (int x = 0; x < w; x++) {
658
+ float b = 0f, g = 0f, r = 0f, a = 0f;
659
+ for (int k = -radius; k <= radius; k++) {
660
+ int sx = x + k;
661
+ if (sx < 0 || sx >= w) continue;
662
+ int idx = (rowOff + sx) * 4;
663
+ float wt = kernel[k + radius];
664
+ b += src[idx] * wt;
665
+ g += src[idx + 1] * wt;
666
+ r += src[idx + 2] * wt;
667
+ a += src[idx + 3] * wt;
668
+ }
669
+ int dstIdx = (rowOff + x) * 4;
670
+ tmp[dstIdx] = b;
671
+ tmp[dstIdx + 1] = g;
672
+ tmp[dstIdx + 2] = r;
673
+ tmp[dstIdx + 3] = a;
674
+ }
675
+ }
676
+ // Vertical pass
677
+ for (int y = 0; y < h; y++) {
678
+ int rowOff = y * w;
679
+ for (int x = 0; x < w; x++) {
680
+ float b = 0f, g = 0f, r = 0f, a = 0f;
681
+ for (int k = -radius; k <= radius; k++) {
682
+ int sy = y + k;
683
+ if (sy < 0 || sy >= h) continue;
684
+ int idx = (sy * w + x) * 4;
685
+ float wt = kernel[k + radius];
686
+ b += tmp[idx] * wt;
687
+ g += tmp[idx + 1] * wt;
688
+ r += tmp[idx + 2] * wt;
689
+ a += tmp[idx + 3] * wt;
690
+ }
691
+ int dstIdx = (rowOff + x) * 4;
692
+ src[dstIdx] = b;
693
+ src[dstIdx + 1] = g;
694
+ src[dstIdx + 2] = r;
695
+ src[dstIdx + 3] = a;
696
+ }
697
+ }
698
+ }
699
+
700
+ private static void CompositeBlurredLayer(float[] accum, int bufSize, float scale, float pad, float stdDev, Action<Graphics> drawAction) {
701
+ using (var bmp = new Bitmap(bufSize, bufSize, PixelFormat.Format32bppPArgb)) {
702
+ using (var g = Graphics.FromImage(bmp)) {
703
+ g.Clear(Color.Transparent);
704
+ g.SmoothingMode = SmoothingMode.AntiAlias;
705
+ g.ScaleTransform(scale, scale);
706
+ g.TranslateTransform(pad, pad);
707
+ drawAction(g);
708
+ }
709
+ var rect = new Rectangle(0, 0, bufSize, bufSize);
710
+ var data = bmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb);
711
+ byte[] bytes = new byte[bufSize * bufSize * 4];
712
+ Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
713
+ bmp.UnlockBits(data);
714
+
715
+ float[] layer = new float[bytes.Length];
716
+ for (int i = 0; i < bytes.Length; i++) layer[i] = bytes[i] / 255.0f;
717
+
718
+ GaussianBlurPArgb(layer, bufSize, bufSize, stdDev * scale);
719
+
720
+ for (int i = 0; i < accum.Length; i += 4) {
721
+ float sa = layer[i + 3];
722
+ if (sa <= 0.0001f) continue;
723
+ float invSa = 1.0f - sa;
724
+ accum[i] = layer[i] + accum[i] * invSa;
725
+ accum[i + 1] = layer[i + 1] + accum[i + 1] * invSa;
726
+ accum[i + 2] = layer[i + 2] + accum[i + 2] * invSa;
727
+ accum[i + 3] = sa + accum[i + 3] * invSa;
728
+ }
729
+ }
730
+ }
731
+
732
+ private static void DrawRotatedEllipse(Graphics g, float cx, float cy, float rx, float ry, float angle, Color fill) {
733
+ var st = g.Save();
734
+ g.TranslateTransform(cx, cy);
735
+ g.RotateTransform(angle);
736
+ g.TranslateTransform(-cx, -cy);
737
+ using (var brush = new SolidBrush(fill)) {
738
+ g.FillEllipse(brush, cx - rx, cy - ry, rx * 2f, ry * 2f);
739
+ }
740
+ g.Restore(st);
741
+ }
742
+
743
+ 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) {
744
+ var st = g.Save();
745
+ using (var m = new Matrix(m11, m12, m21, m22, dx, dy)) {
746
+ g.MultiplyTransform(m, MatrixOrder.Prepend);
747
+ }
748
+ using (var brush = new SolidBrush(fill)) {
749
+ g.FillEllipse(brush, cx - rx, cy - ry, rx * 2f, ry * 2f);
750
+ }
751
+ g.Restore(st);
752
+ }
753
+
754
+ private static Bitmap GetAntigravityColorField() {
755
+ if (AntigravityFieldCache != null) return AntigravityFieldCache;
756
+ // Covers SVG [-60..240] at scale 0.4 -> 120x120 buffer, cropped to [0..180] = 72x72.
757
+ const float pad = 60f;
758
+ const float scale = 0.4f;
759
+ const int bufSize = 120;
760
+ const int cropOffset = 24;
761
+ const int cropSize = 72;
762
+
763
+ float[] accum = new float[bufSize * bufSize * 4];
764
+ // Base fill #3186FF
765
+ float baseB = 0xFF / 255.0f, baseG = 0x86 / 255.0f, baseR = 0x31 / 255.0f;
766
+ for (int i = 0; i < accum.Length; i += 4) {
767
+ accum[i] = baseB;
768
+ accum[i + 1] = baseG;
769
+ accum[i + 2] = baseR;
770
+ accum[i + 3] = 1.0f;
771
+ }
772
+
773
+ 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)));
774
+ 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)));
775
+ 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)));
776
+ 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)));
777
+ 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)));
778
+ 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)));
779
+ 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)));
780
+ CompositeBlurredLayer(accum, bufSize, scale, pad, 19.7631f, g => {
781
+ using (var p = ParseSvgPath(AntigravityPath7, FillMode.Winding))
782
+ using (var br = new SolidBrush(Color.FromArgb(0x31, 0x86, 0xFF))) {
783
+ g.FillPath(br, p);
784
+ }
785
+ });
786
+ CompositeBlurredLayer(accum, bufSize, scale, pad, 17.6843f, g => {
787
+ using (var p = ParseSvgPath(AntigravityPath8, FillMode.Winding))
788
+ using (var br = new SolidBrush(Color.FromArgb(0x74, 0x9B, 0xFF))) {
789
+ g.FillPath(br, p);
790
+ }
791
+ });
792
+ 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)));
793
+ 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)));
794
+
795
+ var field = new Bitmap(cropSize, cropSize, PixelFormat.Format32bppArgb);
796
+ var rect = new Rectangle(0, 0, cropSize, cropSize);
797
+ var outData = field.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
798
+ byte[] outBytes = new byte[cropSize * cropSize * 4];
799
+ for (int y = 0; y < cropSize; y++) {
800
+ for (int x = 0; x < cropSize; x++) {
801
+ int si = ((y + cropOffset) * bufSize + (x + cropOffset)) * 4;
802
+ int di = (y * cropSize + x) * 4;
803
+ float a = Math.Max(0.0001f, Math.Min(1.0f, accum[si + 3]));
804
+ outBytes[di] = (byte)Math.Max(0, Math.Min(255, (int)Math.Round((accum[si] / a) * 255.0f)));
805
+ outBytes[di + 1] = (byte)Math.Max(0, Math.Min(255, (int)Math.Round((accum[si + 1] / a) * 255.0f)));
806
+ outBytes[di + 2] = (byte)Math.Max(0, Math.Min(255, (int)Math.Round((accum[si + 2] / a) * 255.0f)));
807
+ outBytes[di + 3] = 255;
808
+ }
809
+ }
810
+ Marshal.Copy(outBytes, 0, outData.Scan0, outBytes.Length);
811
+ field.UnlockBits(outData);
812
+ AntigravityFieldCache = field;
813
+ return field;
814
+ }
815
+
816
+ private static Bitmap RenderMonoSvg(string svgPath, float viewBox, int pixelSize, Color color) {
817
+ int ss = Math.Max(pixelSize * 2, 32);
818
+ using (var hi = new Bitmap(ss, ss, PixelFormat.Format32bppArgb)) {
819
+ using (var g = Graphics.FromImage(hi)) {
820
+ g.Clear(Color.Transparent);
821
+ g.SmoothingMode = SmoothingMode.HighQuality;
822
+ g.PixelOffsetMode = PixelOffsetMode.HighQuality;
823
+ float s = ss / viewBox;
824
+ g.ScaleTransform(s, s);
825
+ using (var path = ParseSvgPath(svgPath, FillMode.Winding))
826
+ using (var brush = new SolidBrush(color)) {
827
+ g.FillPath(brush, path);
828
+ }
829
+ }
830
+ var dst = new Bitmap(pixelSize, pixelSize, PixelFormat.Format32bppArgb);
831
+ using (var g = Graphics.FromImage(dst)) {
832
+ g.Clear(Color.Transparent);
833
+ g.InterpolationMode = InterpolationMode.HighQualityBicubic;
834
+ g.SmoothingMode = SmoothingMode.HighQuality;
835
+ g.PixelOffsetMode = PixelOffsetMode.HighQuality;
836
+ g.DrawImage(hi, new Rectangle(0, 0, pixelSize, pixelSize));
837
+ }
838
+ return dst;
839
+ }
840
+ }
841
+
842
+ private static Bitmap RenderAntigravitySvg(int pixelSize, float opacity) {
843
+ int ss = Math.Max(pixelSize * 2, 36);
844
+ var field = GetAntigravityColorField();
845
+ using (var hiColor = new Bitmap(ss, ss, PixelFormat.Format32bppArgb))
846
+ using (var hiMask = new Bitmap(ss, ss, PixelFormat.Format32bppArgb)) {
847
+ using (var gc = Graphics.FromImage(hiColor)) {
848
+ gc.InterpolationMode = InterpolationMode.HighQualityBicubic;
849
+ gc.PixelOffsetMode = PixelOffsetMode.HighQuality;
850
+ gc.DrawImage(field, new Rectangle(0, 0, ss, ss));
851
+ }
852
+ using (var gm = Graphics.FromImage(hiMask)) {
853
+ gm.Clear(Color.Transparent);
854
+ gm.SmoothingMode = SmoothingMode.HighQuality;
855
+ gm.PixelOffsetMode = PixelOffsetMode.HighQuality;
856
+ float s = ss / 180.0f;
857
+ gm.ScaleTransform(s, s);
858
+ using (var path = ParseSvgPath(AntigravitySilhouettePath, FillMode.Winding))
859
+ using (var brush = new SolidBrush(Color.White)) {
860
+ gm.FillPath(brush, path);
861
+ }
862
+ }
863
+
864
+ var rect = new Rectangle(0, 0, ss, ss);
865
+ var cData = hiColor.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
866
+ var mData = hiMask.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
867
+ int byteLen = ss * ss * 4;
868
+ byte[] cBytes = new byte[byteLen];
869
+ byte[] mBytes = new byte[byteLen];
870
+ Marshal.Copy(cData.Scan0, cBytes, 0, byteLen);
871
+ Marshal.Copy(mData.Scan0, mBytes, 0, byteLen);
872
+ for (int i = 0; i < byteLen; i += 4) {
873
+ cBytes[i + 3] = (byte)Math.Max(0, Math.Min(255, (int)Math.Round(mBytes[i + 3] * opacity)));
874
+ }
875
+ Marshal.Copy(cBytes, 0, cData.Scan0, byteLen);
876
+ hiColor.UnlockBits(cData);
877
+ hiMask.UnlockBits(mData);
878
+
879
+ var dst = new Bitmap(pixelSize, pixelSize, PixelFormat.Format32bppArgb);
880
+ using (var g = Graphics.FromImage(dst)) {
881
+ g.Clear(Color.Transparent);
882
+ g.InterpolationMode = InterpolationMode.HighQualityBicubic;
883
+ g.SmoothingMode = SmoothingMode.HighQuality;
884
+ g.PixelOffsetMode = PixelOffsetMode.HighQuality;
885
+ g.DrawImage(hiColor, new Rectangle(0, 0, pixelSize, pixelSize));
886
+ }
887
+ return dst;
888
+ }
889
+ }
890
+
891
+ public static Bitmap GetBrandIcon(string provider, int pixelSize, bool running, bool darkText) {
892
+ int size = Math.Max(8, pixelSize);
893
+ string p = (provider ?? "codex").Trim().ToLowerInvariant();
894
+ string key = p + "|" + size + "|" + (running ? "1" : "0") + "|" + (darkText ? "1" : "0");
895
+ Bitmap cached;
896
+ if (Cache.TryGetValue(key, out cached)) return cached;
897
+
898
+ if (Cache.Count >= 64) {
899
+ foreach (var item in Cache.Values) item.Dispose();
900
+ Cache.Clear();
901
+ }
902
+
903
+ Bitmap rendered;
904
+ if (p == "claude") {
905
+ Color c = running ? Color.FromArgb(255, 217, 119, 6) : Color.FromArgb(184, 217, 119, 6);
906
+ rendered = RenderMonoSvg(ClaudeSvgPath, 24.0f, size, c);
907
+ } else if (p == "antigravity" || p == "gemini") {
908
+ rendered = RenderAntigravitySvg(size, running ? 1.0f : 0.72f);
909
+ } else {
910
+ Color c = running
911
+ ? (darkText ? Color.FromArgb(255, 17, 17, 17) : Color.FromArgb(255, 245, 245, 247))
912
+ : (darkText ? Color.FromArgb(184, 96, 96, 102) : Color.FromArgb(184, 161, 161, 170));
913
+ rendered = RenderMonoSvg(CodexSvgPath, 320.0f, size, c);
914
+ }
915
+ Cache[key] = rendered;
916
+ return rendered;
917
+ }
918
+ }
919
+ '@
920
+
921
+ Add-Type -TypeDefinition $svgCode -ReferencedAssemblies @("System.Drawing")
922
+ $script:brandSvgRendererReady = $true
923
+ return $true
924
+ }
925
+
926
+ function Resolve-HudCodexIconDark {
927
+ $mode = ([string]$script:hudCodexIconMode).Trim().ToLowerInvariant()
928
+ if ($mode -eq "black") { return $true }
929
+ if ($mode -eq "white") { return $false }
930
+ return [bool]$script:hudDarkText
931
+ }
932
+
933
+ function Draw-BrandIcon($Graphics, [string]$Provider, [single]$X, [single]$Y, [single]$Size, [bool]$Running = $true) {
934
+ $pixelSize = [math]::Max(8, [int][math]::Round($Size))
935
+ if (Initialize-BrandSvgRenderer) {
936
+ $iconBitmap = [AiBatterySvgIcons]::GetBrandIcon($Provider, $pixelSize, $Running, (Resolve-HudCodexIconDark))
937
+ if ($iconBitmap) {
938
+ $state = $Graphics.Save()
939
+ try {
940
+ $Graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
941
+ $Graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
942
+ $Graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
943
+ $Graphics.DrawImage($iconBitmap, [System.Drawing.RectangleF]::new($X, $Y, $Size, $Size))
944
+ } finally {
945
+ $Graphics.Restore($state)
946
+ }
947
+ return
948
+ }
949
+ }
950
+ }
951
+
952
+ function New-RoundedRectPath([single]$X, [single]$Y, [single]$Width, [single]$Height, [single]$Radius) {
953
+ $path = [System.Drawing.Drawing2D.GraphicsPath]::new()
954
+ $r = [single][math]::Max(0.1, [math]::Min($Radius, [math]::Min($Width / 2.0, $Height / 2.0)))
955
+ $d = [single]($r * 2.0)
956
+ $path.AddArc($X, $Y, $d, $d, 180, 90)
957
+ $path.AddArc(($X + $Width - $d), $Y, $d, $d, 270, 90)
958
+ $path.AddArc(($X + $Width - $d), ($Y + $Height - $d), $d, $d, 0, 90)
959
+ $path.AddArc($X, ($Y + $Height - $d), $d, $d, 90, 90)
960
+ $path.CloseFigure()
961
+ return $path
962
+ }
963
+
964
+ function Get-MenuBatteryFillColor([Nullable[int]]$Percent, [bool]$Running = $true) {
965
+ if (-not $Running) {
966
+ return $(if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(113, 113, 122) } else { [System.Drawing.Color]::FromArgb(161, 161, 170) })
967
+ }
968
+ if ($null -eq $Percent) {
969
+ return $(if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(24, 24, 24) } else { [System.Drawing.Color]::FromArgb(255, 255, 255) })
970
+ }
971
+ if ($Percent -le 20) { return [System.Drawing.Color]::FromArgb(255, 69, 58) }
972
+ if ($Percent -le 40) { return [System.Drawing.Color]::FromArgb(255, 159, 10) }
973
+ return [System.Drawing.Color]::FromArgb(48, 209, 88)
974
+ }
975
+
976
+ function Get-HorizontalHudUnit {
977
+ return [double]($script:hudScale * 1.18)
978
+ }
979
+
980
+ function Get-HorizontalProviderDetailText($Parts) {
981
+ $segments = @()
982
+ if ($Parts.ResetValue) { $segments += [string]$Parts.ResetValue }
983
+ if ($Parts.WeekValue) { $segments += [string]$Parts.WeekValue }
984
+ if (-not $segments.Count -and $Parts.ExtraText) { $segments += [string]$Parts.ExtraText }
985
+ return ($segments -join " · ")
986
+ }
987
+
988
+ function Measure-HorizontalBrandHudWidth($Texts, $DrawFont) {
989
+ $padX = Scale-HudValue 10
990
+ if (-not $Texts -or -not $Texts.Rows -or $Texts.Rows.Count -eq 0) {
991
+ return Scale-HudValue 150
992
+ }
993
+ $count = $Texts.Rows.Count
994
+ $slotStep = Scale-HudValue 64
995
+ $slotContent = Scale-HudValue 56
996
+ $contentW = (($count - 1) * $slotStep) + $slotContent
997
+ return [math]::Max((Scale-HudValue 80), ($contentW + ($padX * 2)))
998
+ }
999
+
1000
+ function Draw-HorizontalBrandHud($Graphics, [int]$Width, [int]$Height, $Texts, $DrawFont) {
1001
+ $Graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
1002
+ $Graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::Default
1003
+
1004
+ if ($script:hudContrastBackdrop -or (-not $script:hudTransparentSurface)) {
1005
+ $radius = [single][math]::Min((Scale-HudValue 8), [math]::Floor(($Height - 2) / 2))
1006
+ $bgPath = New-RoundedRectPath ([single]0.5) ([single]0.5) ([single]($Width - 1)) ([single]($Height - 1)) $radius
1007
+ $bgColor = if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(244, 244, 248) } else { [System.Drawing.Color]::FromArgb(28, 28, 32) }
1008
+ $borderColor = if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(196, 196, 204) } else { [System.Drawing.Color]::FromArgb(68, 68, 74) }
1009
+ $bgBrush = [System.Drawing.SolidBrush]::new($bgColor)
1010
+ $borderPen = [System.Drawing.Pen]::new($borderColor, 1.0)
1011
+ try {
1012
+ $Graphics.FillPath($bgBrush, $bgPath)
1013
+ $Graphics.DrawPath($borderPen, $bgPath)
1014
+ } finally {
1015
+ $bgBrush.Dispose()
1016
+ $borderPen.Dispose()
1017
+ $bgPath.Dispose()
1018
+ }
1019
+ }
1020
+
1021
+ $flags = [System.Windows.Forms.TextFormatFlags]::NoPadding -bor [System.Windows.Forms.TextFormatFlags]::SingleLine -bor [System.Windows.Forms.TextFormatFlags]::NoPrefix
1022
+ if (-not $Texts -or -not $Texts.Rows -or $Texts.Rows.Count -eq 0) {
1023
+ $msg = if ($script:hudHorizontalMessage) { $script:hudHorizontalMessage } else { "AI --" }
1024
+ $msgY = [math]::Max(0, [int][math]::Floor(($Height - $DrawFont.Height) / 2))
1025
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $msg, $DrawFont, [System.Drawing.Point]::new((Scale-HudValue 8), $msgY), (Get-HudMutedTextColor), $flags)
1026
+ return
1027
+ }
1028
+
1029
+ # Crisp integer pixel layout matching macOS / Linux horizontal menu bar:
1030
+ # [Real Brand SVG Icon] + right column: [Solid crisp pill bar] above [hinted GDI bold %].
1031
+ $padX = Scale-HudValue 10
1032
+ $slotStep = Scale-HudValue 64
1033
+ $meterOffsetX = Scale-HudValue 24
1034
+ $meterW = Scale-HudValue 30
1035
+ $meterH = [math]::Max(4, (Scale-HudValue 6))
1036
+ if (($meterH % 2) -ne 0) { $meterH += 1 }
1037
+ $contentH = Scale-HudValue 26
1038
+ $originY = [int][math]::Floor(($Height - $contentH) / 2)
1039
+ $pctFontSize = [single][math]::Max(6, (Scale-HudValue 11))
1040
+ $pctFont = [System.Drawing.Font]::new("Segoe UI", $pctFontSize, [System.Drawing.FontStyle]::Bold, [System.Drawing.GraphicsUnit]::Pixel)
1041
+ $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
1042
+
1043
+ try {
1044
+ $index = 0
1045
+ foreach ($row in $Texts.Rows) {
1046
+ $slotX = $padX + ($index * $slotStep)
1047
+ $provider = [string]$row.Provider
1048
+ $parts = $row.Parts
1049
+ $running = [bool]$parts.Running
1050
+ $percent = $parts.Percent
1051
+
1052
+ $iconDim = if ($provider -eq "claude") { Scale-HudValue 19 } else { Scale-HudValue 21 }
1053
+ $iconY = [int][math]::Floor(($Height - $iconDim) / 2)
1054
+ Draw-BrandIcon $Graphics $provider ([single]$slotX) ([single]$iconY) ([single]$iconDim) $running
1055
+
1056
+ # Integer-snapped opaque pill bar (zero TransparencyKey fringe or subpixel blur)
1057
+ $meterX = $slotX + $meterOffsetX
1058
+ $meterY = $originY + (Scale-HudValue 3)
1059
+ $pillRadius = [single]([math]::Floor($meterH / 2))
1060
+ $trackFillColor = if ($script:hudDarkText) {
1061
+ [System.Drawing.Color]::FromArgb(232, 232, 238)
1062
+ } else {
1063
+ [System.Drawing.Color]::FromArgb(38, 38, 44)
1064
+ }
1065
+ $outlineColor = if ($script:hudDarkText) {
1066
+ if ($running) { [System.Drawing.Color]::FromArgb(72, 72, 80) } else { [System.Drawing.Color]::FromArgb(148, 148, 158) }
1067
+ } else {
1068
+ if ($running) { [System.Drawing.Color]::FromArgb(148, 148, 158) } else { [System.Drawing.Color]::FromArgb(92, 92, 102) }
1069
+ }
1070
+ $trackPath = New-RoundedRectPath ([single]$meterX) ([single]$meterY) ([single]$meterW) ([single]$meterH) $pillRadius
1071
+ $trackBrush = [System.Drawing.SolidBrush]::new($trackFillColor)
1072
+ $outlinePen = [System.Drawing.Pen]::new($outlineColor, 1.0)
1073
+ try {
1074
+ $Graphics.FillPath($trackBrush, $trackPath)
1075
+ $Graphics.DrawPath($outlinePen, $trackPath)
1076
+ } finally {
1077
+ $trackBrush.Dispose()
1078
+ $outlinePen.Dispose()
1079
+ $trackPath.Dispose()
1080
+ }
1081
+
1082
+ if ($null -ne $percent) {
1083
+ $clamped = [math]::Max(0, [math]::Min(100, [int]$percent))
1084
+ $inset = if ($meterH -le 4) { 1 } else { [math]::Max(2, (Scale-HudValue 2)) }
1085
+ $innerW = [math]::Max(2, $meterW - ($inset * 2))
1086
+ $innerH = [math]::Max(2, $meterH - ($inset * 2))
1087
+ $fillW = [int][math]::Round(($clamped / 100.0) * $innerW)
1088
+ if ($clamped -gt 0 -and $fillW -lt 2) { $fillW = 2 }
1089
+ if ($fillW -gt 0) {
1090
+ $innerX = $meterX + $inset
1091
+ $innerY = $meterY + $inset
1092
+ $fillBrush = [System.Drawing.SolidBrush]::new((Get-MenuBatteryFillColor $percent $running))
1093
+ try {
1094
+ if ($innerH -le 2) {
1095
+ $Graphics.FillRectangle($fillBrush, $innerX, $innerY, $fillW, $innerH)
1096
+ } else {
1097
+ $fillPath = New-RoundedRectPath ([single]$innerX) ([single]$innerY) ([single]$fillW) ([single]$innerH) ([single]($innerH / 2.0))
1098
+ try {
1099
+ $Graphics.FillPath($fillBrush, $fillPath)
1100
+ } finally {
1101
+ $fillPath.Dispose()
1102
+ }
1103
+ }
1104
+ } finally {
1105
+ $fillBrush.Dispose()
1106
+ }
1107
+ }
1108
+ }
1109
+
1110
+ # Crisp native Win32 hinted percentage text centered under pill bar
1111
+ $pctText = if ($null -eq $percent) { "--" } else { "$([int]$percent)%" }
1112
+ $pctColor = if ($running) {
1113
+ if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(20, 20, 24) } else { [System.Drawing.Color]::FromArgb(255, 255, 255) }
1114
+ } else {
1115
+ if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(108, 108, 116) } else { [System.Drawing.Color]::FromArgb(164, 164, 174) }
1116
+ }
1117
+ $pctRect = [System.Drawing.Rectangle]::new(
1118
+ ($meterX - (Scale-HudValue 4)),
1119
+ ($meterY + $meterH + (Scale-HudValue 2)),
1120
+ ($meterW + (Scale-HudValue 8)),
1121
+ (Scale-HudValue 15)
1122
+ )
1123
+ $pctBackColor = if ($script:hudContrastBackdrop -or (-not $script:hudTransparentSurface)) {
1124
+ if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(244, 244, 248) } else { [System.Drawing.Color]::FromArgb(28, 28, 32) }
1125
+ } elseif ($script:hudDarkText) {
1126
+ [System.Drawing.Color]::FromArgb(254, 254, 254)
1127
+ } else {
1128
+ [System.Drawing.Color]::FromArgb(18, 18, 18)
1129
+ }
1130
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $pctText, $pctFont, $pctRect, $pctColor, $pctBackColor, $pctFlags)
1131
+ $index += 1
1132
+ }
1133
+ } finally {
1134
+ $pctFont.Dispose()
1135
+ }
1136
+ }
1137
+
1138
+ function Get-VerticalRailProviderTag([string]$Provider) {
1139
+ switch ($Provider) {
1140
+ "codex" { return "CDX" }
1141
+ "claude" { return "CLD" }
1142
+ "antigravity" { return "AGY" }
1143
+ default { return "AI" }
1144
+ }
1145
+ }
1146
+
1147
+ function Get-VerticalRailTagColor([string]$Provider, [bool]$Running = $true) {
1148
+ switch ($Provider) {
1149
+ "antigravity" {
1150
+ if ($script:hudDarkText) {
1151
+ return $(if ($Running) { [System.Drawing.Color]::FromArgb(37, 99, 235) } else { [System.Drawing.Color]::FromArgb(75, 118, 200) })
1152
+ }
1153
+ return $(if ($Running) { [System.Drawing.Color]::FromArgb(96, 165, 250) } else { [System.Drawing.Color]::FromArgb(76, 132, 204) })
1154
+ }
1155
+ "claude" {
1156
+ if ($script:hudDarkText) {
1157
+ return $(if ($Running) { [System.Drawing.Color]::FromArgb(217, 119, 6) } else { [System.Drawing.Color]::FromArgb(180, 112, 48) })
1158
+ }
1159
+ return $(if ($Running) { [System.Drawing.Color]::FromArgb(249, 115, 22) } else { [System.Drawing.Color]::FromArgb(204, 110, 42) })
1160
+ }
1161
+ default {
1162
+ if ($script:hudDarkText) {
1163
+ return $(if ($Running) { [System.Drawing.Color]::FromArgb(20, 20, 24) } else { [System.Drawing.Color]::FromArgb(92, 92, 102) })
1164
+ }
1165
+ return $(if ($Running) { [System.Drawing.Color]::FromArgb(255, 255, 255) } else { [System.Drawing.Color]::FromArgb(204, 204, 212) })
1166
+ }
1167
+ }
1168
+ }
1169
+
1170
+ function Get-VerticalRailMetrics {
1171
+ $padY = Scale-HudValue 8
1172
+ $tagH = Scale-HudValue 14
1173
+ $tagGap = Scale-HudValue 3
1174
+ $batH = Scale-HudValue 30
1175
+ $batGap = Scale-HudValue 3
1176
+ $pctH = Scale-HudValue 14
1177
+ $pctGap = Scale-HudValue 2
1178
+ $valH = Scale-HudValue 12
1179
+ $lblH = Scale-HudValue 10
1180
+ $pairGap = Scale-HudValue 3
1181
+ $divGap = Scale-HudValue 11
1182
+ $blockH = ($tagH + $tagGap) + ($batH + $batGap) + ($pctH + $pctGap) + ($valH + $lblH + $pairGap) + ($valH + $lblH)
1183
+ return [PSCustomObject]@{
1184
+ Width = Scale-HudValue 38
1185
+ PadX = Scale-HudValue 3
1186
+ PadY = $padY
1187
+ TagH = $tagH
1188
+ TagGap = $tagGap
1189
+ BatH = $batH
1190
+ BatGap = $batGap
1191
+ PctH = $pctH
1192
+ PctGap = $pctGap
1193
+ ValH = $valH
1194
+ LblH = $lblH
1195
+ PairGap = $pairGap
1196
+ DivGap = $divGap
1197
+ BlockH = $blockH
1198
+ }
1199
+ }
1200
+
1201
+ function Get-VerticalRailRowStrings($Row) {
1202
+ $parts = $Row.Parts
1203
+ $percent = $parts.Percent
1204
+ $tag = Get-VerticalRailProviderTag ([string]$Row.Provider)
1205
+ $pctText = if ($null -eq $percent) { "--%" } else { "$([int]$percent)%" }
1206
+ $primaryLbl = "5h"
1207
+ $resetVal = "--:--"
1208
+ if ($parts.ResetValue) {
1209
+ $rawReset = [string]$parts.ResetValue
1210
+ if ($rawReset -match '^(\S+)\s+(.+)$') {
1211
+ $primaryLbl = $Matches[1]
1212
+ $resetVal = $Matches[2]
1213
+ } else {
1214
+ $resetVal = $rawReset
1215
+ }
1216
+ }
1217
+ $weekLbl = "7d"
1218
+ $weekVal = "--%"
1219
+ if ($parts.WeekValue) {
1220
+ $rawWeek = [string]$parts.WeekValue
1221
+ if ($rawWeek -match '^(\S+)\s+(.+)$') {
1222
+ $weekLbl = $Matches[1]
1223
+ $weekVal = $Matches[2]
1224
+ } else {
1225
+ $weekVal = $rawWeek
1226
+ }
1227
+ }
1228
+ return [PSCustomObject]@{
1229
+ Tag = $tag
1230
+ PctText = $pctText
1231
+ PrimaryLbl = $primaryLbl
1232
+ ResetVal = $resetVal
1233
+ WeekLbl = $weekLbl
1234
+ WeekVal = $weekVal
1235
+ }
1236
+ }
1237
+
1238
+ function Measure-VerticalRailHudSize($Texts) {
1239
+ $m = Get-VerticalRailMetrics
1240
+ $rows = if ($Texts -and $Texts.Rows -and $Texts.Rows.Count -gt 0) { $Texts.Rows } else { @() }
1241
+ $count = [math]::Max(1, $rows.Count)
1242
+ $h = ($m.PadY * 2) + ($count * $m.BlockH) + ([math]::Max(0, $count - 1) * $m.DivGap)
1243
+
1244
+ $flags = [System.Windows.Forms.TextFormatFlags]::SingleLine -bor [System.Windows.Forms.TextFormatFlags]::NoPadding -bor [System.Windows.Forms.TextFormatFlags]::NoPrefix
1245
+ $bounds = [System.Drawing.Size]::new(256, 64)
1246
+ $maxContentW = [math]::Max(6, (Scale-HudValue 8))
1247
+
1248
+ $tagFont = [System.Drawing.Font]::new("Cascadia Mono", [single](Scale-HudValue 12), [System.Drawing.FontStyle]::Bold, [System.Drawing.GraphicsUnit]::Pixel)
1249
+ $pctFont = [System.Drawing.Font]::new("Segoe UI", [single](Scale-HudValue 11), [System.Drawing.FontStyle]::Bold, [System.Drawing.GraphicsUnit]::Pixel)
1250
+ $lblFont = [System.Drawing.Font]::new("Segoe UI", [single](Scale-HudValue 8.5), [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Pixel)
1251
+ $valFont = [System.Drawing.Font]::new("Cascadia Mono", [single](Scale-HudValue 10), [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Pixel)
1252
+ try {
1253
+ if ($rows.Count -eq 0) {
1254
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText("AI--", $valFont, $bounds, $flags).Width)
1255
+ } else {
1256
+ foreach ($row in $rows) {
1257
+ $items = Get-VerticalRailRowStrings $row
1258
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText($items.Tag, $tagFont, $bounds, $flags).Width)
1259
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText($items.PctText, $pctFont, $bounds, $flags).Width)
1260
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText($items.PrimaryLbl, $lblFont, $bounds, $flags).Width)
1261
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText($items.ResetVal, $valFont, $bounds, $flags).Width)
1262
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText($items.WeekLbl, $lblFont, $bounds, $flags).Width)
1263
+ $maxContentW = [math]::Max($maxContentW, [System.Windows.Forms.TextRenderer]::MeasureText($items.WeekVal, $valFont, $bounds, $flags).Width)
1264
+ }
1265
+ }
1266
+ } finally {
1267
+ $tagFont.Dispose()
1268
+ $pctFont.Dispose()
1269
+ $lblFont.Dispose()
1270
+ $valFont.Dispose()
1271
+ }
1272
+
1273
+ # Allocate only the measured content width plus minimal side padding.
1274
+ $w = $maxContentW + ($m.PadX * 2) + (Scale-HudValue 2)
1275
+ $w = [math]::Max((Scale-HudValue 32), [math]::Min((Scale-HudValue 56), $w))
1276
+ return [System.Drawing.Size]::new([int]$w, [int]$h)
1277
+ }
1278
+
1279
+ 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) {
1280
+ if ([string]::IsNullOrEmpty($Text)) { return }
1281
+ $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
1282
+ $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
1283
+ $fitLimit = if ($FitMaxWidth -gt 0) { $FitMaxWidth } else { [math]::Max(10, $Rect.Width - 6) }
1284
+ $px = $StartPx
1285
+ $minPx = [single][math]::Max(5.5, (Scale-HudValue 7))
1286
+ $drawFont = $null
1287
+ try {
1288
+ while ($true) {
1289
+ if ($drawFont) { $drawFont.Dispose() }
1290
+ $drawFont = [System.Drawing.Font]::new($Family, $px, $Style, [System.Drawing.GraphicsUnit]::Pixel)
1291
+ $sz = [System.Windows.Forms.TextRenderer]::MeasureText($Text, $drawFont, [System.Drawing.Size]::new(256, 64), $measureFlags)
1292
+ if ($sz.Width -le $fitLimit -or $px -le $minPx) { break }
1293
+ $px = [single][math]::Max($minPx, $px - 0.5)
1294
+ }
1295
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $Text, $drawFont, $Rect, $Color, $BackColor, $drawFlags)
1296
+ } finally {
1297
+ if ($drawFont) { $drawFont.Dispose() }
1298
+ }
1299
+ }
1300
+
1301
+ function Draw-VerticalRailHud($Graphics, [int]$Width, [int]$Height, $Texts, $CustomBackColor = $null, $CustomBorderColor = $null) {
1302
+ $Graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
1303
+ $Graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::Default
1304
+
1305
+ $backColor = if ($null -ne $CustomBackColor) {
1306
+ $CustomBackColor
1307
+ } elseif ($script:hudContrastBackdrop -or (-not $script:hudTransparentSurface)) {
1308
+ if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(244, 244, 248) } else { [System.Drawing.Color]::FromArgb(28, 28, 32) }
1309
+ } elseif ($script:hudDarkText) {
1310
+ [System.Drawing.Color]::FromArgb(254, 254, 254)
1311
+ } else {
1312
+ [System.Drawing.Color]::FromArgb(18, 18, 18)
1313
+ }
1314
+
1315
+ if ($null -ne $CustomBackColor -or $script:hudContrastBackdrop -or (-not $script:hudTransparentSurface)) {
1316
+ $radius = [single][math]::Min((Scale-HudValue 6), [math]::Floor(($Width - 2) / 2))
1317
+ $bgPath = New-RoundedRectPath ([single]0.5) ([single]0.5) ([single]($Width - 1)) ([single]($Height - 1)) $radius
1318
+ $bgBrush = [System.Drawing.SolidBrush]::new($backColor)
1319
+ $borderColor = if ($null -ne $CustomBorderColor) {
1320
+ $CustomBorderColor
1321
+ } elseif ($script:hudDarkText) {
1322
+ [System.Drawing.Color]::FromArgb(196, 196, 204)
1323
+ } else {
1324
+ [System.Drawing.Color]::FromArgb(68, 68, 74)
1325
+ }
1326
+ $borderPen = [System.Drawing.Pen]::new($borderColor, 1.0)
1327
+ try {
1328
+ $Graphics.FillPath($bgBrush, $bgPath)
1329
+ $Graphics.DrawPath($borderPen, $bgPath)
1330
+ } finally {
1331
+ $bgBrush.Dispose()
1332
+ $borderPen.Dispose()
1333
+ $bgPath.Dispose()
1334
+ }
1335
+ }
1336
+
1337
+ $rows = if ($Texts -and $Texts.Rows -and $Texts.Rows.Count -gt 0) { $Texts.Rows } else { @() }
1338
+ if ($rows.Count -eq 0) {
1339
+ $msgRect = [System.Drawing.Rectangle]::new(2, [int][math]::Floor($Height / 2) - (Scale-HudValue 8), ($Width - 4), (Scale-HudValue 16))
1340
+ Draw-FittedRailText $Graphics "AI--" "Cascadia Mono" ([single](Scale-HudValue 10)) ([System.Drawing.FontStyle]::Bold) $msgRect (Get-HudMutedTextColor) $backColor
1341
+ return
1342
+ }
1343
+
1344
+ $m = Get-VerticalRailMetrics
1345
+ $padX = $m.PadX
1346
+ $innerW = [math]::Max(12, $Width - ($padX * 2))
1347
+ $divInset = [math]::Min([int][math]::Floor($Width / 4), $padX + (Scale-HudValue 1))
1348
+ $y = $m.PadY
1349
+ $tagH = $m.TagH
1350
+ $batH = $m.BatH
1351
+ $pctH = $m.PctH
1352
+ $valH = $m.ValH
1353
+ $lblH = $m.LblH
1354
+ $divGap = $m.DivGap
1355
+ $divColor = if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(170, 170, 180) } else { [System.Drawing.Color]::FromArgb(74, 74, 84) }
1356
+ $divPen = [System.Drawing.Pen]::new($divColor, 1.0)
1357
+
1358
+ try {
1359
+ $idx = 0
1360
+ foreach ($row in $rows) {
1361
+ if ($idx -gt 0) {
1362
+ $divY = $y + [int][math]::Floor($divGap / 2)
1363
+ $Graphics.DrawLine($divPen, $divInset, $divY, ($Width - $divInset), $divY)
1364
+ $y += $divGap
1365
+ }
1366
+ $parts = $row.Parts
1367
+ $items = Get-VerticalRailRowStrings $row
1368
+ $running = [bool]$parts.Running
1369
+ $percent = $parts.Percent
1370
+ $primaryColor = if ($running) {
1371
+ if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(20, 20, 24) } else { [System.Drawing.Color]::FromArgb(245, 245, 247) }
1372
+ } else {
1373
+ if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(108, 108, 116) } else { [System.Drawing.Color]::FromArgb(154, 154, 164) }
1374
+ }
1375
+ $mutedColor = if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(120, 120, 128) } else { [System.Drawing.Color]::FromArgb(128, 128, 138) }
1376
+
1377
+ # 1. AGY (blue) / CDX (white) / CLD (orange)
1378
+ $tagColor = Get-VerticalRailTagColor ([string]$row.Provider) $running
1379
+ $tagRect = [System.Drawing.Rectangle]::new(0, $y, $Width, $tagH)
1380
+ Draw-FittedRailText $Graphics $items.Tag "Cascadia Mono" ([single](Scale-HudValue 12)) ([System.Drawing.FontStyle]::Bold) $tagRect $tagColor $backColor $innerW
1381
+ $y += $tagH + $m.TagGap
1382
+
1383
+ # 2. Vertical battery gauge (centered slim rail + bottom-to-top fill)
1384
+ $cx = [int][math]::Floor($Width / 2)
1385
+ $railW = [math]::Max(2, (Scale-HudValue 2))
1386
+ $barW = [math]::Max(4, (Scale-HudValue 8))
1387
+ $railBrush = [System.Drawing.SolidBrush]::new($(if ($script:hudDarkText) { [System.Drawing.Color]::FromArgb(180, 180, 188) } else { [System.Drawing.Color]::FromArgb(84, 84, 94) }))
1388
+ try {
1389
+ $Graphics.FillRectangle($railBrush, [int]($cx - [math]::Floor($railW / 2)), $y, $railW, $batH)
1390
+ } finally {
1391
+ $railBrush.Dispose()
1392
+ }
1393
+ if ($null -ne $percent) {
1394
+ $clamped = [math]::Max(0, [math]::Min(100, [int]$percent))
1395
+ $fillH = [int][math]::Round(($clamped / 100.0) * $batH)
1396
+ if ($clamped -gt 0 -and $fillH -lt 2) { $fillH = 2 }
1397
+ if ($fillH -gt 0) {
1398
+ $fillColor = Get-MenuBatteryFillColor $percent $running
1399
+ $fillBrush = [System.Drawing.SolidBrush]::new($fillColor)
1400
+ try {
1401
+ $Graphics.FillRectangle($fillBrush, [int]($cx - [math]::Floor($barW / 2)), ($y + $batH - $fillH), $barW, $fillH)
1402
+ } finally {
1403
+ $fillBrush.Dispose()
1404
+ }
1405
+ }
1406
+ }
1407
+ $y += $batH + $m.BatGap
1408
+
1409
+ # 3. Percent directly below battery
1410
+ $pctColor = if ($running) { Get-MenuBatteryFillColor $percent $true } else { $primaryColor }
1411
+ $pctRect = [System.Drawing.Rectangle]::new(0, $y, $Width, $pctH)
1412
+ Draw-FittedRailText $Graphics $items.PctText "Segoe UI" ([single](Scale-HudValue 11)) ([System.Drawing.FontStyle]::Bold) $pctRect $pctColor $backColor $innerW
1413
+ $y += $pctH + $m.PctGap
1414
+
1415
+ # 4. Primary window label (e.g. "5h") + reset time beneath
1416
+ $fiveLblRect = [System.Drawing.Rectangle]::new(0, $y, $Width, $lblH)
1417
+ Draw-FittedRailText $Graphics $items.PrimaryLbl "Segoe UI" ([single](Scale-HudValue 8.5)) ([System.Drawing.FontStyle]::Regular) $fiveLblRect $mutedColor $backColor $innerW
1418
+ $y += $lblH
1419
+ $resetRect = [System.Drawing.Rectangle]::new(0, $y, $Width, $valH)
1420
+ Draw-FittedRailText $Graphics $items.ResetVal "Cascadia Mono" ([single](Scale-HudValue 10)) ([System.Drawing.FontStyle]::Regular) $resetRect $primaryColor $backColor $innerW
1421
+ $y += $valH + $m.PairGap
1422
+
1423
+ # 5. Secondary window label (e.g. "7d") + weekly % beneath
1424
+ $weekLblRect = [System.Drawing.Rectangle]::new(0, $y, $Width, $lblH)
1425
+ Draw-FittedRailText $Graphics $items.WeekLbl "Segoe UI" ([single](Scale-HudValue 8.5)) ([System.Drawing.FontStyle]::Regular) $weekLblRect $mutedColor $backColor $innerW
1426
+ $y += $lblH
1427
+ $weekRect = [System.Drawing.Rectangle]::new(0, $y, $Width, $valH)
1428
+ Draw-FittedRailText $Graphics $items.WeekVal "Cascadia Mono" ([single](Scale-HudValue 10)) ([System.Drawing.FontStyle]::Regular) $weekRect $primaryColor $backColor $innerW
1429
+ $y += $valH
1430
+ $idx += 1
1431
+ }
1432
+ } finally {
1433
+ $divPen.Dispose()
1434
+ }
1435
+ }
1436
+
1437
+ function Format-DetailResetText([string]$Value) {
1438
+ if ([string]::IsNullOrWhiteSpace($Value)) { return "" }
1439
+ # Widen the space between the window label (e.g. "5h") and time ("18:34" / "--:--").
1440
+ return ($Value -replace '^(\S+)\s+(.+)$', '$1 $2')
1441
+ }
1442
+
1443
+ function Get-HorizontalDetailCardLayout($Texts) {
1444
+ $rows = if ($Texts -and $Texts.Rows -and $Texts.Rows.Count -gt 0) { $Texts.Rows } else { @() }
1445
+ $rowCount = [math]::Max(1, $rows.Count)
1446
+ $padX = Scale-HudDpiValue 14
1447
+ $padY = Scale-HudDpiValue 8
1448
+ $rowH = Scale-HudDpiValue 36
1449
+ $footerH = Scale-HudDpiValue 34
1450
+ $nameW = Scale-HudDpiValue 52
1451
+ $barX = $padX + $nameW + (Scale-HudDpiValue 12)
1452
+ $barW = Scale-HudDpiValue 116
1453
+ $barH = Scale-HudDpiValue 8
1454
+ $pctX = $barX + $barW + (Scale-HudDpiValue 10)
1455
+ $pctW = Scale-HudDpiValue 40
1456
+ $resetX = $pctX + $pctW + (Scale-HudDpiValue 14)
1457
+
1458
+ $metaFont = [System.Drawing.Font]::new("Segoe UI", [single](Scale-HudDpiValue 12), [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Pixel)
1459
+ $flags = [System.Windows.Forms.TextFormatFlags]::NoPadding -bor [System.Windows.Forms.TextFormatFlags]::SingleLine -bor [System.Windows.Forms.TextFormatFlags]::NoPrefix
1460
+ $resetW = Scale-HudDpiValue 48
1461
+ $weekW = Scale-HudDpiValue 46
1462
+ $extraW = 0
1463
+ $hasWeek = $false
1464
+ try {
1465
+ foreach ($row in $rows) {
1466
+ $p = $row.Parts
1467
+ if ($p.ResetValue) {
1468
+ $resetDisplay = Format-DetailResetText ([string]$p.ResetValue)
1469
+ $sz = [System.Windows.Forms.TextRenderer]::MeasureText($resetDisplay, $metaFont, [System.Drawing.Size]::new(512, 64), $flags)
1470
+ $resetW = [math]::Max($resetW, [int]$sz.Width + (Scale-HudDpiValue 2))
1471
+ }
1472
+ if ($p.WeekValue) {
1473
+ $hasWeek = $true
1474
+ $sz = [System.Windows.Forms.TextRenderer]::MeasureText([string]$p.WeekValue, $metaFont, [System.Drawing.Size]::new(512, 64), $flags)
1475
+ $weekW = [math]::Max($weekW, [int]$sz.Width + (Scale-HudDpiValue 2))
1476
+ }
1477
+ if (-not $p.ResetValue -and -not $p.WeekValue -and $p.ExtraText) {
1478
+ $sz = [System.Windows.Forms.TextRenderer]::MeasureText([string]$p.ExtraText, $metaFont, [System.Drawing.Size]::new(512, 64), $flags)
1479
+ $extraW = [math]::Max($extraW, [int]$sz.Width + (Scale-HudDpiValue 2))
1480
+ }
1481
+ }
1482
+ } finally {
1483
+ $metaFont.Dispose()
1484
+ }
1485
+
1486
+ $metaGap = Scale-HudDpiValue 14
1487
+ $weekX = $resetX + $resetW + $metaGap
1488
+ $metaRight = if ($hasWeek) { $weekX + $weekW } else { $resetX + [math]::Max($resetW, $extraW) }
1489
+ $metaRight = [math]::Max($metaRight, ($resetX + $extraW))
1490
+ $width = [math]::Max((Scale-HudDpiValue 400), ($metaRight + $padX))
1491
+ # Shift week/reset right if card hit minimum width so right edge stays balanced.
1492
+ $extraShift = ($width - $padX) - $metaRight
1493
+ if ($extraShift -gt 0) {
1494
+ $resetX += $extraShift
1495
+ $weekX += $extraShift
1496
+ }
1497
+ $height = ($rowCount * $rowH) + ($padY * 2) + $footerH
1498
+
1499
+ return @{
1500
+ Width = [int]$width
1501
+ Height = [int]$height
1502
+ PadX = [int]$padX
1503
+ PadY = [int]$padY
1504
+ RowH = [int]$rowH
1505
+ FooterH = [int]$footerH
1506
+ NameX = [int]$padX
1507
+ NameW = [int]$nameW
1508
+ BarX = [int]$barX
1509
+ BarW = [int]$barW
1510
+ BarH = [int]$barH
1511
+ PctX = [int]$pctX
1512
+ PctW = [int]$pctW
1513
+ ResetX = [int]$resetX
1514
+ ResetW = [int]$resetW
1515
+ WeekX = [int]$weekX
1516
+ WeekW = [int]$weekW
1517
+ }
1518
+ }
1519
+
1520
+ function Get-HorizontalDetailCardSize($Texts) {
1521
+ $layout = Get-HorizontalDetailCardLayout $Texts
1522
+ return [System.Drawing.Size]::new($layout.Width, $layout.Height)
1523
+ }
1524
+
1525
+ function Get-HorizontalDetailFooterRects([int]$Width, [int]$Height) {
1526
+ $footerH = Scale-HudDpiValue 34
1527
+ $y = $Height - $footerH
1528
+ $btnW = Scale-HudDpiValue 86
1529
+ return @{
1530
+ Refresh = [System.Drawing.Rectangle]::new((Scale-HudDpiValue 14), $y, $btnW, $footerH)
1531
+ Quit = [System.Drawing.Rectangle]::new(($Width - $btnW - (Scale-HudDpiValue 14)), $y, $btnW, $footerH)
1532
+ }
1533
+ }
1534
+
1535
+ function Draw-HorizontalDetailCard($Graphics, [int]$Width, [int]$Height, $Texts) {
1536
+ $Graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
1537
+ $Graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
1538
+ $Graphics.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::ClearTypeGridFit
1539
+
1540
+ $lightCard = [bool]$script:hudDarkText
1541
+ $cardBack = if ($lightCard) { [System.Drawing.Color]::FromArgb(246, 246, 250) } else { [System.Drawing.Color]::FromArgb(38, 38, 43) }
1542
+ $cardBorder = if ($lightCard) { [System.Drawing.Color]::FromArgb(204, 204, 212) } else { [System.Drawing.Color]::FromArgb(72, 72, 78) }
1543
+ $bgPath = New-RoundedRectPath ([single]0.5) ([single]0.5) ([single]($Width - 1)) ([single]($Height - 1)) ([single](Scale-HudDpiValue 10))
1544
+ $bgBrush = [System.Drawing.SolidBrush]::new($cardBack)
1545
+ $borderPen = [System.Drawing.Pen]::new($cardBorder, 1.0)
1546
+ try {
1547
+ $Graphics.FillPath($bgBrush, $bgPath)
1548
+ $Graphics.DrawPath($borderPen, $bgPath)
1549
+ } finally {
1550
+ $bgBrush.Dispose()
1551
+ $borderPen.Dispose()
1552
+ $bgPath.Dispose()
1553
+ }
1554
+
1555
+ $layout = Get-HorizontalDetailCardLayout $Texts
1556
+ $nameFont = [System.Drawing.Font]::new("Segoe UI", [single](Scale-HudDpiValue 13), [System.Drawing.FontStyle]::Bold, [System.Drawing.GraphicsUnit]::Pixel)
1557
+ $metaFont = [System.Drawing.Font]::new("Segoe UI", [single](Scale-HudDpiValue 12), [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Pixel)
1558
+ $footerFont = [System.Drawing.Font]::new("Segoe UI", [single](Scale-HudDpiValue 12), [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Pixel)
1559
+ $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
1560
+ $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
1561
+ $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
1562
+
1563
+ try {
1564
+ $rows = if ($Texts -and $Texts.Rows -and $Texts.Rows.Count -gt 0) { $Texts.Rows } else { @() }
1565
+ $idx = 0
1566
+ foreach ($row in $rows) {
1567
+ $y = $layout.PadY + ($idx * $layout.RowH)
1568
+ $parts = $row.Parts
1569
+ $running = [bool]$parts.Running
1570
+ $percent = $parts.Percent
1571
+ $primaryColor = if ($lightCard) {
1572
+ if ($running) { [System.Drawing.Color]::FromArgb(24, 24, 28) } else { [System.Drawing.Color]::FromArgb(110, 110, 118) }
1573
+ } else {
1574
+ if ($running) { [System.Drawing.Color]::FromArgb(245, 245, 247) } else { [System.Drawing.Color]::FromArgb(161, 161, 170) }
1575
+ }
1576
+ $metaColor = if ($lightCard) {
1577
+ if ($running) { [System.Drawing.Color]::FromArgb(96, 96, 106) } else { [System.Drawing.Color]::FromArgb(132, 132, 140) }
1578
+ } else {
1579
+ if ($running) { [System.Drawing.Color]::FromArgb(161, 161, 170) } else { [System.Drawing.Color]::FromArgb(142, 142, 147) }
1580
+ }
1581
+
1582
+ $label = switch ([string]$row.Provider) {
1583
+ "claude" { "Claude" }
1584
+ "antigravity" { "Gemini" }
1585
+ default { "Codex" }
1586
+ }
1587
+ $nameRect = [System.Drawing.Rectangle]::new($layout.NameX, $y, $layout.NameW, $layout.RowH)
1588
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $label, $nameFont, $nameRect, $primaryColor, $leftFlags)
1589
+
1590
+ $barY = [single]($y + (($layout.RowH - $layout.BarH) / 2.0))
1591
+ $trackPath = New-RoundedRectPath ([single]$layout.BarX) $barY ([single]$layout.BarW) ([single]$layout.BarH) ([single]($layout.BarH / 2.0))
1592
+ $trackFill = if ($lightCard) {
1593
+ if ($running) { [System.Drawing.Color]::FromArgb(224, 224, 232) } else { [System.Drawing.Color]::FromArgb(232, 232, 238) }
1594
+ } else {
1595
+ [System.Drawing.Color]::FromArgb($(if ($running) { 26 } else { 15 }), 255, 255, 255)
1596
+ }
1597
+ $trackStroke = if ($lightCard) {
1598
+ [System.Drawing.Color]::FromArgb(196, 196, 204)
1599
+ } else {
1600
+ [System.Drawing.Color]::FromArgb($(if ($running) { 36 } else { 61 }), 255, 255, 255)
1601
+ }
1602
+ $trackBrush = [System.Drawing.SolidBrush]::new($trackFill)
1603
+ $trackPen = [System.Drawing.Pen]::new($trackStroke, 1.0)
1604
+ try {
1605
+ $Graphics.FillPath($trackBrush, $trackPath)
1606
+ $Graphics.DrawPath($trackPen, $trackPath)
1607
+ } finally {
1608
+ $trackBrush.Dispose()
1609
+ $trackPen.Dispose()
1610
+ $trackPath.Dispose()
1611
+ }
1612
+
1613
+ if ($null -ne $percent) {
1614
+ $clamped = [math]::Max(0, [math]::Min(100, [int]$percent))
1615
+ $fillW = [single](($clamped / 100.0) * $layout.BarW)
1616
+ if ($clamped -gt 0 -and $fillW -lt (Scale-HudDpiValue 4)) { $fillW = [single](Scale-HudDpiValue 4) }
1617
+ if ($fillW -gt 0.5) {
1618
+ $fillPath = New-RoundedRectPath ([single]$layout.BarX) $barY $fillW ([single]$layout.BarH) ([single]($layout.BarH / 2.0))
1619
+ $fillColor = if (-not $running) {
1620
+ if ($lightCard) { [System.Drawing.Color]::FromArgb(148, 148, 156) } else { [System.Drawing.Color]::FromArgb(161, 161, 170) }
1621
+ } elseif ($clamped -le 20) {
1622
+ if ($lightCard) { [System.Drawing.Color]::FromArgb(220, 38, 38) } else { [System.Drawing.Color]::FromArgb(255, 69, 58) }
1623
+ } elseif ($clamped -le 40) {
1624
+ if ($lightCard) { [System.Drawing.Color]::FromArgb(217, 119, 6) } else { [System.Drawing.Color]::FromArgb(255, 159, 10) }
1625
+ } else {
1626
+ if ($lightCard) { [System.Drawing.Color]::FromArgb(34, 178, 72) } else { [System.Drawing.Color]::FromArgb(48, 209, 88) }
1627
+ }
1628
+ $fillBrush = [System.Drawing.SolidBrush]::new($fillColor)
1629
+ try {
1630
+ $Graphics.FillPath($fillBrush, $fillPath)
1631
+ } finally {
1632
+ $fillBrush.Dispose()
1633
+ $fillPath.Dispose()
1634
+ }
1635
+ }
1636
+ }
1637
+
1638
+ $pctText = if ($null -eq $percent) { "--%" } else { "$([int]$percent)%" }
1639
+ $pctRect = [System.Drawing.Rectangle]::new($layout.PctX, $y, $layout.PctW, $layout.RowH)
1640
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $pctText, $nameFont, $pctRect, $primaryColor, $rightFlags)
1641
+
1642
+ if ($parts.ResetValue -or $parts.WeekValue) {
1643
+ if ($parts.ResetValue) {
1644
+ $resetRect = [System.Drawing.Rectangle]::new($layout.ResetX, $y, $layout.ResetW, $layout.RowH)
1645
+ $resetDisplay = Format-DetailResetText ([string]$parts.ResetValue)
1646
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $resetDisplay, $metaFont, $resetRect, $metaColor, $leftFlags)
1647
+ }
1648
+ if ($parts.WeekValue) {
1649
+ $weekRect = [System.Drawing.Rectangle]::new($layout.WeekX, $y, $layout.WeekW, $layout.RowH)
1650
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, [string]$parts.WeekValue, $metaFont, $weekRect, $metaColor, $leftFlags)
1651
+ }
1652
+ } elseif ($parts.ExtraText) {
1653
+ $extraW = [math]::Max(1, ($Width - $layout.PadX) - $layout.ResetX)
1654
+ $extraRect = [System.Drawing.Rectangle]::new($layout.ResetX, $y, $extraW, $layout.RowH)
1655
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, [string]$parts.ExtraText, $metaFont, $extraRect, $metaColor, $rightFlags)
1656
+ }
1657
+ $idx += 1
1658
+ }
1659
+
1660
+ $divY = $Height - $layout.FooterH
1661
+ $divColor = if ($lightCard) { [System.Drawing.Color]::FromArgb(216, 216, 224) } else { [System.Drawing.Color]::FromArgb(62, 62, 68) }
1662
+ $divPen = [System.Drawing.Pen]::new($divColor, 1.0)
1663
+ try {
1664
+ $Graphics.DrawLine($divPen, $layout.PadX, $divY, ($Width - $layout.PadX), $divY)
1665
+ } finally {
1666
+ $divPen.Dispose()
1667
+ }
1668
+
1669
+ $rects = Get-HorizontalDetailFooterRects $Width $Height
1670
+ $footerColor = if ($lightCard) { [System.Drawing.Color]::FromArgb(48, 48, 56) } else { [System.Drawing.Color]::FromArgb(200, 200, 206) }
1671
+ $refreshText = if (Get-Command Get-HudUiText -ErrorAction SilentlyContinue) { Get-HudUiText "Refresh" "새로고침" } else { "Refresh" }
1672
+ $quitText = if (Get-Command Get-HudUiText -ErrorAction SilentlyContinue) { Get-HudUiText "Quit" "종료" } else { "Quit" }
1673
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $refreshText, $footerFont, $rects.Refresh, $footerColor, $leftFlags)
1674
+ [System.Windows.Forms.TextRenderer]::DrawText($Graphics, $quitText, $footerFont, $rects.Quit, $footerColor, $rightFlags)
1675
+ } finally {
1676
+ $nameFont.Dispose()
1677
+ $metaFont.Dispose()
1678
+ $footerFont.Dispose()
1679
+ }
1680
+ }