Re: Hit detection on shapes within window
Re: Hit detection on shapes within window
- Subject: Re: Hit detection on shapes within window
- From: Arnaud Forgiel <email@hidden>
- Date: Wed, 13 Nov 2002 01:55:52 -0800 (PST)
On Wednesday, Nov 13, 2002, at 01:33AM, John Scalo <email@hidden> wrote:
>
I have a window with several closely placed images with odd shapes (i.e. not
>
rectangular or oval). I'd like to detect mouse clicks on these shapes and
>
momentarily change their image to a "pressed" state (using another image)
>
until the mouse is released.
>
>
My first inclination is to map the NSImages to NSBezierPaths and use
>
containsPoint: sending it the mouse down coordinates when the mouse is
>
clicked. However for the life of me I can't see how to get an NSBezierPath
>
from an NSImage. Is this possible? Perhaps in AppKit World all NSImages are
>
rectangular regardless of their content and alpha mask.
>
>
Another thought was to just implement these images as buttons with no border
>
and "momentary change" behavior (using the "pressed" image as the alt
>
image), but that really doesn't work because the rectangular representation
>
of the button is still used for hit detection rather than alpha mask part of
>
the image. Can NSButtonCell be subclassed to alter this behavior?
>
>
Any other approaches to consider here?
>
>
Thanks!
>
John
John,
The easiest way could be to test the pixel in your image under the cursor. It should work if the background color (neutral) is of a constant color (i.e. white). Once you've got the color of the pixel under the cursor, you just test it against the background color, and if it's different, you're in the shape!
Regards,
Arnaud
_______________________________________________
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.