How do I make GUI elements react to clicks?

Hi!

First of all I want to say that I know about tonegodGUI and Nifty. I’m just considering all alternatives.

How do I make GUI elements react to clicks? Do I just use a Ray and check for collisions or what is the recommended way? Can I add some kind of eventlistener to things?

@tuffe said: Hi!

First of all I want to say that I know about tonegodGUI and Nifty. I’m just considering all alternatives.

How do I make GUI elements react to clicks? Do I just use a Ray and check for collisions or what is the recommended way? Can I add some kind of eventlistener to things?

You could just use three classes from Lemur and do it.

This class is an app state that handles mouse picking on whatever scene roots you give… it works in 3D and 2D:
http://code.google.com/p/jmonkeyplatform-contributions/source/browse/trunk/Lemur/src/com/simsilica/lemur/event/MouseAppState.java

It then delivers events to any spatial with a MouseEventControl:
http://code.google.com/p/jmonkeyplatform-contributions/source/browse/trunk/Lemur/src/com/simsilica/lemur/event/MouseEventControl.java

…which in turn will deliver those events to MouseListeners:
http://code.google.com/p/jmonkeyplatform-contributions/source/browse/trunk/Lemur/src/com/simsilica/lemur/event/MouseListener.java

You ca either look at how I did it or just add the Lemur.jar as a dependency and use them directly. It’s a pretty small library.

1 Like

Just in case it’s needed… Lemur links are here: http://hub.jmonkeyengine.org/forum/topic/lemur-repo-link/

OK! Thanks!