On 28-Jan-10, at 9:38 AM, David Duncan wrote:

On Jan 28, 2010, at 9:26 AM, K. Darcy Otto wrote:

The problem is that I'm having difficulty setting up the NSTrackingAreas. Given CA layer x, I want to discover the position of x in the window so I can set up the tracking area. Is this the right way to solve this problem? If so, how do I get the rect for layer x?

NSRectFromCGRect() is basically just a typecast, but you need a coordinate conversion. The way to do this is to first convert the bounds of layer X to a rectangle in the coordinate system of your view's layer, which can be done with -convertRect:fromLayer: (note, you want bounds NOT frame here – if you use frame you need to convert from layer x's superlayer because the frame is in the layer' superlayer's coordinate system).

Thank you for this; but I'm still having a few problems. Here's what I have as part of -mouseDragged (where hitLayer is the CA layer that has been identified):

CGRect p,q;
p = [hitLayer bounds];
q = [[hitLayer superlayer] convertRect:p fromLayer:hitLayer];

Now, q is in the coordinate system of the superlayer - I'm not sure how to get it into the coordinate system of the view (there is no - convertRect:fromLayer: for the view). I've tried the NSView methods - convertRect:toView: and -convertRectToBase: without success.

Overall you may find it easier to simply setup a tracking area for the entire view and then hit test to find the layer of interest instead, especially since moving the layers around would mean moving the tracking areas around too.

Yes, I think this will be my fallback position. I actually have only a few areas that need to be tracked and only at certain times, which is why I'm trying with a series of NSTrackingArea first. Thanks again._______________________________________________

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 arch...@mail-archive.com

Reply via email to