// // KMOpenFileGuideProperty.swift // PDF Reader Pro Edition // // Created by Niehaoyu on 2023/12/8. // import Cocoa class KMOpenFileGuideProperty: NSView, NibLoadable { @IBOutlet weak var contendView: NSView! @IBOutlet weak var shadowView: NSView! @IBOutlet weak var bigCircleView: NSView! @IBOutlet weak var smallCircleView: NSView! @IBOutlet weak var circleLeftConst: NSLayoutConstraint! @IBOutlet weak var tipInfoView: NSView! @IBOutlet weak var tipTitleLabel: NSTextField! @IBOutlet weak var tipSubTitleLabel: NSTextField! @IBOutlet weak var skipButton: HyperLinkButton! @IBOutlet weak var stepLabel: NSTextField! @IBOutlet weak var previousBox: KMBox! @IBOutlet weak var previouseLabel: NSTextField! @IBOutlet weak var previousButton: KMButton! @IBOutlet weak var nextBox: KMBox! @IBOutlet weak var nextLabel: NSTextField! @IBOutlet weak var nextButton: KMButton! var circleRect: CGRect = .zero var clickHandle: ((_ view: KMOpenFileGuideProperty, _ actionType: KMGuideActionType)->Void)? override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. } deinit { DistributedNotificationCenter.default.removeObserver(self) } override func awakeFromNib() { super.awakeFromNib() self.bigCircleView.wantsLayer = true self.bigCircleView.layer?.cornerRadius = CGRectGetWidth(self.bigCircleView.frame)/2 self.bigCircleView.layer?.borderWidth = 3 self.smallCircleView.wantsLayer = true self.smallCircleView.layer?.cornerRadius = CGRectGetWidth(self.smallCircleView.frame)/2 self.smallCircleView.layer?.borderWidth = 3 self.tipInfoView.wantsLayer = true self.tipInfoView.layer?.borderWidth = 2 self.tipInfoView.layer?.cornerRadius = 8 self.tipInfoView.layer?.masksToBounds = true self.tipTitleLabel.stringValue = NSLocalizedString("Show/Hide Properties", comment: "") self.tipSubTitleLabel.stringValue = NSLocalizedString("Click “Properties” to expand and collapse the right properties panel.", comment: "") self.skipButton.title = NSLocalizedString("Skip", comment: "") self.previouseLabel.stringValue = NSLocalizedString("Previous", comment: "") self.stepLabel.stringValue = NSLocalizedString("2/3", comment: "") self.nextLabel.stringValue = NSLocalizedString("Next", comment: "") self.previousBox.borderWidth = 1 self.previousBox.cornerRadius = 2 self.previousBox.fillColor = NSColor.clear self.nextBox.borderWidth = 1 self.nextBox.cornerRadius = 2 self.nextBox.fillColor = NSColor.clear self.skipButton.mouseMoveCallback = { [weak self] mouseEntered in if KMAppearance.isDarkMode() { if mouseEntered { self?.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H1()) } else { self?.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0()) } } else { if mouseEntered { self?.skipButton.setTitleColor(KMAppearance.KMColor_Layout_M()) } else { self?.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0()) } } } self.previousButton.mouseMoveCallback = { [weak self] mouseEntered in if KMAppearance.isDarkMode() { if mouseEntered { self?.previousBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.5) } else { self?.previousBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.3) } } else { if mouseEntered { self?.previousBox.borderColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1) } else { self?.previousBox.borderColor = NSColor(red: 0, green: 0, blue: 0, alpha: 0.15) } } } self.nextButton.mouseMoveCallback = { [weak self] mouseEntered in if KMAppearance.isDarkMode() { if mouseEntered { self?.nextBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.5) } else { self?.nextBox.borderColor = NSColor.clear } } else { if mouseEntered { self?.nextBox.borderColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1) } else { self?.nextBox.borderColor = NSColor.clear } } } self.shadowView.wantsLayer = true self.shadowView.layer?.borderWidth = 0 self.shadowView.layer?.shadowColor = NSColor.black.withAlphaComponent(0.55).cgColor self.shadowView.layer?.shadowOpacity = 0.1 self.shadowView.layer?.shadowRadius = 3.0 let shadowPath = NSBezierPath(rect: self.shadowView.bounds) if #available(macOS 14.0, *) { self.shadowView.layer?.shadowPath = shadowPath.kmCGPath() } DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil) self.updateViewColor() } func updateViewColor() { if self.circleRect.origin.x > 500 { self.circleLeftConst.constant = CGRectGetMinX(self.circleRect) - CGRectGetWidth(self.bigCircleView.frame)/2 + CGRectGetWidth(self.circleRect)/2 } else { if self.window != nil { self.circleLeftConst.constant = CGRectGetWidth(self.window!.frame) - 50 } } if KMAppearance.isDarkMode() { self.tipInfoView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1).cgColor self.tipInfoView.layer?.backgroundColor = NSColor.black.cgColor self.tipTitleLabel.textColor = KMAppearance.KMColor_Layout_W0() self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H1() self.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0()) self.stepLabel.textColor = KMAppearance.KMColor_Layout_H1() self.previouseLabel.textColor = KMAppearance.KMColor_Layout_H1() self.nextLabel.textColor = KMAppearance.KMColor_Layout_H1() self.previousBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.3) self.previousBox.fillColor = NSColor.clear self.nextBox.borderColor = NSColor.clear self.nextBox.fillColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.3) self.bigCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor self.smallCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor } else { self.tipInfoView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1).cgColor self.tipInfoView.layer?.backgroundColor = NSColor.white.cgColor self.tipTitleLabel.textColor = KMAppearance.KMColor_Layout_M() self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H0() self.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0()) self.stepLabel.textColor = KMAppearance.KMColor_Layout_H1() self.previouseLabel.textColor = KMAppearance.KMColor_Layout_M() self.nextLabel.textColor = KMAppearance.KMColor_Layout_M() self.previousBox.borderColor = NSColor(red: 0, green: 0, blue: 0, alpha: 0.15) self.previousBox.fillColor = NSColor.clear self.nextBox.borderColor = NSColor.clear self.nextBox.fillColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 0.1) self.smallCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor self.bigCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor } } //MARK: IBAction @IBAction func skipAction(_ sender: Any) { guard let callBack = self.clickHandle else { return } callBack(self, .skip) } @IBAction func previouseAction(_ sender: Any) { guard let callBack = self.clickHandle else { return } callBack(self, .previous) } @IBAction func nextAction(_ sender: Any) { guard let callBack = self.clickHandle else { return } callBack(self, .next) } @objc func themeChange() { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { self.updateViewColor() } } }