KMConvertGuideView.swift 9.0 KB

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