Re: How to make NSWindow redraw vacated rects "ifNeeded"?
Re: How to make NSWindow redraw vacated rects "ifNeeded"?
- Subject: Re: How to make NSWindow redraw vacated rects "ifNeeded"?
- From: Bob Smith <email@hidden>
- Date: Mon, 9 Apr 2007 14:12:09 -0700
On Apr 8, 2007, at 8:36 AM, Jerry Krinock wrote:
I often find myself needing to sprinkle in what I feel are extra -
display messages to NSWindows to when I want them to update.
Yesterday I isolated a demo which gets me closer to understanding
this.
In the following demo project, I create a window with an NSBox. I
send it a -setNeedsDisplay, then move it to a new location using -
setFrame:, and then -setNeedsDisplay again. My thinking is that I
am "marking" both the old and new rects as needing display, so that
its NSWindow will know to redraw both rects.
Not true; with -setNeedsDisplay: all you are doing is telling the
view itself that it needs to be redrawn, but that redraw will occur
in the area the view occupies when the next display cycle occurs, not
at the time -setNeedsDisplay: is sent (so multiple -setNeedsDisplay:
messages are redundant). To get the behavior you are expecting, you
need to inform the view's superview of the change in location, by
telling the superview to redraw in the subview's old frame. By
moving the subview from one location to another you are exposing
whatever part of the superview was underneath the subview at the old
location, hence you have to tell the superview to redraw that area.
You were expecting that to occur automatically when -setNeedsDisplay:
is sent to a subview before it is moved, but that isn't the way it
works.
But then after telling the window to -displayIfNeeded, I get two
NSBox, one in the old location, and one in the new location.
Telling the window to -display, instead of -displayIfNeeded, gets
the desired result, but this seems inefficient. What's the correct
idiom to get a vacated rect redrawn?
It is inefficient, you are redrawing the entire content view and
discarding any optimizations. The correct approach would be:
[[someView superview] setNeedsDisplayInRect:[someView frame]];
[someView setFrame:...];
[someView setNeedsDisplay:YES];
[theWindow displayIfNeeded];
Hope this helps!
Bob S.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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