Authored by Justin R. Miller

adapt #231 for configurability

Merge commit 'adf08cbe' into develop
@@ -84,6 +84,9 @@ @@ -84,6 +84,9 @@
84 /** The bounding box of the shape in the current viewport. */ 84 /** The bounding box of the shape in the current viewport. */
85 @property (nonatomic, readonly) CGRect pathBoundingBox; 85 @property (nonatomic, readonly) CGRect pathBoundingBox;
86 86
  87 +/** An additional pixel area around the shape that is applied to touch hit testing events. Defaults to none. */
  88 +@property (nonatomic, assign) CGFloat additionalTouchPadding;
  89 +
87 /** @name Drawing Shapes */ 90 /** @name Drawing Shapes */
88 91
89 /** Move the drawing pen to a projected point. 92 /** Move the drawing pen to a projected point.
@@ -435,10 +435,24 @@ @@ -435,10 +435,24 @@
435 { 435 {
436 // if shape is not filled with a color, do a simple "point on path" test 436 // if shape is not filled with a color, do a simple "point on path" test
437 // 437 //
438 - UIGraphicsBeginImageContext(self.bounds.size);  
439 - CGContextAddPath(UIGraphicsGetCurrentContext(), shapeLayer.path);  
440 - containsPoint = CGContextPathContainsPoint(UIGraphicsGetCurrentContext(), thePoint, kCGPathStroke);  
441 - UIGraphicsEndImageContext(); 438 + if (self.additionalTouchPadding)
  439 + {
  440 + CGPathRef tapTargetPath = CGPathCreateCopyByStrokingPath(shapeLayer.path, nil, fmaxf(self.additionalTouchPadding, shapeLayer.lineWidth), 0, 0, 0);
  441 +
  442 + if (tapTargetPath)
  443 + {
  444 + containsPoint = [[UIBezierPath bezierPathWithCGPath:tapTargetPath] containsPoint:thePoint];
  445 +
  446 + CGPathRelease(tapTargetPath);
  447 + }
  448 + }
  449 + else
  450 + {
  451 + UIGraphicsBeginImageContext(self.bounds.size);
  452 + CGContextAddPath(UIGraphicsGetCurrentContext(), shapeLayer.path);
  453 + containsPoint = CGContextPathContainsPoint(UIGraphicsGetCurrentContext(), thePoint, kCGPathStroke);
  454 + UIGraphicsEndImageContext();
  455 + }
442 } 456 }
443 else 457 else
444 { 458 {