views:

680

answers:

2

I have an NSWindow subclass (GameWindow) containing an NSOpenGLView subclass (GameView).

The app is windowed (does not go fullscreen).

An OpenGL animation in GameView is fired ~30 times a second by a timer.

For presentation reasons, the GameView animation MUST continue regardless of what else is happening in the app. The only time it should stop is in the case of a fatal error.

I need to present various "modal" Cocoa windows (e.g. choose new game, confirm quit, etc.) while the animation in GameWindow continues. Some of these could be sheets, but major ones need to appear as standalone windows (complete with WebViews).

MY QUESTION: how can I display these "dialog" windows such that my app timer continues to fire, my animation continues, but user input to the GameView in the GameWindow is blocked until the "dialog" window is dismissed by the user?

(I need to support Tiger + Leopard at this time).

+1  A: 

Have you tried the regular sheet/dialog techniques? They should work fine for this situation. Timers are scheduled as part of the run loop, which doesn't stop when you have a modal sheet or window, so it should be able to continue on rendering in the background while events are blocked.

[NSApp beginSheet:sheetWindow modalForWindow:mainWindow modalDelegate:nil didEndSelector:NULL contextInfo:nil];

(Except fill in your own delegate and end selector if needed.)

Joel Levin
Oh, I see! I had believed that calling -modalForWindow on my sheet or "dialog" window would block both timers and events to my GameWindow until the user dismissed the dialog.I shall give it a try. Thanks VERY much for your help Joel and your super-quick response.
A: 

If you want to keep the current modal windows (without moving to sheets), you can try scheduling the NSTimer yourself in something besides the default runloop mode (NSDefaultRunLoopMode), which hangs as soon as that runloop stops running.

atebits