Gui Mouse Events and iphoneTouch Events **SOLVED**
by john m ingato · in iTorque 2D · 02/11/2010 (10:57 pm) · 18 replies
Hi. I have a question regarding gui buttons and the oniPhoneTouch events. I am using all oniPhoneTouch events oniPhoneToucTap for various functions. I now laid a gui over the scene with some buttons. The problem I'm running into is that the oniPhoneTouch events are still being triggered when I touch my GuiBitmapButtonCtrl. I was hoping that the GuiBitmapButtonCtrl would intercept the touch and the other functions would not get called. I chaged to using onMouse events to call my functions instead to try on the desktop and it worked as expected. Is there a way to accomplish this using the oniPhoneTouch events?
Also, for my my GuiBitmapButtonCtrl, I know you can set a command to it to call a function when touched, but can I also have use onMouseUp with it somehow so I can know when they release the button?
Thanks
-John
Also, for my my GuiBitmapButtonCtrl, I know you can set a command to it to call a function when touched, but can I also have use onMouseUp with it somehow so I can know when they release the button?
Thanks
-John
#2
if your onmouse stuff does not work you potentially didn't upgrade a pre 1.3 project correctly. see the corresponding 3x++ posting thread :)
likely your main screen gui has not set min extent and extent correctly
02/12/2010 (9:15 pm)
you can have both at the same time.if your onmouse stuff does not work you potentially didn't upgrade a pre 1.3 project correctly. see the corresponding 3x++ posting thread :)
likely your main screen gui has not set min extent and extent correctly
#3
I create a sample project and a very basic gui with one GuiBitmapButtonCtrl and I set the command to "guiTest();"
now I add these to functions.
now if I run the game and tap anywhere on the screen besides where my GuiBitmapButtonCtrl is I get "Screen Tapped" in the console, but if I tap on the GuiBitmapButtonCtrl I get both "Screen Tapped" and "Gui Button Pressed". I would expect the Gui block the oniPhoneTouchTap so that only it's function gets called. If I'm pressing on a GUI button I'm obviously not going to want my other gameplay functions being called.
What I was referring to with the onMouseDown is that if I use t2dSceneWindow::onMouseDown instead of oniPhoneTouchTap it works as expected and the one function gets called.
02/12/2010 (9:54 pm)
Hi Mark, Excuse my ingorance, but I'm not sure I follow. I created this project starting with 1.3. It's not that onMouse stuff insn't working, it that both events are being triggered instead of just the gui one. Let me give you an example of what I mean. I create a sample project and a very basic gui with one GuiBitmapButtonCtrl and I set the command to "guiTest();"
now I add these to functions.
function guiTest()
{
echo("Gui Button Pressed");
}
function oniPhoneTouchTap ( %touchCount, %touchX, %touchY )
{
echo("Screen Tapped");
}now if I run the game and tap anywhere on the screen besides where my GuiBitmapButtonCtrl is I get "Screen Tapped" in the console, but if I tap on the GuiBitmapButtonCtrl I get both "Screen Tapped" and "Gui Button Pressed". I would expect the Gui block the oniPhoneTouchTap so that only it's function gets called. If I'm pressing on a GUI button I'm obviously not going to want my other gameplay functions being called.
What I was referring to with the onMouseDown is that if I use t2dSceneWindow::onMouseDown instead of oniPhoneTouchTap it works as expected and the one function gets called.
#4
oniphonexxx is meant to happen always as it is not related to any object in the gui or scene at all, its only related to the screen.
its just this "feature" (onMouseXY) thats breaking the consistency as it is working on the iphone too not just the platform where you have a mouse at all
02/12/2010 (10:08 pm)
the behavior is the expected behavior, anything else would be incorrect.oniphonexxx is meant to happen always as it is not related to any object in the gui or scene at all, its only related to the screen.
its just this "feature" (onMouseXY) thats breaking the consistency as it is working on the iphone too not just the platform where you have a mouse at all
#5
Also, any thoughts on the other question? How to get an onMouseUp callback for a gui element? Is it possible?
Thanks
02/12/2010 (10:13 pm)
ah, I see. I didn't realize that. Thank you for clarifying that. Does the t2dSceneWindow::onMouseDown still work on the device? I didn't try it on the device, just the desktop. I thought we were supposed to use the oniPhoneTouch events in there place.Also, any thoughts on the other question? How to get an onMouseUp callback for a gui element? Is it possible?
Thanks
#6
as for the onmouseup: most would likely use sprites for them on the iphone to get more features and better performance and on them you can just use the normal callbacks
if you use real buttons then its the "AltCommand" where you insert the name of the function on button up
02/12/2010 (10:24 pm)
Yupp, still works on the device :-)as for the onmouseup: most would likely use sprites for them on the iphone to get more features and better performance and on them you can just use the normal callbacks
if you use real buttons then its the "AltCommand" where you insert the name of the function on button up
#7
I tried testing out the Command and altCommand on my button and noticed something odd. First off, AltCommand doesn't seem to ever call a function when I press the button. If I just put the Command there it works, but it doesn't get called when I press down. it gets called when I lift my finger up. And for some reason it is getting called twice. My function just echos our the word down, and it shows twice in the console ever time I lift my finger off the button.
I also put an echo in the t2dSceneWindow::onMouseDown and that gets echoed out twice when touching the screen. But if I run the app on the desktop and click, it only gets echoed once.
02/13/2010 (4:05 am)
I would would use a sprite, but I'm panning the camera around when I drag so I'd have to reposition it as I move the camera and I also have another gui background this button needs to be on top of that.I tried testing out the Command and altCommand on my button and noticed something odd. First off, AltCommand doesn't seem to ever call a function when I press the button. If I just put the Command there it works, but it doesn't get called when I press down. it gets called when I lift my finger up. And for some reason it is getting called twice. My function just echos our the word down, and it shows twice in the console ever time I lift my finger off the button.
I also put an echo in the t2dSceneWindow::onMouseDown and that gets echoed out twice when touching the screen. But if I run the app on the desktop and click, it only gets echoed once.
#8
But back to the main issue, I still need individual funtions to run onMouseUp and onMouseDown for my GuiBitmapButtonCtrl. AltCommand didn't seem to do the trick. Any other suggestions would be great.
Thanks very much for the help :)
02/13/2010 (2:39 pm)
OK, I figured out that my functions were not actually getting run twice. It just seems that whenever I echo something out on the device, it echos it twice. Not a big deal. But back to the main issue, I still need individual funtions to run onMouseUp and onMouseDown for my GuiBitmapButtonCtrl. AltCommand didn't seem to do the trick. Any other suggestions would be great.
Thanks very much for the help :)
#9
on Line 171:
and on line 237:
Then you can use buttonName::onMouseDown and buttonName::onMouseUp
02/13/2010 (4:01 pm)
Ok, I found a solution. Here's what I did in case anybody else wants to do it. I editied the file gui/buttons/GuiBaseButtonCtrl.cc and added this.on Line 171:
void GuiButtonBaseCtrl::onMouseDown(const GuiEvent &event)
{
if (! mActive)
return;
if (mProfile->mCanKeyFocus)
setFirstResponder();
if (mProfile->mSoundButtonDown)
{
F32 pan = (F32(event.mousePoint.x)/F32(Canvas->mBounds.extent.x)*2.0f-1.0f)*0.8f;
AUDIOHANDLE handle = alxCreateSource(mProfile->mSoundButtonDown);
alxPlay(handle);
}
//lock the mouse
mouseLock();
mDepressed = true;
//update
setUpdate();
//ADD THIS------------------------------
if(mUseMouseEvents)
Con::executef(this, 1, "onMouseDown");
//ADD THIS------------------------------
}and on line 237:
void GuiButtonBaseCtrl::onMouseUp(const GuiEvent &event)
{
if (! mActive)
return;
mouseUnlock();
setUpdate();
//ADD THIS------------------------------
if(mUseMouseEvents)
Con::executef(this, 1, "onMouseUp");
//ADD THIS------------------------------
//if we released the mouse within this control, perform the action
if (mDepressed)
onAction();
mDepressed = false;
}Then you can use buttonName::onMouseDown and buttonName::onMouseUp
#10
for buttons / Torque GUI you should not use such an approach at all, you should use the Command and AltCommand field and insert the corresponding functions there.
02/13/2010 (5:42 pm)
well thats a hack, not really a solution.for buttons / Torque GUI you should not use such an approach at all, you should use the Command and AltCommand field and insert the corresponding functions there.
#11
02/13/2010 (5:45 pm)
Well, that would be ideal. That was the solution I was hoping for, but the command seems to get called onmouseup and the altCommand doesn't seem to get called at all.
#12
if you check the functions you posted above you see that the up is executing the action.
But you are right, AltCommand seems to do nothing, have to go through my torque notes to see what it is intend to be doing (likely right click or alike a near unhearable voice in the back of my head says)
It highly depends what you want to use it for, for movement etc one wouldn't use the gui anyway, the gui isn't really optimal performance wise (its distinct from the whole t2d stuff thus it does not benefit the least bit from the optimizations on that end!). Thats why its commonly recommend to use sprites as the sample project does it too and on them the mouse callbacks work too.
I would really only use GUI where gui makes sense (static screens where the game is paused, or single screen elements that have no input interaction directly like points - life etc)
02/13/2010 (6:13 pm)
hmm well they are not directly related to down and up.if you check the functions you posted above you see that the up is executing the action.
But you are right, AltCommand seems to do nothing, have to go through my torque notes to see what it is intend to be doing (likely right click or alike a near unhearable voice in the back of my head says)
It highly depends what you want to use it for, for movement etc one wouldn't use the gui anyway, the gui isn't really optimal performance wise (its distinct from the whole t2d stuff thus it does not benefit the least bit from the optimizations on that end!). Thats why its commonly recommend to use sprites as the sample project does it too and on them the mouse callbacks work too.
I would really only use GUI where gui makes sense (static screens where the game is paused, or single screen elements that have no input interaction directly like points - life etc)
#13
I've never really made my own source code files, like new classes and stuff. I've followed tutorials to modify things in the past. How would I go about making a new class for it? ....if it's not to difficult.
02/13/2010 (6:26 pm)
well, here's what I was to accomplish. I'm making a sniper game and I have the camera bobbing around to simulate the players breathing. I wanted this button to press it and hold your breath to steady the sniper and if you let go it will begin bobbing again. So I need to know when the player touches the button and releases the button.I've never really made my own source code files, like new classes and stuff. I've followed tutorials to modify things in the past. How would I go about making a new class for it? ....if it's not to difficult.
#14
02/13/2010 (6:41 pm)
You can look at button classes that extend from the basebutton. Generally it shouldn't be too much work as you only want to expand these two functions so you overwrite them in the extended class and first call the function on the base class and then your own extension (the script callback) in extension.
#16
Btw on the original idea of me with the t2d scene object based approach and for example the GenericButton behavior from the old projects: Don't forget you can also bind the object to follow the camera through t2dscenewindow functionality (sadly primarily documented in the tdn archive ... someone seems to have though that cutting 100% of the scripting reference would be helpfull for anyone ...)
02/13/2010 (6:56 pm)
Glad to hear :)Btw on the original idea of me with the t2d scene object based approach and for example the GenericButton behavior from the old projects: Don't forget you can also bind the object to follow the camera through t2dscenewindow functionality (sadly primarily documented in the tdn archive ... someone seems to have though that cutting 100% of the scripting reference would be helpfull for anyone ...)
#17
02/13/2010 (11:08 pm)
oh man, I didn't even think of trying to mount an object to the camera. That would of been a good idea. Well, it's working as it is now, so I'll go with the way it is. Thanks :)
#18
02/13/2010 (11:31 pm)
yeah :) working is working :D
Torque Owner john m ingato
Also, you would think having an onMouseUp callback for gui elements would be basic too. Am I missing something?