On Jan 21, 2013, at 5:12 PM, Graham Cox <[email protected]> wrote:
> My question is, is there a way to directly convert coordinates between two
> unrelated layers in a tree, or are these methods implemented by recursion up
> to a common parent node and then back down to the target layer? If I had some
> hint of how this was done in the real CALayer architecture it would help me
> avoid wasting time trying various blind alleys.
Unless and until someone chimes in with a more sophisticated solution, you
could convert the rect from layer A to the root layer, and from the root layer
to layer B, then find out if that bogs down performance.
Say you already have:
- (CGRect)convertRectFromSuperlayer:(CGRect)superRect;
- (CGRect)convertRectToSuperlayer:(CGRect)localRect;
Then you could have:
// Composed in Mail without regard for efficiency.
- (CGRect)convertRectToRootLayer:(CGRect)localRect
{
CGRect result = localRect;
MyLayer *layer = self;
while ([layer superlayer])
{
result = [layer convertRectToSuperlayer:result];
layer = [layer superlayer];
}
return result;
}
// Recursion.
- (CGRect)convertRectFromRootLayer:(CGRect)rootRect
{
if ([self superlayer] == nil)
{
return rootRect;
}
CGRect superRect = [[self superlayer] convertRectFromRootLayer:rootRect];
return [self convertRectFromSuperlayer:superRect];
}
// Assumes otherLayer has same root layer.
- (CGRect)convertRect:(CGRect)localRect toLayer:(MyLayer *)otherLayer
{
CGRect rootRect = [self convertToRootLayer:localRect];
return [otherLayer convertFromRootLayer:rootRect];
}
--Andy
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]