SPB Git

Repository Public

make-icon.swift 3.1 KB 60 lines swift

1// Renders the NEXTERM app icon (rounded dark tile, accent prompt chevron and cursor) at every2// size the asset catalog needs. Usage: swift Scripts/make-icon.swift <output-dir>3import AppKit45let outDir = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : "Resources/Assets.xcassets/AppIcon.appiconset"6let sizes: [(String, Int)] = [("icon_16x16", 16), ("icon_16x16@2x", 32), ("icon_32x32", 32), ("icon_32x32@2x", 64),7                              ("icon_128x128", 128), ("icon_128x128@2x", 256), ("icon_256x256", 256), ("icon_256x256@2x", 512),8                              ("icon_512x512", 512), ("icon_512x512@2x", 1024)]910func render(_ px: Int) -> Data {11    let size = CGFloat(px)12    let image = NSImage(size: NSSize(width: size, height: size))13    image.lockFocus()14    let ctx = NSGraphicsContext.current!.cgContext15    ctx.clear(CGRect(x: 0, y: 0, width: size, height: size))16    // macOS icon grid: the tile occupies ~80% of the canvas.17    let inset = size * 0.118    let tile = CGRect(x: inset, y: inset, width: size - 2 * inset, height: size - 2 * inset)19    let radius = tile.width * 0.22520    let path = NSBezierPath(roundedRect: tile, xRadius: radius, yRadius: radius)21    let gradient = NSGradient(colors: [NSColor(srgbRed: 0.13, green: 0.15, blue: 0.20, alpha: 1),22                                       NSColor(srgbRed: 0.05, green: 0.06, blue: 0.09, alpha: 1)])!23    gradient.draw(in: path, angle: -90)24    // Subtle top highlight25    NSColor.white.withAlphaComponent(0.06).setStroke()26    path.lineWidth = max(1, size * 0.006)27    path.stroke()28    // Prompt chevron ">" in accent blue29    let accent = NSColor(srgbRed: 0.478, green: 0.635, blue: 0.969, alpha: 1)30    let stroke = NSBezierPath()31    let w = tile.width32    let x0 = tile.minX + w * 0.24, y0 = tile.minY + w * 0.6633    stroke.move(to: NSPoint(x: x0, y: y0))34    stroke.line(to: NSPoint(x: x0 + w * 0.20, y: tile.minY + w * 0.48))35    stroke.line(to: NSPoint(x: x0, y: tile.minY + w * 0.30))36    stroke.lineWidth = w * 0.08537    stroke.lineCapStyle = .round38    stroke.lineJoinStyle = .round39    accent.setStroke()40    stroke.stroke()41    // Cursor block42    let cursor = CGRect(x: tile.minX + w * 0.52, y: tile.minY + w * 0.30, width: w * 0.22, height: w * 0.085)43    NSColor(srgbRed: 0.84, green: 0.85, blue: 0.88, alpha: 1).setFill()44    NSBezierPath(roundedRect: cursor, xRadius: w * 0.02, yRadius: w * 0.02).fill()45    image.unlockFocus()46    let rep = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: px, pixelsHigh: px, bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false, colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0)!47    rep.size = NSSize(width: size, height: size)48    NSGraphicsContext.saveGraphicsState()49    NSGraphicsContext.current = NSGraphicsContext(bitmapImageRep: rep)50    image.draw(in: NSRect(x: 0, y: 0, width: size, height: size))51    NSGraphicsContext.restoreGraphicsState()52    return rep.representation(using: .png, properties: [:])!53}5455for (name, px) in sizes {56    let url = URL(fileURLWithPath: outDir).appendingPathComponent("\(name).png")57    try! render(px).write(to: url)58}59print("icons written to \(outDir)")60
Files main
Menu

Theme