KMOpenFileGuideProperty.swift 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. //
  2. // KMOpenFileGuideProperty.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/12/8.
  6. //
  7. import Cocoa
  8. class KMOpenFileGuideProperty: 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 circleLeftConst: NSLayoutConstraint!
  14. @IBOutlet weak var tipInfoView: NSView!
  15. @IBOutlet weak var tipTitleLabel: NSTextField!
  16. @IBOutlet weak var tipSubTitleLabel: NSTextField!
  17. @IBOutlet weak var skipButton: HyperLinkButton!
  18. @IBOutlet weak var stepLabel: NSTextField!
  19. @IBOutlet weak var previousBox: KMBox!
  20. @IBOutlet weak var previouseLabel: NSTextField!
  21. @IBOutlet weak var previousButton: KMButton!
  22. @IBOutlet weak var nextBox: KMBox!
  23. @IBOutlet weak var nextLabel: NSTextField!
  24. @IBOutlet weak var nextButton: KMButton!
  25. var circleRect: CGRect = .zero
  26. var clickHandle: ((_ view: KMOpenFileGuideProperty, _ actionType: KMGuideActionType)->Void)?
  27. override func draw(_ dirtyRect: NSRect) {
  28. super.draw(dirtyRect)
  29. // Drawing code here.
  30. }
  31. deinit {
  32. DistributedNotificationCenter.default.removeObserver(self)
  33. }
  34. override func awakeFromNib() {
  35. super.awakeFromNib()
  36. self.bigCircleView.wantsLayer = true
  37. self.bigCircleView.layer?.cornerRadius = NSWidth(self.bigCircleView.frame)/2
  38. self.bigCircleView.layer?.borderWidth = 3
  39. self.smallCircleView.wantsLayer = true
  40. self.smallCircleView.layer?.cornerRadius = NSWidth(self.smallCircleView.frame)/2
  41. self.smallCircleView.layer?.borderWidth = 3
  42. self.tipInfoView.wantsLayer = true
  43. self.tipInfoView.layer?.borderWidth = 2
  44. self.tipInfoView.layer?.cornerRadius = 8
  45. self.tipInfoView.layer?.masksToBounds = true
  46. self.tipTitleLabel.stringValue = NSLocalizedString("Show/Hide Properties", comment: "")
  47. self.tipSubTitleLabel.stringValue = NSLocalizedString("Click “Properties” to expand and collapse the right properties panel.", comment: "")
  48. self.skipButton.title = NSLocalizedString("Skip", comment: "")
  49. self.previouseLabel.stringValue = NSLocalizedString("Previous", comment: "")
  50. self.stepLabel.stringValue = NSLocalizedString("2/3", comment: "")
  51. self.nextLabel.stringValue = NSLocalizedString("Next", comment: "")
  52. self.previousBox.borderWidth = 1
  53. self.previousBox.cornerRadius = 2
  54. self.previousBox.fillColor = NSColor.clear
  55. self.nextBox.borderWidth = 1
  56. self.nextBox.cornerRadius = 2
  57. self.nextBox.fillColor = 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.nextButton.mouseMoveCallback = { [weak self] mouseEntered in
  89. if KMAppearance.isDarkMode() {
  90. if mouseEntered {
  91. self?.nextBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.5)
  92. } else {
  93. self?.nextBox.borderColor = NSColor.clear
  94. }
  95. } else {
  96. if mouseEntered {
  97. self?.nextBox.borderColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1)
  98. } else {
  99. self?.nextBox.borderColor = NSColor.clear
  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 self.circleRect.origin.x > 500 {
  117. self.circleLeftConst.constant = NSMinX(self.circleRect) - NSWidth(self.bigCircleView.frame)/2 + NSWidth(self.circleRect)/2
  118. } else {
  119. if self.window != nil {
  120. self.circleLeftConst.constant = NSWidth(self.window!.frame) - 50
  121. }
  122. }
  123. if KMAppearance.isDarkMode() {
  124. self.tipInfoView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1).cgColor
  125. self.tipInfoView.layer?.backgroundColor = NSColor.black.cgColor
  126. self.tipTitleLabel.textColor = KMAppearance.KMColor_Layout_W0()
  127. self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H1()
  128. self.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0())
  129. self.stepLabel.textColor = KMAppearance.KMColor_Layout_H1()
  130. self.previouseLabel.textColor = KMAppearance.KMColor_Layout_H1()
  131. self.nextLabel.textColor = KMAppearance.KMColor_Layout_H1()
  132. self.previousBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.3)
  133. self.previousBox.fillColor = NSColor.clear
  134. self.nextBox.borderColor = NSColor.clear
  135. self.nextBox.fillColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.3)
  136. self.bigCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
  137. self.smallCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
  138. } else {
  139. self.tipInfoView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1).cgColor
  140. self.tipInfoView.layer?.backgroundColor = NSColor.white.cgColor
  141. self.tipTitleLabel.textColor = KMAppearance.KMColor_Layout_M()
  142. self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H0()
  143. self.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0())
  144. self.stepLabel.textColor = KMAppearance.KMColor_Layout_H1()
  145. self.previouseLabel.textColor = KMAppearance.KMColor_Layout_M()
  146. self.nextLabel.textColor = KMAppearance.KMColor_Layout_M()
  147. self.previousBox.borderColor = NSColor(red: 0, green: 0, blue: 0, alpha: 0.15)
  148. self.previousBox.fillColor = NSColor.clear
  149. self.nextBox.borderColor = NSColor.clear
  150. self.nextBox.fillColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 0.1)
  151. self.smallCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
  152. self.bigCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
  153. }
  154. }
  155. //MARK: IBAction
  156. @IBAction func skipAction(_ sender: Any) {
  157. guard let callBack = self.clickHandle else {
  158. return
  159. }
  160. callBack(self, .skip)
  161. }
  162. @IBAction func previouseAction(_ sender: Any) {
  163. guard let callBack = self.clickHandle else {
  164. return
  165. }
  166. callBack(self, .previous)
  167. }
  168. @IBAction func nextAction(_ sender: Any) {
  169. guard let callBack = self.clickHandle else {
  170. return
  171. }
  172. callBack(self, .next)
  173. }
  174. @objc func themeChange() {
  175. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  176. self.updateViewColor()
  177. }
  178. }
  179. }