KMOpenFileGuidePanel.swift 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //
  2. // KMOpenFileGuidePanel.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/12/8.
  6. //
  7. import Cocoa
  8. class KMOpenFileGuidePanel: NSView, NibLoadable {
  9. @IBOutlet weak var contendView: NSView!
  10. @IBOutlet weak var bigCircleView: NSView!
  11. @IBOutlet weak var smallCircleView: NSView!
  12. @IBOutlet weak var shadowView: NSView!
  13. @IBOutlet weak var infoContendView: NSView!
  14. @IBOutlet weak var tipTitleLabel: NSTextField!
  15. @IBOutlet weak var tipSubTitleLabel: NSTextField!
  16. @IBOutlet weak var skipButton: HyperLinkButton!
  17. @IBOutlet weak var stepLabel: NSTextField!
  18. @IBOutlet weak var nextBox: KMBox!
  19. @IBOutlet weak var nextLabel: NSTextField!
  20. @IBOutlet weak var nextButton: KMButton!
  21. @IBOutlet weak var circleLeftConst: NSLayoutConstraint!
  22. @objc var _circleRect: CGRect = .zero
  23. var clickHandle: ((_ view: KMOpenFileGuidePanel, _ actionType: KMGuideActionType)->Void)?
  24. override func draw(_ dirtyRect: NSRect) {
  25. super.draw(dirtyRect)
  26. // Drawing code here.
  27. }
  28. deinit {
  29. DistributedNotificationCenter.default.removeObserver(self)
  30. }
  31. override func awakeFromNib() {
  32. super.awakeFromNib()
  33. self.bigCircleView.wantsLayer = true
  34. self.bigCircleView.layer?.cornerRadius = NSWidth(self.bigCircleView.frame)/2
  35. self.bigCircleView.layer?.borderWidth = 3
  36. self.smallCircleView.wantsLayer = true
  37. self.smallCircleView.layer?.cornerRadius = NSWidth(self.smallCircleView.frame)/2
  38. self.smallCircleView.layer?.borderWidth = 3
  39. self.infoContendView.wantsLayer = true
  40. self.infoContendView.layer?.borderWidth = 2
  41. self.infoContendView.layer?.cornerRadius = 8
  42. self.infoContendView.layer?.masksToBounds = true
  43. self.tipTitleLabel.stringValue = NSLocalizedString("Show/Hide Panel", comment: "")
  44. self.tipSubTitleLabel.stringValue = NSLocalizedString("Click “Panel” to expand and collapse the left navigation panel.", comment: "")
  45. self.skipButton.title = NSLocalizedString("Skip", comment: "")
  46. self.stepLabel.stringValue = NSLocalizedString("1/3", comment: "")
  47. self.nextLabel.stringValue = NSLocalizedString("Next", comment: "")
  48. self.nextBox.borderWidth = 1
  49. self.nextBox.cornerRadius = 2
  50. self.skipButton.mouseMoveCallback = { [weak self] mouseEntered in
  51. if KMAppearance.isDarkMode() {
  52. if mouseEntered {
  53. self?.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H1())
  54. } else {
  55. self?.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0())
  56. }
  57. } else {
  58. if mouseEntered {
  59. self?.skipButton.setTitleColor(KMAppearance.KMColor_Layout_M())
  60. } else {
  61. self?.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0())
  62. }
  63. }
  64. }
  65. self.nextButton.mouseMoveCallback = { [weak self] mouseEntered in
  66. if KMAppearance.isDarkMode() {
  67. if mouseEntered {
  68. self?.nextBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.5)
  69. } else {
  70. self?.nextBox.borderColor = NSColor.clear
  71. }
  72. } else {
  73. if mouseEntered {
  74. self?.nextBox.borderColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1)
  75. } else {
  76. self?.nextBox.borderColor = NSColor.clear
  77. }
  78. }
  79. }
  80. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  81. self.updateViewColor()
  82. self.shadowView.wantsLayer = true
  83. self.shadowView.layer?.borderWidth = 0
  84. self.shadowView.layer?.shadowColor = NSColor.black.withAlphaComponent(0.55).cgColor
  85. self.shadowView.layer?.shadowOpacity = 0.1
  86. self.shadowView.layer?.shadowRadius = 3.0
  87. let shadowPath = NSBezierPath(rect: self.shadowView.bounds)
  88. if #available(macOS 14.0, *) {
  89. self.shadowView.layer?.shadowPath = shadowPath.kmCGPath()
  90. }
  91. }
  92. @objc var circleRect: CGRect {
  93. set {
  94. _circleRect = newValue;
  95. }
  96. get {
  97. return _circleRect;
  98. }
  99. }
  100. func updateViewColor() {
  101. self.circleLeftConst.constant = NSMinX(self.circleRect) - NSWidth(self.bigCircleView.frame)/2 + NSWidth(self.circleRect)/2
  102. if KMAppearance.isDarkMode() {
  103. self.infoContendView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1).cgColor
  104. self.infoContendView.layer?.backgroundColor = NSColor.black.cgColor
  105. self.tipTitleLabel.textColor = KMAppearance.KMColor_Layout_W0()
  106. self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H1()
  107. self.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0())
  108. self.stepLabel.textColor = KMAppearance.KMColor_Layout_H1()
  109. self.nextLabel.textColor = KMAppearance.KMColor_Layout_H1()
  110. self.nextBox.borderColor = NSColor.clear
  111. self.nextBox.fillColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.3)
  112. self.bigCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
  113. self.smallCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
  114. } else {
  115. self.infoContendView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1).cgColor
  116. self.infoContendView.layer?.backgroundColor = NSColor.white.cgColor
  117. self.tipTitleLabel.textColor = KMAppearance.KMColor_Layout_M()
  118. self.tipSubTitleLabel.textColor = KMAppearance.KMColor_Layout_H0()
  119. self.skipButton.setTitleColor(KMAppearance.KMColor_Layout_H0())
  120. self.stepLabel.textColor = KMAppearance.KMColor_Layout_H1()
  121. self.nextBox.borderColor = NSColor.clear
  122. self.nextBox.fillColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 0.1)
  123. self.nextLabel.textColor = KMAppearance.KMColor_Layout_M()
  124. self.bigCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
  125. self.smallCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
  126. }
  127. }
  128. //MARK: IBAction
  129. @IBAction func nextAction(_ sender: Any) {
  130. guard let callBack = self.clickHandle else {
  131. return
  132. }
  133. callBack(self, .next)
  134. }
  135. @IBAction func skipAction(_ sender: Any) {
  136. guard let callBack = self.clickHandle else {
  137. return
  138. }
  139. callBack(self, .skip)
  140. }
  141. @objc func themeChange() {
  142. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  143. self.updateViewColor()
  144. }
  145. }
  146. }