On 19.06.2011, at 14:46, Matthias Arndt wrote:
> 1. Sleeping the drawing loop in drawRect: (or make the runLoop wait for some 
> time) and use [... flushGraphics]: Freezes the GUI, as the app is 
> single-threaded

 sleep() will block the thread you're in. That's never a good idea (unless the 
alternative would be a tight loop doing nothing ...). It's always a better idea 
to handle pauses by registering for a callback of some sort at a later time, 
then doing your work in there. That way the system is free to do other things 
in the meantime, like process events.

> 2. Moving the drawing in a 2nd thread and then pause this one: AFAIK is 
> drawing in a second thread not allowed in Cocoa

 Sure drawing from a second thread is allowed. Quartz is pretty much 
thread-safe. But there are some limits on what you can do from inside an 
NSView. But you'e free to e.g. create an NSImage in another thread, draw into 
that, then hand that off to the main thread which would then actually draw it 
to the screen.

 So you could draw a partial image, then make a copy, hand that off to the main 
thread asynchronously and continue drawing onto the original, handing off more 
copies as needed. Although depending on how many animation steps we're talking 
that may not perform well either.

> 3. Limit the drawing loop to an increasing high bound, and setup a timer to 
> fire [self setNeedsDisplay:YES] periodically: Causes the first x paths being 
> redrawn at each animation step, resulting in a bad performance

 You mean the first time would draw 1 … 100. The next would draw 1 … 100 and 
100 … 200 ? So 1 … 100 gets drawn twice … ?

> 4. Same approach, but skipping the first x paths in the next animation step: 
> Corrupted display, e. g. while resizing in an animation

 Yeah. You definitely need to keep some state (e.g. in an ivar) that knows how 
much should be drawn on a redraw. My NSImage-based approach would take care of 
this problem because the "current" animation image would always be there, and 
you could just redraw that.

 Of course, if your window gets resized, you may have a smaller image than your 
view size, but only until the next animation step, so you could probably just 
draw it in the right position and draw a pattern (like Maps.app on the iPhone 
does it) in the empty areas in the meantime.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to