// // KMScreenShotEditViewController.swift // PDF Reader Pro // // Created by liujiajie on 2024/1/24. // import Cocoa typealias editButtonClickCallBack = (_ captureOrNot: Bool) -> () typealias editSizeCallBack = (_ size: CGSize) -> () let KTextFieldFontSize = 12//输入框大小 let KLabelFontSize = 14//提示框字体大小 let kLeftRightGap = 10//左右边距 let kTopBottomGap = 10//上下边距 let kMaskViewBorderLineWidth = 8 //maskView的线边框 let selectMinWidthAndHeight = 40 class KMScreenShotEditViewController: NSViewController{ @IBOutlet var widthIdentifyLabel: NSTextField! @IBOutlet var heightIdentifyLabel: NSTextField! @IBOutlet var widthLabel: NSTextField! @IBOutlet var heightLabel: NSTextField! @IBOutlet var confirmButton: NSButton! @IBOutlet var cancelButton: NSButton! @IBOutlet var widthStepper: NSStepper! @IBOutlet var heightStepper: NSStepper! var buttonCallBack: editButtonClickCallBack? var sizeCallBack: editSizeCallBack? override func viewDidLoad() { super.viewDidLoad() view.wantsLayer = true view.layer?.backgroundColor = KMAppearance.viewBackgroundColor().cgColor localizedLanguage() } func localizedLanguage() { widthIdentifyLabel.stringValue = NSLocalizedString("Width", comment: "") + ":" heightIdentifyLabel.stringValue = NSLocalizedString("Height", comment: "") + ":" confirmButton.title = NSLocalizedString("OK", comment: "") cancelButton.title = NSLocalizedString("Cancel", comment: "") } @IBAction func buttonClicked_ConfirmButton(_ sender: Any) { if let callback = buttonCallBack { callback(true) } } @IBAction func buttonClicked_CancelButton(_ sender: Any) { if let callback = buttonCallBack { callback(false) } } @IBAction func stepperClicked_WidthStepper(_ sender: NSStepper) { widthLabel.integerValue = widthStepper.integerValue heightLabel.integerValue = heightStepper.integerValue if widthStepper.integerValue >= selectMinWidthAndHeight && heightStepper.integerValue >= selectMinWidthAndHeight { sizeCallBack?(CGSize(width: widthStepper.integerValue, height: heightStepper.integerValue)) } else { sender.integerValue = selectMinWidthAndHeight } } @IBAction func stepperClicked_HeightStepper(_ sender: NSStepper) { widthLabel.integerValue = widthStepper.integerValue heightLabel.integerValue = heightStepper.integerValue if widthStepper.integerValue >= selectMinWidthAndHeight && heightStepper.integerValue >= selectMinWidthAndHeight { sizeCallBack?(CGSize(width: widthStepper.integerValue, height: heightStepper.integerValue)) } else { sender.integerValue = selectMinWidthAndHeight } } func updateSize(withRect rect: CGRect) { widthLabel.integerValue = Int(rect.size.width) heightLabel.integerValue = Int(rect.size.height) guard let screen = NSScreen.screens.first else { return } let xMax = screen.frame.size.width let yMax = screen.frame.size.height widthStepper.minValue = Double(selectMinWidthAndHeight) widthStepper.minValue = Double(selectMinWidthAndHeight) widthStepper.maxValue = Double(xMax - rect.origin.x) heightStepper.maxValue = Double(yMax - rect.origin.y) widthStepper.valueWraps = false widthStepper.valueWraps = false widthStepper.increment = 1.0 heightStepper.increment = 1.0 widthStepper.integerValue = Int(rect.size.width) heightStepper.integerValue = Int(rect.size.height) } }