CPDFSquigglyViewController.m 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // CPDFSquigglyViewController.m
  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 "CPDFSquigglyViewController.h"
  13. #import "CPDFAnnotationBaseViewController_Header.h"
  14. @interface CPDFSquigglyViewController ()
  15. @end
  16. @implementation CPDFSquigglyViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. // Do any additional setup after loading the view.
  20. }
  21. - (void)commomInitTitle {
  22. self.titleLabel.text = NSLocalizedString(@"Squiggly", nil);
  23. self.sampleView.selecIndex = CPDFSamplesSquiggly;
  24. self.colorView.selectedColor = self.annotStyle.color;
  25. }
  26. - (void)commomInitFromAnnotStyle {
  27. self.sampleView.color = self.annotStyle.color;
  28. self.sampleView.opcity = self.annotStyle.opacity;
  29. self.opacitySliderView.opacitySlider.value = self.annotStyle.opacity;
  30. self.opacitySliderView.startLabel.text = [NSString stringWithFormat:@"%d%%", (int)((self.opacitySliderView.opacitySlider.value/1)*100)];
  31. [self.sampleView setNeedsDisplay];
  32. }
  33. #pragma mark - CPDFColorSelectViewDelegate
  34. - (void)selectColorView:(CPDFColorSelectView *)select color:(UIColor *)color {
  35. self.sampleView.color = color;
  36. self.annotStyle.color = color;
  37. if (self.delegate && [self.delegate respondsToSelector:@selector(squigglyViewController:annotStyle:)]) {
  38. [self.delegate squigglyViewController:self annotStyle:self.annotStyle];
  39. }
  40. [self.sampleView setNeedsDisplay];
  41. }
  42. #pragma mark - CPDFColorPickerViewDelegate
  43. - (void)pickerView:(CPDFColorPickerView *)colorPickerView color:(UIColor *)color {
  44. self.sampleView.color = color;
  45. self.annotStyle.color = color;
  46. if (self.delegate && [self.delegate respondsToSelector:@selector(squigglyViewController:annotStyle:)]) {
  47. [self.delegate squigglyViewController:self annotStyle:self.annotStyle];
  48. }
  49. [self.sampleView setNeedsDisplay];
  50. CGFloat red, green, blue, alpha;
  51. [color getRed:&red green:&green blue:&blue alpha:&alpha];
  52. self.opacitySliderView.opacitySlider.value = alpha;
  53. self.opacitySliderView.startLabel.text = [NSString stringWithFormat:@"%d%%", (int)((self.opacitySliderView.opacitySlider.value/1)*100)];
  54. [self updatePreferredContentSizeWithTraitCollection:self.traitCollection];
  55. }
  56. #pragma mark - CPDFOpacitySliderViewDelegate
  57. - (void)opacitySliderView:(CPDFOpacitySliderView *)opacitySliderView opacity:(CGFloat)opacity {
  58. self.sampleView.opcity = opacity;
  59. self.annotStyle.opacity = opacity;
  60. if (self.delegate && [self.delegate respondsToSelector:@selector(squigglyViewController:annotStyle:)]) {
  61. [self.delegate squigglyViewController:self annotStyle:self.annotStyle];
  62. }
  63. [self.sampleView setNeedsDisplay];
  64. }
  65. #pragma mark - UIColorPickerViewControllerDelegate
  66. - (void)colorPickerViewControllerDidFinish:(UIColorPickerViewController *)viewController API_AVAILABLE(ios(14.0)) {
  67. self.sampleView.color = viewController.selectedColor;
  68. self.annotStyle.color = self.sampleView.color;
  69. if (self.delegate && [self.delegate respondsToSelector:@selector(squigglyViewController:annotStyle:)]) {
  70. [self.delegate squigglyViewController:self annotStyle:self.annotStyle];
  71. }
  72. [self.sampleView setNeedsDisplay];
  73. CGFloat red, green, blue, alpha;
  74. [viewController.selectedColor getRed:&red green:&green blue:&blue alpha:&alpha];
  75. self.opacitySliderView.opacitySlider.value = alpha;
  76. self.opacitySliderView.startLabel.text = [NSString stringWithFormat:@"%d%%", (int)((self.opacitySliderView.opacitySlider.value/1)*100)];
  77. }
  78. @end