I have a need to draw as if to the entire screen as an overlay. For this 
purpose I have created an invisible window that covers the entire desktop, and 
in that I have a view set as its contentView in which I can draw my content in 
the normal manner (-drawRect:, etc). The window and view are transparent, so 
anything drawn in the view appears on top of any other screen content. That’s 
all working - I can draw whatever I like and it draws completely as expected.

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. 
So far nothing I have tried has worked.

What seems to be needed is to a) convert a rect from the original view to the 
backing, which according to docs is the window’s backing store, relative to the 
window and pixel-aligned. Then b) convert from the window to the screen 
coordinates, then c) convert to the overlay window from screen coordinates and 
then d) convert from overlay window coordinates to the content view coordinates 
(which may do nothing, though this view is set to return YES from -isFlipped, 
since I need to draw text in my overlay easily).

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



_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to