onMouseDragged and onRightMouseDragged not working in T3D?
by Travis Vroman · in Torque 3D Professional · 10/13/2009 (2:42 pm) · 16 replies
More specifically, it's not working within PlayGui, a GameTSCtrl. First off, I'd like to mention the functionality I'm looking to achieve here. Normally, I want the cursor to show at all times. This I have working. onRightMouseDown and onRightMouseUp work just fine as well.
However, when the user right clicks and drags (not just right click, but drag), I want to hide the cursor and go into freelook mode.
I had a theory about how to tackle this, and it seemed as if it should work. In playGui.cs, I've added the following code:
Note that toggleMouseLook is a custom script function I have set up. For now, just disregard it. The reason I say that is that the echo statement above it should be called no matter what when we drag the right mouse button. But, it doesn't.
So, I figured this is probably an engine-side issue. So I went in and looked at gameTSCtrl.cpp and gameTSCtrl.h to investigate. I found that there was no function for onRightMouseDragged!
So, I looked at how the other functions were laid out, such as void GameTSCtrl::onRightMouseUp(const GuiEvent &evt). I copied this function, changed some parameters and came up with the following:
I figured, hey - even if he parent function doesn't get called, at least I'll get console spam, right? Wrong. This function never gets called either, even though it compiles fine.
So my question here is, how do I get the GameTSCtrl to recognize when I drag the right mouse button? What am I doing wrong? Am I missing something here?
Thanks,
-Travis
However, when the user right clicks and drags (not just right click, but drag), I want to hide the cursor and go into freelook mode.
I had a theory about how to tackle this, and it seemed as if it should work. In playGui.cs, I've added the following code:
function PlayGui::onRightMouseDragged(%this)
{
echo("dragging right mouse");
toggleMouseLook(true);
}Note that toggleMouseLook is a custom script function I have set up. For now, just disregard it. The reason I say that is that the echo statement above it should be called no matter what when we drag the right mouse button. But, it doesn't.
So, I figured this is probably an engine-side issue. So I went in and looked at gameTSCtrl.cpp and gameTSCtrl.h to investigate. I found that there was no function for onRightMouseDragged!
So, I looked at how the other functions were laid out, such as void GameTSCtrl::onRightMouseUp(const GuiEvent &evt). I copied this function, changed some parameters and came up with the following:
void GameTSCtrl::onRightMouseDragged(const GuiEvent &evt)
{
Parent::onRightMouseDragged(evt);
Con::errorf("right mouse dragged");
if( isMethod( "onRightMouseDragged" ) )
makeScriptCall( "onRightMouseDragged", evt );
}I figured, hey - even if he parent function doesn't get called, at least I'll get console spam, right? Wrong. This function never gets called either, even though it compiles fine.
So my question here is, how do I get the GameTSCtrl to recognize when I drag the right mouse button? What am I doing wrong? Am I missing something here?
Thanks,
-Travis
#2
10/14/2009 (7:55 am)
I'm having this same problem here, since i'm a noob, i thought that i was using in a wrong way the playgui::onRightMouseDragged , i'm trying to use this to be able to rotate the camera in the game mode, like the world editor mode that you drag the right mouse button, i think travis is trying to do the same.
#3
First off, to answer your questions Jesse, yes I updated the header files appropriately (otherwise it would never compile!). In fact, it compiles perfectly - no errors or warnings.
I've gone ahead and attempted to implement the whole thing on the engine side instead of in script. There are several changes I've made to the code, and I'll list what I have here.
T3D\gameTSCtrl.cpp - In the section where near void GameTSCtrl::onMouseDown(const GuiEvent &evt), I added the following function.
This code works as it should. (I know, its a bit messy and needs cleaning up, but it works.)
The problematic portion is
I've commented out the reference to the Parent's function, because after tracing it I found that there's nothing in it. So, I decided to build in my functionality here.
This function works until I right click and drag the mouse. From that point on, this function is not called whenever I right click, and wont come out of mouse look mode.
So, my question is - how do I go about getting this function to work while in mouse look mode? I need to be able to detect when the right button is released so I can unhide the cursor.
Thanks,
-Travis
10/14/2009 (2:54 pm)
Okay, I've made some corrections and narrowed down the problem a bit.First off, to answer your questions Jesse, yes I updated the header files appropriately (otherwise it would never compile!). In fact, it compiles perfectly - no errors or warnings.
I've gone ahead and attempted to implement the whole thing on the engine side instead of in script. There are several changes I've made to the code, and I'll list what I have here.
T3D\gameTSCtrl.cpp - In the section where near void GameTSCtrl::onMouseDown(const GuiEvent &evt), I added the following function.
void GameTSCtrl::onRightMouseDragged(const GuiEvent &evt)
{
// We don't want to use the parent function here because it's empty.
//Parent::onRightMouseDragged(evt);
GuiCanvas *canvas = getRoot();
if( !canvas )
return;
PlatformWindow *window = static_cast<GuiCanvas*>(getRoot())->getPlatformWindow();
if( !window )
return;
if(mRightMouseDown)
{
// Disable the mouse cursor. This will set us into mouselook mode.
window->setMouseLocked(true);
canvas->setCursorON( false );
}
else
{
// Re-enable the mouse cursor. Is this check needed here?
window->setMouseLocked(false);
canvas->setCursorON( true );
}
// See if there is a script function. If so, execute it.
if( isMethod( "onRightMouseDragged" ) )
makeScriptCall( "onRightMouseDragged", evt );
}This code works as it should. (I know, its a bit messy and needs cleaning up, but it works.)
The problematic portion is
void GameTSCtrl::onRightMouseUp(const GuiEvent &evt)
{
// We don't want to use the parent function here because it's empty.
//Parent::onRightMouseUp(evt);
mRightMouseDown = false;
mouseUnlock();
Con::errorf("onRightMouseUp");
//if( isMethod( "onRightMouseUp" ) )
//makeScriptCall( "onRightMouseUp", evt );
}I've commented out the reference to the Parent's function, because after tracing it I found that there's nothing in it. So, I decided to build in my functionality here.
This function works until I right click and drag the mouse. From that point on, this function is not called whenever I right click, and wont come out of mouse look mode.
So, my question is - how do I go about getting this function to work while in mouse look mode? I need to be able to detect when the right button is released so I can unhide the cursor.
Thanks,
-Travis
#4
I would just put 2 functions in. It really seems like your thinking a little to hard about this.
If I have my cursor on the playgui already then when I right click and hold it will hide it and I will regain movement by mouse and when I let go.
10/14/2009 (8:10 pm)
If I was you and I wanted to implement some simple functionality such as this. I would just script it in Torque Script. I mean to be honestI would just put 2 functions in. It really seems like your thinking a little to hard about this.
assuming that the PlayGui is your GameTSCtrl name
function playGui::onRightMouseDown()
{
schedule(0, 0, "hideCursor");
}
function playGui::onRightMouseUp()
{
schedule(0, 0, "showCursor");
}If I have my cursor on the playgui already then when I right click and hold it will hide it and I will regain movement by mouse and when I let go.
#5
10/14/2009 (8:30 pm)
jessel: i tried this code before, and tried this one exactly the way you wrote, but this didn't work, i think the problem is when we are in the nocursor mode, the system don't detect the onrightmouseup() in the playgui, and i don't know if there is another GameTSCtrl to manipulate
#6
Any insight from the GG team would be much appreciated as well. :)
Thanks guys,
-Travis
10/14/2009 (8:36 pm)
Right, this was something I tried as well. It doesnt work for the reason that Chico says. However, as opposed to another GameTSCtrl, I think what is happening is that the gameTSCtrl loses control of the input when the cursor is turned off, and the control is instead given to the actionMap. I haven't yet confirmed this, though. Any insight from the GG team would be much appreciated as well. :)
Thanks guys,
-Travis
#7
So, a simpler way perhaps would be to just do this
This way if you click the middle mouse it goes to non-cursor mode and if you click it again it goes to cursor mode
10/14/2009 (8:42 pm)
Edit ok It apears I forgot that when you cursor goes away that you can't call an onRightMouseUp call at that point since the cursor isn't available.So, a simpler way perhaps would be to just do this
//hide the cursor if its is active
function playGui::onRightMouseDown()
{
schedule(0, 0, "hideCursor");
}
//show the cursor if it is inactive
//add this to your control binds
moveMap.bind( mouse, button2, showCursor );This way if you click the middle mouse it goes to non-cursor mode and if you click it again it goes to cursor mode
#8
about the EditTSCtrl source code, since the world editor has a similar control.
10/14/2009 (9:46 pm)
thanks for this code JesseL, but i think this extra bind, won't work very well for a final user, it's not so intuitive, I'm trying to find something that Matt Huston posted in my other topic http://www.garagegames.com/community/forums/viewthread/103493about the EditTSCtrl source code, since the world editor has a similar control.
#9
10/15/2009 (8:02 pm)
Sigh so I sat through searching for a way to make this work like it did in TGEA but. No luck. Already spent like 5 hours on this so I'm done. Good Luck!
#10
If you change this condition it'll get you past the first hurdle, possibly by adding a new condition in that or for a mouselook drag.
10/20/2009 (12:12 am)
Couple threads about this bouncing around. In http://www.garagegames.com/community/forums/viewthread/104041 it is noted that the reason mouse input stops processing is because in GuiCanvas::processInputEvent it checks if mCursorEnabled prior to calling processMouseEvent.If you change this condition it'll get you past the first hurdle, possibly by adding a new condition in that or for a mouselook drag.
#11
My only problem with that is finding a way to access the camera's position/rotation from the GameTSCtrl. Any thoughts on this?
10/20/2009 (1:55 pm)
I'm beginning to wonder if I should attempt to control the actual rotation of the camera in the onRightMouseDragged() function itself instead of relying on hiding the mouse cursor and such. Take, for example, the way the GuiObjectView works.My only problem with that is finding a way to access the camera's position/rotation from the GameTSCtrl. Any thoughts on this?
#12
10/20/2009 (8:29 pm)
So I tried implementing a similar solution to what Jesse suggested...hiding the cursor in PlayGui's onRightMouseDown, and showing it in the ActionMap's button1 up callback - the problem is the callback isn't called because it ignores a "break" even (mouse up, key up, etc) if it doesn't have a matching "make" event (key down, mouse button down, etc) - looks like a small code change could pretty easily fix this, but I don't think it's doable script-only.
#13
10/21/2009 (1:10 am)
Hm, interesting. I wonder if it pointed to an empty function for the make event, if that would work? I'm not at a computer to check it right now, so I'll have to try later. If anyone else has any luck, please let me know :)
#14
In PlayGui.cs:
In default.bind.cs:
And then I added the following in the public portion of the GameTSCtrl class:
And then I put in the following as a function definition:
I'm assuming a similarly exposed onRightMouseDown here, but if you hold the right mouse button down and move, you can look around, and it should let you get back to things (with a bug!) once you release.
So what's the bug? Well... I think it has to do with the Pitch and Yaw functions, but what I'm noticing is that if you right-click and drag around, when you let go, the mouse position is offset from it's actual position. At first, I thought it was just mucking with the object selection code I had, because I would need to click off to the sides or above/below the object I wanted to select, but then I noticed that as I moved the cursor about 100 pixels above some buttons, they were highlighting as if the cursor had entered the control. Now, I realize that the cursor probably is entering the control, but is being rendered in a significantly different position (not consistently off- I believe it has to do with whatever movements you make during that mouse dragging).
However, if that problem is solved, then you get a solution to being able to use the mouselook via right-click and drag... I'm still working on it myself, so if I stumble across it I'll post here. Though if anyone else wants to test it out and investigate, I'm not complaining ;)
10/27/2009 (7:24 pm)
What I did to get it to work (and cause another interesting bug):In PlayGui.cs:
function PlayGui::onRightMouseDown(%this, %doubleClick)
{
$rightMouseDown = 1;
GlobalActionMap.bind( mouse, xaxis, yaw );
GlobalActionMap.bind( mouse, yaxis, pitch );
}
function PlayGui::onRightMouseUp(%this, %doubleClick)
{
$rightMouseDown = 0;
GlobalActionMap.unbind( mouse, xaxis);
GlobalActionMap.unbind( mouse, yaxis);
}In default.bind.cs:
$rightMouseDown = 0; //At the top of the file
function yaw(%val)
{
if($rightMouseDown)
{
%yawAdj = getMouseAdjustAmount(%val);
if(ServerConnection.isControlObjectRotDampedCamera())
{
// Clamp and scale
%yawAdj = mClamp(%yawAdj, -m2Pi()+0.01, m2Pi()-0.01);
%yawAdj *= 0.5;
}
$mvYaw += %yawAdj;
}
}
function pitch(%val)
{
if($rightMouseDown)
{
%pitchAdj = getMouseAdjustAmount(%val);
if(ServerConnection.isControlObjectRotDampedCamera())
{
// Clamp and scale
%pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
%pitchAdj *= 0.5;
}
$mvPitch += %pitchAdj;
}
}And then I added the following in the public portion of the GameTSCtrl class:
virtual void onRightMouseUp(const GuiEvent &evt);
And then I put in the following as a function definition:
void GameTSCtrl::onRightMouseUp(const GuiEvent &evt)
{
Parent::onRightMouseUp(evt);
//I prefer to do it this way, don't ask me why... The other way is just fine though :P
Con::executef(this, "onRightMouseUp", Con::getIntArg(evt.mouseClickCount));
}I'm assuming a similarly exposed onRightMouseDown here, but if you hold the right mouse button down and move, you can look around, and it should let you get back to things (with a bug!) once you release.
So what's the bug? Well... I think it has to do with the Pitch and Yaw functions, but what I'm noticing is that if you right-click and drag around, when you let go, the mouse position is offset from it's actual position. At first, I thought it was just mucking with the object selection code I had, because I would need to click off to the sides or above/below the object I wanted to select, but then I noticed that as I moved the cursor about 100 pixels above some buttons, they were highlighting as if the cursor had entered the control. Now, I realize that the cursor probably is entering the control, but is being rendered in a significantly different position (not consistently off- I believe it has to do with whatever movements you make during that mouse dragging).
However, if that problem is solved, then you get a solution to being able to use the mouselook via right-click and drag... I'm still working on it myself, so if I stumble across it I'll post here. Though if anyone else wants to test it out and investigate, I'm not complaining ;)
#15
06/29/2010 (3:53 am)
How can i Rotate the Camera with the Left Mouse Button? Any Forum ?Shall I have to integrate with the Engine?
#16
Make sure your playGui.gui got the noCursor flag set to "0"
Then add
somewhere in a client startup script and the MouseUp function will trigger. Then to make the cursor hide/show add this functions in playGui.cs
or onRightMouseDown/Up for using right mouse button.
10/19/2011 (11:17 am)
A year to late; but I solved this with a flag in Canvas.Make sure your playGui.gui got the noCursor flag set to "0"
Then add
Canvas.setFieldValue("alwaysHandleMouseButtons", 1);somewhere in a client startup script and the MouseUp function will trigger. Then to make the cursor hide/show add this functions in playGui.cs
function PlayGui::onMouseDown(%this, %pos, %start, %ray)
{
hideCursor();
}
function PlayGui::onMouseUp(%this, %pos, %start, %ray)
{
showCursor();
}or onRightMouseDown/Up for using right mouse button.
Torque Owner JesseL
Pyrotronics-Games
Example:
Did you make the appropriate changes to the Header file?
Did you make a script function and What does your script function look like?
What did you base your function off of? Did you use a Drag like control like a slider bar?