How to run continuously?
How to run continuously?
- Subject: How to run continuously?
- From: Nick Turner <email@hidden>
- Date: Mon, 24 Dec 2001 18:40:31 -0800
Greetings and merriment!
I'm a rank newbie at Cocoa, but I have a long background in OS 9 with
C++.
I have several very simple apps written for OS 9 that put up windows and
run continous art in whichever window is in front. When the window is
deselected the art stops and the window saves its contents (using
copybits) into an offscreen bitmap so that it has something to update
from.
Now I am trying to do something similar in Cocoa.
I want to have a window with an NSView that displays an image, and the
image is being constantly updated by a full-time drawing routine. I
want to get as much CPU as possible to run the drawing code, and I want
the view's contents to reflect the drawing in real time as it happens.
This would be something like the graphics feature of iTunes, only
without the music to drive it.
Where do I put the drawing code, and what's the best way to set up the
image? Under OS 9 I could have a routine that gets called during the
event loop's idle time, runs for a tenth of a second or so while drawing
directly into the window's grafport (safe because we know the window's
in front and fully updated), and then returns. The app would then run
the next pass of the event loop and the idle routine would get called
again. Easy!
It's different with Cocoa -- I can't seem to find any kind of idle time
processor. Is there a way to intercept NSApplication's event loop and
grab a tenth of a second to do some drawing? Is there some delegation I
can make from NSApplication, or maybe some NSApplication method I can
override? What's the best way to handle user actions like window
resizes? If the window (and thus the view) is resized, I'd like the
drawing to stop, then start again when the resize is complete.
Do I need to be drawing into an NSBitMapImageRep? If so, is there a way
to update the NSView in real time?
I get the feeling that I am missing something really obvious... :-)
If this is solved in the docs somewhere, I'd sure appreciate a pointer.
Thanks, Cocoa fans! It's a great toolset.
Nick Turner