Re: two things (newbie)
Re: two things (newbie)
- Subject: Re: two things (newbie)
- From: Shawn Erickson <email@hidden>
- Date: Thu, 10 Jun 2004 09:01:20 -0700
On Jun 10, 2004, at 8:53 AM, John Stiles wrote:
On Jun 10, 2004, at 8:01 AM, Shawn Erickson wrote:
On Jun 10, 2004, at 7:12 AM, Rolando Abarca wrote:
On Wed, 9 Jun 2004, John Terranova wrote:
[self setNeedsDisplay:YES]; // ??
and what's the difference between that and [self display]?
The first thing is the right way and the second is the wrong way. :-)
Seriously what setNeedsDisplay does it marks things as being dirty
and hence needing to be redrawn. You can call this multiple times in
a given event loop on the same of differing view objects and the view
system will build up the set of things that needed to be redrawn.
Then when the event comes around to it all of the dirty things will
be drawn in a more optimized phase and only once. If you call display
you can easily incur over drawing, etc.
So the right way is to use setNeedsDisplay: or better yet
setNeedsDisplayInRect:. The view system will call displayIfNeeded,
etc. for you then.
Frankly, I've found the opposite was true in my code.
As with anything it depends on the situation...
I had a big custom-class NSView which occasionally needed small
rectangles in it to be updated.
When I called -setNeedsDisplayInRect several times, all that happened
was that my multiple tiny rectangles were coalesced into one gigantic
rectangle. I ended up using -displayInRect to avoid this behavior.
This was under 10.2.x and 10.3.x.
In 10.3. you can use needToDrawRect: or getRectsBeingDrawn:count: in
combination with setNeedsDisplayInRect: to get at the smaller
rectangles to optimize your drawing. Doing so can help avoid over
drawing, in particular the possibility that you call displayInRect:
multiple time for the same or overlapping rects in a given refresh
cycle.
Read over the following for more information...
<
http://developer.apple.com/documentation/Cocoa/Conceptual/DrawViews/
Tasks/OptimizingDrawing.html#//apple_ref/doc/uid/20002079/1003680>.
-Shawn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.