CDSignatureDrawViewController.swift 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // CDSignatureDrawViewController.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/10/16.
  6. //
  7. import Cocoa
  8. class CDSignatureDrawViewController: NSViewController, CDSDrawViewDelegate {
  9. @IBOutlet weak var drawView: CDSDrawView!
  10. @IBOutlet weak var cancelButton: NSButton!
  11. @IBOutlet weak var applyButton: NSButton!
  12. @IBOutlet weak var clearButton: NSButton!
  13. var drawImage: NSImage!
  14. var actionBlock: ((_ drawVC: CDSignatureDrawViewController, _ drawImage: NSImage)->Void)?
  15. override func viewDidAppear() {
  16. super.viewDidAppear()
  17. self.view.window?.title = ""
  18. self.view.window?.styleMask = [self.view.window!.styleMask, .fullSizeContentView]
  19. self.view.window?.titlebarAppearsTransparent = true
  20. self.view.window?.backgroundColor = NSColor(red: 252.0/255.0, green: 253.0/255.0, blue: 255.0/255.0, alpha: 1.0)
  21. self.view.window?.standardWindowButton(.closeButton)?.isHidden = true
  22. self.view.window?.standardWindowButton(.miniaturizeButton)?.isHidden = true
  23. self.view.window?.standardWindowButton(.zoomButton)?.isHidden = true
  24. self.drawView.clearImage()
  25. }
  26. override func viewDidLoad() {
  27. super.viewDidLoad()
  28. // Do view setup here.
  29. self.cancelButton.title = NSLocalizedString("Cancel", comment: "")
  30. self.applyButton.title = NSLocalizedString("Apply", comment: "")
  31. self.clearButton.title = NSLocalizedString("Clear", comment: "")
  32. self.drawView?.wantsLayer = true
  33. self.drawView?.layer?.borderWidth = 1.0
  34. self.drawView?.layer?.cornerRadius = 8.0
  35. self.drawView?.layer?.borderColor = NSColor(red: 165.0/255.0, green: 167.0/255.0, blue: 179.0/255.0, alpha: 1.0).cgColor
  36. self.drawView?.layer?.backgroundColor = NSColor(red: 1, green: 1, blue: 1, alpha: 1.0).cgColor
  37. self.drawView.delegate = self;
  38. self.drawView.drawColor = NSColor.black
  39. self.drawView.strokeRadius = 2.0;
  40. self.drawView.drawImage = self.drawImage
  41. }
  42. //MARK: IBAction
  43. @IBAction func closeAction(_ sender: NSButton) {
  44. self.dismiss(self)
  45. }
  46. @IBAction func clearAction(_ sender: NSButton) {
  47. self.drawView.clearImage()
  48. }
  49. @IBAction func cancelAction(_ sender: NSButton) {
  50. self.dismiss(self)
  51. }
  52. @IBAction func applyAction(_ sender: NSButton) {
  53. var image = NSImage(size: .zero)
  54. if self.drawView.signatureImage() != nil {
  55. image = self.drawView.signatureImage()
  56. }
  57. guard let callBack = self.actionBlock else {
  58. return
  59. }
  60. callBack(self, image)
  61. self.cancelAction(self.cancelButton)
  62. }
  63. }