Skip to content

Commit

Permalink
Added drawing code
Browse files Browse the repository at this point in the history
  • Loading branch information
Torin Nguyen committed Jul 5, 2012
1 parent 727e52f commit 2c24618
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions WTMGlyphDemo/WTMGlyphDetectorView.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

@interface WTMGlyphDetectorView : UIView
@property (nonatomic, strong) id delegate;
@property (nonatomic, assign) BOOL enableDrawing;

- (void)loadTemplatesWithNames:(NSString*)firstTemplate, ... NS_REQUIRES_NIL_TERMINATION;

Expand Down
45 changes: 44 additions & 1 deletion WTMGlyphDemo/WTMGlyphDetectorView.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
@interface WTMGlyphDetectorView() <WTMGlyphDelegate>
@property (nonatomic, strong) WTMGlyphDetector *glyphDetector;
@property (nonatomic, strong) NSMutableArray *glyphNamesArray;
@property (nonatomic, strong) UIBezierPath *myPath;
@end

@implementation WTMGlyphDetectorView
@synthesize delegate;
@synthesize myPath;
@synthesize enableDrawing;
@synthesize glyphDetector;
@synthesize glyphNamesArray;

Expand All @@ -24,6 +27,14 @@ - (id)initWithFrame:(CGRect)frame
self = [super initWithFrame:frame];
if (self) {
[self initGestureDetector];

self.backgroundColor = [UIColor clearColor];
self.enableDrawing = YES;

self.myPath = [[UIBezierPath alloc]init];
self.myPath.lineCapStyle = kCGLineCapRound;
self.myPath.miterLimit = 0;
self.myPath.lineWidth = 10;
}
return self;
}
Expand Down Expand Up @@ -96,15 +107,26 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//This is basically the content of resetIfTimeout
BOOL hasTimeOut = [self.glyphDetector hasTimedOut];
if (hasTimeOut) {
[self.glyphDetector reset];
NSLog(@"Gesture detector reset");
[self.glyphDetector reset];

if (self.enableDrawing) {
[self.myPath removeAllPoints];
//This is not recommended for production, but it's ok here since we don't have a lot to draw
[self setNeedsDisplay];
}
}

UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
[self.glyphDetector addPoint:point];

[super touchesBegan:touches withEvent:event];

if (!self.enableDrawing)
return;

[self.myPath moveToPoint:point];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
Expand All @@ -114,6 +136,14 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
[self.glyphDetector addPoint:point];

[super touchesMoved:touches withEvent:event];

if (!self.enableDrawing)
return;

[self.myPath addLineToPoint:point];

//This is not recommended for production, but it's ok here since we don't have a lot to draw
[self setNeedsDisplay];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
Expand All @@ -126,4 +156,17 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
[super touchesEnded:touches withEvent:event];
}


- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];

if (!self.enableDrawing)
return;

[[UIColor whiteColor] setStroke];
[self.myPath strokeWithBlendMode:kCGBlendModeNormal alpha:0.5];
}


@end

0 comments on commit 2c24618

Please sign in to comment.