123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- //
- // KMOpenFileGuideToolbar.swift
- // PDF Reader Pro Edition
- //
- // Created by Niehaoyu on 2023/12/8.
- //
- import Cocoa
- class KMOpenFileGuideToolbar: 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 tipInfoView: NSView!
- @IBOutlet weak var tipTitleLabel: NSTextField!
- @IBOutlet weak var tipSubTitleLabel: NSTextField!
- @IBOutlet weak var tipImageView: NSImageView!
- @IBOutlet weak var skipButton: HyperLinkButton!
- @IBOutlet weak var stepLabel: NSTextField!
- @IBOutlet weak var previousBox: KMBox!
- @IBOutlet weak var previousLabel: NSTextField!
- @IBOutlet weak var previousButton: KMButton!
- @IBOutlet weak var finishBox: KMBox!
- @IBOutlet weak var finishLabel: NSTextField!
- @IBOutlet weak var finishButton: KMButton!
-
-
-
-
- var clickHandle: ((_ view: KMOpenFileGuideToolbar, _ 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 = CGRectGetHeight(self.bigCircleView.frame)/2
- self.bigCircleView.layer?.borderWidth = 3
-
- self.smallCircleView.wantsLayer = true
- self.smallCircleView.layer?.cornerRadius = CGRectGetHeight(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("Customize Toolbar", comment: "")
- self.tipSubTitleLabel.stringValue = NSLocalizedString("Right-click on the toolbar, select “Customize Toolbar“ in drop-down bar. Then reorder, add or remove tools displayed in the toolbar by simple drag and drop.", comment: "")
- self.skipButton.title = NSLocalizedString("Skip", comment: "")
- self.previousLabel.stringValue = NSLocalizedString("Previous", comment: "")
- self.stepLabel.stringValue = NSLocalizedString("3/3", comment: "")
- self.finishLabel.stringValue = NSLocalizedString("Finish", comment: "")
-
- self.previousBox.borderWidth = 1
- self.previousBox.cornerRadius = 2
- self.previousBox.fillColor = NSColor.clear
-
- self.finishBox.borderWidth = 1
- self.finishBox.cornerRadius = 2
- self.finishBox.fillColor = NSColor.clear
- self.finishBox.borderColor = 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.finishButton.mouseMoveCallback = { [weak self] mouseEntered in
- if KMAppearance.isDarkMode() {
- if mouseEntered {
- self?.finishBox.fillColor = NSColor(red: 23/255, green: 85/255, blue: 178/255, alpha: 1)
- } else {
- self?.finishBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
- }
- } else {
- if mouseEntered {
- self?.finishBox.fillColor = NSColor(red: 56/255, green: 100/255, blue: 176/255, alpha: 1)
- } else {
- self?.finishBox.fillColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1)
- }
- }
- }
-
- 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 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.previousLabel.textColor = KMAppearance.KMColor_Layout_H1()
- self.finishLabel.textColor = NSColor.white
- self.previousBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.3)
- self.previousBox.fillColor = NSColor.clear
- self.finishBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
-
- 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.previousLabel.textColor = KMAppearance.KMColor_Layout_H2()
- self.previousBox.borderColor = NSColor(red: 0, green: 0, blue: 0, alpha: 0.15)
- self.previousBox.fillColor = NSColor.clear
- self.finishBox.fillColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1)
- self.finishLabel.textColor = NSColor.white
-
- 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
- }
- }
-
- //IBAction
- @IBAction func skipAction(_ sender: Any) {
- guard let callBack = self.clickHandle else {
- return
- }
- callBack(self, .skip)
-
- }
-
- @IBAction func previousAction(_ sender: Any) {
- guard let callBack = self.clickHandle else {
- return
- }
- callBack(self, .previous)
-
- }
-
- @IBAction func finishAction(_ sender: Any) {
- guard let callBack = self.clickHandle else {
- return
- }
- callBack(self, .finish)
-
- }
-
- @objc func themeChange() {
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
- self.updateViewColor()
- }
- }
-
-
- }
|