Game Development Community

How to enable onMouseEnter and onMouseLeave in a guiWindow [code]

by Max Kielland · in Torque Game Builder · 02/06/2013 (1:14 pm) · 0 replies

I have a number of floating windows in my GUI and every time I move my mouse over a window I want it to display the standard cursor.
What I needed was the onMouseEnter() callback in the guiWindow, so I added a few lines:

in source/gui/containers/guiWindowCtrl.h add these lines some where after the other mouse events.

void onMouseEnter(const GuiEvent &);
void onMouseLeave(const GuiEvent &);

in source/gui/containers/guiWindowCtrl.cc add these lines at the bottom.

void GuiWindowCtrl::onMouseEnter(const GuiEvent &event)
{
   Con::executef( this, 1, "onMouseEnter" );
}

void GuiWindowCtrl::onMouseLeave(const GuiEvent &)
{
   Con::executef( this, 1, "onMouseLeave" );
}

That's it. Now you can hook up some callbacks to

function MyWindow::onMouseEnter(%this, %modifier, %worldPosition, %clicks)

...and...

function MyWindow::onMouseLeave(%this, %modifier, %worldPosition, %clicks)

Okay, this is not covering the case where the mouse moves directly to a child control, but it's close enough to be useful, enjoy...