123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- //
- // KMConvertGuideView.swift
- // PDF Reader Pro Edition
- //
- // Created by Niehaoyu on 2023/12/11.
- //
- import Cocoa
- class KMConvertGuideView: NSView, NibLoadable {
- @IBOutlet weak var contendView: NSView!
- @IBOutlet weak var shadowView: NSView!
-
- @IBOutlet weak var bigCircleView: NSView!
- @IBOutlet weak var smallCircleView: NSView!
- @IBOutlet weak var circleTopConst: NSLayoutConstraint!
-
- @IBOutlet weak var tipInfoView: NSView!
- @IBOutlet weak var iconImage: NSImageView!
- @IBOutlet weak var titleLabel: NSTextField!
- @IBOutlet weak var tipInfoLabel1: NSTextField!
- @IBOutlet weak var tipInfoLabel2: NSTextField!
- @IBOutlet weak var tipInfoLabel3: NSTextField!
- @IBOutlet weak var tipInfoLabel4: NSTextField!
-
- @IBOutlet weak var closeBox: KMBox!
- @IBOutlet weak var closeLabel: NSTextField!
- @IBOutlet weak var closeButton: KMButton!
-
- @IBOutlet weak var convertBox: KMBox!
- @IBOutlet weak var convertLabel: NSTextField!
- @IBOutlet weak var convertButton: KMButton!
-
- @objc var _circleRect: CGRect = .zero
- var clickHandle: ((_ view: KMConvertGuideView, _ actionType: KMGuideActionType)->Void)?
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- deinit {
- DistributedNotificationCenter.default.removeObserver(self)
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- self.bigCircleView.wantsLayer = true
- self.bigCircleView.layer?.cornerRadius = CGRectGetHeight(self.bigCircleView.frame)/2
- self.bigCircleView.layer?.borderWidth = 3
-
- self.smallCircleView.wantsLayer = true
- self.smallCircleView.layer?.cornerRadius = CGRectGetHeight(self.smallCircleView.frame)/2
- self.smallCircleView.layer?.borderWidth = 3
-
- self.tipInfoView.wantsLayer = true
- self.tipInfoView.layer?.borderWidth = 2
- self.tipInfoView.layer?.cornerRadius = 8
- self.tipInfoView.layer?.masksToBounds = true
-
- self.closeBox.wantsLayer = true
- self.closeBox.borderWidth = 1
- self.closeBox.cornerRadius = 2
- self.closeBox.fillColor = NSColor.clear
-
- self.convertBox.wantsLayer = true
- self.convertBox.cornerRadius = 4
- self.convertBox.borderWidth = 0
- self.convertBox.fillColor = NSColor.clear
-
- self.titleLabel.font = NSFont.SFProTextSemiboldFont(14)
- self.tipInfoLabel1.font = NSFont.SFProTextRegularFont(14)
- self.tipInfoLabel2.font = NSFont.SFProTextRegularFont(14)
- self.tipInfoLabel3.font = NSFont.SFProTextRegularFont(14)
- self.tipInfoLabel4.font = NSFont.SFProTextRegularFont(14)
- self.closeLabel.font = NSFont.SFProTextSemiboldFont(13)
- self.convertLabel.font = NSFont.SFProTextSemiboldFont(14)
-
- self.titleLabel.stringValue = NSLocalizedString("The Best PDF Converter", comment: "")
- self.tipInfoLabel1.stringValue = NSLocalizedString("Free convert first 10 pages.", comment: "")
- self.tipInfoLabel2.stringValue = NSLocalizedString("Convert PDFs to various file formats in high accuracy.", comment: "")
- self.tipInfoLabel3.stringValue = NSLocalizedString("Create PDFs from images or Office files.", comment: "")
- self.tipInfoLabel4.stringValue = NSLocalizedString("Batch convert PDFs to improve productivity.", comment: "")
- self.closeLabel.stringValue = NSLocalizedString("Close", comment: "")
- self.convertLabel.stringValue = NSLocalizedString("Convert All Pages", comment: "")
-
- self.closeButton.mouseMoveCallback = { [weak self] mouseEntered in
- if KMAppearance.isDarkMode() {
- if mouseEntered {
- self?.closeBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.5)
- } else {
- self?.closeBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.3)
- }
- } else {
- if mouseEntered {
- self?.closeBox.borderColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 0.5)
- } else {
- self?.closeBox.borderColor = NSColor.black.withAlphaComponent(0.15)
- }
- }
- }
-
- self.convertButton.mouseMoveCallback = { [weak self] mouseEntered in
- if mouseEntered {
- self?.convertBox.fillColor = NSColor(red: 23/255, green: 85/255, blue: 178/255, alpha: 1)
- } else {
- self?.convertBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
- }
- }
-
- self.shadowView.wantsLayer = true
- self.shadowView.layer?.borderWidth = 0
- self.shadowView.layer?.shadowColor = NSColor.black.withAlphaComponent(0.55).cgColor
- self.shadowView.layer?.shadowOpacity = 0.1
- self.shadowView.layer?.shadowRadius = 3.0
- let shadowPath = NSBezierPath(rect: self.shadowView.bounds)
- if #available(macOS 14.0, *) {
- self.shadowView.layer?.shadowPath = shadowPath.kmCGPath()
- }
-
- DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
- self.updateViewColor()
- }
-
- @objc var circleRect: CGRect {
- set {
- _circleRect = newValue;
- }
- get {
- return _circleRect;
- }
- }
-
- func updateViewColor() {
- if self.window != nil {
- self.circleTopConst.constant = (self.window?.frame.size.height)! - self.circleRect.origin.y - CGRectGetHeight(self.bigCircleView.frame) + 50
- }
-
- if KMAppearance.isDarkMode() {
- self.tipInfoView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1).cgColor
- self.tipInfoView.layer?.backgroundColor = NSColor.black.cgColor
- self.titleLabel.textColor = KMAppearance.KMColor_Layout_W0()
- self.tipInfoLabel1.textColor = KMAppearance.KMColor_Interactive_A0()
- self.tipInfoLabel2.textColor = KMAppearance.KMColor_Layout_H1()
- self.tipInfoLabel3.textColor = KMAppearance.KMColor_Layout_H1()
- self.tipInfoLabel4.textColor = KMAppearance.KMColor_Layout_H1()
- self.closeLabel.textColor = KMAppearance.KMColor_Layout_H1()
- self.convertLabel.textColor = KMAppearance.KMColor_Layout_W0()
-
- self.closeBox.borderColor = NSColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.3)
- self.convertBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
-
- self.bigCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
- self.smallCircleView.layer?.borderColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 0.7).cgColor
-
- } else {
- self.tipInfoView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1).cgColor
- self.tipInfoView.layer?.backgroundColor = NSColor.white.cgColor
- self.titleLabel.textColor = KMAppearance.KMColor_Interactive_M0()
- self.tipInfoLabel1.textColor = KMAppearance.KMColor_Interactive_A0()
- self.tipInfoLabel2.textColor = KMAppearance.KMColor_Layout_H0()
- self.tipInfoLabel3.textColor = KMAppearance.KMColor_Layout_H0()
- self.tipInfoLabel4.textColor = KMAppearance.KMColor_Layout_H0()
- self.closeLabel.textColor = KMAppearance.KMColor_Layout_H1()
- self.convertLabel.textColor = KMAppearance.KMColor_Layout_W0()
-
- self.closeBox.borderColor = NSColor.black.withAlphaComponent(0.15)
- self.convertBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
-
- self.smallCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
- self.bigCircleView.layer?.borderColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 0.4).cgColor
- }
- }
-
- //MARK: IBAction
- @IBAction func closeAction(_ sender: Any) {
- guard let callBack = self.clickHandle else {
- return
- }
- callBack(self, .skip)
- }
-
- @IBAction func convertAction(_ sender: Any) {
- guard let callBack = self.clickHandle else {
- return
- }
- callBack(self, .purchase)
- FMTrackEventManager.defaultManager.trackOnceEvent(event: "PUW", withProperties: ["PUW_Btn":"Btn_PUW_StartGuideConvert_Buy"])
- }
-
- @objc func themeChange() {
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
- self.updateViewColor()
- }
- }
- }
|