Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Preview/PreviewApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import AppKit
/// NecoSaverPreview --snapshot out.png --cats 5 # override the saved cat count
/// NecoSaverPreview --snapshot out.png --speed 4 # override the saved speed
/// NecoSaverPreview --snapshot out.png --picture pic.png # override the backdrop
/// NecoSaverPreview --snapshot out.png --grey # ... or leave the grey showing
/// NecoSaverPreview --snapshot out.png --no-picture # ... or leave the black
/// NecoSaverPreview --snapshot out.png --options # render the Options sheet instead
///
/// `--size` is in points; snapshots are written at 2x, as on a Retina display.
Expand Down Expand Up @@ -123,7 +123,7 @@ enum PreviewApp {
if let picture = options.picture {
settings.picturePath = picture
}
if options.grey {
if options.noPicture {
settings.pictureEnabled = false
}

Expand Down Expand Up @@ -217,7 +217,7 @@ private struct Options {
var cats: Int?
var speed: Double?
var picture: String?
var grey = false
var noPicture = false

init(_ arguments: some Sequence<String>) throws {
var explicitSize = false
Expand All @@ -228,8 +228,8 @@ private struct Options {
showOptions = true
case "--preview":
isPreview = true
case "--grey":
grey = true
case "--no-picture":
noPicture = true
case "--snapshot", "--frames", "--size", "--cats", "--speed", "--picture":
let raw = try Self.value(after: argument, from: &iterator)
try set(argument, to: raw, explicitSize: &explicitSize)
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ random point instead of the pointer.
| Cats | 1 | 1–8 | Cats on screen. Each one wanders on its own. |
| Size | 64 pt | 32–192 pt | How big the cat is drawn. Walking speed and the size of the mess scale with it. |
| Speed | 1.00× | 0.2–3.0 | |
| Picture | on, your wallpaper | | The picture the cats walk on, by path. Type one, or press `Choose…`. Turn it off, or empty the field, for the grey. |
| Grey level | 0% | 0–100% | The colour behind the cats when no picture is drawn, either by choice or because the path could not be read. |
| Picture | on, your wallpaper | | The picture the cats walk on, by path. Type one, or press `Choose…`. Turn it off, or empty the field, for a plain black screen. |
| Paw prints | on | | Dropped while running; fade out after 12 s. |
| Scratch marks | on | | Dropped while the cat works its claws; fade out after 20 s. |

Expand Down
6 changes: 0 additions & 6 deletions Sources/ConfigureSheetController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ final class ConfigureSheetController: NSObject {
let integer: (Double) -> String = { String(Int($0.rounded())) }
let multiplier: (Double) -> String = { String(format: "%.2f×", $0) }
let points: (Double) -> String = { String(format: "%.0f pt", $0 * Double(Sprites.width)) }
let percent: (Double) -> String = { String(format: "%.0f%%", $0 * 100) }
let settings = NecoSaverSettings.self

return [
Expand All @@ -100,11 +99,6 @@ final class ConfigureSheetController: NSObject {
describe: multiplier, read: { $0.speed },
write: { $0.speed = $1 }),
makePictureRow(),
// Named for what it does. It is the whole backdrop only when no
// picture is drawn, so "Background" would overstate it.
makeRow(title: "Grey level:", control: makeSlider(range: settings.backgroundRange),
describe: percent, read: { $0.background },
write: { $0.background = $1 }),
makeCheckboxRow(title: "Paw prints", read: { $0.pawsEnabled },
write: { $0.pawsEnabled = $1 }),
makeCheckboxRow(title: "Scratch marks", read: { $0.scratchEnabled },
Expand Down
2 changes: 1 addition & 1 deletion Sources/Litter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class LitterField {
/// How much bigger than Neco's own cat these marks belong to (Tuning.unit), so
/// the mess grows with the sprite.
var unit: CGFloat = 1
/// Mark colour, picked against the background by the engine.
/// Mark colour, picked against the backdrop by the engine.
var ink: NSColor = .black

private var marks: [Mark] = []
Expand Down
8 changes: 4 additions & 4 deletions Sources/NecoSaverEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class NecoSaverEngine {

/// The desktop picture to sit the cats on. Supplied by the host rather than
/// read here: the wallpaper is per display, and only the view knows which
/// display it landed on. Left nil, the backdrop is `settings.background`.
/// display it landed on. Left nil, the backdrop is plain black.
var wallpaper: Wallpaper? {
didSet { configureLitter() }
}
Expand Down Expand Up @@ -91,7 +91,7 @@ final class NecoSaverEngine {
if let backdrop {
backdrop.draw(in: rect, context: context)
} else {
context.setFillColor(NSColor(calibratedWhite: settings.background, alpha: 1).cgColor)
context.setFillColor(NSColor.black.cgColor)
context.fill(rect)
}

Expand All @@ -112,7 +112,7 @@ final class NecoSaverEngine {
Tuning(scale: settings.size, speedFactor: settings.speed)
}

/// The picture to sit the cats on, if one was supplied. Nil leaves the grey:
/// The picture to sit the cats on, if one was supplied. Nil leaves the black:
/// either it was asked for, or nothing could be read.
private var backdrop: Wallpaper? {
settings.pictureEnabled ? wallpaper : nil
Expand All @@ -124,7 +124,7 @@ final class NecoSaverEngine {
litter.unit = tuning.unit
// Dark marks vanish on a dark backdrop and vice versa, so the ink takes the
// opposite end from whatever the floor turns out to be.
let floor = backdrop.map { $0.brightness(in: bounds) } ?? CGFloat(settings.background)
let floor = backdrop.map { $0.brightness(in: bounds) } ?? 0
litter.ink = NSColor(calibratedWhite: floor < 0.5 ? 0.9 : 0.1, alpha: 1)
}
}
16 changes: 3 additions & 13 deletions Sources/NecoSaverSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ struct NecoSaverSettings: Equatable {
/// size Neco itself uses.
var size: Double
var speed: Double
/// Background grey level, 0 = black ... 1 = white. The cat is black ink on a
/// white body, so it reads at either end; the litter marks flip to suit. Used
/// whenever no picture is drawn, either by choice or because none could be read.
var background: Double
/// Draw `picturePath` behind the cats rather than the flat grey.
/// Draw `picturePath` behind the cats rather than the plain black.
var pictureEnabled: Bool
/// The picture to draw. Seeded once with the desktop's wallpaper (see
/// `seedPicturePath`), an ordinary saved value from then on; empty, or naming
/// a file that cannot be read, leaves the grey showing.
/// a file that cannot be read, leaves the black showing.
var picturePath: String
var pawsEnabled: Bool
var scratchEnabled: Bool
Expand All @@ -33,7 +29,6 @@ struct NecoSaverSettings: Equatable {
catCount: 1,
size: 2.0,
speed: 1.0,
background: 0.0,
pictureEnabled: true,
picturePath: "",
pawsEnabled: true,
Expand All @@ -43,13 +38,11 @@ struct NecoSaverSettings: Equatable {
static let catCountRange = 1 ... 8
static let sizeRange = 1.0 ... 6.0
static let speedRange = 0.2 ... 3.0
static let backgroundRange = 0.0 ... 1.0

private enum Key {
static let catCount = "catCount"
static let size = "size"
static let speed = "speed"
static let background = "background"
static let pictureEnabled = "pictureEnabled"
static let picturePath = "picturePath"
static let pawsEnabled = "pawsEnabled"
Expand All @@ -62,7 +55,6 @@ struct NecoSaverSettings: Equatable {
Key.catCount: standard.catCount,
Key.size: standard.size,
Key.speed: standard.speed,
Key.background: standard.background,
Key.pictureEnabled: standard.pictureEnabled,
Key.picturePath: standard.picturePath,
Key.pawsEnabled: standard.pawsEnabled,
Expand All @@ -79,7 +71,6 @@ struct NecoSaverSettings: Equatable {
catCount: catCountRange.clamping(store.integer(forKey: Key.catCount)),
size: sizeRange.clamping(store.double(forKey: Key.size)),
speed: speedRange.clamping(store.double(forKey: Key.speed)),
background: backgroundRange.clamping(store.double(forKey: Key.background)),
pictureEnabled: store.bool(forKey: Key.pictureEnabled),
picturePath: store.string(forKey: Key.picturePath) ?? standard.picturePath,
pawsEnabled: store.bool(forKey: Key.pawsEnabled),
Expand All @@ -99,7 +90,7 @@ struct NecoSaverSettings: Equatable {
/// Fills in the picture on first run, when nothing has been chosen yet: the
/// desktop's own wallpaper stands in, and is written down. From then on it is
/// an ordinary saved value — changing the wallpaper later leaves the backdrop
/// alone, and clearing the field leaves the grey.
/// alone, and clearing the field leaves the black.
mutating func seedPicturePath(with path: String) {
guard picturePath.isEmpty, !path.isEmpty, let store = Self.store else { return }
picturePath = path
Expand All @@ -112,7 +103,6 @@ struct NecoSaverSettings: Equatable {
store.set(catCount, forKey: Key.catCount)
store.set(size, forKey: Key.size)
store.set(speed, forKey: Key.speed)
store.set(background, forKey: Key.background)
store.set(pictureEnabled, forKey: Key.pictureEnabled)
store.set(picturePath, forKey: Key.picturePath)
store.set(pawsEnabled, forKey: Key.pawsEnabled)
Expand Down
2 changes: 1 addition & 1 deletion Sources/NecoSaverView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class NecoSaverView: ScreenSaverView {
}

/// Reads a picture only when one is going to be drawn — decoding one costs
/// several megabytes that a grey backdrop has no use for.
/// several megabytes that a black backdrop has no use for.
private func loadWallpaper() {
engine.wallpaper = Wallpaper.matching(engine.settings, on: window?.screen)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Wallpaper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import AppKit
/// (plus `com.apple.security.assets.pictures.read-only`), so a picture anywhere on
/// disk opens with no bookmark and no panel. Everything here degrades to `nil`
/// rather than throwing — a path can name a file that has moved, or a video — and
/// the engine falls back to a plain grey.
/// the engine falls back to plain black.
@MainActor
struct Wallpaper {
private let image: NSImage
private let scaling: NSImageScaling
private let allowsClipping: Bool
private let fillColor: NSColor

/// The picture the settings ask for, or nil to leave the grey showing.
/// The picture the settings ask for, or nil to leave the black showing.
static func matching(_ settings: NecoSaverSettings, on screen: NSScreen?) -> Wallpaper? {
guard settings.pictureEnabled else { return nil }
return picture(atPath: settings.picturePath, on: screen)
Expand Down
Loading