discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Redraw view in setFrame?


From: Lundberg, Johannes
Subject: Re: Redraw view in setFrame?
Date: Thu, 31 Oct 2013 15:30:54 +0900

Hi Nikolaus

Thanks for your input.

With NSViewAnimation call to setNeedsDisplay can not be done for each frame (unless you add progress callback for each frame which seems like a stupid thing). So I think we should add some call to setNeedsDisplay in NSViewAnimation class. After all, an (view)animation wants to be redrawn each frame...

For NSView, I don't mind using setNeedsDisplay whenever I change a frame. I mean, that's is also what the documentation says, even though Cocoa seems to do it differently (which is why I think it is a bit weird and also why I was surprised when I didn't need calling setNeedsDisplay)..

However, currently a call to setNeedsDisplay does not redraw the old frame which is a serious problem. Try animating a view's frame and you'll see.
Even calling setNeedsDisplay before and after changing frame sometimes causes garbage from the moving view to remain (not being cleared) where the view has been.

I don't know if using [[self superview] setNeedsDisplayInRect:oldFrame] would make a difference. I'll give it a shot.
 



--
Johannes Lundberg
BRILLIANTSERVICE CO., LTD.


On Thu, Oct 31, 2013 at 2:45 PM, Dr. H. Nikolaus Schaller <hns@goldelico.com> wrote:
Hi,

Am 31.10.2013 um 03:07 schrieb Lundberg, Johannes:

> Hi All!
>
> I've been playing with the NSViewAnimation class and discovered that the view is not redrawn between animation steps.
>
> First I was thinking that a call could be made to [_target setNeedsDisplay] at each animation step in NSViewAnimation.m but wouldn't it be better to do that in NSView's setFrame?

https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSView_Class/Reference/NSView.html#//apple_ref/occ/instm/NSView/setFrame:

"It neither redisplays the receiver nor marks it as needing display. You must do this yourself with display or setNeedsDisplay:."

>
> Whenever you change the frame of a view don't you want it to always redraw anyway?

Not necessarily. A view may be hidden. Or resized several times. Well, a setNeedsDisplay:YES wouldn't do any harm - an invisible view isn't drawn even if set to needsDisplay... But it costs calculation time (especially for rotated and scaled views).

>
> This seems to be the case on Cocoa. I've attached a Xcode 5 project example app that shows that view is redrawn without calling setNeedsDisplay when changing frame. (not sure if the same applies to Cocoa Touch though...)

It may be done but you should never rely on it in your code.

>
> Another thing is that when moving or shrinking a view setNeedsDisplay needs to be called before and after the new frame is set otherwise the area of the old frame view won't be cleared.
>
> Have this kind of code in your app is not so elegant.
>
> [view setNeedsDisplay:YES];
> view.frame = newFrame;
> [view setNeedsDisplay:YES];
>
> I propose that we move that into NSView. I made a dirty fix that may not be the optimal way to do it but it shows what I want to do with this proposal.
>
>
> in NSView's - (void) setFrame: (NSRect)frameRect i added two calls to setNeedsDisplay like this:
>
>   if (changedSize == YES || changedOrigin == YES)
>     {
>       [self setNeedsDisplay:YES];

[[self superview] setNeedsDisplayInRect:oldFrame] would be more correct IMHO.

>       [self _setFrameAndClearAutoresizingError: frameRect];
>       [self setNeedsDisplay:YES];
>       ......
>
> What do you guys think?

IMHO it could be done, just in case that some application is not doing it correctly. But this may help programmers to do it not correctly and writing wrong code which makes porting to other *STEP platforms fail.

Just my 2ct.

-- hns


reply via email to

[Prev in Thread] Current Thread [Next in Thread]