Get mouse state for GUI

I wanted to have a go at creating a simple GUI for my program (mostly to learn about how GUI’s are put together from the ground up), and ran into the problem of how to get the input to my controls.



At the moment, the only way I know of doing this is implementing something along the lines of



[java]inputManager.addMapping(“GUI_Mouse_Left”,

new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); // trigger 2: left-button click

inputManager.addMapping(“GUI_Mouse_Right”,

new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));

inputManager.addMapping(“GUI_Mouse_Middle”,

new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));

inputManager.addListener(actionListener, “GUI_Mouse_Left”, “GUI_Mouse_Right”, “GUI_Mouse_Middle”);



inputManager.addMapping(“GUI_Mouse_X”, new MouseAxisTrigger(MouseInput.AXIS_X, false));

inputManager.addMapping(“GUI_Mouse_Y”, new MouseAxisTrigger(MouseInput.AXIS_Y, false));

inputManager.addMapping(“GUI_Mouse_WHEEL”, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));

inputManager.addListener(analogListener, “GUI_Mouse_X”, “GUI_Mouse_Y”, “GUI_Mouse_WHEEL”);[/java]



and then in the analogListener



[java]private AnalogListener analogListener = new AnalogListener() {

public void onAnalog(String name, float value, float tpf) {

if (name.equals(“GUI_Mouse_X”)) {

// Do something

}

if (name.equals(“GUI_Mouse_Y”)) {

// Do something

}

if (name.equals(“GUI_Mouse_WHEEL”)) {

// Do something

}

}

};[/java]



However, this seems very inefficient since I would have to have three different event listeners in my gui which would deal with the three mouse directions (third is the wheel).



Is there any way to just get a mouse object which contains all the current mouse state so I can use it like this (or similar) :



[java]

mouseState = getMouseState()

// mouseState would contain x, y, wheel, buttonPressed[3] or something like this

gui.passMouse(mouseState)

[/java]

Not really… but it sounds like a RawInputListener is more what you want. That’s what I use in my own GUI code.

Ok, that makes sense, and exposes the functionality I need. Could you just explain what the beginInput and endInput methods do, and how they are supposed to be used?

My understanding:



events are sent per frame. There could have been numerous events in a given frame. You will get beginInput() and endInput() around the set of events that happened in a single frame.



Personally, I just ignore these methods. They are useful if you need to calculate a tpf for your events but otherwise, I don’t see them as being useful for a UI.