CPDFSquigglyViewController.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // CPDFSquigglyViewController.swift
  3. // ComPDFKit_Tools
  4. //
  5. // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. import UIKit
  13. @objc protocol CPDFSquigglyViewControllerDelegate: AnyObject {
  14. @objc optional func squigglyViewController(_ squigglyViewController: CPDFSquigglyViewController, annotStyle: CAnnotStyle)
  15. }
  16. class CPDFSquigglyViewController: CPDFAnnotationBaseViewController {
  17. weak var delegate: CPDFSquigglyViewControllerDelegate?
  18. // MARK: - ViewController Methods
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. }
  22. override func commomInitTitle() {
  23. titleLabel?.text = NSLocalizedString("Squiggly", comment: "")
  24. sampleView?.selecIndex = .highlight
  25. colorView?.selectedColor = annotStyle?.color
  26. }
  27. // MARK: - CPDFColorSelectViewDelegate
  28. override func selectColorView(_ select: CPDFColorSelectView, color: UIColor) {
  29. sampleView?.color = color
  30. annotStyle?.setColor(color)
  31. if annotStyle != nil {
  32. delegate?.squigglyViewController?(self, annotStyle: annotStyle!)
  33. }
  34. sampleView?.setNeedsDisplay()
  35. }
  36. // MARK: - CPDFColorPickerViewDelegate
  37. override func pickerView(_ colorPickerView: CPDFColorPickerView, color: UIColor) {
  38. sampleView?.color = color
  39. annotStyle?.setColor(color)
  40. if annotStyle != nil {
  41. delegate?.squigglyViewController?(self, annotStyle: annotStyle!)
  42. }
  43. var red: CGFloat = 0
  44. var green: CGFloat = 0
  45. var blue: CGFloat = 0
  46. var alpha: CGFloat = 0
  47. color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
  48. self.opacitySliderView?.opacitySlider?.value = Float(alpha)
  49. self.opacitySliderView?.startLabel?.text = "\(Int(((self.opacitySliderView?.opacitySlider?.value ?? 0) / 1) * 100))%"
  50. updatePreferredContentSizeWithTraitCollection(traitCollection: traitCollection)
  51. }
  52. // MARK: - CPDFOpacitySliderViewDelegate
  53. override func opacitySliderView(_ opacitySliderView: CPDFOpacitySliderView, opacity: CGFloat) {
  54. sampleView?.opcity = opacity
  55. annotStyle?.setOpacity(opacity)
  56. if annotStyle != nil {
  57. delegate?.squigglyViewController?(self, annotStyle: annotStyle!)
  58. }
  59. sampleView?.setNeedsDisplay()
  60. }
  61. // MARK: - UIColorPickerViewControllerDelegate
  62. @available(iOS 14.0, *)
  63. func colorPickerViewControllerDidFinish(_ viewController: UIColorPickerViewController) {
  64. sampleView?.color = viewController.selectedColor
  65. annotStyle?.setColor(viewController.selectedColor)
  66. if annotStyle != nil {
  67. delegate?.squigglyViewController?(self, annotStyle: annotStyle!)
  68. }
  69. var red: CGFloat = 0
  70. var green: CGFloat = 0
  71. var blue: CGFloat = 0
  72. var alpha: CGFloat = 0
  73. viewController.selectedColor.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
  74. self.opacitySliderView?.opacitySlider?.value = Float(alpha)
  75. self.opacitySliderView?.startLabel?.text = "\(Int(((self.opacitySliderView?.opacitySlider?.value ?? 0) / 1) * 100))%"
  76. updatePreferredContentSizeWithTraitCollection(traitCollection: traitCollection)
  77. }
  78. }