CPerimeterMeasureInfoWindowController.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // CPerimeterMeasureInfoWindowController.swift
  3. // Cisdem PDFMaster
  4. //
  5. // Created by wanjun on 2024/7/16.
  6. //
  7. import Cocoa
  8. protocol CPerimeterMeasureInfoWindowControllerDelegate: AnyObject {
  9. func perimeterMeasureInfoWindowControllerSetting(_ perimeterMeasureInfoWindowController: CPerimeterMeasureInfoWindowController)
  10. }
  11. @objcMembers
  12. class CPerimeterMeasureInfoWindowController: NSWindowController {
  13. @IBOutlet weak var scaleLabel: NSTextField!
  14. @IBOutlet weak var lengthLabel: NSTextField!
  15. @IBOutlet weak var precisionLabel: NSTextField!
  16. @IBOutlet weak var angleLabel: NSTextField!
  17. weak var delegate: CPerimeterMeasureInfoWindowControllerDelegate?
  18. var measureInfo: CPDFPerimeterMeasureInfo = CPDFPerimeterMeasureInfo()
  19. convenience init() {
  20. self.init(windowNibName: "CPerimeterMeasureInfoWindowController")
  21. }
  22. override func windowDidLoad() {
  23. super.windowDidLoad()
  24. self.window?.level = .floating
  25. commonInit()
  26. }
  27. func hideFloatingWindow() {
  28. self.window?.orderOut(nil)
  29. }
  30. private func commonInit() {
  31. scaleLabel.stringValue = String(format: "%0.0f %@ = %0.0f %@", measureInfo.rulerBase, measureInfo.rulerBaseUnit, measureInfo.rulerTranslate, measureInfo.rulerTranslateUnit)
  32. switch measureInfo.precision {
  33. case 1:
  34. precisionLabel.stringValue = "1"
  35. case 10:
  36. precisionLabel.stringValue = "0.1"
  37. case 100:
  38. precisionLabel.stringValue = "0.01"
  39. case 1000:
  40. precisionLabel.stringValue = "0.001"
  41. case 10000:
  42. precisionLabel.stringValue = "0.0001"
  43. default:
  44. break
  45. }
  46. }
  47. func reloadData(with measureInfo: CPDFPerimeterMeasureInfo) {
  48. self.measureInfo = measureInfo
  49. scaleLabel.stringValue = String(format: "%0.0f %@ = %0.0f %@", measureInfo.rulerBase, measureInfo.rulerBaseUnit, measureInfo.rulerTranslate, measureInfo.rulerTranslateUnit)
  50. let formatValue = measureInfo.formatValue
  51. lengthLabel.stringValue = ""
  52. if formatValue.count > 4 {
  53. let range = formatValue.index(formatValue.startIndex, offsetBy: 4)..<formatValue.endIndex
  54. lengthLabel.stringValue = String(formatValue[range])
  55. }
  56. switch measureInfo.precision {
  57. case 1:
  58. precisionLabel.stringValue = "1"
  59. case 10:
  60. precisionLabel.stringValue = "0.1"
  61. case 100:
  62. precisionLabel.stringValue = "0.01"
  63. case 1000:
  64. precisionLabel.stringValue = "0.001"
  65. case 10000:
  66. precisionLabel.stringValue = "0.0001"
  67. default:
  68. break
  69. }
  70. }
  71. @IBAction func buttonItemClick_Setting(_ sender: Any) {
  72. delegate?.perimeterMeasureInfoWindowControllerSetting(self)
  73. }
  74. }