Game Development Community

How to get "onMiddleMouseDragged" function working?

by Sean Oloughlin · in Torque Game Builder · 08/13/2012 (8:38 pm) · 2 replies

I want to be able to rotate the camera when i move my mouse with the middle mouse button down but i can seem to get it working right

heres the "onMiddleMouseDragged" call back in gameTSCtrl.cpp
void GameTSCtrl::onMouseMove(const GuiEvent &evt)
{
if(isMethod("onMiddleMouseDragged") && middleMouseIsDown)
	  {   
		 makeScriptCall( "onMiddleMouseDragged", evt );
	  }
}

"middleMouseIsDown" is a Boolean and is set to true when the "onMiddleMouseDown" function is called
void GameTSCtrl::onMiddleMouseDown(const GuiEvent &evt)
{
   Parent::onMiddleMouseDown(evt);
   if( isMethod( "onMiddleMouseDown" ) )
      makeScriptCall( "onMiddleMouseDown", evt );
   
   Con::errorf("Pressed!");
  
   middleMouseIsDown = true;
}

and in script i have a function in playGui.cs
function PlayGui::onMiddleMouseDragged(%this, %pos, %start, %ray)
{
   echo("middle mouse was dragged!");
}

that doesnt run at all? any ideas?

thanks.

#1
08/14/2012 (1:00 am)
The GuiControl class which GameTSCtrl inherits from has onMiddleMouseDragged defined. All you need to do is override this function and get it to execute a callback.

in gameTSCtrl.h,
after:
virtual void onMiddleMouseUp(const GuiEvent &evt);
add:
virtual void onMiddleMouseDragged(const GuiEvent &evt);


then in gameTSCtrl.cpp,
add the function
void GameTSCtrl::onMiddleMouseDragged(const GuiEvent &evt)
{
   Parent::onMiddleMouseDragged(evt);
   if( isMethod( "onMiddleMouseDragged" ) )
      makeScriptCall( "onMiddleMouseDragged", evt );
}

The reason that your version doesn't work is that onMouseMove doesn't get called when you are dragging, the relevant on-Dragged function is called instead when the mouse is moved while a button is pressed.
#2
08/15/2012 (9:06 pm)
thanks mate worked like a charm