1
votes

How to create a custom shaped tracking area in cocoa ? In cocoa I could only find rectangles as tracking area.

Carbon provided this functionality through HIViewNewTrackingArea , through which any HIShapeRef could be registered as a tracking area.Do we have something similar to this in cocoa ?

I have a complex shape in which I want to change mouse cursors at different regions.

One approach I tried was making a big tracking rectangle covering the whole area, and then changing cursor using mouseMoved events.

Could you suggest any other way to do it.

It would have been easier if there was a similar api like HIViewNewTrackingArea in cocoa.

Thanks.

1

1 Answers

3
votes

Tracking areas are only rectangular in the Cocoa frameworks. You could cover your entire area, then create an NSBezierPath (which you keep around but do not stroke or fill) and ask it if the point is inside it via -containsPoint:.

The tracking area "activates" mouse tracking while the path provides your custom-shaped hit detection mechanism.