Mouse right-click inside GUIs
by Jacob · in Torque Game Engine · 01/21/2005 (5:16 pm) · 15 replies
How can I enable right-clicking inside my GUIs to perform a different action than the left-click?
About the author
#2
01/22/2005 (5:55 pm)
Ok, found it but I am still in the learning process of C++ so it's no too clear as to what I would do to perform an action on right mouse click. I mean I know that I need to put my commands in the brackets :) but I don't know the engine and C++ well enough yet to be able to make it to what I would like. What I would like, is to have a field such as "right click command" in the GUI editor, which executes a command on right mouse click, same as "command" currently works for the left click. I thought that perhaps someone had a tutorial for this but I looked at more than 50 pages of threads after doing a seach and didn't find one.
#3
1) create an::onRightClick() script block in a script file and do what it needs to do.
2) Test it out!
To integrate it with the editor however is quite a bit more complex, as the technique is different. Personally, I would probably use Ben's method of creating onRightClick() script functions for any of your GUI's that need the right click functionality to get it working, and then in a second stage, research in the code exactly how the left click == "command field" is done via the editor's technique, and then mimic it for right clicking as well.
01/23/2005 (10:15 am)
Keep in mind that having the functionality of right click in a particular GUI box doing a specific action, and modifying the GUI editor to provide those using the editor to change the specific action that occurs (like the left click "command" concept you mentioned) are two very different things...the first is relatively easy, as Ben hinted at:1) create an
2) Test it out!
To integrate it with the editor however is quite a bit more complex, as the technique is different. Personally, I would probably use Ben's method of creating onRightClick() script functions for any of your GUI's that need the right click functionality to get it working, and then in a second stage, research in the code exactly how the left click == "command field" is done via the editor's technique, and then mimic it for right clicking as well.
#4
01/23/2005 (11:19 am)
Thanks Stephen. I have done as you suggested MyGui::onRightClick() {action I want performed}; but didn't work. Again, this is all new to me so there is probably more that I need to do. By the way, should it be onRightMouseDown instead, since that's what it is in the engine? In any case, I tried that too and didn't work. So, if you or anyone else is willing to give me a very simple example of exactly what I need to do to have an action executed upon right-clicking, I would be very grateful. In the meantime, I may look more in the engine files...but it all looks a bit much for me at this time :)
#5
If it now responds, well, we know what the problem is! If it doesn't, then you'll need to look at the code more in depth. Unfortunately, I don't have access to my source code at the moment so I cannot confirm that right clicking in guiControl.cc is actually active in stock TGE as a mouse event, but I'd certainly take Ben's word for it!
And yes, it's most probably onRightMouseDown/onRightMouseUp, not onRightMouseclick as you discovered--sorry about that!
01/23/2005 (11:31 am)
It's possible that you are running into the issue of the GuiChatHud which "claims" a pretty large portion of the screen in the upper left hand quadrant (from memory, it's about 1/3rd by 1/4th of the screen in the upper left corner in 800x600 mode, becoming smaller as you increase resolutions). You may want to try putting your "right clickable" Gui down near the bottom right of the screen and see if you still get no response.If it now responds, well, we know what the problem is! If it doesn't, then you'll need to look at the code more in depth. Unfortunately, I don't have access to my source code at the moment so I cannot confirm that right clicking in guiControl.cc is actually active in stock TGE as a mouse event, but I'd certainly take Ben's word for it!
And yes, it's most probably onRightMouseDown/onRightMouseUp, not onRightMouseclick as you discovered--sorry about that!
#6
I have scripted MyGuiControl::onRightMouseDown() to work with a GuiBitmapButtonCtrl and made sure that nothing like the ChatHud is covering it up and it is not working unless "MyGuiControl" is a GuiDragDropButtonCtrl. I have checked the log and onRightMouseDown doesn't get called when the right button is clicked on my GuiBitmapButtonCtrl. So, being at a point where having this work would help me move along in my inventory GUI design, I sure would appreciate some help. Thanks!
03/01/2005 (2:16 pm)
Ok, it's time for me to re-visit this... I have looked through the code but there are too many onRightMouseDown methods for me to figure out what to do. I would like to be able to right click on any GuiControl that needs this extra functionality and have an action performed, the same as it works with the GuiDragDropButtonCtrl in Stefan (Beffy's) resource - for which I am very grateful by the way.I have scripted MyGuiControl::onRightMouseDown() to work with a GuiBitmapButtonCtrl and made sure that nothing like the ChatHud is covering it up and it is not working unless "MyGuiControl" is a GuiDragDropButtonCtrl. I have checked the log and onRightMouseDown doesn't get called when the right button is clicked on my GuiBitmapButtonCtrl. So, being at a point where having this work would help me move along in my inventory GUI design, I sure would appreciate some help. Thanks!
#7
03/03/2005 (8:10 pm)
Anyone...?
#8
03/06/2005 (8:39 pm)
Still hoping for some direction on this one (Performing an action on right click on a GuiBitmapButtonCtrl)
#9
03/06/2005 (9:20 pm)
Did you implement right click functionality in the source code? This isn't something that happens script only...Take a look at the various "pick and click" resources for some implementation suggestions.
#10
03/08/2005 (4:37 am)
If you want every gui and control to have the functionality you can go to line 827 in GuiControl.cc and make it look like this...void GuiControl::onRightMouseUp(const GuiEvent &event)
{
// Gonzo - Give every control a right click
Con::executef(this, 4, "onRightClick", event);
}
#11
03/08/2005 (8:20 am)
Thank you Gonzo, I really appreciate it! This opens up many possibilities. Do you happen to know how to capture event modifiers for the mouse buttons - especially the left? It would be nice to have it work for any Gui Control the same as in the GuiDragDropButtonCtlr resource where one can right click, shift right click, ctrl right clic...etc...and have different things happen with each.
#12
11/14/2006 (3:02 pm)
Did you guys ever get this working?
#13
08/16/2007 (10:30 am)
I have this working, I would just like to know if anyone knows of a function that gives your the coordintates of the mouse. to be able to use to make a popup window at the point where you right click the mouse?
#14
Now everytime you right click the 2 global script variables will be set (on mouse up) with the location of the click.
Also, you may want to check out This article I put up on TDN regarding tooltips, which may help in what you are trying to do.
08/16/2007 (11:05 am)
You could make GuiControl::onRightMouseUp (in guiControl.cpp) look like the following:void GuiControl::onRightMouseUp(const GuiEvent &event)
{
Con::setIntVariable("$MousePointX", event.mousePoint.x);
Con::setIntVariable("$MousePointY", event.mousePoint.y);
}Now everytime you right click the 2 global script variables will be set (on mouse up) with the location of the click.
Also, you may want to check out This article I put up on TDN regarding tooltips, which may help in what you are trying to do.
#15
08/16/2007 (9:24 pm)
Thanks Jacob, that does exactly what I needed.
Associate Kyle Carter