From e1dcb706bd8fce90ee2b595c2f6b796ca9e6b130 Mon Sep 17 00:00:00 2001 From: Tres Wong-Godfrey Date: Sun, 9 Oct 2016 17:53:07 -0700 Subject: [PATCH 1/2] Mod: Allow JotViewControllerDelegate To Know When Drawing Happens --- jot/JotViewController.h | 28 ++++++++++++++++++++++++++++ jot/JotViewController.m | 22 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/jot/JotViewController.h b/jot/JotViewController.h index 0f29456..134a872 100644 --- a/jot/JotViewController.h +++ b/jot/JotViewController.h @@ -215,6 +215,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 +235,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..1027d07 100644 --- a/jot/JotViewController.m +++ b/jot/JotViewController.m @@ -243,6 +243,22 @@ - (void)setDrawingConstantStrokeWidth:(BOOL)drawingConstantStrokeWidth } } +#pragma mark - external draw point handlers +-(void) startTouchAtPoint:(CGPoint) point withColor:(UIColor *) color { + self.drawView.strokeColor = color; + [self.drawView drawTouchBeganAtPoint:point]; +} + +-(void) moveTouchToPoint:(CGPoint) point withColor:(UIColor *) color { + self.drawView.strokeColor = color; + [self.drawView drawTouchMovedToPoint:point]; +} + +-(void) endTouch { + [self.drawView drawTouchEnded]; +} + + #pragma mark - Undo - (void)clearAll @@ -335,6 +351,8 @@ - (void)jotDrawingContainerTouchBeganAtPoint:(CGPoint)touchPoint { if (self.state == JotViewStateDrawing) { [self.drawView drawTouchBeganAtPoint:touchPoint]; + if([self.delegate respondsToSelector:@selector(jotViewController:touchesBeganAtPoint:color:)]) + [self.delegate jotViewController:self touchesBeganAtPoint:touchPoint color: self.drawingColor]; } } @@ -342,6 +360,8 @@ - (void)jotDrawingContainerTouchMovedToPoint:(CGPoint)touchPoint { if (self.state == JotViewStateDrawing) { [self.drawView drawTouchMovedToPoint:touchPoint]; + if([self.delegate respondsToSelector:@selector(jotViewController:touchesMovedToPoint:color:)]) + [self.delegate jotViewController:self touchesMovedToPoint:touchPoint color: self.drawingColor]; } } @@ -349,6 +369,8 @@ - (void)jotDrawingContainerTouchEnded { if (self.state == JotViewStateDrawing) { [self.drawView drawTouchEnded]; + if([self.delegate respondsToSelector:@selector(jotViewControllerTouchesEnded:)]) + [self.delegate jotViewControllerTouchesEnded:self]; } } From 87e048d16a746be0366f817dbcfc1ad45a565345 Mon Sep 17 00:00:00 2001 From: Tres Wong-Godfrey Date: Tue, 11 Oct 2016 05:03:00 -0700 Subject: [PATCH 2/2] Mod: Allow Erasing Of Drawing Using User Touch Events --- jot/JotTouchBezier.m | 10 +++++++--- jot/JotViewController.h | 10 ++++++++++ jot/JotViewController.m | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) 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 134a872..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. diff --git a/jot/JotViewController.m b/jot/JotViewController.m index 1027d07..b3d9435 100644 --- a/jot/JotViewController.m +++ b/jot/JotViewController.m @@ -24,6 +24,7 @@ @interface JotViewController ()