Search in sources :

Example 1 with MouseButtonEvent

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

the class IosTouchHandler method generateMouseEvent.

// TODO: Ring Buffer for mouse events?
protected InputEvent generateMouseEvent(TouchEvent event) {
    InputEvent inputEvent = null;
    int newX;
    int newY;
    int newDX;
    int newDY;
    if (iosInput.isMouseEventsInvertX()) {
        newX = (int) (iosInput.invertX(event.getX()));
        newDX = (int) event.getDeltaX() * -1;
    } else {
        newX = (int) event.getX();
        newDX = (int) event.getDeltaX();
    }
    if (iosInput.isMouseEventsInvertY()) {
        newY = (int) (iosInput.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) MouseButtonEvent(com.jme3.input.event.MouseButtonEvent)

Example 2 with MouseButtonEvent

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

the class LwjglMouseInput method update.

public void update() {
    if (!context.isRenderable())
        return;
    while (Mouse.next()) {
        int btn = Mouse.getEventButton();
        int wheelDelta = Mouse.getEventDWheel();
        int xDelta = Mouse.getEventDX();
        int yDelta = Mouse.getEventDY();
        int x = Mouse.getX();
        int y = Mouse.getY();
        curWheel += wheelDelta;
        if (cursorVisible) {
            xDelta = x - curX;
            yDelta = y - curY;
            curX = x;
            curY = y;
        } else {
            x = curX + xDelta;
            y = curY + yDelta;
            curX = x;
            curY = y;
        }
        if (xDelta != 0 || yDelta != 0 || wheelDelta != 0) {
            MouseMotionEvent evt = new MouseMotionEvent(x, y, xDelta, yDelta, curWheel, wheelDelta);
            evt.setTime(Mouse.getEventNanoseconds());
            listener.onMouseMotionEvent(evt);
        }
        if (btn != -1) {
            MouseButtonEvent evt = new MouseButtonEvent(btn, Mouse.getEventButtonState(), x, y);
            evt.setTime(Mouse.getEventNanoseconds());
            listener.onMouseButtonEvent(evt);
        }
    }
}
Also used : MouseMotionEvent(com.jme3.input.event.MouseMotionEvent) MouseButtonEvent(com.jme3.input.event.MouseButtonEvent)

Example 3 with MouseButtonEvent

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

the class AwtMouseInput method mousePressed.

public void mousePressed(MouseEvent awtEvt) {
    // Must flip Y!
    int y = component.getHeight() - awtEvt.getY();
    MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(awtEvt), true, awtEvt.getX(), y);
    evt.setTime(awtEvt.getWhen());
    synchronized (eventQueue) {
        eventQueue.add(evt);
    }
}
Also used : MouseButtonEvent(com.jme3.input.event.MouseButtonEvent)

Example 4 with MouseButtonEvent

use of com.jme3.input.event.MouseButtonEvent 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 5 with MouseButtonEvent

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

the class NewtMouseInput method mousePressed.

@Override
public void mousePressed(MouseEvent newtEvt) {
    mousePressedX = newtEvt.getX();
    mousePressedY = component.getSurfaceHeight() - newtEvt.getY();
    MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(newtEvt), true, mousePressedX, mousePressedY);
    evt.setTime(newtEvt.getWhen());
    synchronized (eventQueue) {
        eventQueue.add(evt);
    }
}
Also used : MouseButtonEvent(com.jme3.input.event.MouseButtonEvent)

Aggregations

MouseButtonEvent (com.jme3.input.event.MouseButtonEvent)9 MouseMotionEvent (com.jme3.input.event.MouseMotionEvent)3 InputEvent (com.jme3.input.event.InputEvent)2 KeyInputEvent (com.jme3.input.event.KeyInputEvent)1