KMAIIconGuideView.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // KMAIIconGuideView.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2024/3/1.
  6. //
  7. import Cocoa
  8. class KMAIIconGuideView: NSView, NibLoadable {
  9. @IBOutlet weak var contendView: NSView!
  10. @IBOutlet weak var shadowView: NSView!
  11. @IBOutlet weak var infoContendView: NSView!
  12. @IBOutlet weak var titleLabel: NSTextField!
  13. @IBOutlet weak var subTitleLabel: NSTextField!
  14. @IBOutlet weak var finishBox: KMBox!
  15. @IBOutlet weak var finishBoxLabel: NSTextField!
  16. @IBOutlet weak var finishBoxBtn: KMButton!
  17. var clickHandle: ((_ view: KMAIIconGuideView, _ actionType: KMGuideActionType)->Void)?
  18. override func draw(_ dirtyRect: NSRect) {
  19. super.draw(dirtyRect)
  20. // Drawing code here.
  21. }
  22. deinit {
  23. DistributedNotificationCenter.default.removeObserver(self)
  24. }
  25. override func awakeFromNib() {
  26. super.awakeFromNib()
  27. self.infoContendView.wantsLayer = true
  28. self.infoContendView.layer?.borderWidth = 2
  29. self.infoContendView.layer?.cornerRadius = 8
  30. self.infoContendView.layer?.masksToBounds = true
  31. self.titleLabel.stringValue = NSLocalizedString("Show/Hide AI robot icon", comment: "")
  32. self.subTitleLabel.stringValue = NSLocalizedString("Right-click to hide AI robot icon. Show the icon again from the top right corner “My AI Credit”. ", comment: "")
  33. self.finishBoxLabel.stringValue = NSLocalizedString("Got it", comment: "")
  34. self.finishBox.wantsLayer = true
  35. self.finishBox.borderWidth = 1
  36. self.finishBox.cornerRadius = 2
  37. self.finishBoxBtn.mouseMoveCallback = {[weak self] mouseEntered in
  38. if KMAppearance.isDarkMode() {
  39. if mouseEntered {
  40. self?.finishBox.fillColor = NSColor(red: 23/255, green: 85/255, blue: 178/255, alpha: 1)
  41. } else {
  42. self?.finishBox.fillColor = KMAppearance.KMColor_Interactive_A0()
  43. }
  44. } else {
  45. if mouseEntered {
  46. self?.finishBox.fillColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1)
  47. } else {
  48. self?.finishBox.fillColor = NSColor(red: 56/255, green: 100/255, blue: 176/255, alpha: 1)
  49. }
  50. }
  51. }
  52. self.shadowView.wantsLayer = true
  53. self.shadowView.layer?.borderWidth = 0
  54. self.shadowView.layer?.shadowColor = NSColor.black.withAlphaComponent(0.55).cgColor
  55. self.shadowView.layer?.shadowOpacity = 0.1
  56. self.shadowView.layer?.shadowRadius = 3.0
  57. let shadowPath = NSBezierPath(rect: self.shadowView.bounds)
  58. if #available(macOS 14.0, *) {
  59. self.shadowView.layer?.shadowPath = shadowPath.PDFListViewCGPath()
  60. }
  61. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  62. self.updateViewColor()
  63. }
  64. func updateViewColor() {
  65. if KMAppearance.isDarkMode() {
  66. self.infoContendView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1).cgColor
  67. self.infoContendView.layer?.backgroundColor = NSColor.black.cgColor
  68. self.titleLabel.textColor = KMAppearance.KMColor_Layout_W0()
  69. self.subTitleLabel.textColor = KMAppearance.KMColor_Layout_H1()
  70. self.finishBoxLabel.textColor = NSColor.white
  71. self.finishBox.borderColor = NSColor.clear
  72. self.finishBox.fillColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1)
  73. } else {
  74. self.infoContendView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1).cgColor
  75. self.infoContendView.layer?.backgroundColor = NSColor.white.cgColor
  76. self.titleLabel.textColor = KMAppearance.KMColor_Layout_M()
  77. self.subTitleLabel.textColor = KMAppearance.KMColor_Layout_H0()
  78. self.finishBox.borderColor = NSColor.clear
  79. self.finishBox.fillColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1)
  80. self.finishBoxLabel.textColor = NSColor.white
  81. }
  82. }
  83. //MARK: IBAction
  84. @IBAction func finishBtnAction(_ sender: KMButton) {
  85. guard let callBack = self.clickHandle else {
  86. return
  87. }
  88. callBack(self, .getIt)
  89. }
  90. @objc func themeChange() {
  91. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  92. self.updateViewColor()
  93. }
  94. }
  95. }