GUI widget clicked and how to sort what was clicked?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Mars_999
Posts: 136
Joined: Sat Dec 08, 2012 7:59 pm

GUI widget clicked and how to sort what was clicked?

Post by Mars_999 »

I am not sure what I am doing wrong, but here I go....

I have a button on the screen and a bunch of meshes and what I am trying to do is click a mesh node to select it, then click on move to move my player mesh to that selected node. What happens is, the MOVE button when clicked I end up placing the mesh at the GUI buttons position and not the selected node...

When using

getSceneNodeFromScreenCoordinatesBB(app.GetDevice()->getCursorControl()->getPosition(), 0, true);

would this stop taking hits after it hits the widget? because I am not sure if these GUI widgets are included in all collisions? If so how can I exclude them so when I click the widget I can ignore it's position but keep my selected node I clicked on with my left mouse button... I am thinking maybe this is a logic problem but just wanted to make sure first there isn't any function call or parameter I am missing to help me...

THanks!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: GUI widget clicked and how to sort what was clicked?

Post by CuteAlien »

You did run into a common problem in games. Your gui and your 3d scene both want the mouse-clicks. Avoiding that depends often on the situation - the easiest way which might work in your case is probably if you ignore _all_ mouseclicks that happen when you click while over _any_ gui-element.

You get the mouse-events in your eventreceiver before Irrlicht sees them. To ignore some events you can return true in your eventreceiver for those. You can use IGUIEnvironment::getHovered() to figure out if an gui-element - and which one - is below the mouse. But please read the documentation as it mentions one problem (and a workaround for that problem).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Mars_999
Posts: 136
Joined: Sat Dec 08, 2012 7:59 pm

Re: GUI widget clicked and how to sort what was clicked?

Post by Mars_999 »

I am not sure what you are saying to do here...

I looked and see it says to use getRootGUIElement(), but what is the process I should be doing here... I was looking for a more detailed explanation of what I should do...

Thanks!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: GUI widget clicked and how to sort what was clicked?

Post by CuteAlien »

It says to use getRootGUIElement()->getElementFromPoint. That way you know if an element is below the mouse (and even which one) and can decide for example not to use that mouse-click to move the player mesh in that click. Not sure what more explanations you are looking for - this gives you the info you need (it's over the gui or not) - what you then do with that information is application specific.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Mars_999
Posts: 136
Joined: Sat Dec 08, 2012 7:59 pm

Re: GUI widget clicked and how to sort what was clicked?

Post by Mars_999 »

okay, so getRootGUIElement()->getElementFromPoint can be called outside of the event receiver to determine what GUI I am above then... if so that is what I would need AFAIK!

Thanks!
Mars_999
Posts: 136
Joined: Sat Dec 08, 2012 7:59 pm

Re: GUI widget clicked and how to sort what was clicked?

Post by Mars_999 »

THat works!

THanks cutealien
Post Reply