Search in sources :

Example 6 with MouseInput

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);
        }
    }
}
Also used : MouseInput(org.terasology.input.MouseInput)

Example 7 with MouseInput

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()));
        }
    });
}
Also used : MouseAction(org.terasology.input.device.MouseAction) MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) MouseMotionListener(java.awt.event.MouseMotionListener) MouseInput(org.terasology.input.MouseInput)

Aggregations

MouseInput (org.terasology.input.MouseInput)7 MouseAction (org.terasology.input.device.MouseAction)2 MouseEvent (java.awt.event.MouseEvent)1 MouseListener (java.awt.event.MouseListener)1 MouseMotionListener (java.awt.event.MouseMotionListener)1 ButtonState (org.terasology.input.ButtonState)1