Repeating a command while control is active (solution/technique)
by Stephen Zepp · in Torque Game Engine · 06/18/2004 (7:58 am) · 21 replies
This technique is suggested for the (pretty rare) situations where you want to be able to have a command repeated continuously while the mouse is "inside" a particular area of the GUI. It is not a "drop in and play" resource, but more of a description/example of a technique you can use for your own project.
If all you need to do is to change the state of buttons, graphics, or other "one time" state changes, then I would suggest you look at the general properties of other GuiCtls.
Overview:
When the mouse first enters a gui control, the event.onMouseEnter is triggered. Similarily, when the mouse leaves a control, .onMouseLeave is triggered. Using scripting, you can catch these events and perform actions in script.
Sometimes, you want a certain command to be executed repeatedly when the mouse is within a certain control. This technique gives you the basics of having this happen, using schedule() and cancel().
First, you should create your Gui object. I used GuiMouseEventCtl, with a default profile, since I didn't want the "hotspot" on the screen to be visible. I would suggest that you make sure the ctl doesn't overlap any other ctl's, simply for ease of deconfliction. You could use FirstResponder to handle any overlaps, but for the purpose of this technique we are keeping it basic.
Once you have the object, give it a name (we'll use CatchMouseLeft, which is an area of the screen that is on the left border of the window, 20 pixels wide, from top to bottom). Now you can write your scripts to catch and process the events.
In this example, we want to send a "user input: scroll orbit camera clockwise" command every 50 milliseconds for however long the mouse is within our control.
Note: We have already written the AdvancedCamera modifications to handle an "orbit cam" (which will be available as part of the AdvCamera resource in a few days), as well as the server scripts to handle user input for the orbit cam and pass to the code. These commands and files are not part of this technique, other than as an example for how to implement.
It is critical that you have the CatchMouseLeft::onMouseLeave function, otherwise your scheduled repeat events will never end!
EDIT: Does anyone know how to put tick marks and quotes in a ..code.. ../code.. segment so they show properly? :)
Further Edit: Intersting....as soon as I edited the message, it did it automatically!
If all you need to do is to change the state of buttons, graphics, or other "one time" state changes, then I would suggest you look at the general properties of other GuiCtls.
Overview:
When the mouse first enters a gui control, the event
Sometimes, you want a certain command to be executed repeatedly when the mouse is within a certain control. This technique gives you the basics of having this happen, using schedule() and cancel().
First, you should create your Gui object. I used GuiMouseEventCtl, with a default profile, since I didn't want the "hotspot" on the screen to be visible. I would suggest that you make sure the ctl doesn't overlap any other ctl's, simply for ease of deconfliction. You could use FirstResponder to handle any overlaps, but for the purpose of this technique we are keeping it basic.
Once you have the object, give it a name (we'll use CatchMouseLeft, which is an area of the screen that is on the left border of the window, 20 pixels wide, from top to bottom). Now you can write your scripts to catch and process the events.
In this example, we want to send a "user input: scroll orbit camera clockwise" command every 50 milliseconds for however long the mouse is within our control.
Note: We have already written the AdvancedCamera modifications to handle an "orbit cam" (which will be available as part of the AdvCamera resource in a few days), as well as the server scripts to handle user input for the orbit cam and pass to the code. These commands and files are not part of this technique, other than as an example for how to implement.
function CatchMouseLeft::onMouseEnter()
{
// first, do the command
commandToServer('MouseBounceLeft');
//next, schedule the next iteration, and save the EventId for later cancel
$Gui::CurrentBounceIterationEventId = schedule(50, 0, repeatBounceLeft);
}
function CatchMouseLeft::onMouseLeave()
{
// we're done being "in the box", cancel any pending events
cancel($Gui::CurrentBounceIterationEventId);
}
function repeatBounceLeft()
{
// perform action
commandToServer('MouseBounceLeft');
// reschedule
$Gui::CurrentBounceIterationEventId = schedule(50, 0, repeatBounceLeft);
}It is critical that you have the CatchMouseLeft::onMouseLeave function, otherwise your scheduled repeat events will never end!
EDIT: Does anyone know how to put tick marks and quotes in a ..code.. ../code.. segment so they show properly? :)
Further Edit: Intersting....as soon as I edited the message, it did it automatically!
Torque Owner gamer
SimConsoleEvent *evt = new SimConsoleEvent(argc, argv, true);
S32 ret = Sim::postEvent(refObject, evt, Sim::getCurrentTime() + timeDelta);
which means argv must contain the name of a console method. is there a pure c++ engine approach without creating console method?
thanks