Files
playFun-uni/scripts/generate-tab-icons.ps1
2026-10-12 11:22:54 +08:00

77 lines
2.8 KiB
PowerShell

Add-Type -AssemblyName System.Drawing
# Draw 27px line icons at 3x resolution for the native tab bar.
function Draw-TabIcon {
param(
[System.Drawing.Graphics] $Graphics,
[System.Drawing.Pen] $Pen,
[string] $Name
)
switch ($Name) {
'home' {
$Graphics.DrawLine($Pen, 3, 11, 12, 4)
$Graphics.DrawLine($Pen, 12, 4, 21, 11)
$Graphics.DrawLine($Pen, 5, 10, 5, 21)
$Graphics.DrawLine($Pen, 19, 10, 19, 21)
$Graphics.DrawLine($Pen, 5, 21, 19, 21)
$Graphics.DrawLine($Pen, 10, 21, 10, 15)
$Graphics.DrawLine($Pen, 10, 15, 14, 15)
$Graphics.DrawLine($Pen, 14, 15, 14, 21)
}
'match' {
$Graphics.DrawEllipse($Pen, 4, 4, 6, 9)
$Graphics.DrawEllipse($Pen, 14, 4, 6, 9)
$Graphics.DrawLine($Pen, 7, 13, 3, 21)
$Graphics.DrawLine($Pen, 17, 13, 21, 21)
$Graphics.DrawLine($Pen, 10, 17, 14, 17)
$Graphics.DrawEllipse($Pen, 10.5, 3, 3, 3)
}
'rank' {
$Graphics.DrawRectangle($Pen, 3, 15, 6, 6)
$Graphics.DrawRectangle($Pen, 9, 11, 6, 10)
$Graphics.DrawRectangle($Pen, 15, 17, 6, 4)
$Graphics.DrawLine($Pen, 3, 21, 21, 21)
$Graphics.DrawEllipse($Pen, 10, 3, 4, 4)
}
'shop' {
$Graphics.DrawRectangle($Pen, 4, 8, 16, 13)
$Graphics.DrawArc($Pen, 8, 3, 8, 10, 180, 180)
$Graphics.DrawLine($Pen, 8, 8, 8, 9)
$Graphics.DrawLine($Pen, 16, 8, 16, 9)
}
'me' {
$Graphics.DrawEllipse($Pen, 8, 3, 8, 8)
$Graphics.DrawBezier($Pen, 4, 21, 4, 10, 20, 10, 20, 21)
$Graphics.DrawLine($Pen, 4, 21, 20, 21)
}
}
}
# Match the native tab bar text colors in pages.json.
$colors = @{ normal = '#9ba59e'; selected = '#4c9b53' }
$names = @('home', 'match', 'rank', 'shop', 'me')
$outputDirectory = Join-Path $PSScriptRoot '..\src\static\tabbar'
New-Item -ItemType Directory -Force -Path $outputDirectory | Out-Null
foreach ($name in $names) {
foreach ($state in $colors.Keys) {
# Keep the background transparent and antialias the strokes.
$bitmap = [System.Drawing.Bitmap]::new(81, 81)
$graphics = [System.Drawing.Graphics]::FromImage($bitmap)
$graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
$graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
$graphics.ScaleTransform(3, 3)
$pen = [System.Drawing.Pen]::new([System.Drawing.ColorTranslator]::FromHtml($colors[$state]), 1.8)
$pen.StartCap = [System.Drawing.Drawing2D.LineCap]::Round
$pen.EndCap = [System.Drawing.Drawing2D.LineCap]::Round
$pen.LineJoin = [System.Drawing.Drawing2D.LineJoin]::Round
Draw-TabIcon -Graphics $graphics -Pen $pen -Name $name
$bitmap.Save((Join-Path $outputDirectory "$name-$state.png"), [System.Drawing.Imaging.ImageFormat]::Png)
$pen.Dispose()
$graphics.Dispose()
$bitmap.Dispose()
}
}