Re: Screen <--> View Coordinate system conversion
Re: Screen <--> View Coordinate system conversion
- Subject: Re: Screen <--> View Coordinate system conversion
- From: Graham Cox <email@hidden>
- Date: Sat, 16 Jan 2016 17:19:14 +1100
> On 16 Jan 2016, at 5:02 PM, Ken Thomases <email@hidden> wrote:
>
> What is calling -setNeedsDisplayInRect:, in response to what event or occurrence, and with what rect?
It’s complicated, but events that start off in view1, and also draw stuff there, end up also drawing overlaid graphics in view2 (the overlay). Ideally, I want both views to use the same coordinate system, so that the coordinates in view1 don’t need to be individually translated when used to draw elements in view2. This allows the overlaid graphic elements to not need to care which view they’re drawn in - in some cases they may be drawn in view1, but in other cases in the overlay view. Since these elements effectively draw themselves from stored coordinate values, I don’t want them having to examine which view they’re in and doing translation in one case and not the other - instead, the view they’re drawn in takes care of it such that they draw properly in any case.
Also, part of the reason for this is that the overlay view is a new adaptation of a large amount of existing code, so if I can get it to work as proposed, I don’t need to modify any of the older objects at all.
> You can tell view1 to post bounds-changed and frame-changed notifications (set postsBoundsChangedNotifications and postsFrameChangedNotifications, respectively) and then observe NSViewBoundsDidChangeNotification and NSViewFrameDidChangeNotification. In response, you can call -scrollRect:by: to both copy the drawn bits and translate the dirty rectangles or you can call -translateRectsNeedingDisplayInRect:by: to do just the latter.
I’m aware of those notifications, but for various reasons they’re overkill for this - the overlay view is ordered in and out only now and again, so it doesn’t need to be in synch except when it’s actually in use - which means I can probably use the fact that it is ordered in to synch it up with the other view. The other view can’t change while the overlay is in place.
> It's not clear to me why you're applying a transform to draw using view1's coordinate system, but that should only affect drawing. You could try to maintain view2's bounds such that it keeps in sync with view1's, but I'm not sure what that buys you.
It buys me not needing to translate all the individual coordinate values, but instead make the view match the original coordinates so I can draw using them unmodified.
In fact this is now 90% working, it’s just the refresh that’s out of kilter, which is no surprise since the CTM is only modified when drawing. I think I’m close….
—Graham
_______________________________________________
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