ai-battery 0.2.1 → 0.2.3

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.
@@ -1,4 +1,4 @@
1
- param(
1
+ param(
2
2
  [int]$Interval = 2,
3
3
  [string]$Position = $(if ($env:AI_BATTERY_HUD_POSITION) { $env:AI_BATTERY_HUD_POSITION } elseif ($env:CLAUDEX_BATTERY_HUD_POSITION) { $env:CLAUDEX_BATTERY_HUD_POSITION } else { "saved" }),
4
4
  [ValidateSet("tray", "statusline", "floating", "icon", "rail", "horizontal")]
@@ -7,6 +7,9 @@ param(
7
7
  [string]$BatteryCommandBase64 = "",
8
8
  [string]$InitialJsonBase64 = "",
9
9
  [int]$Width = 282,
10
+ [double]$Scale = $(if ($env:AI_BATTERY_HUD_SCALE) { [double]$env:AI_BATTERY_HUD_SCALE } elseif ($env:CLAUDEX_BATTERY_HUD_SCALE) { [double]$env:CLAUDEX_BATTERY_HUD_SCALE } else { 0.0 }),
11
+ [ValidateSet("", "white", "black")]
12
+ [string]$CodexIcon = $(if ($env:AI_BATTERY_CODEX_ICON_COLOR) { $env:AI_BATTERY_CODEX_ICON_COLOR } else { "" }),
10
13
  [string]$Backdrop = $(if ($env:AI_BATTERY_HUD_BACKDROP) { $env:AI_BATTERY_HUD_BACKDROP } elseif ($env:CLAUDEX_BATTERY_HUD_BACKDROP) { $env:CLAUDEX_BATTERY_HUD_BACKDROP } else { "off" }),
11
14
  [string]$Text = $(if ($env:AI_BATTERY_HUD_TEXT) { $env:AI_BATTERY_HUD_TEXT } elseif ($env:CLAUDEX_BATTERY_HUD_TEXT) { $env:CLAUDEX_BATTERY_HUD_TEXT } else { "light" }),
12
15
  [string]$Transparent = "",
@@ -31,7 +34,32 @@ param(
31
34
  $ErrorActionPreference = "Stop"
32
35
  Add-Type -AssemblyName System.Drawing
33
36
  [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
34
- if ($env:AI_BATTERY_HUD_DEBUG_LOG) { Add-Content $env:AI_BATTERY_HUD_DEBUG_LOG "boot dock=$DockWindowHandle placement=$DockPlacement once=$Once mode=$Mode" }
37
+ if ($env:AI_BATTERY_HUD_DEBUG_LOG) { Add-Content $env:AI_BATTERY_HUD_DEBUG_LOG "boot dock=$DockWindowHandle placement=$DockPlacement once=$Once mode=$Mode scale=$Scale codexIcon=$CodexIcon" }
38
+
39
+ function Get-HudUiLanguage {
40
+ $candidates = @()
41
+ if (-not [string]::IsNullOrWhiteSpace($env:LANGUAGE)) {
42
+ $candidates += ($env:LANGUAGE -split ":")
43
+ } else {
44
+ foreach ($val in @($env:LC_ALL, $env:LC_MESSAGES, $env:LANG)) {
45
+ if (-not [string]::IsNullOrWhiteSpace($val)) { $candidates += $val }
46
+ }
47
+ try { $candidates += [System.Globalization.CultureInfo]::CurrentUICulture.Name } catch { }
48
+ }
49
+ foreach ($candidate in $candidates) {
50
+ $base = ([string]$candidate).Trim().ToLowerInvariant() -replace '[_@.\-].*$', ''
51
+ if ($base -eq "ko") { return "ko" }
52
+ if ($base -eq "en") { return "en" }
53
+ if ((@("c", "posix") -contains $base) -and (-not [string]::IsNullOrWhiteSpace($env:LANGUAGE))) { return "en" }
54
+ }
55
+ return "en"
56
+ }
57
+
58
+ $script:hudLanguage = Get-HudUiLanguage
59
+ function Get-HudUiText([string]$English, [string]$Korean) {
60
+ if ($script:hudLanguage -eq "ko") { return $Korean }
61
+ return $English
62
+ }
35
63
 
36
64
  if (-not [string]::IsNullOrWhiteSpace($BatteryCommandBase64)) {
37
65
  try {
@@ -366,6 +394,7 @@ function Write-HudPosition($Point) {
366
394
  Y = [int]$Point.Y
367
395
  Width = $width
368
396
  Height = $height
397
+ Scale = [double]$script:hudUserScale
369
398
  } | ConvertTo-Json -Compress
370
399
  Write-HudTextAtomic (Get-HudStatePath) $payload
371
400
  } catch {
@@ -450,6 +479,9 @@ using System.Runtime.InteropServices;
450
479
  using System.Windows.Forms;
451
480
  public class AiBatteryHudForm : Form {
452
481
  private const int WM_GETMINMAXINFO = 0x0024;
482
+ private const int WM_MOUSEWHEEL = 0x020A;
483
+ private const int MK_CONTROL = 0x0008;
484
+ public event Action<int> HudCtrlWheel;
453
485
  [StructLayout(LayoutKind.Sequential)]
454
486
  private struct POINT {
455
487
  public int X;
@@ -464,6 +496,19 @@ public class AiBatteryHudForm : Form {
464
496
  public POINT ptMaxTrackSize;
465
497
  }
466
498
  protected override void WndProc(ref Message m) {
499
+ if (m.Msg == WM_MOUSEWHEEL) {
500
+ long wp = m.WParam.ToInt64();
501
+ int keys = (int)(wp & 0xFFFF);
502
+ if ((keys & MK_CONTROL) != 0) {
503
+ int delta = (short)((wp >> 16) & 0xFFFF);
504
+ var handler = HudCtrlWheel;
505
+ if (handler != null) {
506
+ handler(delta);
507
+ m.Result = IntPtr.Zero;
508
+ return;
509
+ }
510
+ }
511
+ }
467
512
  base.WndProc(ref m);
468
513
  if (m.Msg == WM_GETMINMAXINFO && m.LParam != IntPtr.Zero) {
469
514
  MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(MINMAXINFO));
@@ -508,6 +553,24 @@ try {
508
553
  # The default is already GDI text rendering on older WinForms.
509
554
  }
510
555
 
556
+ $script:hudUserScale = 1.0
557
+ if ($DockWindowHandle -eq 0) {
558
+ if ($Scale -gt 0) {
559
+ $script:hudUserScale = [math]::Round([math]::Max(0.5, [math]::Min(3.0, [double]$Scale)), 2)
560
+ } elseif ($Position -eq "saved") {
561
+ $savedForScale = Read-HudPlacement
562
+ if ($savedForScale -and $null -ne $savedForScale.Scale) {
563
+ try {
564
+ $parsedSavedScale = [double]$savedForScale.Scale
565
+ if (-not [double]::IsNaN($parsedSavedScale) -and -not [double]::IsInfinity($parsedSavedScale) -and $parsedSavedScale -ge 0.5 -and $parsedSavedScale -le 3.0) {
566
+ $script:hudUserScale = [math]::Round($parsedSavedScale, 2)
567
+ }
568
+ } catch { }
569
+ }
570
+ }
571
+ }
572
+ $script:hudCodexIconMode = ([string]$CodexIcon).Trim().ToLowerInvariant()
573
+
511
574
  . (Join-Path $PSScriptRoot "rendering.ps1")
512
575
 
513
576
  if ($Mode -eq "tray") {
@@ -684,6 +747,13 @@ $script:hudSurfaceBackColor = if ($script:hudTransparentSurface) {
684
747
  } else {
685
748
  $script:hudChromeBackColor
686
749
  }
750
+ $script:hudStackBackColor = if ($script:dockTuiStatusline) {
751
+ $script:hudChromeBackColor
752
+ } elseif ($script:hudContrastBackdrop -or (-not $script:hudTransparentSurface)) {
753
+ $script:hudChromeBackColor
754
+ } else {
755
+ $script:hudSurfaceBackColor
756
+ }
687
757
  $form.Opacity = if ($script:dockTuiStatusline) {
688
758
  1.0
689
759
  } else {
@@ -701,7 +771,9 @@ function New-HudMainFont {
701
771
  [System.Drawing.GraphicsUnit]::Pixel
702
772
  )
703
773
  }
704
- return [System.Drawing.Font]::new("Segoe UI", $(if ($Mode -eq "statusline") { 8.5 } else { 9 }), [System.Drawing.FontStyle]::Regular)
774
+ $basePt = if ($Mode -eq "statusline") { 8.5 } else { 9.0 }
775
+ $scaledPt = [single][math]::Max(5.5, ($basePt * (Clamp-HudUserScale $script:hudUserScale)))
776
+ return [System.Drawing.Font]::new("Segoe UI", $scaledPt, [System.Drawing.FontStyle]::Regular)
705
777
  }
706
778
 
707
779
  function New-HudSymbolFont {
@@ -713,11 +785,14 @@ function New-HudSymbolFont {
713
785
  [System.Drawing.GraphicsUnit]::Pixel
714
786
  )
715
787
  }
716
- return [System.Drawing.Font]::new("Cascadia Mono", $(if ($Mode -eq "statusline") { 11.5 } else { 12 }), [System.Drawing.FontStyle]::Regular)
788
+ $basePt = if ($Mode -eq "statusline") { 11.5 } else { 12.0 }
789
+ $scaledPt = [single][math]::Max(7.0, ($basePt * (Clamp-HudUserScale $script:hudUserScale)))
790
+ return [System.Drawing.Font]::new("Cascadia Mono", $scaledPt, [System.Drawing.FontStyle]::Regular)
717
791
  }
718
792
 
719
793
  $font = New-HudMainFont
720
794
  $symbolFont = New-HudSymbolFont
795
+ $menuFont = [System.Drawing.Font]::new("Segoe UI", 9, [System.Drawing.FontStyle]::Regular)
721
796
 
722
797
  $panel = New-Object System.Windows.Forms.TableLayoutPanel
723
798
  Enable-HudDoubleBuffering $panel
@@ -732,7 +807,7 @@ $panel.Padding = if ($script:dockTuiStatusline) {
732
807
  } else {
733
808
  New-HudPadding 10 7 10 6
734
809
  }
735
- $panel.BackColor = $script:hudSurfaceBackColor
810
+ $panel.BackColor = $script:hudStackBackColor
736
811
  $panel.RowStyles.Add([System.Windows.Forms.RowStyle]::new([System.Windows.Forms.SizeType]::Percent, $(if ($script:dockTuiStatusline) { 100 } else { 50 }))) | Out-Null
737
812
  if (-not $script:dockTuiStatusline) {
738
813
  $panel.RowStyles.Add([System.Windows.Forms.RowStyle]::new([System.Windows.Forms.SizeType]::Percent, 50)) | Out-Null
@@ -748,7 +823,7 @@ function New-HudRow {
748
823
  $row.WrapContents = $false
749
824
  $row.Margin = [System.Windows.Forms.Padding]::new(0)
750
825
  $row.Padding = [System.Windows.Forms.Padding]::new(0)
751
- $row.BackColor = $script:hudSurfaceBackColor
826
+ $row.BackColor = if ($null -ne $script:hudStackBackColor) { $script:hudStackBackColor } else { $script:hudSurfaceBackColor }
752
827
  return $row
753
828
  }
754
829
 
@@ -759,7 +834,7 @@ function New-HudLabel([int]$RightMargin = 0) {
759
834
  $label.Height = Scale-HudValue 18
760
835
  $label.Font = $font
761
836
  $label.UseCompatibleTextRendering = $false
762
- $label.BackColor = $script:hudSurfaceBackColor
837
+ $label.BackColor = if ($null -ne $script:hudStackBackColor) { $script:hudStackBackColor } else { $script:hudSurfaceBackColor }
763
838
  $label.Margin = New-HudPadding 0 0 $RightMargin 0
764
839
  $label.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft
765
840
  return $label
@@ -770,7 +845,7 @@ function New-HudIconBox {
770
845
  $box.Width = Scale-HudValue 40
771
846
  $box.Height = Scale-HudValue 18
772
847
  $box.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::Zoom
773
- $box.BackColor = $script:hudSurfaceBackColor
848
+ $box.BackColor = if ($null -ne $script:hudStackBackColor) { $script:hudStackBackColor } else { $script:hudSurfaceBackColor }
774
849
  $box.ForeColor = Get-HudBatteryTextColor $true
775
850
  $box.Margin = New-HudPadding 0 0 2 0
776
851
  $box.add_Paint({
@@ -1107,12 +1182,145 @@ function Test-PointInBounds($Bounds, [System.Drawing.Point]$Point) {
1107
1182
  }
1108
1183
 
1109
1184
  $menu = New-Object System.Windows.Forms.ContextMenuStrip
1110
- $menu.Font = $font
1185
+ $menu.Font = $menuFont
1111
1186
  $menu.AutoClose = $true
1112
1187
  $script:hudMenuOpenedAt = [datetime]::UtcNow
1113
1188
  $script:hudMenuLastInsideAt = [datetime]::UtcNow
1114
1189
  $script:hudMenuReadyForOutsideClick = $false
1115
1190
  $toggleLayoutItem = $null
1191
+ $iconModeItem = $null
1192
+ $railModeItem = $null
1193
+ $stackModeItem = $null
1194
+ $largerSizeItem = $null
1195
+ $smallerSizeItem = $null
1196
+ $resetSizeItem = $null
1197
+ $whiteTextItem = $null
1198
+ $blackTextItem = $null
1199
+ $backdropItem = $null
1200
+
1201
+ function Update-HudMenuChecks {
1202
+ if ($iconModeItem) { $iconModeItem.Checked = ($script:hudCustomLayout -eq "icon") }
1203
+ if ($railModeItem) { $railModeItem.Checked = ($script:hudCustomLayout -eq "rail") }
1204
+ if ($stackModeItem) { $stackModeItem.Checked = ($script:hudCustomLayout -eq "stack") }
1205
+ if ($whiteTextItem) { $whiteTextItem.Checked = (-not $script:hudDarkText) }
1206
+ if ($blackTextItem) { $blackTextItem.Checked = ([bool]$script:hudDarkText) }
1207
+ if ($backdropItem) { $backdropItem.Checked = ([bool]$script:hudContrastBackdrop) }
1208
+ if ($resetSizeItem) {
1209
+ $pct = [int][math]::Round((Clamp-HudUserScale $script:hudUserScale) * 100)
1210
+ $resetSizeItem.Text = if ($pct -eq 100) {
1211
+ Get-HudUiText "Reset Size (100%)" "기본 크기 (100%)"
1212
+ } else {
1213
+ Get-HudUiText "Reset Size (100%) · $pct%" "기본 크기 (100%) · $pct%"
1214
+ }
1215
+ }
1216
+ }
1217
+
1218
+ function Apply-HudAppearance {
1219
+ if ($script:dockTuiStatusline) { return }
1220
+ $script:hudChromeBackColor = if ($script:hudDarkText) {
1221
+ [System.Drawing.Color]::FromArgb(244, 244, 248)
1222
+ } else {
1223
+ [System.Drawing.Color]::FromArgb(24, 24, 24)
1224
+ }
1225
+ if ($script:hudTransparentSurface) {
1226
+ $transparentBackColor = if ($script:hudDarkText) {
1227
+ [System.Drawing.Color]::FromArgb(254, 254, 254)
1228
+ } else {
1229
+ [System.Drawing.Color]::FromArgb(18, 18, 18)
1230
+ }
1231
+ $form.BackColor = $transparentBackColor
1232
+ $form.TransparencyKey = $transparentBackColor
1233
+ } else {
1234
+ $form.BackColor = $script:hudChromeBackColor
1235
+ }
1236
+ $script:hudSurfaceBackColor = if ($script:hudTransparentSurface) {
1237
+ $form.BackColor
1238
+ } else {
1239
+ $script:hudChromeBackColor
1240
+ }
1241
+ $script:hudStackBackColor = if ($script:hudContrastBackdrop -or (-not $script:hudTransparentSurface)) {
1242
+ $script:hudChromeBackColor
1243
+ } else {
1244
+ $script:hudSurfaceBackColor
1245
+ }
1246
+ $panel.BackColor = $script:hudStackBackColor
1247
+ if ($script:horizontalPaintPanel) {
1248
+ $script:horizontalPaintPanel.BackColor = $script:hudSurfaceBackColor
1249
+ }
1250
+ $dividerColor = Get-DividerColor
1251
+ foreach ($entry in $script:hudProviderRows.Values) {
1252
+ $entry.Row.BackColor = $script:hudStackBackColor
1253
+ foreach ($ctrl in $entry.Controls) {
1254
+ if ($ctrl -is [System.Windows.Forms.Panel]) {
1255
+ $ctrl.BackColor = $dividerColor
1256
+ } else {
1257
+ $ctrl.BackColor = $script:hudStackBackColor
1258
+ }
1259
+ }
1260
+ }
1261
+ if ($providerDivider) { $providerDivider.BackColor = $dividerColor }
1262
+ if ($script:detailPopupForm -and -not $script:detailPopupForm.IsDisposed) {
1263
+ $script:detailPopupForm.BackColor = if ($script:hudDarkText) {
1264
+ [System.Drawing.Color]::FromArgb(246, 246, 250)
1265
+ } else {
1266
+ [System.Drawing.Color]::FromArgb(38, 38, 43)
1267
+ }
1268
+ $script:detailPopupForm.Invalidate()
1269
+ }
1270
+ $script:hudBatteryRenderKeys = @{}
1271
+ $script:hudVisualKey = $null
1272
+ Update-HudFromSnapshot $script:latestSnapshot
1273
+ if ($script:horizontalPaintPanel) { $script:horizontalPaintPanel.Invalidate() }
1274
+ $form.Invalidate($true)
1275
+ Update-HudMenuChecks
1276
+ }
1277
+
1278
+ function Set-HudUserScale([double]$NextScale, [switch]$SkipSave) {
1279
+ if ($script:dockTuiStatusline) { return }
1280
+ $clamped = Clamp-HudUserScale $NextScale
1281
+ if ([math]::Abs($clamped - $script:hudUserScale) -lt 0.005) { return }
1282
+ $script:hudUserScale = $clamped
1283
+ Update-HudDpiScale
1284
+ $script:hudTwoRowHeight = Scale-HudValue 44
1285
+ $script:hudOneRowHeight = [math]::Max((Scale-HudValue 20), $script:hudTwoRowHeight - (Scale-HudValue 18))
1286
+
1287
+ $oldFont = $script:font
1288
+ $oldSymbolFont = $script:symbolFont
1289
+ $script:font = New-HudMainFont
1290
+ $script:symbolFont = New-HudSymbolFont
1291
+
1292
+ $panel.Padding = if (@("floating", "statusline", "icon", "rail", "horizontal") -contains $Mode) {
1293
+ New-HudPadding 6 4 2 3
1294
+ } else {
1295
+ New-HudPadding 10 7 10 6
1296
+ }
1297
+ foreach ($entry in $script:hudProviderRows.Values) {
1298
+ foreach ($ctrl in $entry.Controls) {
1299
+ if ($ctrl -is [System.Windows.Forms.Label]) {
1300
+ $ctrl.Font = $script:font
1301
+ $ctrl.Height = Scale-HudValue 18
1302
+ } elseif ($ctrl -is [System.Windows.Forms.PictureBox]) {
1303
+ $ctrl.Width = Scale-HudValue 42
1304
+ $ctrl.Height = Scale-HudValue 18
1305
+ $ctrl.Margin = New-HudPadding 0 0 2 0
1306
+ } elseif ($ctrl -is [System.Windows.Forms.Panel]) {
1307
+ $ctrl.Width = Scale-HudValue 1
1308
+ $ctrl.Height = Scale-HudValue 12
1309
+ $ctrl.Margin = New-HudPadding 4 3 4 3
1310
+ }
1311
+ }
1312
+ }
1313
+ if ($oldFont) { try { $oldFont.Dispose() } catch { } }
1314
+ if ($oldSymbolFont) { try { $oldSymbolFont.Dispose() } catch { } }
1315
+
1316
+ $script:hudBatteryRenderKeys = @{}
1317
+ $script:hudVisualKey = $null
1318
+ Update-HudFromSnapshot $script:latestSnapshot
1319
+ if ($script:horizontalPaintPanel) { $script:horizontalPaintPanel.Invalidate() }
1320
+ if (-not $SkipSave) { Save-HudPositionIfReady }
1321
+ Update-HudMenuChecks
1322
+ }
1323
+
1116
1324
  if (-not $script:dockTuiStatusline) {
1117
1325
  $setHudLayout = {
1118
1326
  param([string]$NextLayout)
@@ -1126,16 +1334,48 @@ if (-not $script:dockTuiStatusline) {
1126
1334
  }
1127
1335
  $script:hudVisualKey = $null
1128
1336
  Update-HudFromSnapshot $script:latestSnapshot
1337
+ Update-HudMenuChecks
1129
1338
  }
1130
- $iconModeItem = $menu.Items.Add("Icon Panel")
1339
+ $iconModeItem = $menu.Items.Add((Get-HudUiText "Icon Panel" "아이콘 패널"))
1131
1340
  $iconModeItem.add_Click({ & $setHudLayout "icon" })
1132
- $railModeItem = $menu.Items.Add("Rail Panel")
1341
+ $railModeItem = $menu.Items.Add((Get-HudUiText "Rail Panel" "세로 레일"))
1133
1342
  $railModeItem.add_Click({ & $setHudLayout "rail" })
1134
- $stackModeItem = $menu.Items.Add("Stack Panel")
1343
+ $stackModeItem = $menu.Items.Add((Get-HudUiText "Stack Panel" "스택 패널"))
1135
1344
  $stackModeItem.add_Click({ & $setHudLayout "stack" })
1136
1345
  $menu.Items.Add("-") | Out-Null
1346
+
1347
+ $largerSizeItem = $menu.Items.Add((Get-HudUiText "Larger (+)" "크게 (+)"))
1348
+ $largerSizeItem.add_Click({ Set-HudUserScale ($script:hudUserScale + 0.15) })
1349
+ $smallerSizeItem = $menu.Items.Add((Get-HudUiText "Smaller (-)" "작게 (-)"))
1350
+ $smallerSizeItem.add_Click({ Set-HudUserScale ($script:hudUserScale - 0.15) })
1351
+ $resetSizeItem = $menu.Items.Add((Get-HudUiText "Reset Size (100%)" "기본 크기 (100%)"))
1352
+ $resetSizeItem.add_Click({ Set-HudUserScale 1.0 })
1353
+ $menu.Items.Add("-") | Out-Null
1354
+
1355
+ $whiteTextItem = $menu.Items.Add((Get-HudUiText "White Text" "흰색 글자"))
1356
+ $whiteTextItem.add_Click({
1357
+ $script:hudDarkText = $false
1358
+ $script:hudCodexIconMode = ""
1359
+ Apply-HudAppearance
1360
+ })
1361
+ $blackTextItem = $menu.Items.Add((Get-HudUiText "Black Text" "검은색 글자"))
1362
+ $blackTextItem.add_Click({
1363
+ $script:hudDarkText = $true
1364
+ $script:hudCodexIconMode = ""
1365
+ Apply-HudAppearance
1366
+ })
1367
+ $backdropItem = $menu.Items.Add((Get-HudUiText "Backdrop" "배경 표시"))
1368
+ $backdropItem.add_Click({
1369
+ $script:hudContrastBackdrop = -not $script:hudContrastBackdrop
1370
+ Apply-HudAppearance
1371
+ })
1372
+ $menu.Items.Add("-") | Out-Null
1373
+
1374
+ $refreshMenuItem = $menu.Items.Add((Get-HudUiText "Refresh" "새로고침"))
1375
+ $refreshMenuItem.add_Click({ try { Start-SnapshotFetch } catch { } })
1376
+ Update-HudMenuChecks
1137
1377
  }
1138
- $exitItem = $menu.Items.Add("Exit")
1378
+ $exitItem = $menu.Items.Add((Get-HudUiText "Quit AI Battery" "AI Battery 종료"))
1139
1379
  $exitItem.add_Click({ $form.Close() })
1140
1380
  $menu.add_Opened({
1141
1381
  $script:hudMenuOpenedAt = [datetime]::UtcNow
@@ -1329,7 +1569,7 @@ function Update-HorizontalDetailPopupBounds {
1329
1569
  $script:detailPopupForm.Size = $size
1330
1570
  $screen = [System.Windows.Forms.Screen]::FromControl($form)
1331
1571
  $work = $screen.WorkingArea
1332
- $gap = Scale-HudValue 6
1572
+ $gap = Scale-HudDpiValue 6
1333
1573
  $x = $form.Left + [int][math]::Floor(($form.Width - $size.Width) / 2)
1334
1574
  $x = [math]::Max($work.Left + $gap, [math]::Min($work.Right - $size.Width - $gap, $x))
1335
1575
  $y = $form.Bottom + $gap
@@ -1338,7 +1578,7 @@ function Update-HorizontalDetailPopupBounds {
1338
1578
  }
1339
1579
  $y = [math]::Max($work.Top + $gap, [math]::Min($work.Bottom - $size.Height - $gap, $y))
1340
1580
  $script:detailPopupForm.Location = [System.Drawing.Point]::new([int]$x, [int]$y)
1341
- $regionPath = New-RoundedRectPath ([single]0) ([single]0) ([single]$size.Width) ([single]$size.Height) ([single](Scale-HudValue 10))
1581
+ $regionPath = New-RoundedRectPath ([single]0) ([single]0) ([single]$size.Width) ([single]$size.Height) ([single](Scale-HudDpiValue 10))
1342
1582
  try {
1343
1583
  $oldRegion = $script:detailPopupForm.Region
1344
1584
  $script:detailPopupForm.Region = [System.Drawing.Region]::new($regionPath)
@@ -1364,7 +1604,11 @@ function Toggle-HorizontalDetailPopup {
1364
1604
  $popup.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None
1365
1605
  $popup.ShowInTaskbar = $false
1366
1606
  $popup.TopMost = $true
1367
- $popup.BackColor = [System.Drawing.Color]::FromArgb(38, 38, 43)
1607
+ $popup.BackColor = if ($script:hudDarkText) {
1608
+ [System.Drawing.Color]::FromArgb(246, 246, 250)
1609
+ } else {
1610
+ [System.Drawing.Color]::FromArgb(38, 38, 43)
1611
+ }
1368
1612
  $popup.add_Paint({
1369
1613
  param($sender, $event)
1370
1614
  Draw-HorizontalDetailCard $event.Graphics $sender.Width $sender.Height $script:latestHudTexts
@@ -1399,12 +1643,64 @@ $dragging = $false
1399
1643
  $dragOffset = [System.Drawing.Point]::new(0, 0)
1400
1644
  $script:dragStartScreen = [System.Drawing.Point]::new(0, 0)
1401
1645
  $script:dragMoved = $false
1646
+ $script:resizeDrag = $null
1647
+
1648
+ function Get-HudResizeCorner([int]$LocalX, [int]$LocalY, [int]$Width, [int]$Height) {
1649
+ if ($script:dockTuiStatusline -or $Width -le 0 -or $Height -le 0) { return $null }
1650
+ $maxZone = [math]::Max(10, (Scale-HudDpiValue 12))
1651
+ $zone = [math]::Max(6, [math]::Min($maxZone, [int][math]::Floor([math]::Min($Width, $Height) / 4)))
1652
+ $left = $LocalX -lt $zone
1653
+ $right = $LocalX -ge ($Width - $zone)
1654
+ $top = $LocalY -lt $zone
1655
+ $bottom = $LocalY -ge ($Height - $zone)
1656
+ if ($top -and $left) { return "nw" }
1657
+ if ($top -and $right) { return "ne" }
1658
+ if ($bottom -and $left) { return "sw" }
1659
+ if ($bottom -and $right) { return "se" }
1660
+ return $null
1661
+ }
1662
+
1663
+ function Set-HudResizeCursor([string]$Corner) {
1664
+ $cursor = if ($Corner -eq "nw" -or $Corner -eq "se") {
1665
+ [System.Windows.Forms.Cursors]::SizeNWSE
1666
+ } elseif ($Corner -eq "ne" -or $Corner -eq "sw") {
1667
+ [System.Windows.Forms.Cursors]::SizeNESW
1668
+ } else {
1669
+ [System.Windows.Forms.Cursors]::Default
1670
+ }
1671
+ foreach ($target in @($form, $hitForm, $panel, $script:horizontalPaintPanel)) {
1672
+ if ($target -and -not $target.IsDisposed -and $target.Cursor -ne $cursor) {
1673
+ $target.Cursor = $cursor
1674
+ }
1675
+ }
1676
+ }
1677
+
1402
1678
  $mouseDown = {
1403
1679
  param($sender, $event)
1404
1680
  if ($event.Button -eq [System.Windows.Forms.MouseButtons]::Left) {
1681
+ $screenPoint = $sender.PointToScreen([System.Drawing.Point]::new($event.X, $event.Y))
1682
+ $localX = $screenPoint.X - $form.Left
1683
+ $localY = $screenPoint.Y - $form.Top
1684
+ $corner = Get-HudResizeCorner $localX $localY $form.Width $form.Height
1685
+ if ($corner) {
1686
+ $script:dragging = $false
1687
+ $script:dragMoved = $false
1688
+ $script:resizeDrag = @{
1689
+ Corner = $corner
1690
+ StartX = $screenPoint.X
1691
+ StartY = $screenPoint.Y
1692
+ StartScale = [double]$script:hudUserScale
1693
+ StartLeft = [int]$form.Left
1694
+ StartTop = [int]$form.Top
1695
+ StartWidth = [math]::Max(1, [int]$form.Width)
1696
+ StartHeight = [math]::Max(1, [int]$form.Height)
1697
+ Moved = $false
1698
+ }
1699
+ Set-HudResizeCursor $corner
1700
+ return
1701
+ }
1405
1702
  $script:dragging = $true
1406
1703
  $script:dragMoved = $false
1407
- $screenPoint = $sender.PointToScreen([System.Drawing.Point]::new($event.X, $event.Y))
1408
1704
  $script:dragStartScreen = $screenPoint
1409
1705
  $script:dragOffset = [System.Drawing.Point]::new(
1410
1706
  ($screenPoint.X - $form.Location.X),
@@ -1414,8 +1710,31 @@ $mouseDown = {
1414
1710
  }
1415
1711
  $mouseMove = {
1416
1712
  param($sender, $event)
1713
+ $screenPoint = $sender.PointToScreen([System.Drawing.Point]::new($event.X, $event.Y))
1714
+ if ($script:resizeDrag) {
1715
+ $dx = $screenPoint.X - $script:resizeDrag.StartX
1716
+ $dy = $screenPoint.Y - $script:resizeDrag.StartY
1717
+ if ((-not $script:resizeDrag.Moved) -and (([math]::Abs($dx) -ge 2) -or ([math]::Abs($dy) -ge 2))) {
1718
+ $script:resizeDrag.Moved = $true
1719
+ Hide-HorizontalDetailPopup
1720
+ }
1721
+ if ($script:resizeDrag.Moved) {
1722
+ $sx = if ($script:resizeDrag.Corner.Contains("w")) { -$dx } else { $dx }
1723
+ $sy = if ($script:resizeDrag.Corner.Contains("n")) { -$dy } else { $dy }
1724
+ $aspect = [double]$script:resizeDrag.StartWidth / [double]$script:resizeDrag.StartHeight
1725
+ $deltaW = ($sx + ($sy * $aspect)) / 2.0
1726
+ $nextScale = Clamp-HudUserScale ($script:resizeDrag.StartScale * (($script:resizeDrag.StartWidth + $deltaW) / [double]$script:resizeDrag.StartWidth))
1727
+ if ([math]::Abs($nextScale - $script:hudUserScale) -ge 0.02) {
1728
+ Set-HudUserScale $nextScale -SkipSave
1729
+ $nextX = if ($script:resizeDrag.Corner.Contains("w")) { $script:resizeDrag.StartLeft + ($script:resizeDrag.StartWidth - $form.Width) } else { $script:resizeDrag.StartLeft }
1730
+ $nextY = if ($script:resizeDrag.Corner.Contains("n")) { $script:resizeDrag.StartTop + ($script:resizeDrag.StartHeight - $form.Height) } else { $script:resizeDrag.StartTop }
1731
+ $form.Location = [System.Drawing.Point]::new([int]$nextX, [int]$nextY)
1732
+ Sync-HitFormBounds
1733
+ }
1734
+ }
1735
+ return
1736
+ }
1417
1737
  if ($script:dragging) {
1418
- $screenPoint = $sender.PointToScreen([System.Drawing.Point]::new($event.X, $event.Y))
1419
1738
  if ((-not $script:dragMoved) -and (([math]::Abs($screenPoint.X - $script:dragStartScreen.X) -ge 4) -or ([math]::Abs($screenPoint.Y - $script:dragStartScreen.Y) -ge 4))) {
1420
1739
  $script:dragMoved = $true
1421
1740
  Hide-HorizontalDetailPopup
@@ -1424,10 +1743,27 @@ $mouseMove = {
1424
1743
  $form.Location = [System.Drawing.Point]::new(($screenPoint.X - $script:dragOffset.X), ($screenPoint.Y - $script:dragOffset.Y))
1425
1744
  Sync-HitFormBounds
1426
1745
  }
1746
+ return
1427
1747
  }
1748
+ $localX = $screenPoint.X - $form.Left
1749
+ $localY = $screenPoint.Y - $form.Top
1750
+ Set-HudResizeCursor (Get-HudResizeCorner $localX $localY $form.Width $form.Height)
1428
1751
  }
1429
1752
  $mouseUp = {
1430
1753
  param($sender, $event)
1754
+ if ($script:resizeDrag) {
1755
+ $wasResizeMoved = [bool]$script:resizeDrag.Moved
1756
+ $script:resizeDrag = $null
1757
+ $screenPoint = $sender.PointToScreen([System.Drawing.Point]::new($event.X, $event.Y))
1758
+ Set-HudResizeCursor (Get-HudResizeCorner ($screenPoint.X - $form.Left) ($screenPoint.Y - $form.Top) $form.Width $form.Height)
1759
+ if ($wasResizeMoved) {
1760
+ Save-HudPositionIfReady
1761
+ Ensure-HudTopMost
1762
+ } elseif ($script:hudHorizontalPanel) {
1763
+ Toggle-HorizontalDetailPopup
1764
+ }
1765
+ return
1766
+ }
1431
1767
  $wasDragging = $script:dragging
1432
1768
  $wasMoved = $script:dragMoved
1433
1769
  $script:dragging = $false
@@ -1442,6 +1778,12 @@ $mouseUp = {
1442
1778
  Ensure-HudTopMost
1443
1779
  }
1444
1780
  }
1781
+ $mouseLeave = {
1782
+ param($sender, $event)
1783
+ if (-not $script:resizeDrag) {
1784
+ Set-HudResizeCursor $null
1785
+ }
1786
+ }
1445
1787
  # A docked HUD is glued to its terminal window; dragging and position saving
1446
1788
  # are floating-mode concepts.
1447
1789
  $canMove = ($DockWindowHandle -eq 0) -and ($Movable -or ((@("floating", "icon", "rail", "horizontal") -contains $Mode) -and (-not $Locked)))
@@ -1462,6 +1804,17 @@ if ($canMove) {
1462
1804
  $control.add_MouseDown($mouseDown)
1463
1805
  $control.add_MouseMove($mouseMove)
1464
1806
  $control.add_MouseUp($mouseUp)
1807
+ $control.add_MouseLeave($mouseLeave)
1808
+ }
1809
+ $ctrlWheelHandler = [Action[int]]{
1810
+ param($delta)
1811
+ $step = if ($delta -gt 0) { 0.1 } elseif ($delta -lt 0) { -0.1 } else { 0 }
1812
+ if ($step -ne 0) { Set-HudUserScale ($script:hudUserScale + $step) }
1813
+ }
1814
+ foreach ($wheelForm in @($form, $hitForm)) {
1815
+ if ($wheelForm -and ($wheelForm -is [AiBatteryHudForm])) {
1816
+ $wheelForm.add_HudCtrlWheel($ctrlWheelHandler)
1817
+ }
1465
1818
  }
1466
1819
  }
1467
1820
 
@@ -1636,6 +1989,7 @@ $form.add_FormClosed({
1636
1989
  }
1637
1990
  $font.Dispose()
1638
1991
  $symbolFont.Dispose()
1992
+ if ($menuFont) { $menuFont.Dispose() }
1639
1993
  if ($script:detailPopupForm -and -not $script:detailPopupForm.IsDisposed) {
1640
1994
  $script:detailPopupForm.Close()
1641
1995
  $script:detailPopupForm.Dispose()