123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- //
- // 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)
- }
- }
|