Files
conjure/Sources/Conjure/LauncherBackground.swift
T

61 lines
2.8 KiB
Swift

import AppKit
@MainActor
enum ThemePalette {
private static let loaded: (scheme: ColorScheme, error: String?) = {
do {
return (try ColorScheme.load(from: ColorScheme.configurationDirectory), nil)
} catch {
return (.sunset, "Color configuration: \(error.localizedDescription)\nUsing the built-in sunset palette. Fix the file and restart Conjure.")
}
}()
static let configurationError = loaded.error
static let background = loaded.scheme.background.withAlphaComponent(0.55)
static let text = loaded.scheme.text
static let secondaryText = loaded.scheme.secondaryText
static let accent = loaded.scheme.accent
static let selectionFill = accent.withAlphaComponent(0.12)
static let selectionBorder = accent.withAlphaComponent(0.30)
static let glow = loaded.scheme.glow
static let keyBackground = loaded.scheme.keyBackground.withAlphaComponent(0.5)
static let error = loaded.scheme.error
}
@MainActor
final class LauncherBackground: NSView {
weak var canvas: NSView?
private let amber = NSGradient(colors: [
ThemePalette.accent.withAlphaComponent(0.18),
ThemePalette.accent.withAlphaComponent(0.065),
ThemePalette.accent.withAlphaComponent(0),
])!
private let ember = NSGradient(colors: [
ThemePalette.glow.withAlphaComponent(0.26),
ThemePalette.glow.withAlphaComponent(0.10),
ThemePalette.glow.withAlphaComponent(0),
])!
override func hitTest(_ point: NSPoint) -> NSView? { nil }
override func draw(_ dirtyRect: NSRect) {
ThemePalette.background.setFill()
dirtyRect.fill()
let canvasBounds = canvas.map { convert($0.bounds, from: $0) } ?? bounds
let upperGlow = NSPoint(x: canvasBounds.minX + canvasBounds.width * 0.58,
y: canvasBounds.minY + canvasBounds.height * 0.94)
ember.draw(fromCenter: upperGlow, radius: 0, toCenter: upperGlow,
radius: canvasBounds.width * 0.40, options: [])
let lowerGlow = NSPoint(x: canvasBounds.minX + canvasBounds.width * 0.88,
y: canvasBounds.minY + canvasBounds.height * 0.10)
amber.draw(fromCenter: lowerGlow, radius: 0, toCenter: lowerGlow,
radius: canvasBounds.width * 0.55, options: [])
let leftGlow = NSPoint(x: canvasBounds.minX + canvasBounds.width * 0.08,
y: canvasBounds.minY + canvasBounds.height * 0.65)
NSGraphicsContext.saveGraphicsState()
NSGraphicsContext.current?.cgContext.setAlpha(0.45)
amber.draw(fromCenter: leftGlow, radius: 0, toCenter: leftGlow,
radius: canvasBounds.width * 0.32, options: [])
NSGraphicsContext.restoreGraphicsState()
}
}