Game Development Community

Is there a callback on window minimizing and maximizing?

by Nicolas Olhaberry · in Torque Game Builder · 04/04/2007 (12:31 pm) · 3 replies

Hi guys. Does anybody knows if its possible to get a callback when the TGB window is minimized and maximized? What I want to do is to pause the game and stop the sounds on minimizing and resume game and sounds on maximizing. I would prefer, if it's possible, a script based solution, since I'm not too familiar with TGB sourcecode yet.

#1
04/04/2007 (8:25 pm)
You currently have to modify the engine to make it call a script method. Here's a post that lists the steps clearly: www.garagegames.com/mg/forums/result.thread.php?qt=35040
#2
04/09/2007 (7:10 pm)
Thanks Richard, I'll give it a try.
#3
04/17/2007 (3:21 pm)
I've added the following code to platformWin32/winWindow.cc to get a callback whithin TGB. The thing is that it seems that callbackUnpause gets called three times when I bring the window back on. Any idea why this is happening? I guess I can write the code in a way that it only reacts to the first call. But I was wondering if I'm not doing something wrong here.

case WM_ACTIVATE:
windowActive = LOWORD(wParam) != WA_INACTIVE;
if( Game->isRunning() )
{
if (Con::isFunction("windowFocusChanged"))
Con::executef( 2, "windowFocusChanged", windowActive ? "1" : "0" );
}

if ( windowActive )
{
setMouseClipping();
windowNotActive = false;

Game->refreshWindow();
Input::activate();

////////////////////////////////////////////////////////////////////////////////////////////////////
Con::executef(2, "eval", "callbackUnpause();"); //add script callback for paused game
////////////////////////////////////////////////////////////////////////////////////////////////////
}
else
{
setMouseClipping();
windowNotActive = true;

DInputManager* mgr = dynamic_cast( Input::getManager() );
if ( !mgr || !mgr->isMouseActive() )
{
// Deactivate all the mouse triggers:
for ( U32 i = 0; i < 3; i++ )
{
if ( mouseButtonState[i] )
mouseButtonEvent( SI_BREAK, KEY_BUTTON0 + i );
}
}
Input::deactivate();

////////////////////////////////////////////////////////////////////////////////////////////////////
Con::executef(2, "eval", "callbackPause();"); //add script callback for paused game
////////////////////////////////////////////////////////////////////////////////////////////////////
}
break;