KMOpenFileGuideToolbar.swift 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //
  2. // KMOpenFileGuideToolbar.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/12/8.
  6. //
  7. import Cocoa
  8. class KMOpenFileGuideToolbar: NSView, NibLoadable {
  9. @IBOutlet weak var contendView: NSView!
  10. @IBOutlet weak var shadowView: NSView!
  11. @IBOutlet weak var bigCircleView: NSView!
  12. @IBOutlet weak var smallCircleView: NSView!
  13. @IBOutlet weak var tipInfoView: NSView!
  14. @IBOutlet weak var tipTitleLabel: NSTextField!
  15. @IBOutlet weak var tipSubTitleLabel: NSTextField!
  16. @IBOutlet weak var tipImageView: NSImageView!
  17. @IBOutlet weak var skipButton: HyperLinkButton!
  18. @IBOutlet weak var stepLabel: NSTextField!
  19. @IBOutlet weak var previousBox: KMBox!
  20. @IBOutlet weak var previousLabel: NSTextField!
  21. @IBOutlet weak var previousButton: KMButton!
  22. @IBOutlet weak var finishBox: KMBox!
  23. @IBOutlet weak var finishLabel: NSTextField!
  24. @IBOutlet weak var finishButton: KMButton!
  25. var clickHandle: ((_ view: KMOpenFileGuideToolbar, _ actionType: KMGuideActionType)->Void)?
  26. override func draw(_ dirtyRect: NSRect) {
  27. super.draw(dirtyRect)
  28. // Drawing code here.
  29. }
  30. deinit {
  31. DistributedNotificationCenter.default.removeObserver(self)
  32. }
  33. override func awakeFromNib() {
  34. super.awakeFromNib()
  35. self.bigCircleView.wantsLayer = true
  36. self.bigCircleView.layer?.cornerRadius = CGRectGetHeight(self.bigCircleView.frame)/2
  37. self.bigCircleView.layer?.borderWidth = 3
  38. self.smallCircleView.wantsLayer = true
  39. self.smallCircleView.layer?.cornerRadius = CGRectGetHeight(self.smallCircleView.frame)/2
  40. self.smallCircleView.layer?.borderWidth = 3
  41. self.tipInfoView.wantsLayer = true
  42. self.tipInfoView.layer?.borderWidth = 2
  43. self.tipInfoView.layer?.cornerRadius = 8
  44. self.tipInfoView.layer?.masksToBounds = true
  45. self.tipTitleLabel.stringValue = NSLocalizedString("Customize Toolbar", comment: "")
  46. 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: "")
  47. self.skipButton.title = NSLocalizedString("Skip", comment: "")
  48. self.previousLabel.stringValue = NSLocalizedString("Previous", comment: "")
  49. self.stepLabel.stringValue = NSLocalizedString("3/3", comment: "")
  50. self.finishLabel.stringValue = NSLocalizedString("Finish", comment: "")
  51. self.previousBox.borderWidth = 1
  52. self.previousBox.cornerRadius = 2
  53. self.previousBox.fillColor = NSColor.clear
  54. self.finishBox.borderWidth = 1
  55. self.finishBox.cornerRadius = 2
  56. self.finishBox.fillColor = NSColor.clear
  57. self.finishBox.borderColor = NSColor.clear
  58. self.skipButton.mouseMoveCallback = { [weak self] mouseEntered in
  59. if KMAppearance.isDarkMode() {
  60. if mouseEntered {
  61. self?.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H1())
  62. } else {
  63. self?.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0())
  64. }
  65. } else {
  66. if mouseEntered {
  67. self?.skipButton.setTitleColor(KMAppearance.KMColor_Layout_M())
  68. } else {
  69. self?.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0())
  70. }
  71. }
  72. }
  73. self.previousButton.mouseMoveCallback = { [weak self] mouseEntered in
  74. if KMAppearance.isDarkMode() {
  75. if mouseEntered {
  76. self?.previousBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.5)
  77. } else {
  78. self?.previousBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.3)
  79. }
  80. } else {
  81. if mouseEntered {
  82. self?.previousBox.borderColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1)
  83. } else {
  84. self?.previousBox.borderColor = NSColor(red: 0, green: 0, blue: 0, alpha: 0.15)
  85. }
  86. }
  87. }
  88. self.finishButton.mouseMoveCallback = { [weak self] mouseEntered in
  89. if KMAppearance.isDarkMode() {
  90. if mouseEntered {
  91. self?.finishBox.fillColor = NSColor(red: 23/255, green: 85/255, blue: 178/255, alpha: 1)
  92. } else {
  93. self?.finishBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
  94. }
  95. } else {
  96. if mouseEntered {
  97. self?.finishBox.fillColor = NSColor(red: 56/255, green: 100/255, blue: 176/255, alpha: 1)
  98. } else {
  99. self?.finishBox.fillColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1)
  100. }
  101. }
  102. }
  103. self.shadowView.wantsLayer = true
  104. self.shadowView.layer?.borderWidth = 0
  105. self.shadowView.layer?.shadowColor = NSColor.black.withAlphaComponent(0.55).cgColor
  106. self.shadowView.layer?.shadowOpacity = 0.1
  107. self.shadowView.layer?.shadowRadius = 3.0
  108. let shadowPath = NSBezierPath(rect: self.shadowView.bounds)
  109. if #available(macOS 14.0, *) {
  110. self.shadowView.layer?.shadowPath = shadowPath.kmCGPath()
  111. }
  112. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  113. self.updateViewColor()
  114. }
  115. func updateViewColor() {
  116. if KMAppearance.isDarkMode() {
  117. self.tipInfoView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1).cgColor
  118. self.tipInfoView.layer?.backgroundColor = NSColor.black.cgColor
  119. self.tipTitleLabel.textColor = KMAppearance.KMColor_Layout_W0()
  120. self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H1()
  121. self.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0())
  122. self.stepLabel.textColor = KMAppearance.KMColor_Layout_H1()
  123. self.previousLabel.textColor = KMAppearance.KMColor_Layout_H1()
  124. self.finishLabel.textColor = NSColor.white
  125. self.previousBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.3)
  126. self.previousBox.fillColor = NSColor.clear
  127. self.finishBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
  128. self.bigCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
  129. self.smallCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
  130. } else {
  131. self.tipInfoView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1).cgColor
  132. self.tipInfoView.layer?.backgroundColor = NSColor.white.cgColor
  133. self.tipTitleLabel.textColor = KMAppearance.KMColor_Layout_M()
  134. self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H0()
  135. self.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0())
  136. self.stepLabel.textColor = KMAppearance.KMColor_Layout_H1()
  137. self.previousLabel.textColor = KMAppearance.KMColor_Layout_H2()
  138. self.previousBox.borderColor = NSColor(red: 0, green: 0, blue: 0, alpha: 0.15)
  139. self.previousBox.fillColor = NSColor.clear
  140. self.finishBox.fillColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1)
  141. self.finishLabel.textColor = NSColor.white
  142. self.smallCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
  143. self.bigCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
  144. }
  145. }
  146. //IBAction
  147. @IBAction func skipAction(_ sender: Any) {
  148. guard let callBack = self.clickHandle else {
  149. return
  150. }
  151. callBack(self, .skip)
  152. }
  153. @IBAction func previousAction(_ sender: Any) {
  154. guard let callBack = self.clickHandle else {
  155. return
  156. }
  157. callBack(self, .previous)
  158. }
  159. @IBAction func finishAction(_ sender: Any) {
  160. guard let callBack = self.clickHandle else {
  161. return
  162. }
  163. callBack(self, .finish)
  164. }
  165. @objc func themeChange() {
  166. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  167. self.updateViewColor()
  168. }
  169. }
  170. }