1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-09-29 16:55:59 +00:00

Switch to transient LED presentation in windowed mode.

This commit is contained in:
Thomas Harte 2021-07-15 19:22:23 -04:00
parent 47a530fd5c
commit 81374b70b5

View File

@ -609,12 +609,12 @@ class MachineDocument:
private var unadornedWindowTitle = "" private var unadornedWindowTitle = ""
private var mouseIsCaptured = false private var mouseIsCaptured = false
private var windowLEDSuffix = "" private var windowTitleSuffix = ""
private func updateWindowTitle() { private func updateWindowTitle() {
var title = self.unadornedWindowTitle var title = self.unadornedWindowTitle
if windowLEDSuffix != "" { if windowTitleSuffix != "" {
title += windowLEDSuffix title += windowTitleSuffix
} }
if mouseIsCaptured { if mouseIsCaptured {
title += " (press ⌘+control to release mouse)" title += " (press ⌘+control to release mouse)"
@ -732,6 +732,11 @@ class MachineDocument:
// If there is such an LED, switch it appropriately. // If there is such an LED, switch it appropriately.
if let led = leds[ledName] { if let led = leds[ledName] {
DispatchQueue.main.async { [self] in DispatchQueue.main.async { [self] in
// Do nothing for no change of state.
if led.isLit == isLit {
return
}
led.levelIndicator.floatValue = isLit ? 1.0 : 0.0 led.levelIndicator.floatValue = isLit ? 1.0 : 0.0
led.isLit = isLit led.isLit = isLit
@ -742,22 +747,28 @@ class MachineDocument:
} }
private func updateActivityViewVisibility() { private func updateActivityViewVisibility() {
// If any LEDs are now visible, make sure the activity view is showing.
// Otherwise, hide it.
if let window = self.windowControllers.first?.window { if let window = self.windowControllers.first?.window {
// If in a window, show the activity view transiently to
// acknowledge changes of state. In full screen show it
// permanently as long as at least one LED is lit.
if window.styleMask.contains(.fullScreen) {
let litLEDs = self.leds.filter { $0.value.isLit }
if litLEDs.isEmpty{
activityFader.animateOut(delay: 0.2)
} else {
activityFader.animateIn()
}
} else {
activityFader.showTransiently(for: 1.0)
}
let litLEDs = self.leds.filter { $0.value.isLit } let litLEDs = self.leds.filter { $0.value.isLit }
if litLEDs.isEmpty || !window.styleMask.contains(.fullScreen) { if litLEDs.isEmpty || !window.styleMask.contains(.fullScreen) {
activityFader.animateOut(delay: window.styleMask.contains(.fullScreen) ? 0.2 : 0.0) activityFader.animateOut(delay: window.styleMask.contains(.fullScreen) ? 0.2 : 0.0)
} else { } else {
activityFader.animateIn() activityFader.animateIn()
} }
// Manipulate the window title.
windowLEDSuffix = ""
for ledName in machine.leds {
windowLEDSuffix += " " + (leds[ledName]!.isLit ? "" : "")
}
updateWindowTitle()
} }
} }
@ -826,6 +837,11 @@ class MachineDocument:
view.layer!.add(fadeAnimation, forKey: "opacity") view.layer!.add(fadeAnimation, forKey: "opacity")
} }
} }
func showTransiently(for period: TimeInterval) {
animateIn()
animateOut(delay: period)
}
} }
// MARK: - Volume Control. // MARK: - Volume Control.