Re: NSBezierPath containsPoint question
Re: NSBezierPath containsPoint question
- Subject: Re: NSBezierPath containsPoint question
- From: p3consulting <email@hidden>
- Date: Tue, 27 Apr 2004 12:54:41 +0200
>
Another way to express this:
>
>
NSPoint mouseLoc; // assume this exists
>
MyDrawableShape *shape; // assume this exists
>
>
NSColor *pointColor = nil;
>
>
[self lockFocus];
>
>
[[NSColor clearColor] set];
>
NSRectFill([shape boundingRect]);
>
>
[shape drawSelf];
>
pointColor = NSReadPixel(mouseLoc);
>
>
[self unlockFocus];
>
>
if ([pointColor alphaComponent] > 0.1) {
>
// you've got a hit...
>
}
>
>
So, assuming something drawable (you could substitute for an image
>
composited to a position, a cell, or whatever, so long as it draws):
>
>
1. first lock focus on yourself, you're doing some on-the-spot drawing
>
2. clear your background to alpha 0, to give clear color to test
>
against later
>
3. draw your drawable thing in its normal location
>
4. use NSReadPixel to discover the pixel color at the given point
>
5. unlock focus since this is all the drawing you need to do
>
>
If the point's alpha component at mouseLoc is clear, then you've
>
missed. If it's opaque then you've got a hit, since it will have been
>
made opaque by the on-the-spot drawing you just did.
>
1. The point to use a small bitmap is to speed-up the test when you
have a lot of items and a big drawing surface
(assuming the clipping algoritm of the underlaying graphic system is
efficient)
2. NSReadPixel is not especially fast
3. if ([pointColor alphaComponent] > 0.1) ?
should be if ([pointColor alphaComponent] != 0.0)
4. messing up with the drawing of the object containing the shapes is
probably a bad idea related to hit testing during a drag-select
operation with autoscroll...
I doubt this idea actually works in that case
Pascal Pochet
email@hidden
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.