GUI button that triggers onMOUSEDOWN?
by Warthog · in iTorque 2D · 07/24/2009 (4:40 pm) · 6 replies
Greetings,
We've run into a little problem. We need GUI buttons that trigger on Mouse Down. The built-in GUI buttons trigger on Mouse Up. I need to implement some onscreen buttons for throwing punches, and the user will expect the punch to occur when he taps down, not when he lifts his finger off.
Is there a way to switch how the GUI buttons behave? Is there some other way of implementing this? GUI controls don't have onMouseDown callbacks.
Thanks much,
Warthog
We've run into a little problem. We need GUI buttons that trigger on Mouse Down. The built-in GUI buttons trigger on Mouse Up. I need to implement some onscreen buttons for throwing punches, and the user will expect the punch to occur when he taps down, not when he lifts his finger off.
Is there a way to switch how the GUI buttons behave? Is there some other way of implementing this? GUI controls don't have onMouseDown callbacks.
Thanks much,
Warthog
#2
07/26/2009 (11:46 am)
The GUI buttons should have a built in onMouseDown method. Check their declaration in the source code. They are child objects of the main GUI object which has onmousedown, so if they don't have it then just add an onmousedown prototype in the engine code for the Gubuttonctrl object type.
#3
Line 191 of GuiButtonBaseCtrl.cc:
EDIT: I looked at the source and updated this post accordingly. You can do the same thing in GuiButtonBaseCtrl::onMouseUp as well.
07/26/2009 (6:53 pm)
GUI buttons have their onMouseDown method called (in GuiButtonBaseCtrl), but they don't call the script function. You can easily add this code:Line 191 of GuiButtonBaseCtrl.cc:
/// ...inside GuiButtonBaseCtrl::onMouseDown
//update
setUpdate();
/// ADD THIS CODE
if(mUseMouseEvents)
{
Con::executef(this, 1, "onMouseDown");
}EDIT: I looked at the source and updated this post accordingly. You can do the same thing in GuiButtonBaseCtrl::onMouseUp as well.
#4
So I need a little help here. Once my changes are made, I need to open the Torque2D.xcodeproj and I need to build to the TGBGame Target. Is that correct?
Do I need to change anything else? Is the project full of mis-spellings and other problems like the iPhone projects?
Once I've built the engine, do I need to do anything else to make sure it gets used?
Thanks. I avoided this as long as I could but I now see it's going to open up all kinds of things to me.
Warthog
07/27/2009 (10:59 am)
Okay, so at last I am being forced into modifying and compiling the engine!So I need a little help here. Once my changes are made, I need to open the Torque2D.xcodeproj and I need to build to the TGBGame Target. Is that correct?
Do I need to change anything else? Is the project full of mis-spellings and other problems like the iPhone projects?
Once I've built the engine, do I need to do anything else to make sure it gets used?
Thanks. I avoided this as long as I could but I now see it's going to open up all kinds of things to me.
Warthog
#5
To add the build flags:
1. Double click the TGBGame target in Xcode.
2. Go to the build tab.
3. Scroll down to "Preprocessor Macros" -- it's near the bottom.
4. Double click to edit the list and add PUAP_OPTIMIZE and PUAP_SCRIPT_CHANGE on separate lines.
5. Build the executable. Next time you run your project from TGB the scripts will be compiled with the updated code.
07/27/2009 (11:28 am)
Yes, just build TGBGame. If you are using optimization flags (PUAP_OPTIMIZE or PUAP_SCRIPT_CHANGE), you will have to add these flags to the build target settings.To add the build flags:
1. Double click the TGBGame target in Xcode.
2. Go to the build tab.
3. Scroll down to "Preprocessor Macros" -- it's near the bottom.
4. Double click to edit the list and add PUAP_OPTIMIZE and PUAP_SCRIPT_CHANGE on separate lines.
5. Build the executable. Next time you run your project from TGB the scripts will be compiled with the updated code.
#6
This worked out great, I set it up to use onMouseDown and onMouseUp and ignore the "action" set only if the useMouseEvents box is checked, if not, it executes the "action" specified and doesn't use the onMouse stuff. Best of both worlds, I think.
My fist time changing the source and I didn't frell it up. Woo Hoo!
07/31/2009 (2:20 pm)
Hey I wanted to say thanks!This worked out great, I set it up to use onMouseDown and onMouseUp and ignore the "action" set only if the useMouseEvents box is checked, if not, it executes the "action" specified and doesn't use the onMouse stuff. Best of both worlds, I think.
My fist time changing the source and I didn't frell it up. Woo Hoo!
Torque 3D Owner Marc Dreamora Schaerer
Gayasoft
If you require buttons that react to regular input, look at the button behavior that comes with the install and do the button as a regular t2dsceneobject.