CPDFDrawArrowView.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // CPDFDrawArrowView.m
  3. // compdfkit-tools
  4. //
  5. // Copyright © 2014-2023 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 "CPDFDrawArrowView.h"
  13. @interface CPDFDrawArrowView ()
  14. @property (nonatomic, assign) CPDFDrawSelectedIndex selectIndex;
  15. @end
  16. @implementation CPDFDrawArrowView
  17. - (instancetype)initWithSelectIndex:(CPDFDrawSelectedIndex)selectIndex {
  18. if (self = [super init]) {
  19. self.selectIndex = selectIndex;
  20. }
  21. return self;
  22. }
  23. - (void)drawRect:(CGRect)rect {
  24. [super drawRect:rect];
  25. CGContextRef context = UIGraphicsGetCurrentContext();
  26. CGPoint start = CGPointMake(CGRectGetMinX(rect), CGRectGetMidY(rect));
  27. CGPoint end = CGPointMake(CGRectGetMaxX(rect), CGRectGetMidY(rect));
  28. [self drawArrow:context startPoint:start endPoint:end];
  29. }
  30. #pragma mark - Private Methods
  31. - (void)drawArrow:(CGContextRef)context startPoint:(CGPoint)start endPoint:(CGPoint)end {
  32. CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
  33. CGContextSetLineWidth(context, 2);
  34. switch (self.selectIndex) {
  35. case CPDFDrawNone:
  36. {
  37. CGContextMoveToPoint(context, start.x, start.y);
  38. CGContextAddLineToPoint(context, end.x, end.y);
  39. CGContextStrokePath(context);
  40. }
  41. break;
  42. case CPDFDrawArrow:
  43. {
  44. CGContextMoveToPoint(context, start.x, start.y);
  45. CGContextAddLineToPoint(context, end.x, end.y);
  46. CGContextMoveToPoint(context, end.x-5, end.y-5);
  47. CGContextAddLineToPoint(context, end.x, end.y);
  48. CGContextAddLineToPoint(context, end.x+5, end.y+5);
  49. CGContextStrokePath(context);
  50. }
  51. break;
  52. case CPDFDrawTriangle:
  53. {
  54. CGContextMoveToPoint(context, start.x, start.y);
  55. CGContextAddLineToPoint(context, end.x, end.y);
  56. CGContextStrokePath(context);
  57. CGContextMoveToPoint(context, end.x-5, end.y-5);
  58. CGContextAddLineToPoint(context, end.x, end.y);
  59. CGContextAddLineToPoint(context, end.x+5, end.y+5);
  60. CGContextFillPath(context);
  61. }
  62. break;
  63. case CPDFDrawSquare:
  64. {
  65. CGContextMoveToPoint(context, start.x, start.y);
  66. CGContextAddLineToPoint(context, end.x, end.y);
  67. CGContextStrokePath(context);
  68. CGContextMoveToPoint(context, end.x-10, end.y);
  69. CGContextAddLineToPoint(context, end.x - 5, end.y - 5);
  70. CGContextAddLineToPoint(context, end.x + 5, end.y + 5);
  71. CGContextAddLineToPoint(context, end.x, end.y+10);
  72. CGContextFillPath(context);
  73. }
  74. break;
  75. case CPDFDrawCircle:
  76. {
  77. CGContextMoveToPoint(context, start.x, start.y);
  78. CGContextAddLineToPoint(context, end.x, end.y);
  79. CGContextStrokePath(context);
  80. CGContextAddArc(context, end.x, end.y, 10, 0, 2*3.14159265358979323846, 0);
  81. CGContextDrawPath(context, kCGPathStroke);
  82. }
  83. break;
  84. case CPDFDrawDiamond:
  85. {
  86. CGContextMoveToPoint(context, start.x, start.y);
  87. CGContextAddLineToPoint(context, end.x, end.y);
  88. CGContextStrokePath(context);
  89. CGContextMoveToPoint(context, end.x-5, end.y-5);
  90. CGContextAddLineToPoint(context, end.x, end.y);
  91. CGContextAddLineToPoint(context, end.x+5, end.y+5);
  92. CGContextAddLineToPoint(context, end.x-10, end.y+10);
  93. CGContextFillPath(context);
  94. }
  95. break;
  96. default:
  97. break;
  98. }
  99. }
  100. @end