Re: Screen <--> View Coordinate system conversion
Re: Screen <--> View Coordinate system conversion
- Subject: Re: Screen <--> View Coordinate system conversion
- From: Roland King <email@hidden>
- Date: Sat, 16 Jan 2016 12:49:00 +0800
> On 16 Jan 2016, at 12:27, Graham Cox <email@hidden> wrote:
>
>
> summary: view -> window -> screen -> window -> view
>
>
> Tried this and many variants of it, nothing works - the coordinates I end up with are not in the visible part of my overlay so don’t appear.
>
>
> A better solution (i.e. less work) but one that needs a similar approach in terms of conversion is to align the coordinate system of the overlay to that of the original view. I’ve tried this by using the original view’s bounds as a rectangle passed through the above coordinate conversion, and used to set up a transform on the overlay view as part of its -drawRect, before it draws anything. In theory this should allow me to pass coordinates directly from the original view unchanged, and have them draw in the overlay in the exact same place on the screen. Trouble is, I just can’t get that to work.
>
> I’m missing something about how to correctly translate coordinates between two separate windows.
>
> If anyone can spell it out step by step that would be great - I just can’t see where my thinking is faulty.
>
> —Graham
>
Do you need to go via the backing store? NSView has a convertRect:toView: which, when passed nil for the view, then you get screen coordinates from the window, then reverse. Remember if you’re using the frame of the view, you want to use the superview to convert it, as frames are in superview coordinates.
Do you have an example going through the chain of views of converted coordinates so we can see if we can figure out where it’s going wrong?
_______________________________________________
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