On3DRightMouseDown
by Justin Mosiman · in Torque Game Engine · 09/12/2006 (6:10 pm) · 6 replies
Hello,
I am trying to get it so that when you right click, an action is performed until you stop right clicking. I have tried to put the action in GuiCtrl::on3DRightMouseDown, but that is only called once. And GuiCtrl::on3DRightMouseUp also is called only once. I could put it in GuiCtrl::on3DRightMouseDragged, but the action isn't preformed when the mouse isn't moving. Is there a good place to put this action?
Thanks,
Justin
I am trying to get it so that when you right click, an action is performed until you stop right clicking. I have tried to put the action in GuiCtrl::on3DRightMouseDown, but that is only called once. And GuiCtrl::on3DRightMouseUp also is called only once. I could put it in GuiCtrl::on3DRightMouseDragged, but the action isn't preformed when the mouse isn't moving. Is there a good place to put this action?
Thanks,
Justin
#2
09/12/2006 (8:19 pm)
If you're looking to repeat an action while the rmb is held down, just schedule a repeating function that is cancelled with onRightMouseUp.
#3
The schedule idea is sort of working. First, I have this for my code:
I am initially calling Con::executef(this, 2, "onRightMouseDrag", "1") within GuiRTSTSCtrl::on3DRightMouseDown, and I stop by switching the "1" to "0" in GuiRTSTSCtrl::on3DRightMouseUp.
This works if I am just scheduling with the up and down engine methods. But since I need to get information from within the GuiRTSTSCtrl::on3DRightMouseDragged method, I need to call this scheduling function within that method also. I tried calling the scheduling function the same way I called it within the right mouse up method, but it didn't work (I'll worry about getting the additional information later).
The scheduling never stops even though %active is set to 0. Can you not schedule the same schedule multiple times? What is a better way to do this?
Sorry for the somewhat long description, hopefully it made sense.
09/13/2006 (7:42 pm)
Thanks for the scheduling idea. I didn't think of doing it recursively.The schedule idea is sort of working. First, I have this for my code:
function GuiRTSTSCtrl::onRightMouseDrag(%this,%active)
echo("active ", %active);
if(%active){
%this.keepMoving = %this.schedule(32,"onRightMouseDrag",%active);
echo("scheduled");
}
else
cancel(%this.keepMoving);
}I am initially calling Con::executef(this, 2, "onRightMouseDrag", "1") within GuiRTSTSCtrl::on3DRightMouseDown, and I stop by switching the "1" to "0" in GuiRTSTSCtrl::on3DRightMouseUp.
This works if I am just scheduling with the up and down engine methods. But since I need to get information from within the GuiRTSTSCtrl::on3DRightMouseDragged method, I need to call this scheduling function within that method also. I tried calling the scheduling function the same way I called it within the right mouse up method, but it didn't work (I'll worry about getting the additional information later).
The scheduling never stops even though %active is set to 0. Can you not schedule the same schedule multiple times? What is a better way to do this?
Sorry for the somewhat long description, hopefully it made sense.
#4
09/13/2006 (11:11 pm)
You should pick one place to do the scheduling (c++ or script), but not both. It sounds as if you are setting up two parallel rrepeating schedule cycles--one from script, and one from c++. Your script looks fine, but I'm betting you aren't properly cancelling out the code version (guess, since we can't see your code yet, but a logical one based on your description).
#5
guiRTSTSCtrl.cc:
Thanks
09/14/2006 (9:01 am)
Can I not call the scheduling function within c++? Here's what I have (removed the irrevelent parts):guiRTSTSCtrl.cc:
void GuiRTSTSCtrl::on3DRightMouseDown(const Gui3DMouseEvent & event)
{
Con::errorf("right down");
Con::executef(this, 2, "onRightMouseDrag", "1");
}
void GuiRTSTSCtrl::on3DRightMouseUp(const Gui3DMouseEvent & event)
{
if(mRightDrag){
mRightDrag = false;
Con::errorf("right up");
Con::executef(this, 2, "onRightMouseDrag", "0");
}
}
void GuiRTSTSCtrl::on3DRightMouseDragged(const Gui3DMouseEvent & event)
{
if( !mRightDrag && ( mRightDragStart.x + DRAG_PIXEL_TOLERANCE < event.mousePoint.x ||
mRightDragStart.y + DRAG_PIXEL_TOLERANCE < event.mousePoint.y ||
mRightDragStart.x < event.mousePoint.x + DRAG_PIXEL_TOLERANCE ||
mRightDragStart.y < event.mousePoint.y + DRAG_PIXEL_TOLERANCE ) )
{
mRightDrag = true;
}
if(mRightDrag){
Con::errorf("right drag");
Con::executef(this, 2, "onRightMouseDrag", "1");
}
}Thanks
#6
09/15/2006 (1:30 pm)
Is my code above correct?
Torque Owner Cinder Games