// // KMWatermarkAdjectivePositionView.swift // PDF Master // // Created by tangchao on 2022/12/17. // import Cocoa class KMWatermarkAdjectivePositionView: KMWatermarkAdjectiveBaseView { @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var positionView: NSView! var myPositionView: KMWatermarkPositionView! @IBOutlet weak var xOffsetTitleLabel: NSTextField! @IBOutlet weak var xOffsetBox: NSBox! var xOffsetStepper: KMWatermarkAdjectiveStepper! @IBOutlet weak var yOffsetTitleLabel: NSTextField! @IBOutlet weak var yOffsetBox: NSBox! var yOffsetStepper: KMWatermarkAdjectiveStepper! override func awakeFromNib() { super.awakeFromNib() titleLabel.stringValue = NSLocalizedString("Position", comment: "") let positionView = KMWatermarkPositionView() positionView.frame = self.positionView.bounds positionView.autoresizingMask = NSView.AutoresizingMask(rawValue: 18) self.positionView.addSubview(positionView) self.myPositionView = positionView positionView.itemClick = { (position: KMWatermarkPosition) in guard let callback = self.itemClick else { return } callback(1, position) } xOffsetTitleLabel.stringValue = NSLocalizedString("X", comment: "") let xStepper = KMWatermarkAdjectiveStepper() xStepper.frame = self.xOffsetBox.contentView!.bounds xStepper.autoresizingMask = NSView.AutoresizingMask(rawValue: 18) self.xOffsetBox.contentView?.addSubview(xStepper) self.xOffsetStepper = xStepper xStepper.valueDidChange = { (value: Double) in guard let callback = self.itemClick else { return } callback(2, value) } yOffsetTitleLabel.stringValue = NSLocalizedString("Y", comment: "") let yStepper = KMWatermarkAdjectiveStepper() yStepper.frame = self.yOffsetBox.contentView!.bounds yStepper.autoresizingMask = NSView.AutoresizingMask(rawValue: 18) self.yOffsetBox.contentView?.addSubview(yStepper) self.yOffsetStepper = yStepper yStepper.valueDidChange = { (value: Double) in guard let callback = self.itemClick else { return } callback(3, value) } } override func setModel(model: KMWatermarkModel) { super.setModel(model: model) if (model.horizontalMode == 0) { if (model.verticalMode == 0) { self.myPositionView.selectPosition(positon: .leftTop) } else if (model.verticalMode == 1) { self.myPositionView.selectPosition(positon: .top) } else if (model.verticalMode == 2) { self.myPositionView.selectPosition(positon: .rightTop) } } if (model.horizontalMode == 1) { if (model.verticalMode == 0) { self.myPositionView.selectPosition(positon: .leftMiddle) } else if (model.verticalMode == 1) { self.myPositionView.selectPosition(positon: .middle) } else if (model.verticalMode == 2) { self.myPositionView.selectPosition(positon: .rightMiddle) } } if (model.horizontalMode == 2) { if (model.verticalMode == 0) { self.myPositionView.selectPosition(positon: .leftBottom) } else if (model.verticalMode == 1) { self.myPositionView.selectPosition(positon: .bottom) } else if (model.verticalMode == 2) { self.myPositionView.selectPosition(positon: .rightBottom) } } self.xOffsetStepper.value = model.horizontalSpace self.yOffsetStepper.value = model.verticalSpace } }