From a9147eab71538bada96f978ceb7b9692250f461f Mon Sep 17 00:00:00 2001 From: Sebastian Hunkeler Date: Sat, 30 Aug 2014 11:08:24 +0200 Subject: [PATCH 1/2] Added new properties --- Source/PPSSignatureView.h | 10 ++++++++++ Source/PPSSignatureView.m | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Source/PPSSignatureView.h b/Source/PPSSignatureView.h index 747315a..ce6605d 100644 --- a/Source/PPSSignatureView.h +++ b/Source/PPSSignatureView.h @@ -1,12 +1,22 @@ #import #import +@protocol PPSSignatureViewDelegate; + @interface PPSSignatureView : GLKView @property (assign, nonatomic) UIColor *strokeColor; @property (assign, nonatomic) BOOL hasSignature; @property (strong, nonatomic) UIImage *signatureImage; +@property(assign, nonatomic) BOOL longPressToEraseEnabled; +@property(nonatomic,readonly) NSUInteger vertexCount; +@property(weak, nonatomic)id signatureViewDelegate; - (void)erase; @end + + +@protocol PPSSignatureViewDelegate +-(void)signatureDidChange:(PPSSignatureView*)signatureView; +@end \ No newline at end of file diff --git a/Source/PPSSignatureView.m b/Source/PPSSignatureView.m index 9ad6d1e..3607433 100644 --- a/Source/PPSSignatureView.m +++ b/Source/PPSSignatureView.m @@ -226,6 +226,13 @@ - (UIImage *)signatureImage return screenshot; } +#pragma mark - Properties + +-(NSUInteger)vertexCount +{ + return length; +} + #pragma mark - Gesture Recognizers @@ -273,7 +280,8 @@ - (void)tap:(UITapGestureRecognizer *)t { - (void)longPress:(UILongPressGestureRecognizer *)lp { - [self erase]; + if(self.longPressToEraseEnabled) + [self erase]; } - (void)pan:(UIPanGestureRecognizer *)p { @@ -358,6 +366,9 @@ - (void)pan:(UIPanGestureRecognizer *)p { } [self setNeedsDisplay]; + + if(self.signatureViewDelegate) + [self.signatureViewDelegate signatureDidChange:self]; } @@ -370,7 +381,7 @@ - (void)setStrokeColor:(UIColor *)strokeColor { #pragma mark - Private - (void)updateStrokeColor { - CGFloat red, green, blue, alpha, white; + CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0, white = 0.0; if (effect && self.strokeColor && [self.strokeColor getRed:&red green:&green blue:&blue alpha:&alpha]) { effect.constantColor = GLKVector4Make(red, green, blue, alpha); } else if (effect && self.strokeColor && [self.strokeColor getWhite:&white alpha:&alpha]) { From 4f6f19d809a9fa7667f6cdb971bdd2e928789b20 Mon Sep 17 00:00:00 2001 From: Sebastian Hunkeler Date: Mon, 23 Feb 2015 23:31:31 +0100 Subject: [PATCH 2/2] Added max stroke width property --- Source/PPSSignatureView.h | 1 + Source/PPSSignatureView.m | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/PPSSignatureView.h b/Source/PPSSignatureView.h index ce6605d..202a3bc 100644 --- a/Source/PPSSignatureView.h +++ b/Source/PPSSignatureView.h @@ -10,6 +10,7 @@ @property (strong, nonatomic) UIImage *signatureImage; @property(assign, nonatomic) BOOL longPressToEraseEnabled; @property(nonatomic,readonly) NSUInteger vertexCount; +@property(assign,nonatomic) float strokeMaxWidth; @property(weak, nonatomic)id signatureViewDelegate; - (void)erase; diff --git a/Source/PPSSignatureView.m b/Source/PPSSignatureView.m index 3607433..eab9f31 100644 --- a/Source/PPSSignatureView.m +++ b/Source/PPSSignatureView.m @@ -2,7 +2,7 @@ #import #define STROKE_WIDTH_MIN 0.004 // Stroke width determined by touch velocity -#define STROKE_WIDTH_MAX 0.030 +#define DEFAULT_STROKE_WIDTH_MAX 0.010 #define STROKE_WIDTH_SMOOTHING 0.5 // Low pass filter alpha #define VELOCITY_CLAMP_MIN 20 @@ -128,6 +128,7 @@ - (void)commonInit { self.context = context; self.drawableDepthFormat = GLKViewDrawableDepthFormat24; self.enableSetNeedsDisplay = YES; + self.strokeMaxWidth = DEFAULT_STROKE_WIDTH_MAX; // Turn on antialiasing self.drawableMultisample = GLKViewDrawableMultisample4X; @@ -302,7 +303,7 @@ - (void)pan:(UIPanGestureRecognizer *)p { float normalizedVelocity = (clampedVelocityMagnitude - VELOCITY_CLAMP_MIN) / (VELOCITY_CLAMP_MAX - VELOCITY_CLAMP_MIN); float lowPassFilterAlpha = STROKE_WIDTH_SMOOTHING; - float newThickness = (STROKE_WIDTH_MAX - STROKE_WIDTH_MIN) * (1 - normalizedVelocity) + STROKE_WIDTH_MIN; + float newThickness = (self.strokeMaxWidth - STROKE_WIDTH_MIN) * (1 - normalizedVelocity) + STROKE_WIDTH_MIN; penThickness = penThickness * lowPassFilterAlpha + newThickness * (1 - lowPassFilterAlpha); if ([p state] == UIGestureRecognizerStateBegan) {