use of org.terasology.input.MouseInput in project Terasology by MovingBlocks.
the class InputSystem method processMouseButtonInput.
/**
* Processes input actions by the mouse buttons, sends input events and updates bind buttons accordingly.
*
* @param delta The length of the current frame.
* @param action The input action to be processed.
*/
private void processMouseButtonInput(float delta, MouseAction action) {
int id = action.getInput().getId();
if (id != MouseInput.NONE.getId()) {
MouseInput button = MouseInput.find(action.getInput().getType(), action.getInput().getId());
boolean consumed = sendMouseEvent(button, action.getState().isDown(), action.getMousePosition(), delta);
BindableButton bind = bindsManager.getMouseButtonBinds().get(button);
if (bind != null) {
updateBindState(bind, action.getInput(), action.getState().isDown(), delta, consumed);
}
}
}
use of org.terasology.input.MouseInput in project Terasology by MovingBlocks.
the class AwtMouseDevice method registerToAwtGlCanvas.
public void registerToAwtGlCanvas(AWTGLCanvas canvas) {
canvas.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
int button = e.getButton() - 1;
buttonStates.add(button);
MouseInput mouseInput = MouseInput.find(InputType.MOUSE_BUTTON, button);
queue.offer(new MouseAction(mouseInput, ButtonState.DOWN, getPosition()));
}
@Override
public void mouseReleased(MouseEvent e) {
int button = e.getButton() - 1;
buttonStates.remove(button);
MouseInput mouseInput = MouseInput.find(InputType.MOUSE_BUTTON, button);
queue.offer(new MouseAction(mouseInput, ButtonState.UP, getPosition()));
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
canvas.addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e) {
updateMouse(e.getX(), e.getY());
}
@Override
public void mouseMoved(MouseEvent e) {
updateMouse(e.getX(), e.getY());
}
});
canvas.addMouseWheelListener(e -> {
int yOffset = e.getUnitsToScroll();
if (yOffset != 0.0) {
int id = (yOffset > 0) ? 1 : -1;
queue.offer(new MouseAction(InputType.MOUSE_WHEEL.getInput(id), 1, getPosition()));
}
});
}
Aggregations