I have two main questions about Nifty GUI, and how it works.
On Android I have explicitly set inputManager.setSimulateMouse(false);
Despite this, Nifty is still able to detect when a button has been pressed.
I can’t see anything at a glance in the architecture to do with touch input, so how is it able to do this?
More importantly: If it is NOT utilizing proper touch events, how do I turn this “feature” off?
Nifty is not swallowing my touch input. I have a game set up where touching the play area will have things happen.
I have Nifty Buttons set up which, using mouse input, are able to block input from being sent to the game if they determine that a Nifty element has been clicked.
How do I make this also happen with touch events?
Might be the “swallowing” is only implemented for the mouse input and not for the touch input? @void256, @iwgeric?
I suppose if that’s the case my alternative question is, is tonegodGUI any better at dealing with this?
All that really matters to me in the long run is that the GUI will be able to determine when I have sent a tap, then either swallow it or filter it down to the game.
CEGUI in C++ has a pretty good example of how to do this, where input is not gathered but instead injected manually by the user. injectMouseButtonDown() will return true or false depending on whether it was over a GUI element.
Using something like this I could at least build from the ground up, but given how Nifty appears to be doing things without having been explicitly told to do them, I find I’m just staring at its behaviour confused at all this hidden, automated listener functionality.
Yeh, theres two ways to handle this generally. You either try to understand and work with how a library works or you write your own. The third option, complaining that X is not like Y or that X is not like you imagine it is always the worst and shouldn’t be considered.
So just to recap, what you’re telling me is that:
A: There is no way to turn off the mouse simulation through a local function similar to inputManager.setSimulateMouse(false)
B: If A is no, then there is no way to explicitly handle touch input directly through Nifty.
C: There is no way visible to the developer, to manually determine through true/false whether Nifty handled input or it should be passed on?
I’m not looking to start an argument, I just need to know the status of these three requirements so I can determine whether Nifty is the right library for me for Android development before I potentially spend a week or more hacking my way around it or failing to do so, when I could be focussing my efforts elsewhere.
I didn’t say any of these things, no.
The setSimulateMouse(false) only determines if touch inputs from Android should be converted into jME Mouse Events. Even with setSimulateMouse(false), Nifty will still receive the Touch Events and process them.
The basic design of the input handling for Nifty is supposed to deal with Touch Input or Mouse Input without user intervention. If the input event (touch or mouse) is consumed by Nifty, then the inputManager will mark the event as consumed so that the event is not sent on to the app.
With that said, Nifty uses raw input events sent from InputManager. The raw input handling in InputManager is processed such that the listeners registered in InputManager are processed in the order that the listeners are added to InputManager. This means that if Nifty is added after adding a RawInputListener from the app, then the app listener will receive the event before Nifty does. If the event is marked as consumed in the app RawInputListener, then Nifty should not see the event. Likewise, if Nifty is registered before any application RawInputListeners, then the app should not receive the event if Nifty consumes the event.
The code for how Nifty uses inputs from jME and how the events are consumed is located in: .
jmonkeyengine/InputSystemJme.java at 3.0 · jMonkeyEngine/jmonkeyengine · GitHub
If you are only using the TouchListener and/or Action/Analog listeners, these listeners are process after all RawInputListeners are done. If jME can determine that Nifty is using the event, then the event is marked as consumed and these listeners do not receive the event.
If Nifty is not correctly consuming the event, that is one thing. If you are looking for a way for the app to process the event before Nifty and consume it so that Nifty does not receive the event, then adding a RawInputListener before adding Nifty to the app should allow you to do that.