From aceca8b5dfc8edd378ee9ff891bccb0f94c69f31 Mon Sep 17 00:00:00 2001 From: gigagamerchaddhruv-spec Date: Wed, 14 Oct 2026 20:18:20 +0530 Subject: feat: launch Bubomb - native macOS menu bar utility ('Configure the boom') --- Sources/BubombUI/Icons/AnimatedBombView.swift | 157 ++++++++++++++++++++ Sources/BubombUI/Icons/BombIconRenderer.swift | 206 ++++++++++++++++++++++++++ 2 files changed, 363 insertions(+) create mode 100644 Sources/BubombUI/Icons/AnimatedBombView.swift create mode 100644 Sources/BubombUI/Icons/BombIconRenderer.swift (limited to 'Sources/BubombUI/Icons') diff --git a/Sources/BubombUI/Icons/AnimatedBombView.swift b/Sources/BubombUI/Icons/AnimatedBombView.swift new file mode 100644 index 0000000..d6f0e0a --- /dev/null +++ b/Sources/BubombUI/Icons/AnimatedBombView.swift @@ -0,0 +1,157 @@ +import SwiftUI + +/// High-fidelity vector bomb illustration with interactive spark and fuse animations. +public struct AnimatedBombView: View { + public var size: CGFloat = 80 + public var isDetonating: Bool = false + public var onClick: (() -> Void)? = nil + + @State private var sparkPhase: Double = 0 + @State private var hoverState: Bool = false + + public init(size: CGFloat = 80, isDetonating: Bool = false, onClick: (() -> Void)? = nil) { + self.size = size + self.isDetonating = isDetonating + self.onClick = onClick + } + + public var body: some View { + Button(action: { + onClick?() + }) { + ZStack { + // Glow behind the bomb when detonating + if isDetonating { + Circle() + .fill( + RadialGradient( + colors: [BubombTheme.accentOrange.opacity(0.4), Color.clear], + center: .center, + startRadius: size * 0.2, + endRadius: size * 0.8 + ) + ) + .scaleEffect(1.2) + } + + Canvas { context, canvasSize in + let w = canvasSize.width + let h = canvasSize.height + let scale = min(w, h) / 100.0 + + // 1. Fuse (Curved rope) + var fuse = Path() + fuse.move(to: CGPoint(x: 50 * scale, y: 35 * scale)) + fuse.addCurve( + to: CGPoint(x: 75 * scale, y: 18 * scale), + control1: CGPoint(x: 50 * scale, y: 20 * scale), + control2: CGPoint(x: 65 * scale, y: 15 * scale) + ) + context.stroke( + fuse, + with: .color(Color(red: 0.65, green: 0.55, blue: 0.40)), + lineWidth: 4 * scale + ) + + // 2. Collar / Cap + let collarRect = CGRect(x: 42 * scale, y: 28 * scale, width: 16 * scale, height: 9 * scale) + let collarPath = Path(roundedRect: collarRect, cornerRadius: 2 * scale) + context.fill( + collarPath, + with: .linearGradient( + Gradient(colors: [Color(red: 0.25, green: 0.25, blue: 0.30), Color(red: 0.15, green: 0.15, blue: 0.18)]), + startPoint: CGPoint(x: 50 * scale, y: 28 * scale), + endPoint: CGPoint(x: 50 * scale, y: 37 * scale) + ) + ) + + // 3. Main Bomb Sphere + let sphereRect = CGRect(x: 15 * scale, y: 33 * scale, width: 70 * scale, height: 70 * scale) + let spherePath = Path(ellipseIn: sphereRect) + context.fill( + spherePath, + with: .radialGradient( + Gradient(colors: [ + Color(red: 0.28, green: 0.29, blue: 0.34), + Color(red: 0.14, green: 0.14, blue: 0.17), + Color(red: 0.08, green: 0.08, blue: 0.10) + ]), + center: CGPoint(x: 40 * scale, y: 55 * scale), + startRadius: 5 * scale, + endRadius: 38 * scale + ) + ) + + // 4. Specular gloss highlight (Upper-left shine) + var gloss = Path() + gloss.addArc( + center: CGPoint(x: 36 * scale, y: 52 * scale), + radius: 24 * scale, + startAngle: .degrees(190), + endAngle: .degrees(260), + clockwise: false + ) + context.stroke( + gloss, + with: .color(Color.white.opacity(0.35)), + style: StrokeStyle(lineWidth: 3.5 * scale, lineCap: .round) + ) + + // 5. Mischievous cute eyes (Restrained, subtle) + let leftEye = Path(ellipseIn: CGRect(x: 42 * scale, y: 64 * scale, width: 4 * scale, height: 5.5 * scale)) + let rightEye = Path(ellipseIn: CGRect(x: 54 * scale, y: 64 * scale, width: 4 * scale, height: 5.5 * scale)) + context.fill(leftEye, with: .color(Color.white.opacity(0.85))) + context.fill(rightEye, with: .color(Color.white.opacity(0.85))) + + // Eye pupils / shine + let leftShine = Path(ellipseIn: CGRect(x: 43.5 * scale, y: 65 * scale, width: 1.8 * scale, height: 1.8 * scale)) + let rightShine = Path(ellipseIn: CGRect(x: 55.5 * scale, y: 65 * scale, width: 1.8 * scale, height: 1.8 * scale)) + context.fill(leftShine, with: .color(Color.black)) + context.fill(rightShine, with: .color(Color.black)) + + // 6. Spark at fuse tip + let sparkCenter = CGPoint(x: 75 * scale, y: 18 * scale) + let sparkRadius = (isDetonating ? 12 : 6) * scale + + // Spark Outer Glow + context.fill( + Path(ellipseIn: CGRect( + x: sparkCenter.x - sparkRadius, + y: sparkCenter.y - sparkRadius, + width: sparkRadius * 2, + height: sparkRadius * 2 + )), + with: .radialGradient( + Gradient(colors: [ + BubombTheme.accentOrange, + BubombTheme.accentAmber.opacity(0.5), + Color.clear + ]), + center: sparkCenter, + startRadius: 1 * scale, + endRadius: sparkRadius + ) + ) + + // Spark Core + context.fill( + Path(ellipseIn: CGRect( + x: sparkCenter.x - 2.5 * scale, + y: sparkCenter.y - 2.5 * scale, + width: 5 * scale, + height: 5 * scale + )), + with: .color(Color(red: 1.0, green: 0.95, blue: 0.4)) + ) + } + .frame(width: size, height: size) + } + .scaleEffect(hoverState ? 1.05 : 1.0) + .animation(.spring(response: 0.25, dampingFraction: 0.7), value: hoverState) + } + .buttonStyle(.plain) + .onHover { isHovered in + self.hoverState = isHovered + } + } +} diff --git a/Sources/BubombUI/Icons/BombIconRenderer.swift b/Sources/BubombUI/Icons/BombIconRenderer.swift new file mode 100644 index 0000000..d68de1f --- /dev/null +++ b/Sources/BubombUI/Icons/BombIconRenderer.swift @@ -0,0 +1,206 @@ +import SwiftUI +#if canImport(AppKit) +import AppKit +#endif + +/// State for the menu bar icon rendering. +public enum MenuBarIconState: Equatable, Sendable { + case idle + case unconfigured + case burning(frame: Int) + case exploded(frame: Int) + case failed +} + +/// Renders native NSImages for menu bar status item and app icons. +public final class BombIconRenderer: @unchecked Sendable { + public static let shared = BombIconRenderer() + + #if canImport(AppKit) + /// Creates an NSImage sized for the macOS menu bar (18x18 pt @ 2x). + public static func menuBarImage(state: MenuBarIconState) -> NSImage { + let size = NSSize(width: 18, height: 18) + let image = NSImage(size: size, flipped: false) { bounds in + let ctx = NSGraphicsContext.current?.cgContext + + switch state { + case .idle: + drawIdleMenuBarBomb(in: bounds, context: ctx, template: true) + case .unconfigured: + drawIdleMenuBarBomb(in: bounds, context: ctx, template: true, unconfiguredBadge: true) + case .burning(let frame): + drawBurningMenuBarBomb(in: bounds, context: ctx, frame: frame) + case .exploded(let frame): + drawExplodingMenuBarBomb(in: bounds, context: ctx, frame: frame) + case .failed: + drawFailedMenuBarBomb(in: bounds, context: ctx) + } + return true + } + + if case .idle = state { + image.isTemplate = true + } else if case .unconfigured = state { + image.isTemplate = true + } else { + image.isTemplate = false + } + return image + } + + // MARK: - Menu Bar Drawing Routines + + private static func drawIdleMenuBarBomb(in bounds: NSRect, context: CGContext?, template: Bool, unconfiguredBadge: Bool = false) { + guard let ctx = context else { return } + ctx.saveGState() + + let baseColor = template ? NSColor.black : NSColor(calibratedRed: 0.15, green: 0.15, blue: 0.18, alpha: 1.0) + baseColor.setFill() + baseColor.setStroke() + + // 1. Bomb Body (Circle) + // Center at (9, 7.5), radius 5.5 + let bodyRect = NSRect(x: 3.5, y: 1.5, width: 11, height: 11) + let bodyPath = NSBezierPath(ovalIn: bodyRect) + bodyPath.fill() + + // 2. Collar / Cap at top of bomb + let collarRect = NSRect(x: 7.0, y: 11.5, width: 4.0, height: 2.0) + let collarPath = NSBezierPath(roundedRect: collarRect, xRadius: 0.5, yRadius: 0.5) + collarPath.fill() + + // 3. Fuse curve + let fusePath = NSBezierPath() + fusePath.move(to: NSPoint(x: 9.0, y: 13.0)) + fusePath.curve(to: NSPoint(x: 13.0, y: 15.0), + controlPoint1: NSPoint(x: 9.0, y: 15.0), + controlPoint2: NSPoint(x: 11.5, y: 16.0)) + fusePath.lineWidth = 1.2 + fusePath.lineCapStyle = .round + fusePath.stroke() + + // 4. Spark at fuse tip + if !template { + let sparkColor = NSColor(calibratedRed: 1.0, green: 0.5, blue: 0.0, alpha: 1.0) + sparkColor.setFill() + let sparkRect = NSRect(x: 12.5, y: 14.5, width: 2.5, height: 2.5) + NSBezierPath(ovalIn: sparkRect).fill() + } + + // 5. If unconfigured, draw small hollow dot or subtle badge + if unconfiguredBadge { + let dotRect = NSRect(x: 8.0, y: 6.0, width: 2.0, height: 2.0) + NSColor.white.setFill() + NSBezierPath(ovalIn: dotRect).fill() + } + + ctx.restoreGState() + } + + private static func drawBurningMenuBarBomb(in bounds: NSRect, context: CGContext?, frame: Int) { + guard let ctx = context else { return } + ctx.saveGState() + + // Dark charcoal bomb body + let bodyColor = NSColor(calibratedRed: 0.20, green: 0.20, blue: 0.23, alpha: 1.0) + bodyColor.setFill() + let bodyRect = NSRect(x: 3.5, y: 1.5, width: 11, height: 11) + NSBezierPath(ovalIn: bodyRect).fill() + + // Collar + let collarRect = NSRect(x: 7.0, y: 11.5, width: 4.0, height: 2.0) + NSBezierPath(roundedRect: collarRect, xRadius: 0.5, yRadius: 0.5).fill() + + // Fuse + let fuseColor = NSColor(calibratedRed: 0.7, green: 0.6, blue: 0.4, alpha: 1.0) + fuseColor.setStroke() + let fusePath = NSBezierPath() + fusePath.move(to: NSPoint(x: 9.0, y: 13.0)) + fusePath.curve(to: NSPoint(x: 12.5, y: 14.5), + controlPoint1: NSPoint(x: 9.0, y: 14.5), + controlPoint2: NSPoint(x: 11.0, y: 15.5)) + fusePath.lineWidth = 1.2 + fusePath.stroke() + + // Burning spark: oscillates in size and color based on frame + let isLarge = (frame % 2 == 0) + let sparkCenter = NSPoint(x: 13.0, y: 15.0) + let sparkRadius: CGFloat = isLarge ? 2.8 : 1.8 + + // Outer warm glow + let glowColor = NSColor(calibratedRed: 1.0, green: 0.35, blue: 0.0, alpha: 0.8) + glowColor.setFill() + let glowRect = NSRect(x: sparkCenter.x - sparkRadius, y: sparkCenter.y - sparkRadius, width: sparkRadius * 2, height: sparkRadius * 2) + NSBezierPath(ovalIn: glowRect).fill() + + // Inner bright spark + let coreColor = NSColor(calibratedRed: 1.0, green: 0.95, blue: 0.2, alpha: 1.0) + coreColor.setFill() + let coreRect = NSRect(x: sparkCenter.x - 1.0, y: sparkCenter.y - 1.0, width: 2.0, height: 2.0) + NSBezierPath(ovalIn: coreRect).fill() + + ctx.restoreGState() + } + + private static func drawExplodingMenuBarBomb(in bounds: NSRect, context: CGContext?, frame: Int) { + guard let ctx = context else { return } + ctx.saveGState() + + // Starburst explosion effect + let center = NSPoint(x: 9.0, y: 9.0) + let burstColor = NSColor(calibratedRed: 1.0, green: 0.45, blue: 0.05, alpha: 1.0) + burstColor.setFill() + burstColor.setStroke() + + // Draw radial burst rays + let rayCount = 8 + let outerR: CGFloat = min(8.5, 5.0 + CGFloat(frame) * 1.5) + let innerR: CGFloat = max(2.0, 3.5 - CGFloat(frame) * 0.5) + + let starPath = NSBezierPath() + for i in 0..<(rayCount * 2) { + let angle = (CGFloat(i) * CGFloat.pi / CGFloat(rayCount)) + (CGFloat(frame) * 0.2) + let radius = (i % 2 == 0) ? outerR : innerR + let pt = NSPoint(x: center.x + cos(angle) * radius, y: center.y + sin(angle) * radius) + if i == 0 { + starPath.move(to: pt) + } else { + starPath.line(to: pt) + } + } + starPath.close() + starPath.fill() + + // Bright yellow core + let coreColor = NSColor(calibratedRed: 1.0, green: 0.95, blue: 0.4, alpha: 1.0) + coreColor.setFill() + let coreRect = NSRect(x: center.x - 2.5, y: center.y - 2.5, width: 5.0, height: 5.0) + NSBezierPath(ovalIn: coreRect).fill() + + ctx.restoreGState() + } + + private static func drawFailedMenuBarBomb(in bounds: NSRect, context: CGContext?, template: Bool = false) { + guard let ctx = context else { return } + ctx.saveGState() + + // Bomb body in muted charcoal + let bodyColor = NSColor(calibratedRed: 0.35, green: 0.35, blue: 0.38, alpha: 1.0) + bodyColor.setFill() + let bodyRect = NSRect(x: 3.5, y: 1.5, width: 11, height: 11) + NSBezierPath(ovalIn: bodyRect).fill() + + // Collar + let collarRect = NSRect(x: 7.0, y: 11.5, width: 4.0, height: 2.0) + NSBezierPath(roundedRect: collarRect, xRadius: 0.5, yRadius: 0.5).fill() + + // Small red warning indicator badge on upper right + let redBadge = NSColor(calibratedRed: 0.95, green: 0.25, blue: 0.25, alpha: 1.0) + redBadge.setFill() + let badgeRect = NSRect(x: 12.0, y: 12.0, width: 3.5, height: 3.5) + NSBezierPath(ovalIn: badgeRect).fill() + + ctx.restoreGState() + } + #endif +} -- cgit v1.2.3