On Jun 20, 2008, at 2:50 , Eugen Belyakov wrote:

I need to implement custom visual component system in OpenGL. And I want to use hitTest-like behavior ( with rotated frame rectangles and so on) to
determine component under cursor.
Could anyone with knowledge of how -hitTest works point me in the right
direction?

I don't have knowledge of how hitTest: is implemented, but I can tell you what I would do if I were implementing something like it. Assuming you have an NSView-style hierarchy of your visual components, the hitTest: method you'll implement should first check if the point is inside itself. If so, continue iterating through all of its sub- components (by invoking hitTest: on each one) until you've located the deepest component that still contains the point. You should send the hitTest: method to the root component in your hierarchy. Something like the following (pseudo-code written in Mail, so standard disclaimer applies):

- (Component *)hitTest:(NSPoint)point
{
        if (!NSPointInRect( point, [self frame] ))
                return nil;

        Component *match = self;

        for (Component *subcomponent in [hitComponent subcomponents])
        {
                Component *nextComponentToTest = [subcomponent hitTest:point];

                if (nextComponentToTest)
                        match = nextComponentToTest;
        }

        return match;
}

You may need to do coordinate conversions as well, depending on whether or not your components maintain their own coordinate spaces relative to their supercomponents. If you need to take rotation into account, then you'll still use NSPointInRect() to find out if the point is at least within the bounding rectangle. Beyond that you'll probably need to work out some vector algebra to get a more accurate hit result.

/brian

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to