• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Reworked Worm example [Re: Small animation]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reworked Worm example [Re: Small animation]


  • Subject: Re: Reworked Worm example [Re: Small animation]
  • From: Troy Stephens <email@hidden>
  • Date: Fri, 23 Jan 2004 16:30:17 -0800

On Jan 21, 2004, at 8:32 PM, Shawn Erickson wrote:
> So for fun I added a new view class called BetterThenBetterWormView to
> Apple's stock Worm example that uses Panther's support of multiple
> invalid rectangles in a drawRect call. If you play with it while
> Quartz Debug is flashing update rectangles you can see the difference
> it makes. The BetterThenBetterWormView is used when you play the game
> or select "Bestest" (yeah yeah). You of course need 10.3+ to use this
> version.
>
> Update Example Source: http://homepage.mac.com/shawnce/misc/Worm.zip

Nicely done! Thanks for sharing your changes with the list. :-)

"BetterThenBetterWormView"'s -performAnimation override sets the right
example for how to use -setNeedsDisplayInRect: to accumulate a more
tightly bounded update area on Panther: Dirty the individual parts,
rather than their union.

> I did notice one funky thing while doing it... it looks like the
> NSView's needsToDrawRect: method is broken. I had to implement my own
> to get it to display correctly in all situations. If you knock out my
> implementation you can see what goes wrong. Is this a known defect? I
> sort of remember something about this a while back...

I'm looking at this now. When the rect list is of size >= 2,
-needsToDrawRect: does an initial trivial-rejection test against the
(already computed) bounding box of the rect list. It looks like
there's a code path in NSView that can cause this bounding rect to be
zeroed out before -drawRect: is invoked, which is what's causing your
intersection tests to sometimes fail.

I'll see about fixing the problem in AppKit. In the meantime, your
override of -needsToDrawRect: is an appropriate workaround. Sorry
about that!

By the way: It may interest you to know that the WormView's "rects
being drawn" list is only ever 1 or 2 rects long (due to combining of
adjacent rects). You can confirm this by adding an NSLog or some debug
drawing code:

[[NSColor redColor] set];
for (i = 0; i < rectCount; i++) {
NSFrameRect(rects[i]);
}

Given this, and the fact that you're drawing the whole worm every
animation step anyway, you aren't really missing anything by not
getting the bounding-box check that AppKit's -needsToDrawRect:
provides.

Troy Stephens
Cocoa frameworks, Apple
_______________________________________________
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.

References: 
 >Small animation (From: Lorenzo <email@hidden>)
 >Re: Small animation (From: Alexander Spohr <email@hidden>)
 >Re: Small animation (From: Douglas Davidson <email@hidden>)
 >Reworked Worm example [Re: Small animation] (From: Shawn Erickson <email@hidden>)

  • Prev by Date: Re: NSXMLParserTroubles (errors and line/column positions
  • Next by Date: Re: Custom Text View
  • Previous by thread: Re: Reworked Worm example [Re: Small animation]
  • Next by thread: Re: Small animation
  • Index(es):
    • Date
    • Thread