Game Development Community

Resize GuiWindowCtrl callback? (SOLVED)

by Eero Karvonen · in Torque 2D Beginner · 06/05/2014 (2:09 pm) · 7 replies

Hi,
I was wondering if there is any useful callback for doing custom stuff when a GuiWindowCtrl has been manually resized from its corner.

Since the callback list for T2D is still incomplete, I went on to look at T3D documentation where I found the following,
GuiWindowCtrl
::onClose ()
::onCollapse ()
::onMaximize ()
::onMinimize ()
::onRestore ()
Where's the respective callback for onResize() / onExtentChange()?

Or any other ideas on how to implement resizing the extent of a SceneWindow placed within a GuiWindowCtrl?

#1
06/26/2014 (1:20 pm)
More generally, what is the secret trick to register when the user resizes a GuiWindowCtrl?
#2
06/26/2014 (10:38 pm)
Aw man - I added a script callback to the GameTSCtrl.
In engine/source/T3D/gameTSCtrl.h add an overload for resize to the class def:
virtual bool resize( const Point2I &newPosition, const Point2I &newExtent );
In engine/source/T3D/gameTSCtrl.cpp make sure the resize() method looks like this:
bool GameTSCtrl::resize( const Point2I &newPosition, const Point2I &newExtent )
{
   RectI oldBounds = getBounds();
   Point2I minExtent = getMinExtent();

   if( !Parent::resize( newPosition, newExtent ) )
      return false;
   
   RectI clientRect = getClientRect();
   layoutControls( clientRect );

   GuiControl *parent = getParent();
   S32 docking = getDocking();
   if( parent && docking != Docking::dockNone && docking != Docking::dockInvalid )
      setUpdateLayout( updateParent );

   // HERE
   onResize_callback(getPosition(), getExtent());
   return true;
}
Also, make sure that you have an IMPLEMENT_CALLBACK set up for it (I put mine right after the ConsoleDocClass() block):
IMPLEMENT_CALLBACK( GameTSCtrl, onResize, void, ( const Point2I& position, const Point2I& extent ), ( position, extent ),
   "Called when a drag&drop operation through GuiDragAndDropControl has entered the control.  This is only called for "
   "topmost visible controls as the GuiDragAndDropControl moves over them.nn"
   "@param control The payload of the drag operation.n"
   "@param dropPoint The point at which the payload would be dropped if it were released now.  Relative to the canvas." );
In script, define the callback:
function PlayGui::onResize(%this, %pos, %ext)
{
    echo(" -- PlayGui::onResize("@%this@", "@%pos@", "@%ext@")");
}
Hope that gives you a few ideas!
#3
06/27/2014 (3:40 am)
@Richard - I'm confused, does your post apply to T2D? There is no GameTSCtrl class.

@Eero - after a brief look through the source, I don't see any callbacks available to know when a GuiWindowCtrl has been resized. It has a weird inheritance - being a child of GuiTextCtrl. Not sure I understand the reasoning there. I'll have to look at this in more detail.
#4
06/27/2014 (5:21 am)
Here is an example on how the SceneWindow has its callback implemented:

void SceneWindow::resize(const Point2I &newPosition, const Point2I &newExtent)
{
    // Resize Parent.
    Parent::resize( newPosition, newExtent);

    // Argument Buffer.
    char argBuffer[64];

    // Format Buffer.
    dSprintf( argBuffer, 64, "%d %d %d %d", newPosition.x, newPosition.y, newExtent.x, newExtent.y );

    // Resize Callback.
    Con::executef( this, 2, "onExtentChange", argBuffer );
}

The Con::executef line is the important bit of code to create a script callback.
#5
06/27/2014 (6:30 am)
It's from T3D, hoping to provide food for thought in doing this for T2D. And after seeing your post I now remember that T2D does't use the IMPLEMENT_ macros....

However, the process is pretty similar - you still have to override the base's resize method and add the callback code.
#6
06/27/2014 (10:29 am)
I came across a workaround that works for the purpose,
%o = new GuiScriptNotifyCtrl(WindowNotifier)
{
	onParentResized = "1";
};
Window.addGuiControl( %o );

function WindowNotifier::onParentResized( %this )
{
	// do stuff
}
#7
06/27/2014 (2:52 pm)
Oh, that's nifty....