diff --git a/jot/JotTouchBezier.m b/jot/JotTouchBezier.m index 7f5ab76..571e779 100644 --- a/jot/JotTouchBezier.m +++ b/jot/JotTouchBezier.m @@ -23,14 +23,14 @@ + (instancetype)withColor:(UIColor *)color - (void)jotDrawBezier { - if (self.constantWidth) { + if (self.constantWidth || [self isErasing]) { UIBezierPath *bezierPath = [UIBezierPath new]; [bezierPath moveToPoint:self.startPoint]; [bezierPath addCurveToPoint:self.endPoint controlPoint1:self.controlPoint1 controlPoint2:self.controlPoint2]; bezierPath.lineWidth = self.startWidth; bezierPath.lineCapStyle = kCGLineCapRound; [self.strokeColor setStroke]; - [bezierPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.f]; + [bezierPath strokeWithBlendMode:([self isErasing])?kCGBlendModeClear:kCGBlendModeNormal alpha:1.f]; } else { [self.strokeColor setFill]; @@ -61,13 +61,17 @@ - (void)jotDrawBezier } } +- (Boolean) isErasing { + return [self.strokeColor isEqual: [UIColor clearColor]]; +} + + (void)jotDrawBezierPoint:(CGPoint)point withWidth:(CGFloat)width { CGContextRef context = UIGraphicsGetCurrentContext(); if (!context) { return; } - + CGContextFillEllipseInRect(context, CGRectInset(CGRectMake(point.x, point.y, 0.f, 0.f), -width / 2.f, -width / 2.f)); } diff --git a/jot/JotViewController.h b/jot/JotViewController.h index 0f29456..edb4ce0 100644 --- a/jot/JotViewController.h +++ b/jot/JotViewController.h @@ -175,6 +175,16 @@ typedef NS_ENUM(NSUInteger, JotViewState){ */ - (void)clearText; +/** + * Enter 'Erase' mode. User touch interaction will erase drawing + */ +- (void)startErasingDrawing; + +/** + * Enter normal drawing mode + */ +- (void)endErasingDrawing; + /** * Overlays the drawing and text on the given background image at the full * resolution of the image. @@ -215,6 +225,12 @@ typedef NS_ENUM(NSUInteger, JotViewState){ */ - (UIImage *)renderImageWithScale:(CGFloat)scale onColor:(UIColor *)color; +-(void) startTouchAtPoint:(CGPoint) point withColor:(UIColor *) color; + +-(void) moveTouchToPoint:(CGPoint) point withColor:(UIColor *) color; + +-(void) endTouch; + @end @protocol JotViewControllerDelegate @@ -229,4 +245,26 @@ typedef NS_ENUM(NSUInteger, JotViewState){ */ - (void)jotViewController:(JotViewController *)jotViewController isEditingText:(BOOL)isEditing; +/** + * Called whenever the user begins a stroke in JotDrawView + * @param jotViewController The JotDrawViewController to which the delegate is associated + * @param point the point of the touch + * @param color the current stroke color + */ +-(void) jotViewController:(JotViewController *)jotViewController touchesBeganAtPoint:(CGPoint)point color:(UIColor *) color; + +/** + * Called whenever the user is drawing a stroke + * @param jotViewController The JotDrawViewController to which the delegate is associated + * @param point the point of the touch + * @param color the current stroke color + */ +-(void) jotViewController:(JotViewController *)jotViewController touchesMovedToPoint:(CGPoint)point color:(UIColor *) color; + +/** + * Called whenever the user completes a stroke + * @param jotViewController The JotDrawViewController to which the delegate is associated + */ +-(void) jotViewControllerTouchesEnded:(JotViewController *)jotViewController; + @end diff --git a/jot/JotViewController.m b/jot/JotViewController.m index 30148dd..b3d9435 100644 --- a/jot/JotViewController.m +++ b/jot/JotViewController.m @@ -24,6 +24,7 @@ @interface JotViewController ()