Re: Hit detection on shapes within window
Re: Hit detection on shapes within window
- Subject: Re: Hit detection on shapes within window
- From: Scott Anguish <email@hidden>
- Date: Wed, 13 Nov 2002 01:07:30 -0500
On Tuesday, November 12, 2002, at 07:33 PM, John Scalo 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?
Yes. Hit detection in an NSImage is fairly simple.
You can first eliminate the image entirely if it doesn't contain the
point within the bounds rect. If it does, then you need only see if
that specific pixel in the image is on or not. There are numerous
discussions on this archived on this list.
Last week in fact, I answered this
Here is someone doing something similar, and a thread where it was
discussed
http://cocoa.mamasam.com/COCOADEV/2001/09/2/13509.php
(look at both JCR's response, and Ken Dyke's)
getting the color of a specific pixel is a pretty common operation,
but it's dependent on the format of the underlying graphic at this
point.. the bit level and format... you could simplify this if your
image is always the same depth..
it'd be better if it was part of the API though.
_______________________________________________
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.