Re: Screen <--> View Coordinate system conversion
Re: Screen <--> View Coordinate system conversion
- Subject: Re: Screen <--> View Coordinate system conversion
- From: Ken Thomases <email@hidden>
- Date: Fri, 15 Jan 2016 23:10:57 -0600
On Jan 15, 2016, at 10:27 PM, Graham Cox <email@hidden> wrote:
>
> I have a need to draw as if to the entire screen as an overlay.
> Where I’m having a problem is that I need the overlay content to match up to objects drawn in another view, in another window. This view can be scrolled and zoomed arbitrarily. So I need to convert coordinates from this original view up to the screen coordinates, then back down to my overlay window’s contentView.
NSView* view1 = /* ... */;
NSRect rect = /* some rect in view1's internal coordinate space (relative to its bounds, not its frame) */;
NSView* view2 = /* some view in another window */;
rect = [view1 convertRect:rect toView:nil];
rect = [view1.window convertRectToScreen:rect];
rect = [view2.window convertRectFromScreen:rect];
rect = [view2 convertRect:rect fromView:nil];
rect is now in view2's internal coordinate space.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden