diff --git a/ViMac-Swift/BorderView.swift b/ViMac-Swift/BorderView.swift index e4fe9e3..4c9cbc9 100644 --- a/ViMac-Swift/BorderView.swift +++ b/ViMac-Swift/BorderView.swift @@ -9,14 +9,13 @@ import Cocoa class BorderView: NSView { - let SIZE = CGFloat(2) - let borderColor = NSColor.red + let SIZE = CGFloat(3) override func draw(_ dirtyRect: NSRect) { let rect = cleanRect(dirtyRect: dirtyRect, size: SIZE) let border = NSBezierPath.init(rect: rect) border.lineWidth = SIZE - self.borderColor.set() + UserPreferences.ScrollMode.ScrollFrameColorProperty.readColor().set() border.stroke() } diff --git a/ViMac-Swift/HintView.swift b/ViMac-Swift/HintView.swift index 24b1264..ec746ee 100644 --- a/ViMac-Swift/HintView.swift +++ b/ViMac-Swift/HintView.swift @@ -11,7 +11,6 @@ import AXSwift class HintView: NSView { static let borderColor = NSColor.darkGray - static let backgroundColor = NSColor(red: 255 / 255, green: 224 / 255, blue: 112 / 255, alpha: 1) static let untypedHintColor = NSColor.black static let typedHintColor = NSColor(red: 212 / 255, green: 172 / 255, blue: 58 / 255, alpha: 1) @@ -33,7 +32,7 @@ class HintView: NSView { self.layer?.borderWidth = borderWidth - self.layer?.backgroundColor = HintView.backgroundColor.cgColor + self.layer?.backgroundColor = UserPreferences.HintMode.HintColorProperty.readColor().cgColor self.layer?.borderColor = HintView.borderColor.cgColor self.layer?.cornerRadius = cornerRadius diff --git a/ViMac-Swift/Preferences/HintModePreferenceViewController.swift b/ViMac-Swift/Preferences/HintModePreferenceViewController.swift index c319f8d..5f87514 100644 --- a/ViMac-Swift/Preferences/HintModePreferenceViewController.swift +++ b/ViMac-Swift/Preferences/HintModePreferenceViewController.swift @@ -9,6 +9,7 @@ final class HintModePreferenceViewController: NSViewController, NSTextFieldDeleg private var grid: NSGridView! private var customCharactersField: NSTextField! private var textSizeField: NSTextField! + private var hintColorWell: NSColorWell! init() { if #available(OSX 11.0, *) { @@ -59,7 +60,17 @@ final class HintModePreferenceViewController: NSViewController, NSTextFieldDeleg textSizeField.stringValue = UserPreferences.HintMode.TextSizeProperty.readUnvalidated() ?? "" let textSizeRow: [NSView] = [textSizeLabel, textSizeField] grid.addRow(with: textSizeRow) - + + let hintColorLabel = NSTextField(labelWithString: "Hint Color:") + hintColorWell = NSColorWell() + hintColorWell.action = #selector(onHintColorWellEdit) + hintColorWell.color = UserPreferences.HintMode.HintColorProperty.readColor() + hintColorWell.widthAnchor.constraint(equalToConstant: 25).isActive = true + hintColorWell.heightAnchor.constraint(equalToConstant: 25).isActive = true + + let hintColorRow: [NSView] = [hintColorLabel, hintColorWell] + grid.addRow(with: hintColorRow) + self.view.addSubview(grid) NSLayoutConstraint.activate([ @@ -71,7 +82,12 @@ final class HintModePreferenceViewController: NSViewController, NSTextFieldDeleg grid.centerYAnchor.constraint(equalTo: view.centerYAnchor), ]) } - + + @objc func onHintColorWellEdit() { + let value = hintColorWell.color + UserPreferences.HintMode.HintColorProperty.saveColor(value: value) + } + func onCustomCharactersFieldChange() { let value = customCharactersField.stringValue UserPreferences.HintMode.CustomCharactersProperty.save(value: value) diff --git a/ViMac-Swift/Preferences/ScrollModePreferenceViewController.swift b/ViMac-Swift/Preferences/ScrollModePreferenceViewController.swift index 18bf33d..89b1859 100644 --- a/ViMac-Swift/Preferences/ScrollModePreferenceViewController.swift +++ b/ViMac-Swift/Preferences/ScrollModePreferenceViewController.swift @@ -11,7 +11,8 @@ final class ScrollModePreferenceViewController: NSViewController, NSTextFieldDel private var scrollSensitivityView: NSSlider! private var revHorizontalScrollView: NSButton! private var revVerticalScrollView: NSButton! - + private var scrollFrameColorWell: NSColorWell! + init() { if #available(OSX 11.0, *) { self.toolbarItemIcon = NSImage(systemSymbolName: "dpad", accessibilityDescription: nil)! @@ -68,6 +69,15 @@ final class ScrollModePreferenceViewController: NSViewController, NSTextFieldDel revVerticalScrollView.state = UserPreferences.ScrollMode.ReverseVerticalScrollProperty.read() ? .on : .off grid.addRow(with: [NSGridCell.emptyContentView, revVerticalScrollView]) + let scrollColorLabel = NSTextField(labelWithString: "Scroll Color:") + scrollFrameColorWell = NSColorWell() + scrollFrameColorWell.action = #selector(onScrollFrameColorWellEdit) + scrollFrameColorWell.color = UserPreferences.ScrollMode.ScrollFrameColorProperty.readColor() + scrollFrameColorWell.widthAnchor.constraint(equalToConstant: 25).isActive = true + scrollFrameColorWell.heightAnchor.constraint(equalToConstant: 25).isActive = true + + let scrollColorRow: [NSView] = [scrollColorLabel, scrollFrameColorWell] + grid.addRow(with: scrollColorRow) self.view.addSubview(grid) @@ -81,7 +91,12 @@ final class ScrollModePreferenceViewController: NSViewController, NSTextFieldDel ]) } - func isScrollKeysValid(keys: String) -> Bool { + @objc func onScrollFrameColorWellEdit() { + let value = scrollFrameColorWell.color + UserPreferences.ScrollMode.ScrollFrameColorProperty.saveColor(value: value) + } + + func isScrollKeysValid(keys: String) -> Bool { return UserPreferences.ScrollMode.ScrollKeysProperty.isValid(value: keys) } diff --git a/ViMac-Swift/UserDefaults/UserDefaultsProperties.swift b/ViMac-Swift/UserDefaults/UserDefaultsProperties.swift index c876bd2..6673b48 100644 --- a/ViMac-Swift/UserDefaults/UserDefaultsProperties.swift +++ b/ViMac-Swift/UserDefaults/UserDefaultsProperties.swift @@ -15,6 +15,9 @@ struct UserDefaultsProperties { static let keySequenceScrollModeEnabled = UserDefaultsProperty.init("keySequenceScrollModeEnabled", defaultValue: false) static let keySequenceScrollMode = UserDefaultsProperty.init("keySequenceScrollMode", defaultValue: "") static let keySequenceResetDelay = UserDefaultsProperty.init("keySequenceResetDelay", defaultValue: "0.25") + + static let hintColor = UserDefaultsProperty.init("hintColor", defaultValue: NSColor(red: 255 / 255, green: 224 / 255, blue: 112 / 255, alpha: 1)) + static let scrollFrameColor = UserDefaultsProperty.init("scrollFrameColor", defaultValue: NSColor(red: 255 / 255, green: 0 / 255, blue: 0 / 255, alpha: 1)) static let AXEnhancedUserInterfaceEnabled = UserDefaultsProperty.init("AXEnhancedUserInterfaceEnabled", defaultValue: false) static let AXManualAccessibilityEnabled = UserDefaultsProperty.init("AXManualAccessibilityEnabled", defaultValue: false) diff --git a/ViMac-Swift/UserPreferences.swift b/ViMac-Swift/UserPreferences.swift index b84b36c..9fd2123 100644 --- a/ViMac-Swift/UserPreferences.swift +++ b/ViMac-Swift/UserPreferences.swift @@ -32,6 +32,17 @@ extension PreferenceProperty { } } +func stringColor(colorString: String) -> NSColor { + let components = colorString.split(separator: " ") + return NSColor(red: CGFloat((components[0] as NSString).doubleValue), + green: CGFloat((components[1] as NSString).doubleValue), + blue: CGFloat((components[2] as NSString).doubleValue), + alpha: CGFloat((components[3] as NSString).doubleValue) ) +} +func colorString(color: NSColor) -> String { + return String(format: "%f %f %f %f", color.redComponent, color.greenComponent, color.blueComponent, color.alphaComponent) +} + struct UserPreferences { struct HintMode { class CustomCharactersProperty : PreferenceProperty { @@ -68,6 +79,29 @@ struct UserPreferences { return Float(read())! } } + + class HintColorProperty : PreferenceProperty { + + typealias T = String + + static var key = "HintColor" + + static var defaultValue = colorString(color: UserDefaultsProperties.hintColor.read()) + + static func readColor() -> NSColor { + let string = read() + return stringColor(colorString: string) + } + + static func saveColor(value: NSColor) { + self.save(value: colorString(color: value)) + } + + static func isValid(value: String) -> Bool { + return true + } + + } } struct ScrollMode { @@ -168,5 +202,29 @@ struct UserPreferences { return true } } + + class ScrollFrameColorProperty : PreferenceProperty { + + typealias T = String + + static var key = "ScrollColor" + + static var defaultValue = colorString(color: UserDefaultsProperties.scrollFrameColor.read()) + + static func readColor() -> NSColor { + let string = read() + return stringColor(colorString: string) + } + + static func saveColor(value: NSColor) { + self.save(value: colorString(color: value)) + } + + static func isValid(value: String) -> Bool { + return true + } + + } + } }