diff --git a/Lib/KeyHolder.xcodeproj/project.pbxproj b/Lib/KeyHolder.xcodeproj/project.pbxproj index b3033c4..a4dbec8 100644 --- a/Lib/KeyHolder.xcodeproj/project.pbxproj +++ b/Lib/KeyHolder.xcodeproj/project.pbxproj @@ -7,13 +7,11 @@ objects = { /* Begin PBXBuildFile section */ - 090C241F2462DF49007746B4 /* ClearButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 090C241E2462DF49007746B4 /* ClearButton.swift */; }; 093B1449245B262F00D00737 /* Magnet.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA21712B2072183500A63D31 /* Magnet.framework */; }; 312C0FDF1D13AA1F00973348 /* KeyHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 312C0FDE1D13AA1F00973348 /* KeyHolder.h */; settings = {ATTRIBUTES = (Public, ); }; }; 312C0FE61D13AA1F00973348 /* KeyHolder.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 312C0FDB1D13AA1F00973348 /* KeyHolder.framework */; }; 312C0FEB1D13AA1F00973348 /* KeyHolderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 312C0FEA1D13AA1F00973348 /* KeyHolderTests.swift */; }; 31FAEB611D13CC39008A6D6E /* RecordView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31FAEB601D13CC39008A6D6E /* RecordView.swift */; }; - FA8D7841247AB738007BFAC1 /* NSColorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8D7840247AB738007BFAC1 /* NSColorExtension.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -41,7 +39,6 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 090C241E2462DF49007746B4 /* ClearButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClearButton.swift; sourceTree = ""; }; 312C0FDB1D13AA1F00973348 /* KeyHolder.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = KeyHolder.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 312C0FDE1D13AA1F00973348 /* KeyHolder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KeyHolder.h; sourceTree = ""; }; 312C0FE01D13AA1F00973348 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -50,7 +47,6 @@ 312C0FEC1D13AA1F00973348 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 31FAEB601D13CC39008A6D6E /* RecordView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordView.swift; sourceTree = ""; }; FA2171252072183500A63D31 /* Magnet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Magnet.xcodeproj; path = ../Carthage/Checkouts/Magnet/Lib/Magnet.xcodeproj; sourceTree = ""; }; - FA8D7840247AB738007BFAC1 /* NSColorExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSColorExtension.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -95,9 +91,7 @@ 312C0FDD1D13AA1F00973348 /* KeyHolder */ = { isa = PBXGroup; children = ( - FA8D783D247AB71C007BFAC1 /* Extensions */, 31FAEB601D13CC39008A6D6E /* RecordView.swift */, - 090C241E2462DF49007746B4 /* ClearButton.swift */, 312C0FDE1D13AA1F00973348 /* KeyHolder.h */, 312C0FE01D13AA1F00973348 /* Info.plist */, ); @@ -122,14 +116,6 @@ name = Products; sourceTree = ""; }; - FA8D783D247AB71C007BFAC1 /* Extensions */ = { - isa = PBXGroup; - children = ( - FA8D7840247AB738007BFAC1 /* NSColorExtension.swift */, - ); - path = Extensions; - sourceTree = ""; - }; FA99CB492072180B00B04AB9 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -272,9 +258,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 090C241F2462DF49007746B4 /* ClearButton.swift in Sources */, 31FAEB611D13CC39008A6D6E /* RecordView.swift in Sources */, - FA8D7841247AB738007BFAC1 /* NSColorExtension.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Lib/KeyHolder/ClearButton.swift b/Lib/KeyHolder/ClearButton.swift deleted file mode 100644 index c04a7f6..0000000 --- a/Lib/KeyHolder/ClearButton.swift +++ /dev/null @@ -1,87 +0,0 @@ -// -// ClearButton.swift -// -// KeyHolder -// GitHub: https://github.com/clipy -// HP: https://clipy-app.com -// -// Copyright © 2015-2020 Clipy Project. -// - -import Cocoa - -final class ClearButton: NSButton { - - // MARK: - Initialize - override init(frame frameRect: NSRect) { - super.init(frame: frameRect) - initView() - } - - required init?(coder: NSCoder) { - super.init(coder: coder) - initView() - } - - private func initView() { - isBordered = false - wantsLayer = true - layer?.masksToBounds = true - title = "" - } - - // MARK: - Layout - // swiftlint:disable function_body_length - override func draw(_ dirtyRect: NSRect) { - super.draw(dirtyRect) - layer?.cornerRadius = bounds.height / 2 - layer?.sublayers?.forEach { $0.removeFromSuperlayer() } - // Background Circle - let circleFillLayer = CAShapeLayer() - circleFillLayer.frame = bounds - circleFillLayer.fillColor = (isHighlighted) ? NSColor.clearHighlightedBackgroundFill.cgColor : NSColor.clearBackgroundFill.cgColor - let circlePath = CGMutablePath() - circlePath.addEllipse(in: bounds) - circlePath.closeSubpath() - circleFillLayer.path = circlePath - // Clear X - let clearLayer = CAShapeLayer() - clearLayer.frame = bounds - let clearPath = CGMutablePath() - clearPath.addEllipse(in: bounds) - clearPath.closeSubpath() - // Draw X - let xMargin = bounds.width * 0.3 - let yMargin = bounds.height * 0.3 - let bottomAnchor = bounds.height - yMargin - let rightAnchor = bounds.width - xMargin - let lineWidth: CGFloat = 1.5 - let radius = lineWidth / 2 - let cornerWidth = lineWidth / sqrt(2) - let harfCornerWidth = cornerWidth / 2 - clearPath.move(to: CGPoint(x: xMargin - harfCornerWidth, y: yMargin + harfCornerWidth)) - clearPath.addLine(to: CGPoint(x: bounds.midX - cornerWidth, y: bounds.midY)) - clearPath.addLine(to: CGPoint(x: xMargin - harfCornerWidth, y: bottomAnchor - harfCornerWidth)) - clearPath.addArc(tangent1End: CGPoint(x: xMargin - harfCornerWidth, y: bottomAnchor + harfCornerWidth), tangent2End: CGPoint(x: xMargin + harfCornerWidth, y: bottomAnchor + harfCornerWidth), radius: radius) - clearPath.addLine(to: CGPoint(x: bounds.midX, y: bounds.midY + cornerWidth)) - clearPath.addLine(to: CGPoint(x: rightAnchor - harfCornerWidth, y: bottomAnchor + harfCornerWidth)) - clearPath.addArc(tangent1End: CGPoint(x: rightAnchor + harfCornerWidth, y: bottomAnchor + harfCornerWidth), tangent2End: CGPoint(x: rightAnchor + harfCornerWidth, y: bottomAnchor - harfCornerWidth), radius: radius) - clearPath.addLine(to: CGPoint(x: bounds.midX + cornerWidth, y: bounds.midY)) - clearPath.addLine(to: CGPoint(x: rightAnchor + harfCornerWidth, y: yMargin + harfCornerWidth)) - clearPath.addArc(tangent1End: CGPoint(x: rightAnchor + harfCornerWidth, y: yMargin - harfCornerWidth), tangent2End: CGPoint(x: rightAnchor - harfCornerWidth, y: yMargin - harfCornerWidth), radius: radius) - clearPath.addLine(to: CGPoint(x: bounds.midX, y: bounds.midY - cornerWidth)) - clearPath.addLine(to: CGPoint(x: xMargin + harfCornerWidth, y: yMargin - harfCornerWidth)) - clearPath.addArc(tangent1End: CGPoint(x: xMargin - harfCornerWidth, y: yMargin - harfCornerWidth), tangent2End: CGPoint(x: xMargin - harfCornerWidth, y: yMargin + harfCornerWidth), radius: radius) - clearPath.closeSubpath() - clearLayer.path = clearPath - clearLayer.lineWidth = 0 - clearLayer.fillColor = NSColor.black.cgColor - clearLayer.strokeColor = NSColor.black.cgColor - clearLayer.fillRule = .evenOdd - circleFillLayer.mask = clearLayer - // Layer - layer?.addSublayer(circleFillLayer) - } - // swiftlint:enable function_body_length - -} diff --git a/Lib/KeyHolder/Extensions/NSColorExtension.swift b/Lib/KeyHolder/Extensions/NSColorExtension.swift deleted file mode 100644 index 5be65ca..0000000 --- a/Lib/KeyHolder/Extensions/NSColorExtension.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// NSColorExtension.swift -// -// KeyHolder -// GitHub: https://github.com/clipy -// HP: https://clipy-app.com -// -// Copyright © 2015-2020 Clipy Project. -// - -import AppKit - -extension NSColor { - static let clearBackgroundFill: NSColor = { - return NSColor(red: 0.749019608, green: 0.749019608, blue: 0.749019608, alpha: 1) - }() - static let clearHighlightedBackgroundFill: NSColor = { - return NSColor(red: 0.525490196, green: 0.525490196, blue: 0.525490196, alpha: 1) - }() -} diff --git a/Lib/KeyHolder/RecordView.swift b/Lib/KeyHolder/RecordView.swift index 04aefb3..3bdae7f 100644 --- a/Lib/KeyHolder/RecordView.swift +++ b/Lib/KeyHolder/RecordView.swift @@ -60,7 +60,16 @@ open class RecordView: NSView { } } - private let clearButton = ClearButton() + private let clearButton: NSButton = { + let button = NSButton() + button.isBordered = false + button.imagePosition = .imageOnly + button.imageScaling = .scaleProportionallyUpOrDown + button.focusRingType = .none + button.contentTintColor = .tertiaryLabelColor + button.image = NSImage(systemSymbolName: "xmark.circle.fill", accessibilityDescription: "clear") + return button + }() private let modifierEventHandler = ModifierEventHandler() private let validModifiers: [NSEvent.ModifierFlags] = [.shift, .control, .option, .command] private let validModifiersText: [NSString] = ["⇧", "⌃", "⌥", "⌘"] @@ -165,6 +174,7 @@ open class RecordView: NSView { let x = bounds.width - clearSize - marginX let y = (bounds.height - clearSize) / 2 clearButton.frame = NSRect(x: x, y: y, width: clearSize, height: clearSize) + clearButton.font = .systemFont(ofSize: floor(clearSize)) switch clearButtonMode { case .always: clearButton.isHidden = false