Search in sources :

Example 6 with MouseMotionEvent

use of com.jme3.input.event.MouseMotionEvent in project jmonkeyengine by jMonkeyEngine.

the class AndroidTouchInput method generateMouseEvent.

// TODO: Ring Buffer for mouse events?
public InputEvent generateMouseEvent(TouchEvent event) {
    InputEvent inputEvent = null;
    int newX;
    int newY;
    int newDX;
    int newDY;
    // MouseEvents do not support multi-touch, so only evaluate 1 finger pointer events
    if (!isSimulateMouse() || numPointers > 1) {
        return null;
    }
    if (isMouseEventsInvertX()) {
        newX = (int) (invertX(event.getX()));
        newDX = (int) event.getDeltaX() * -1;
    } else {
        newX = (int) event.getX();
        newDX = (int) event.getDeltaX();
    }
    if (isMouseEventsInvertY()) {
        newY = (int) (invertY(event.getY()));
        newDY = (int) event.getDeltaY() * -1;
    } else {
        newY = (int) event.getY();
        newDY = (int) event.getDeltaY();
    }
    switch(event.getType()) {
        case DOWN:
            // Handle mouse down event
            inputEvent = new MouseButtonEvent(0, true, newX, newY);
            inputEvent.setTime(event.getTime());
            break;
        case UP:
            // Handle mouse up event
            inputEvent = new MouseButtonEvent(0, false, newX, newY);
            inputEvent.setTime(event.getTime());
            break;
        case HOVER_MOVE:
        case MOVE:
            inputEvent = new MouseMotionEvent(newX, newY, newDX, newDY, (int) event.getScaleSpan(), (int) event.getDeltaScaleSpan());
            inputEvent.setTime(event.getTime());
            break;
    }
    return inputEvent;
}
Also used : MouseMotionEvent(com.jme3.input.event.MouseMotionEvent) InputEvent(com.jme3.input.event.InputEvent) KeyInputEvent(com.jme3.input.event.KeyInputEvent) MouseButtonEvent(com.jme3.input.event.MouseButtonEvent)

Example 7 with MouseMotionEvent

use of com.jme3.input.event.MouseMotionEvent in project jmonkeyengine by jMonkeyEngine.

the class NewtMouseInput method update.

@Override
public void update() {
    if (!component.hasFocus())
        return;
    if (cursorMoved) {
        int newX = location.getX();
        int newY = location.getY();
        int newWheel = wheelPos;
        // invert DY
        int actualX = lastKnownLocation.getX();
        int actualY = component.getSurfaceHeight() - lastKnownLocation.getY();
        MouseMotionEvent evt = new MouseMotionEvent(actualX, actualY, newX - lastEventX, lastEventY - newY, wheelPos, lastEventWheel - wheelPos);
        listener.onMouseMotionEvent(evt);
        lastEventX = newX;
        lastEventY = newY;
        lastEventWheel = newWheel;
        cursorMoved = false;
    }
    synchronized (eventQueue) {
        eventQueueCopy.clear();
        eventQueueCopy.addAll(eventQueue);
        eventQueue.clear();
    }
    int size = eventQueueCopy.size();
    for (int i = 0; i < size; i++) {
        listener.onMouseButtonEvent(eventQueueCopy.get(i));
    }
}
Also used : MouseMotionEvent(com.jme3.input.event.MouseMotionEvent) Point(com.jogamp.nativewindow.util.Point)

Example 8 with MouseMotionEvent

use of com.jme3.input.event.MouseMotionEvent in project jmonkeyengine by jMonkeyEngine.

the class GlfwMouseInput method onWheelScroll.

private void onWheelScroll(long window, double xOffset, double yOffset) {
    mouseWheel += yOffset;
    final MouseMotionEvent mouseMotionEvent = new MouseMotionEvent(mouseX, mouseY, 0, 0, mouseWheel, (int) Math.round(yOffset));
    mouseMotionEvent.setTime(getInputTimeNanos());
    mouseMotionEvents.add(mouseMotionEvent);
}
Also used : MouseMotionEvent(com.jme3.input.event.MouseMotionEvent)

Example 9 with MouseMotionEvent

use of com.jme3.input.event.MouseMotionEvent in project jmonkeyengine by jMonkeyEngine.

the class GlfwMouseInput method onCursorPos.

private void onCursorPos(long window, double xpos, double ypos) {
    int xDelta;
    int yDelta;
    int x = (int) Math.round(xpos);
    int y = context.getSettings().getHeight() - (int) Math.round(ypos);
    if (mouseX == 0) {
        mouseX = x;
    }
    if (mouseY == 0) {
        mouseY = y;
    }
    xDelta = x - mouseX;
    yDelta = y - mouseY;
    mouseX = x;
    mouseY = y;
    if (xDelta != 0 || yDelta != 0) {
        final MouseMotionEvent mouseMotionEvent = new MouseMotionEvent(x, y, xDelta, yDelta, mouseWheel, 0);
        mouseMotionEvent.setTime(getInputTimeNanos());
        mouseMotionEvents.add(mouseMotionEvent);
    }
}
Also used : MouseMotionEvent(com.jme3.input.event.MouseMotionEvent)

Aggregations

MouseMotionEvent (com.jme3.input.event.MouseMotionEvent)9 MouseButtonEvent (com.jme3.input.event.MouseButtonEvent)3 InputEvent (com.jme3.input.event.InputEvent)2 KeyInputEvent (com.jme3.input.event.KeyInputEvent)1 Point (com.jogamp.nativewindow.util.Point)1