Search in sources :

Example 1 with MouseAction

use of org.terasology.input.device.MouseAction in project Terasology by MovingBlocks.

the class LwjglMouseDevice method getInputQueue.

@Override
public Queue<MouseAction> getInputQueue() {
    Queue<MouseAction> result = Queues.newArrayDeque();
    while (Mouse.next()) {
        if (Mouse.getEventButton() != -1) {
            ButtonState state = (Mouse.getEventButtonState()) ? ButtonState.DOWN : ButtonState.UP;
            result.add(new MouseAction(InputType.MOUSE_BUTTON.getInput(Mouse.getEventButton()), state, getPosition()));
        }
        if (Mouse.getEventDWheel() != 0) {
            int id = (Mouse.getEventDWheel() > 0) ? 1 : -1;
            result.add(new MouseAction(InputType.MOUSE_WHEEL.getInput(id), id * Mouse.getEventDWheel() / 120, getPosition()));
        }
    }
    return result;
}
Also used : MouseAction(org.terasology.input.device.MouseAction) ButtonState(org.terasology.input.ButtonState)

Example 2 with MouseAction

use of org.terasology.input.device.MouseAction in project Terasology by MovingBlocks.

the class InputSystem method processMouseInput.

private void processMouseInput(float delta) {
    if (!isCapturingMouse()) {
        return;
    }
    Vector2i deltaMouse = mouse.getDelta();
    // process mouse movement x axis
    if (deltaMouse.x != 0) {
        float xValue = deltaMouse.x * inputDeviceConfig.getMouseSensitivity();
        MouseAxisEvent event = MouseAxisEvent.create(MouseAxis.X, xValue, delta);
        send(event);
    }
    // process mouse movement y axis
    if (deltaMouse.y != 0) {
        int yMovement = inputDeviceConfig.isMouseYAxisInverted() ? deltaMouse.y * -1 : deltaMouse.y;
        float yValue = yMovement * inputDeviceConfig.getMouseSensitivity();
        MouseAxisEvent event = MouseAxisEvent.create(MouseAxis.Y, yValue, delta);
        send(event);
    }
    // process mouse clicks
    for (MouseAction action : mouse.getInputQueue()) {
        switch(action.getInput().getType()) {
            case MOUSE_BUTTON:
                processMouseButtonInput(delta, action);
                break;
            case MOUSE_WHEEL:
                processMouseWheelInput(delta, action);
                break;
            default:
                break;
        }
    }
}
Also used : MouseAction(org.terasology.input.device.MouseAction) Vector2i(org.terasology.math.geom.Vector2i) MouseAxisEvent(org.terasology.input.events.MouseAxisEvent)

Aggregations

MouseAction (org.terasology.input.device.MouseAction)2 ButtonState (org.terasology.input.ButtonState)1 MouseAxisEvent (org.terasology.input.events.MouseAxisEvent)1 Vector2i (org.terasology.math.geom.Vector2i)1