123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626 |
- //
- // KMBackgroundPropertyController.swift
- // PDF Reader Pro
- //
- // Created by Niehaoyu on 2024/11/6.
- //
- import Cocoa
- import KMComponentLibrary
- @objc protocol KMBackgroundPropertyControllerDelegate: AnyObject {
-
- //水印数据有更新
- @objc optional func backgroundPropertyControllerDidUpdate(_ controller: KMBackgroundPropertyController)
-
- //切换到模板界面
- @objc optional func backgroundPropertyControllerDidChangetoTemplate(_ controller: KMBackgroundPropertyController)
-
- //成功保存到模板
- @objc optional func backgroundPropertyControllerSaveTemplateSuccess(_ controller: KMBackgroundPropertyController, _ data: KMBackgroundModel)
-
- //取消修改模板信息
- @objc optional func backgroundPropertyControllerCancelTemplateEdit(_ controller: KMBackgroundPropertyController)
-
- @objc optional func backgroundPropertyControllerFinishTemplateEdit(_ controller: KMBackgroundPropertyController)
-
- }
- class KMBackgroundPropertyController: NSViewController {
-
- @IBOutlet var contendView: NSView!
- @IBOutlet var leftTopButton: ComponentButton!
- @IBOutlet var titleLabel: NSTextField!
- @IBOutlet var templateButton: ComponentButton!
-
- @IBOutlet var typeTabsBGView: NSView!
- @IBOutlet var typeTabs: ComponentTabs!
-
- @IBOutlet var infoContendView: NSView!
- @IBOutlet var infoContendTopConst: NSLayoutConstraint!
- //Text
- @IBOutlet var textBGView: NSView!
- @IBOutlet var colorLabel: NSTextField!
- @IBOutlet var fontColorGroup: ComponentCColorGroup!
-
- //File
- @IBOutlet var fileBGView: NSView!
- @IBOutlet var fileInputView: ComponentInput!
- @IBOutlet var fileInputAddonView: ComponentInputAddon!
-
- //Appearance
- @IBOutlet var appearanceBGView: NSView!
- @IBOutlet var appearanceLabel: NSTextField!
- @IBOutlet var appearance_RotateSelect: ComponentSelect!
- @IBOutlet var appearance_OpacitySelect: ComponentSelect!
- @IBOutlet var appearanceScaleCheckbox: ComponentCheckBox!
- @IBOutlet var appearanceScaleSelect: ComponentSelect!
- @IBOutlet var appearanceBGTopConst: NSLayoutConstraint!
-
- //Position
- @IBOutlet var positionBGView: NSView!
- @IBOutlet var positionLabel: NSTextField!
- @IBOutlet var positionItemView: ComponentCPosition!
- @IBOutlet var positionXInput: ComponentInputNumber!
- @IBOutlet var positionYInput: ComponentInputNumber!
-
- //Save
- @IBOutlet var saveTemplateBGView: NSView!
- @IBOutlet var saveButton: ComponentButton!
-
- private var textTabProperty = ComponentTabsProperty(tabsType: .underline_Fill, state: .normal, showIcon: false, title: KMLocalizedString("Color"))
- private var fileTabProperty = ComponentTabsProperty(tabsType: .underline_Fill, state: .normal, showIcon: false, title: KMLocalizedString("File"))
-
-
- weak open var delegate: KMBackgroundPropertyControllerDelegate?
-
- var originalDataDict: Dictionary<String, Any>?
- var backgroundData: KMBackgroundModel = KMBackgroundModel()
-
- var editSubType: KMPDFEditSubModeType = .none
-
- //MARK: - func
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- setupProperty()
-
- }
-
- func setupProperty() {
- contendView.wantsLayer = true
- contendView.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle").cgColor
-
- titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
- titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-bold")
-
- leftTopButton.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, onlyIcon: true, icon: NSImage(named: "watermark_arrowLeft"), keepPressState: false)
- leftTopButton.setTarget(self, action: #selector(leftTopButtonClicked(_:)))
-
- templateButton.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, onlyIcon: true, icon: NSImage(named: "icon_wm_template"), keepPressState: false)
- templateButton.setTarget(self, action: #selector(templateButtonClicked(_:)))
-
- typeTabs.updateItemProperty([textTabProperty, fileTabProperty])
- typeTabs.delegate = self
-
-
- //Text
- let colorAProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: KMBackgroundModel.defaultColors()[0])
- let colorBProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: KMBackgroundModel.defaultColors()[1])
- let colorCProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: KMBackgroundModel.defaultColors()[2])
- let colorDProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: KMBackgroundModel.defaultColors()[3])
- let colorEProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: true, color: KMBackgroundModel.defaultColors()[4])
-
- fontColorGroup.setUpWithColorPropertys([colorAProperty, colorBProperty, colorCProperty, colorDProperty], customItemProperty: colorEProperty)
- fontColorGroup.delegate = self
-
- //File
- fileInputView.properties = ComponentInputProperty(size: .s,
- state:.pressed ,
- placeholder: "Select Source File...",
- text: "",
- creatable: false)
- fileInputView.properties.propertyInfo.cornerRadius_topLeft = 0
- fileInputView.properties.propertyInfo.cornerRadius_topRight = 0
- fileInputView.properties.propertyInfo.cornerRadius_bottomLeft = 0
- fileInputView.properties.propertyInfo.cornerRadius_bottomRight = 0
- fileInputView.reloadData()
-
- fileInputAddonView.properties = ComponentInputAddonProperty(size: .s,
- state: .normal,
- addOnBefore: false,
- onlyRead: false,
- addonType: .imageWithColor,
- iconImage: NSImage(named: "icon_folder"))
- fileInputAddonView.setTarget(self, action: #selector(chooseURLAction(_ :)))
-
- //Appearance
- appearanceLabel.stringValue = KMLocalizedString("Appearance")
- appearanceLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
- appearanceLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
-
- appearance_RotateSelect.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- creatable: true,
- text: "0°",
- textUnit: "°",
- regexString: "0123456789-")
- var rotateItems: [ComponentMenuitemProperty] = []
- for string in ["0°", "45°", "-45°", "90°", "-90°"] {
- let item = ComponentMenuitemProperty(type: .normal, text: string)
- rotateItems.append(item)
- }
- appearance_RotateSelect.updateMenuItemsArr(rotateItems)
- appearance_RotateSelect.delegate = self
-
- appearance_OpacitySelect.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- creatable: true,
- text: "100%",
- textUnit: "%",
- regexString: "0123456789")
- var opacityItems: [ComponentMenuitemProperty] = []
- for string in ["25%", "50%", "75%", "100%"] {
- let item = ComponentMenuitemProperty(type: .normal, text: string)
- opacityItems.append(item)
- }
- appearance_OpacitySelect.updateMenuItemsArr(opacityItems)
- appearance_OpacitySelect.delegate = self
-
- appearanceScaleCheckbox.properties = ComponentCheckBoxProperty(size: .s, text: KMLocalizedString("Scale relative to target page"), checkboxType: .normal)
- appearanceScaleCheckbox.setTarget(self, action: #selector(checkBoxClicked(_:)))
-
- appearanceScaleSelect.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- creatable: true,
- text: "100%",
- textUnit: "%",
- regexString: "0123456789")
- var appearanceScaleItems: [ComponentMenuitemProperty] = []
- for string in ["25%", "50%", "75%", "100%", "125%", "150%","200%"] {
- let item = ComponentMenuitemProperty(type: .normal, text: string)
- appearanceScaleItems.append(item)
- }
- appearanceScaleSelect.updateMenuItemsArr(appearanceScaleItems)
- appearanceScaleSelect.delegate = self
-
- //Position
- positionLabel.stringValue = KMLocalizedString("Position (mm)")
- positionLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
- positionLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
-
- positionItemView.properties = ComponentCPositionProperty(rowCount: 3, columnCount: 3, dash: false, selRow: 1, selColumn: 1)
- positionItemView.delegate = self
-
- positionXInput.properties = ComponentInputNumberProperty(alignment: .left,
- size: .s,
- minSize: -1000,
- maxSize: 1000,
- text: "0")
- positionXInput.delegate = self
-
- positionYInput.properties = ComponentInputNumberProperty(alignment: .left,
- size: .s,
- minSize: -1000,
- maxSize: 1000,
- text: "0")
- positionYInput.delegate = self
-
- //Save
- saveTemplateBGView.wantsLayer = true
- saveTemplateBGView.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle").cgColor
- saveButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .m, showLeftIcon: true, buttonText: KMLocalizedString("Save as Template"), icon: NSImage(named: "icon_wm_template_save"), keepPressState: false)
- saveButton.setTarget(self, action: #selector(saveButtonClicked(_:)))
-
- }
-
- func reloadData() {
-
- titleLabel.stringValue = KMLocalizedString("Add Background")
- leftTopButton.isHidden = true
- saveTemplateBGView.isHidden = false
- templateButton.properties.icon = NSImage(named: "icon_wm_template")
- templateButton.properties.isDisabled = false
-
- infoContendTopConst.constant = 56
- typeTabsBGView.isHidden = false
- if editSubType == .edit {
- infoContendTopConst.constant = 8
- typeTabsBGView.isHidden = true
-
- titleLabel.stringValue = KMLocalizedString("Edit Background")
- leftTopButton.isHidden = false
- saveTemplateBGView.isHidden = true
- templateButton.properties.icon = NSImage(named: "edit_save")
-
- if backgroundData.type == .image {
- if backgroundData.imagePath == nil {
- templateButton.properties.isDisabled = true
- }
- }
- }
- templateButton.reloadData()
-
- fileBGView.isHidden = true
- textBGView.isHidden = true
-
- textTabProperty.state = .normal
- fileTabProperty.state = .normal
-
- if backgroundData.type == .color {
- textBGView.isHidden = false
- appearanceBGTopConst.constant = 88
- textTabProperty.state = .pressed
- } else if backgroundData.type == .image {
- fileBGView.isHidden = false
- appearanceBGTopConst.constant = 48
- fileTabProperty.state = .pressed
- }
- typeTabs.refreshItems()
-
- //Text
- fontColorGroup.currentColor = backgroundData.color
- fontColorGroup.refreshUI()
-
- //File
- fileInputView.properties.text = backgroundData.imagePath ?? ""
- fileInputView.reloadData()
-
- //Appearance
- appearance_RotateSelect.properties.text = String(format: "%.0f", backgroundData.rotation) + "°"
- appearance_RotateSelect.reloadData()
-
- if backgroundData.opacity > 1 {
- backgroundData.opacity = 1
- }
- appearance_OpacitySelect.properties.text = String(format: "%.0f", backgroundData.opacity*100) + "%"
- appearance_OpacitySelect.reloadData()
-
- appearanceScaleCheckbox.properties.checkboxType = backgroundData.isScale ? .selected : .normal
- appearanceScaleCheckbox.reloadData()
-
- appearanceScaleSelect.properties.isDisabled = backgroundData.isScale ? false : true
- appearanceScaleSelect.properties.text = String(format: "%.0f", backgroundData.scale*100) + "%"
- appearanceScaleSelect.reloadData()
-
- //Position
- if backgroundData.verticalMode == 2 {
- positionItemView.properties.selRow = 0
- } else if backgroundData.verticalMode == 1 {
- positionItemView.properties.selRow = 1
- } else if backgroundData.verticalMode == 0 {
- positionItemView.properties.selRow = 2
- }
-
- if backgroundData.horizontalMode == 0 {
- positionItemView.properties.selColumn = 0
- } else if backgroundData.horizontalMode == 1 {
- positionItemView.properties.selColumn = 1
- } else if backgroundData.horizontalMode == 2 {
- positionItemView.properties.selColumn = 2
- }
- positionItemView.reloadData()
-
- positionXInput.properties.text = String(format: "%.0f", backgroundData.horizontalSpace)
- positionXInput.reloadData()
-
- positionYInput.properties.text = String(format: "%.0f", backgroundData.verticalSpace)
- positionYInput.reloadData()
-
- if backgroundData.type == .color {
- saveButton.properties.isDisabled = false
- } else if backgroundData.type == .image {
- if backgroundData.imagePath != nil {
- saveButton.properties.isDisabled = false
- } else {
- saveButton.properties.isDisabled = true
- }
- }
- saveButton.reloadData()
-
- }
-
- //MARK: - Action
- @objc func leftTopButtonClicked(_ sender: ComponentButton) {
- if sender == leftTopButton {
- var isChanged = false
- if let dict = self.originalDataDict {
- isChanged = KMBackgroundManager.compareIsChangedModel(backgroundData, withDict: dict as NSDictionary)
- }
-
- if isChanged == true {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = KMLocalizedString("Save template changes?")
- alert.informativeText = KMLocalizedString("Cancel and they will not be saved.")
- alert.addButton(withTitle: KMLocalizedString("Save"))
- alert.addButton(withTitle: KMLocalizedString("Cancel"))
- alert.beginSheetModal(for: NSApp.mainWindow!) { (response) in
- if response == NSApplication.ModalResponse.alertFirstButtonReturn {
- let _ = KMBackgroundManager.defaultManager.updateTemplate(model: self.backgroundData)
-
- self.delegate?.backgroundPropertyControllerFinishTemplateEdit?(self)
-
- } else {
- if let dict = self.originalDataDict {
- KMBackgroundManager.defaultManager.updateModel(self.backgroundData, withDict: dict as NSDictionary)
-
- let _ = KMBackgroundManager.defaultManager.updateTemplate(model: self.backgroundData)
- }
- self.delegate?.backgroundPropertyControllerFinishTemplateEdit?(self)
-
- }
- }
- } else {
- delegate?.backgroundPropertyControllerCancelTemplateEdit?(self)
-
- }
- }
-
- }
-
- @objc func templateButtonClicked(_ sender: ComponentButton) {
- if editSubType == .add {
- delegate?.backgroundPropertyControllerDidChangetoTemplate?(self)
- } else if editSubType == .edit {
- let _ = KMBackgroundManager.defaultManager.updateTemplate(model: self.backgroundData)
-
- delegate?.backgroundPropertyControllerFinishTemplateEdit?(self)
- }
- }
-
- @objc func checkBoxClicked(_ sender: ComponentCheckBox) {
- if sender == appearanceScaleCheckbox {
- backgroundData.isScale = appearanceScaleCheckbox.properties.checkboxType == .selected ? true : false
- }
- reloadData()
-
- delegate?.backgroundPropertyControllerDidUpdate?(self)
- }
-
- @objc func saveButtonClicked(_ sender: ComponentButton) {
- let saveWindow: KMWatermarkSaveWindow = KMWatermarkSaveWindow(windowNibName: "KMWatermarkSaveWindow")
- if backgroundData.type == .color {
- saveWindow.nameValue = backgroundData.name
- } else if backgroundData.type == .image {
- saveWindow.nameValue = backgroundData.imagePath?.lastPathComponent ?? ""
- }
- saveWindow.saveHandler = {[weak self] string in
- guard let weakSelf = self else { return }
-
- DispatchQueue.main.async {
- weakSelf.backgroundData.name = string ?? ""
- if KMBackgroundManager.defaultManager.addTemplate(model: weakSelf.backgroundData) {
- weakSelf.delegate?.backgroundPropertyControllerSaveTemplateSuccess?(weakSelf, weakSelf.backgroundData)
- }
- }
- }
- saveWindow.own_beginSheetModal(for: view.window) { string in
-
- }
- }
-
- @objc func chooseURLAction(_ sender: NSView) {
- let openPanel = NSOpenPanel()
- openPanel.canChooseDirectories = false
- openPanel.canChooseFiles = true
- openPanel.allowsMultipleSelection = false
- openPanel.allowedFileTypes = ["jpg", "jpeg", "png", "pdf"]
-
- openPanel.beginSheetModal(for: self.view.window!) { (result) in
- if result == NSApplication.ModalResponse.OK {
- guard let url = openPanel.url else { return }
- let filePath = url.path
-
- let outFolder = KMBackgroundManager.defaultManager.kBackgroundImageFolder
- let fileName = filePath.getLastComponentDeleteExtension
-
- if filePath.extension.lowercased() == ".pdf" {
- let pdf = CPDFDocument(url: url)
- guard !pdf!.isEncrypted else { return }
-
- if let image = self.generateThumbnail(for: url) {
- if let outFolderPath = outFolder?.stringByAppendingPathComponent(fileName + ".png") {
- try?image.pngData()?.write(to: URL(fileURLWithPath: outFolderPath))
- if FileManager.default.fileExists(atPath: outFolderPath) {
- self.backgroundData.imagePath = outFolderPath
-
- self.delegate?.backgroundPropertyControllerDidUpdate?(self)
-
- self.reloadData()
- }
- }
- }
- } else {
- let image = NSImage(contentsOfFile: url.path)
- if image == nil || NSImage.isDamageImage(image, imagePath: url.path) {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = "The file \"\(url.lastPathComponent)\" could not be opened."
- alert.informativeText = "It may be damaged or use a file format that PDF Reader Pro doesn’t recognize."
- alert.addButton(withTitle: "Cancel")
- alert.beginSheetModal(for: NSApp.mainWindow!) { (response) in
- if response == NSApplication.ModalResponse.alertFirstButtonReturn {
- // Cancel button clicked
- }
- }
- return
- }
- if let resultPath = outFolder?.stringByAppendingPathComponent(fileName + ".png") {
- try?FileManager.default.copyItem(atPath: url.path, toPath: resultPath)
-
- self.backgroundData.imagePath = resultPath
- }
-
- self.delegate?.backgroundPropertyControllerDidUpdate?(self)
-
- self.reloadData()
-
- }
- }
- }
- }
-
- func generateThumbnail(for pdfURL: URL) -> NSImage? {
- // 创建PDF文档
- guard let pdfDocument = CGPDFDocument(pdfURL as CFURL),
- let pdfPage = pdfDocument.page(at: 1) else {
- print("打开PDF文件失败")
- return nil
- }
-
- // 获取页面尺寸
- let pageRect = pdfPage.getBoxRect(.mediaBox)
-
- // 创建图形上下文
- let size = NSSize(width: 200, height: 300)
- let bitsPerComponent = 8
- let bytesPerPixel = 4
- let bitmapInfo = CGImageAlphaInfo.premultipliedLast.rawValue
- let context = CGContext(data: nil, width: Int(size.width), height: Int(size.height), bitsPerComponent: bitsPerComponent, bytesPerRow: 0, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: bitmapInfo)
-
- // 绘制PDF页面
- context?.saveGState()
- context?.translateBy(x: 0, y: size.height)
- context?.scaleBy(x: 1.0, y: -1.0) // 反转坐标系
- context?.scaleBy(x: size.width / pageRect.width, y: size.height / pageRect.height) // 缩放
- context?.drawPDFPage(pdfPage)
- context?.restoreGState()
-
- // 创建NSImage
- if let cgImage = context?.makeImage() {
- return NSImage(cgImage: cgImage, size: NSSize(width: size.width, height: size.height))
- } else {
- return nil
- }
- }
-
- //MARK: - Mouse
- override func mouseDown(with event: NSEvent) {
- super.mouseDown(with: event)
-
- view.window?.makeFirstResponder(nil)
-
- }
- }
- //MARK: - ComponentTabsDelegate
- extension KMBackgroundPropertyController: ComponentTabsDelegate {
- func componentTabsDidSelected(_ view: ComponentTabs, _ property: ComponentTabsProperty) {
- if property == textTabProperty {
- backgroundData.type = .color
- } else if property == fileTabProperty {
- backgroundData.type = .image
- }
- reloadData()
-
- delegate?.backgroundPropertyControllerDidUpdate?(self)
- }
- }
- //MARK: - ComponentCColorDelegate
- extension KMBackgroundPropertyController: ComponentCColorDelegate {
- func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
- if view == fontColorGroup {
- backgroundData.color = color ?? NSColor.clear
- }
- reloadData()
-
- delegate?.backgroundPropertyControllerDidUpdate?(self)
- }
- }
- //MARK: - ComponentSelectDelegate
- extension KMBackgroundPropertyController: ComponentSelectDelegate {
- func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
- if view == appearance_OpacitySelect {
- if let text = menuItemProperty?.text {
- let result = text.stringByDeleteCharString("%")
- backgroundData.opacity = result.stringToCGFloat()/100
- }
- } else if view == appearance_RotateSelect {
- if let text = menuItemProperty?.text {
- let result = text.stringByDeleteCharString("°")
- backgroundData.rotation = result.stringToCGFloat()
- }
- } else if view == appearanceScaleSelect {
- if let text = menuItemProperty?.text {
- let result = text.stringByDeleteCharString("%")
- backgroundData.scale = result.stringToCGFloat()/100
- }
- }
- reloadData()
-
- delegate?.backgroundPropertyControllerDidUpdate?(self)
- }
-
- func componentSelectTextDidEndEditing(_ view: ComponentSelect) {
- if view == appearance_OpacitySelect {
- if let text = appearance_OpacitySelect.properties.text {
- let result = text.stringByDeleteCharString("%")
- backgroundData.opacity = result.stringToCGFloat()/100
- }
- } else if view == appearance_RotateSelect {
- if let text = appearance_RotateSelect.properties.text {
- let result = text.stringByDeleteCharString("°")
- backgroundData.rotation = result.stringToCGFloat()
- }
- } else if view == appearanceScaleSelect {
- if let text = appearanceScaleSelect.properties.text {
- let result = text.stringByDeleteCharString("%")
- backgroundData.scale = min(10, result.stringToCGFloat()/100)
- }
- }
-
- reloadData()
-
- delegate?.backgroundPropertyControllerDidUpdate?(self)
-
- }
-
- }
- //MARK: - ComponentCPositionDelegate
- extension KMBackgroundPropertyController: ComponentCPositionDelegate {
- func componentCPositionDidChoose(_ view: NSView, _ row: Int, _ column: Int) {
- if view == positionItemView {
- if row == 0 {
- backgroundData.verticalMode = 2
- } else if row == 1 {
- backgroundData.verticalMode = 1
- } else if row == 2 {
- backgroundData.verticalMode = 0
- }
-
- if column == 0 {
- backgroundData.horizontalMode = 0
- } else if column == 1 {
- backgroundData.horizontalMode = 1
- } else if column == 2 {
- backgroundData.horizontalMode = 2
- }
- }
- reloadData()
-
- delegate?.backgroundPropertyControllerDidUpdate?(self)
- }
- }
- //MARK: - ComponentInputNumberDelegate
- extension KMBackgroundPropertyController: ComponentInputNumberDelegate {
- func componentInputNumberDidValueChanged(inputNumber: ComponentInputNumber?) {
- if inputNumber == positionXInput {
- if let text = inputNumber?.properties.text {
- backgroundData.horizontalSpace = text.stringToCGFloat()
- }
- } else if inputNumber == positionYInput {
- if let text = inputNumber?.properties.text {
- backgroundData.verticalSpace = text.stringToCGFloat()
- }
- }
- reloadData()
-
- delegate?.backgroundPropertyControllerDidUpdate?(self)
- }
- }
|