1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-19 08:31:11 +00:00
CLK/OSBindings/Mac/Clock Signal/Documents/MachinePanel.swift
Thomas Harte 3e0b5433b9 Institutes colour/monochrome screen selection as an Apple II option.
Allowing me to test that straight-through composite still works.
2019-02-12 19:52:32 -05:00

83 lines
2.5 KiB
Swift

//
// MachinePanel.swift
// Clock Signal
//
// Created by Thomas Harte on 02/10/2016.
// Copyright 2016 Thomas Harte. All rights reserved.
//
import Cocoa
class MachinePanel: NSPanel {
var machine: CSMachine!
// MARK: IBActions
final func prefixedUserDefaultsKey(_ key: String) -> String {
return "\(self.machine.userDefaultsPrefix).\(key)"
}
var fastLoadingUserDefaultsKey: String {
return prefixedUserDefaultsKey("fastLoading")
}
@IBOutlet var fastLoadingButton: NSButton?
@IBAction func setFastLoading(_ sender: NSButton!) {
if let fastLoadingMachine = machine as? CSFastLoading {
let useFastLoadingHack = sender.state == .on
fastLoadingMachine.useFastLoadingHack = useFastLoadingHack
UserDefaults.standard.set(useFastLoadingHack, forKey: fastLoadingUserDefaultsKey)
}
}
fileprivate func signalForTag(tag: Int) -> CSMachineVideoSignal {
switch tag {
case 1: return .composite
case 2: return .sVideo
case 3: return .monochromeComposite
default: break
}
return .RGB
}
var displayTypeUserDefaultsKey: String {
return prefixedUserDefaultsKey("displayType")
}
@IBOutlet var displayTypeButton: NSPopUpButton?
@IBAction func setDisplayType(_ sender: NSPopUpButton!) {
if let selectedItem = sender.selectedItem {
machine.videoSignal = signalForTag(tag: selectedItem.tag)
UserDefaults.standard.set(selectedItem.tag, forKey: self.displayTypeUserDefaultsKey)
}
}
func establishStoredOptions() {
let standardUserDefaults = UserDefaults.standard
standardUserDefaults.register(defaults: [
fastLoadingUserDefaultsKey: true,
displayTypeUserDefaultsKey: 0
])
if let fastLoadingMachine = machine as? CSFastLoading {
let useFastLoadingHack = standardUserDefaults.bool(forKey: self.fastLoadingUserDefaultsKey)
fastLoadingMachine.useFastLoadingHack = useFastLoadingHack
self.fastLoadingButton?.state = useFastLoadingHack ? .on : .off
}
if let displayTypeButton = self.displayTypeButton {
// Enable or disable options as per machine support.
var titlesToRemove: [String] = []
for item in displayTypeButton.itemArray {
if !machine.supportsVideoSignal(signalForTag(tag: item.tag)) {
titlesToRemove.append(item.title)
}
}
for title in titlesToRemove {
displayTypeButton.removeItem(withTitle: title)
}
let displayType = standardUserDefaults.integer(forKey: self.displayTypeUserDefaultsKey)
displayTypeButton.selectItem(withTag: displayType)
setDisplayType(displayTypeButton)
}
}
}