public LwjglMouseIterator() {}
@Override
protected MouseState computeNext() {
if (_nextState != null) {
final MouseState rVal = _nextState;
_nextState = null;
return rVal;
}
if (!Mouse.next()) {
return endOfData();
}
final EnumMap<MouseButton, ButtonState> buttons = Maps.newEnumMap(MouseButton.class);
if (Mouse.getButtonCount() > 0) {
final boolean down = Mouse.isButtonDown(0);
processButtonForClick(MouseButton.LEFT, down);
buttons.put(MouseButton.LEFT, down ? ButtonState.DOWN : ButtonState.UP);
}
if (Mouse.getButtonCount() > 1) {
final boolean down = Mouse.isButtonDown(1);
processButtonForClick(MouseButton.RIGHT, down);
buttons.put(MouseButton.RIGHT, down ? ButtonState.DOWN : ButtonState.UP);
}
if (Mouse.getButtonCount() > 2) {
final boolean down = Mouse.isButtonDown(2);
processButtonForClick(MouseButton.MIDDLE, down);
buttons.put(MouseButton.MIDDLE, down ? ButtonState.DOWN : ButtonState.UP);
}
final MouseState nextState = new MouseState(Mouse.getEventX(), Mouse.getEventY(), Mouse.getEventDX(), Mouse
.getEventDY(), Mouse.getEventDWheel(), buttons, null);
if (nextState.getDx() != 0.0 || nextState.getDy() != 0.0) {
_clickArmed.clear();
_clicks.clear();
_sendClickState = false;
}
if (_sendClickState) {
_nextState = nextState;
_sendClickState = false;
return new MouseState(nextState.getX(), nextState.getY(), nextState.getDx(), nextState.getDy(),
nextState.getDwheel(), buttons, EnumMultiset.create(_clicks));
} else {
return nextState;
}
}