Skip to content

Instantly share code, notes, and snippets.

@briandw
Last active December 18, 2015 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briandw/5851343 to your computer and use it in GitHub Desktop.
Save briandw/5851343 to your computer and use it in GitHub Desktop.
rantlab post 1.2
- (void)mouseDown:(NSEvent *)event
{
arrow = [CAShapeLayer layer];
CGFloat minMagnitude = 20;
CGPoint middle = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
CGPoint vector = CGPointMake(target.x-middle.x, target.y-middle.y);
CGFloat magnitude = sqrt(vector.x*vector.x+vector.y*vector.y);
CGPoint start = CGPointMake(middle.x+vector.x/magnitude*minMagnitude, middle.y+vector.y/magnitude*minMagnitude);
CGPathRef startPath = [RLArrowView createPathWithArrowFromPoint:middle
toPoint:start
tailWidth:2.0
headWidth:10.0
headLength:20.0
wiggle:0];
arrow.path = startPath;
arrow.fillColor = [NSColor redColor].CGColor;
arrow.lineWidth = 1;
arrow.fillRule = kCAFillRuleNonZero;
[self.layer addSublayer:arrow];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment