123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- //
- // KMOpenFileGuidePanel.swift
- // PDF Reader Pro Edition
- //
- // Created by Niehaoyu on 2023/12/8.
- //
- import Cocoa
- class KMOpenFileGuidePanel: NSView, NibLoadable {
-
- @IBOutlet weak var contendView: NSView!
-
- @IBOutlet weak var bigCircleView: NSView!
- @IBOutlet weak var smallCircleView: NSView!
-
- @IBOutlet weak var shadowView: NSView!
- @IBOutlet weak var infoContendView: NSView!
- @IBOutlet weak var tipTitleLabel: NSTextField!
- @IBOutlet weak var tipSubTitleLabel: NSTextField!
- @IBOutlet weak var skipButton: HyperLinkButton!
- @IBOutlet weak var stepLabel: NSTextField!
- @IBOutlet weak var nextBox: KMBox!
- @IBOutlet weak var nextLabel: NSTextField!
- @IBOutlet weak var nextButton: KMButton!
-
- @IBOutlet weak var circleLeftConst: NSLayoutConstraint!
-
- @objc var _circleRect: CGRect = .zero
- var clickHandle: ((_ view: KMOpenFileGuidePanel, _ 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 = NSWidth(self.bigCircleView.frame)/2
- self.bigCircleView.layer?.borderWidth = 3
-
- self.smallCircleView.wantsLayer = true
- self.smallCircleView.layer?.cornerRadius = NSWidth(self.smallCircleView.frame)/2
- self.smallCircleView.layer?.borderWidth = 3
-
- self.infoContendView.wantsLayer = true
- self.infoContendView.layer?.borderWidth = 2
- self.infoContendView.layer?.cornerRadius = 8
- self.infoContendView.layer?.masksToBounds = true
-
- self.tipTitleLabel.stringValue = NSLocalizedString("Show/Hide Panel", comment: "")
- self.tipSubTitleLabel.stringValue = NSLocalizedString("Click “Panel” to expand and collapse the left navigation panel.", comment: "")
- self.skipButton.title = NSLocalizedString("Skip", comment: "")
- self.stepLabel.stringValue = NSLocalizedString("1/3", comment: "")
- self.nextLabel.stringValue = NSLocalizedString("Next", comment: "")
-
- self.nextBox.borderWidth = 1
- self.nextBox.cornerRadius = 2
-
- 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.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
- }
- }
- }
-
- DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
- self.updateViewColor()
-
- 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()
- }
- }
-
- @objc var circleRect: CGRect {
- set {
- _circleRect = newValue;
- }
- get {
- return _circleRect;
- }
- }
-
- func updateViewColor() {
-
- self.circleLeftConst.constant = NSMinX(self.circleRect) - NSWidth(self.bigCircleView.frame)/2 + NSWidth(self.circleRect)/2
- if KMAppearance.isDarkMode() {
- self.infoContendView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1).cgColor
- self.infoContendView.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.nextLabel.textColor = KMAppearance.KMColor_Layout_H1()
- 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.infoContendView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1).cgColor
- self.infoContendView.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.nextBox.borderColor = NSColor.clear
- self.nextBox.fillColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 0.1)
- self.nextLabel.textColor = KMAppearance.KMColor_Layout_M()
- self.bigCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
- self.smallCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
-
- }
-
- }
-
- //MARK: IBAction
- @IBAction func nextAction(_ sender: Any) {
- guard let callBack = self.clickHandle else {
- return
- }
- callBack(self, .next)
- }
-
- @IBAction func skipAction(_ sender: Any) {
- guard let callBack = self.clickHandle else {
- return
- }
- callBack(self, .skip)
- }
-
- @objc func themeChange() {
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
- self.updateViewColor()
- }
- }
-
- }
|