NSBezierPath Hit Detection
NSBezierPath Hit Detection
- Subject: NSBezierPath Hit Detection
- From: email@hidden
- Date: Wed, 26 Sep 2001 09:25:40 -0400
Hi,
I'm trying to use the containsPoint method for hit detection of
NSBezierPaths on mouseUp in an NSView. But the only hex that my method
ever detects is the first one in the array.
I've broken the NSView up into an array of frames, each frame has an
NSBezierPath drawn in it to represent the hexagon. After I draw the
path, I add it to another array if necessary.
if ([[pathArray objectAtIndex: row] objectForKey: [NSNumber
numberWithInt: column]] == nil)
{
[[pathArray objectAtIndex: row] setObject:[path copy]
forKey:[NSNumber numberWithInt: column]];
}
I do this so that after I get the eventLocation of the mouseUp I can run
through the array of paths and check each path for containsPoint.
NSPoint eventLocation = [self convertPoint:[event locationInWindow]
fromView: nil];
if ([[[pathArray objectAtIndex: row] objectForKey:[NSNumber
numberWithInt: column]] containsPoint: eventLocation])
{
NSLog(@"Row: %i, Column %i", row, column);
return;
}
This works correctly for the first path only and I believe it's because
every path added to the array has the same info as the first one. How
can I make sure each one I add is unique?
Ken Botwinick
http://homepage.mac.com/kenbotwinick
AOL IM Screen name: kenbotwinick