KMConvertGuideView.swift 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //
  2. // KMConvertGuideView.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/12/11.
  6. //
  7. import Cocoa
  8. class KMConvertGuideView: 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 circleTopConst: NSLayoutConstraint!
  14. @IBOutlet weak var tipInfoView: NSView!
  15. @IBOutlet weak var iconImage: NSImageView!
  16. @IBOutlet weak var titleLabel: NSTextField!
  17. @IBOutlet weak var tipInfoLabel1: NSTextField!
  18. @IBOutlet weak var tipInfoLabel2: NSTextField!
  19. @IBOutlet weak var tipInfoLabel3: NSTextField!
  20. @IBOutlet weak var tipInfoLabel4: NSTextField!
  21. @IBOutlet weak var closeBox: KMBox!
  22. @IBOutlet weak var closeLabel: NSTextField!
  23. @IBOutlet weak var closeButton: KMButton!
  24. @IBOutlet weak var convertBox: KMBox!
  25. @IBOutlet weak var convertLabel: NSTextField!
  26. @IBOutlet weak var convertButton: KMButton!
  27. @objc var _circleRect: CGRect = .zero
  28. var clickHandle: ((_ view: KMConvertGuideView, _ actionType: KMGuideActionType)->Void)?
  29. override func draw(_ dirtyRect: NSRect) {
  30. super.draw(dirtyRect)
  31. // Drawing code here.
  32. }
  33. deinit {
  34. DistributedNotificationCenter.default.removeObserver(self)
  35. }
  36. override func awakeFromNib() {
  37. super.awakeFromNib()
  38. self.bigCircleView.wantsLayer = true
  39. self.bigCircleView.layer?.cornerRadius = NSHeight(self.bigCircleView.frame)/2
  40. self.bigCircleView.layer?.borderWidth = 3
  41. self.smallCircleView.wantsLayer = true
  42. self.smallCircleView.layer?.cornerRadius = NSHeight(self.smallCircleView.frame)/2
  43. self.smallCircleView.layer?.borderWidth = 3
  44. self.tipInfoView.wantsLayer = true
  45. self.tipInfoView.layer?.borderWidth = 2
  46. self.tipInfoView.layer?.cornerRadius = 8
  47. self.tipInfoView.layer?.masksToBounds = true
  48. self.closeBox.wantsLayer = true
  49. self.closeBox.borderWidth = 1
  50. self.closeBox.cornerRadius = 2
  51. self.closeBox.fillColor = NSColor.clear
  52. self.convertBox.wantsLayer = true
  53. self.convertBox.cornerRadius = 4
  54. self.convertBox.borderWidth = 0
  55. self.convertBox.fillColor = NSColor.clear
  56. self.titleLabel.font = NSFont.SFProTextSemiboldFont(14)
  57. self.tipInfoLabel1.font = NSFont.SFProTextRegularFont(14)
  58. self.tipInfoLabel2.font = NSFont.SFProTextRegularFont(14)
  59. self.tipInfoLabel3.font = NSFont.SFProTextRegularFont(14)
  60. self.tipInfoLabel4.font = NSFont.SFProTextRegularFont(14)
  61. self.closeLabel.font = NSFont.SFProTextSemiboldFont(13)
  62. self.convertLabel.font = NSFont.SFProTextSemiboldFont(14)
  63. self.titleLabel.stringValue = NSLocalizedString("The Best PDF Converter", comment: "")
  64. self.tipInfoLabel1.stringValue = NSLocalizedString("Free convert first 10 pages.", comment: "")
  65. self.tipInfoLabel2.stringValue = NSLocalizedString("Convert PDFs to various file formats in high accuracy.", comment: "")
  66. self.tipInfoLabel3.stringValue = NSLocalizedString("Create PDFs from images or Office files.", comment: "")
  67. self.tipInfoLabel4.stringValue = NSLocalizedString("Batch convert PDFs to improve productivity.", comment: "")
  68. self.closeLabel.stringValue = NSLocalizedString("Close", comment: "")
  69. self.convertLabel.stringValue = NSLocalizedString("Convert All Pages", comment: "")
  70. self.closeButton.mouseMoveCallback = { [weak self] mouseEntered in
  71. if KMAppearance.isDarkMode() {
  72. if mouseEntered {
  73. self?.closeBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.5)
  74. } else {
  75. self?.closeBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.3)
  76. }
  77. } else {
  78. if mouseEntered {
  79. self?.closeBox.borderColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 0.5)
  80. } else {
  81. self?.closeBox.borderColor = NSColor.black.withAlphaComponent(0.15)
  82. }
  83. }
  84. }
  85. self.convertButton.mouseMoveCallback = { [weak self] mouseEntered in
  86. if mouseEntered {
  87. self?.convertBox.fillColor = NSColor(red: 23/255, green: 85/255, blue: 178/255, alpha: 1)
  88. } else {
  89. self?.convertBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
  90. }
  91. }
  92. self.shadowView.wantsLayer = true
  93. self.shadowView.layer?.borderWidth = 0
  94. self.shadowView.layer?.shadowColor = NSColor.black.withAlphaComponent(0.55).cgColor
  95. self.shadowView.layer?.shadowOpacity = 0.1
  96. self.shadowView.layer?.shadowRadius = 3.0
  97. let shadowPath = NSBezierPath(rect: self.shadowView.bounds)
  98. if #available(macOS 14.0, *) {
  99. self.shadowView.layer?.shadowPath = shadowPath.kmCGPath()
  100. }
  101. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  102. self.updateViewColor()
  103. }
  104. @objc var circleRect: CGRect {
  105. set {
  106. _circleRect = newValue;
  107. }
  108. get {
  109. return _circleRect;
  110. }
  111. }
  112. func updateViewColor() {
  113. if self.window != nil {
  114. self.circleTopConst.constant = (self.window?.frame.size.height)! - self.circleRect.origin.y - NSHeight(self.bigCircleView.frame) + 50
  115. }
  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.titleLabel.textColor = KMAppearance.KMColor_Layout_W0()
  120. self.tipInfoLabel1.textColor = KMAppearance.KMColor_Interactive_A0()
  121. self.tipInfoLabel2.textColor = KMAppearance.KMColor_Layout_H1()
  122. self.tipInfoLabel3.textColor = KMAppearance.KMColor_Layout_H1()
  123. self.tipInfoLabel4.textColor = KMAppearance.KMColor_Layout_H1()
  124. self.closeLabel.textColor = KMAppearance.KMColor_Layout_H1()
  125. self.convertLabel.textColor = KMAppearance.KMColor_Layout_W0()
  126. self.closeBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.3)
  127. self.convertBox.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.titleLabel.textColor = KMAppearance.KMColor_Interactive_M0()
  134. self.tipInfoLabel1.textColor = KMAppearance.KMColor_Interactive_A0()
  135. self.tipInfoLabel2.textColor = KMAppearance.KMColor_Layout_H0()
  136. self.tipInfoLabel3.textColor = KMAppearance.KMColor_Layout_H0()
  137. self.tipInfoLabel4.textColor = KMAppearance.KMColor_Layout_H0()
  138. self.closeLabel.textColor = KMAppearance.KMColor_Layout_H1()
  139. self.convertLabel.textColor = KMAppearance.KMColor_Layout_W0()
  140. self.closeBox.borderColor = NSColor.black.withAlphaComponent(0.15)
  141. self.convertBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
  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. //MARK: IBAction
  147. @IBAction func closeAction(_ sender: Any) {
  148. guard let callBack = self.clickHandle else {
  149. return
  150. }
  151. callBack(self, .skip)
  152. }
  153. @IBAction func convertAction(_ sender: Any) {
  154. guard let callBack = self.clickHandle else {
  155. return
  156. }
  157. callBack(self, .purchase)
  158. FMTrackEventManager.defaultManager.trackOnceEvent(event: "PUW", withProperties: ["PUW_Btn":"Btn_PUW_StartGuideConvert_Buy"])
  159. }
  160. @objc func themeChange() {
  161. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  162. self.updateViewColor()
  163. }
  164. }
  165. }