Button Hover --> Function
by Chris Byars · in Torque Game Engine · 03/11/2008 (8:58 am) · 6 replies
Anything built into the engine to, when one places the mouse over a button (a GuiBitmapButtonCtrl in my case), a function is called? I need to have hover mouse over events to some of my menu GUIs, so before you select an option, a nice bitmap and text description describe where you are about to go in the menus before you click.
Play Halo and you'll see what I mean.
Any way I could get a function to be called when the mouse hovers over a button?
Play Halo and you'll see what I mean.
Any way I could get a function to be called when the mouse hovers over a button?
#2
there's also onMouseEnter(), onMouseLeave(), and relatedly in this resource, onMouseEnterBounds() and onMouseLeaveBounds().
03/11/2008 (10:05 am)
In addition to built-in tooltips,there's also onMouseEnter(), onMouseLeave(), and relatedly in this resource, onMouseEnterBounds() and onMouseLeaveBounds().
#3
But that resource looks nice. Thanks!
03/11/2008 (1:10 pm)
OnMouseEnter doesn't appear to do a thing. I named one of my GuiBitmapButtonCtrls "createInternet" and then made a function that looked like this:function createInternet::onMouseEnter()
{
echo("LOL!");
}Nothing echoed when I moused over it. Unless I'm using/calling it incorrectly.But that resource looks nice. Thanks!
#4
Add to the .h file a string for the command to run on enter/leave
In the GuiButtonBaseCtrl constructor, initialise both of those
Then hook up the commands as script fields in initPersistFields
Then call the script handler if it exists at the end of onMouseEnter and onMouseLeave
(The on mouse leave code is the same, just switch enter for leave)
Then in script, you just need to enter the command in the onMouseEnter and onMouseLeave fields
03/11/2008 (2:38 pm)
I'm assuming you mean you want a script function to be called on enter/leave. It's easy enough to add. The file you want to edit is guiButtonBaseCtrl.cc/h Add to the .h file a string for the command to run on enter/leave
StringTableEntry mMouseEnterCmd; StringTableEntry mMouseLeaveCmd;
In the GuiButtonBaseCtrl constructor, initialise both of those
mMouseLeaveCmd = mMouseEnterCmd = StringTable->Insert("");Then hook up the commands as script fields in initPersistFields
addGroup("MouseEvents");
addField("onMouseEnter", TypeString, Offset(mMouseEnterCmd, GuiButtonBaseCtrl));
addField("onMouseLeave", TypeString, Offset(mMouseLeaveCmd, GuiButtonBaseCtrl));
endGroup("MouseEvents");Then call the script handler if it exists at the end of onMouseEnter and onMouseLeave
if ( mMouseEnterCmd[0] )
{
char buf[16];
dSprintf( buf, sizeof( buf ), "%d", getId() );
Con::setVariable( "$ThisControl", buf );
Con::evaluate( mMouseEnterCmd, false );
}(The on mouse leave code is the same, just switch enter for leave)
Then in script, you just need to enter the command in the onMouseEnter and onMouseLeave fields
// .... inside your button control onMouseEnter = "echo(\"mouse enter event\");"; onMouseLeave = "echo(\"mouse enter event\");"; // ... rest of button fields
#6
03/11/2008 (4:54 pm)
Edit: Nevermind, stupid error.
Associate Scott Burns
GG Alumni