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: Sat, 16 Jan 2016 00:02:08 -0600
On Jan 15, 2016, at 11:31 PM, Graham Cox <email@hidden> wrote:
>
> What isn’t working is correctly setting the dirty rects when part of the view needs to be refreshed. This is what has been leading me astray - because the dirty region is misaligned, the drawing I’m doing is clipped, so it doesn’t appear unless by chance the dirty region does overlap where I’m trying to draw. I discovered this just now, after I posted originally. If I dirty the ENTIRE overlay view, it draws OK, because the whole view is dirty and so there’s no clipping. This *might* be acceptable because the overlay view only draws a few transitory elements, and doesn’t need to worry too much about limiting drawing for performance. But it would be nicer to be able to let -setNeedsDisplayInRect: work as it should.
What is calling -setNeedsDisplayInRect:, in response to what event or occurrence, and with what rect?
> So the question is how to keep the view aligned to the original view at all necessary times, not just when drawing.
> Is there a better place or better method to set up the overlay’s coordinate system so it is valid at all necessary times? There are the methods -translateOriginToPoint:, -setBoundsOrigin:, -scaleUnitSquareToSize: and so on - these seem likely candidates, but I’m no sure quite where to set these up. I’ll experiment…
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.
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.
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