SPB Git

Repository Public License

dmg-background.swift 2.6 KB 33 lines swift

1// ORIX OS Automation2// File: Scripts/tools/dmg-background.swift3// Description: Draws the disk-image window background (660 × 440 pt, rendered at 2x): ORIX canvas, arrow and install hint.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import AppKit89let out = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : "dmg-background.png"10let size = CGSize(width: 660, height: 440), scale: CGFloat = 211let space = CGColorSpace(name: CGColorSpace.sRGB)!12let c = CGContext(data: nil, width: Int(size.width * scale), height: Int(size.height * scale), bitsPerComponent: 8, bytesPerRow: 0, space: space, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!13c.scaleBy(x: scale, y: scale)14func rgb(_ hex: UInt32, _ a: CGFloat = 1) -> CGColor { CGColor(srgbRed: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: a) }15c.drawLinearGradient(CGGradient(colorsSpace: space, colors: [rgb(0x1D2440), rgb(0x0A0D18)] as CFArray, locations: nil)!, start: CGPoint(x: 0, y: size.height), end: CGPoint(x: 0, y: 0), options: [])16c.drawRadialGradient(CGGradient(colorsSpace: space, colors: [rgb(0x22D3EE, 0.16), rgb(0x22D3EE, 0)] as CFArray, locations: nil)!, startCenter: CGPoint(x: 170, y: 250), startRadius: 0, endCenter: CGPoint(x: 170, y: 250), endRadius: 320, options: [])17// Arrow from the app icon (170, 240 from the bottom) to the Applications alias (490).18c.setStrokeColor(rgb(0x22D3EE, 0.9)); c.setLineWidth(5); c.setLineCap(.round); c.setLineJoin(.round)19c.move(to: CGPoint(x: 272, y: 240)); c.addLine(to: CGPoint(x: 388, y: 240))20c.move(to: CGPoint(x: 368, y: 258)); c.addLine(to: CGPoint(x: 388, y: 240)); c.addLine(to: CGPoint(x: 368, y: 222))21c.strokePath()22NSGraphicsContext.current = NSGraphicsContext(cgContext: c, flipped: false)23func draw(_ text: String, _ font: NSFont, _ color: NSColor, y: CGFloat) {24    let a = NSAttributedString(string: text, attributes: [.font: font, .foregroundColor: color])25    a.draw(at: CGPoint(x: (size.width - a.size().width) / 2, y: y))26}27draw("ORIX OS Automation", .systemFont(ofSize: 24, weight: .bold), .white, y: 372)28draw("Understand Every Pulse of Your Mac.", .systemFont(ofSize: 13, weight: .regular), NSColor(white: 1, alpha: 0.65), y: 348)29draw("Drag ORIX OS Automation to the Applications folder", .systemFont(ofSize: 13, weight: .medium), NSColor(white: 1, alpha: 0.8), y: 52)30let rep = NSBitmapImageRep(cgImage: c.makeImage()!)31rep.size = size   // 144 dpi: Finder shows it at 660 × 440 pt32try! rep.representation(using: .png, properties: [:])!.write(to: URL(fileURLWithPath: out))33
Files main
Menu

Theme