123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // CPDFDrawArrowView.m
- // compdfkit-tools
- //
- // Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
- //
- // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
- // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
- // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
- // This notice may not be removed from this file.
- //
- #import "CPDFDrawArrowView.h"
- @interface CPDFDrawArrowView ()
- @property (nonatomic, assign) CPDFDrawSelectedIndex selectIndex;
- @end
- @implementation CPDFDrawArrowView
- - (instancetype)initWithSelectIndex:(CPDFDrawSelectedIndex)selectIndex {
- if (self = [super init]) {
- self.selectIndex = selectIndex;
- }
- return self;
- }
- - (void)drawRect:(CGRect)rect {
- [super drawRect:rect];
- CGContextRef context = UIGraphicsGetCurrentContext();
- CGPoint start = CGPointMake(CGRectGetMinX(rect), CGRectGetMidY(rect));
- CGPoint end = CGPointMake(CGRectGetMaxX(rect), CGRectGetMidY(rect));
- [self drawArrow:context startPoint:start endPoint:end];
- }
- #pragma mark - Private Methods
- - (void)drawArrow:(CGContextRef)context startPoint:(CGPoint)start endPoint:(CGPoint)end {
- CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
- CGContextSetLineWidth(context, 2);
- switch (self.selectIndex) {
- case CPDFDrawNone:
- {
- CGContextMoveToPoint(context, start.x, start.y);
- CGContextAddLineToPoint(context, end.x, end.y);
- CGContextStrokePath(context);
- }
- break;
- case CPDFDrawArrow:
- {
- CGContextMoveToPoint(context, start.x, start.y);
- CGContextAddLineToPoint(context, end.x, end.y);
-
- CGContextMoveToPoint(context, end.x-5, end.y-5);
- CGContextAddLineToPoint(context, end.x, end.y);
- CGContextAddLineToPoint(context, end.x+5, end.y+5);
- CGContextStrokePath(context);
- }
- break;
- case CPDFDrawTriangle:
- {
- CGContextMoveToPoint(context, start.x, start.y);
- CGContextAddLineToPoint(context, end.x, end.y);
- CGContextStrokePath(context);
-
- CGContextMoveToPoint(context, end.x-5, end.y-5);
- CGContextAddLineToPoint(context, end.x, end.y);
- CGContextAddLineToPoint(context, end.x+5, end.y+5);
- CGContextFillPath(context);
- }
- break;
- case CPDFDrawSquare:
- {
- CGContextMoveToPoint(context, start.x, start.y);
- CGContextAddLineToPoint(context, end.x, end.y);
- CGContextStrokePath(context);
-
- CGContextMoveToPoint(context, end.x-10, end.y);
- CGContextAddLineToPoint(context, end.x - 5, end.y - 5);
- CGContextAddLineToPoint(context, end.x + 5, end.y + 5);
- CGContextAddLineToPoint(context, end.x, end.y+10);
- CGContextFillPath(context);
- }
- break;
- case CPDFDrawCircle:
- {
- CGContextMoveToPoint(context, start.x, start.y);
- CGContextAddLineToPoint(context, end.x, end.y);
- CGContextStrokePath(context);
-
- CGContextAddArc(context, end.x, end.y, 10, 0, 2*3.14159265358979323846, 0);
- CGContextDrawPath(context, kCGPathStroke);
- }
- break;
- case CPDFDrawDiamond:
- {
- CGContextMoveToPoint(context, start.x, start.y);
- CGContextAddLineToPoint(context, end.x, end.y);
- CGContextStrokePath(context);
-
- CGContextMoveToPoint(context, end.x-5, end.y-5);
- CGContextAddLineToPoint(context, end.x, end.y);
- CGContextAddLineToPoint(context, end.x+5, end.y+5);
- CGContextAddLineToPoint(context, end.x-10, end.y+10);
- CGContextFillPath(context);
- }
- break;
- default:
- break;
- }
- }
- @end
|