Search in sources :

Example 6 with TouchEvent

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

the class AndroidGestureProcessor method onDoubleTap.

@Override
public boolean onDoubleTap(MotionEvent event) {
    //The down motion event of the first tap of the double-tap
    // We could use this event to fire off a double tap event, or use
    // DoubleTapEvent with a check for the UP action
    //        logger.log(Level.INFO, "onDoubleTap pointerId: {0}, action: {1}, x: {2}, y: {3}",
    //                new Object[]{touchInput.getPointerId(event), touchInput.getAction(event), event.getX(), event.getY()});
    float jmeX = touchInput.getJmeX(event.getX());
    float jmeY = touchInput.invertY(touchInput.getJmeY(event.getY()));
    TouchEvent touchEvent = touchInput.getFreeTouchEvent();
    touchEvent.set(TouchEvent.Type.DOUBLETAP, jmeX, jmeY, 0, 0);
    touchEvent.setPointerId(touchInput.getPointerId(event));
    touchEvent.setTime(event.getEventTime());
    touchEvent.setPressure(event.getPressure());
    touchInput.addEvent(touchEvent);
    return true;
}
Also used : TouchEvent(com.jme3.input.event.TouchEvent)

Example 7 with TouchEvent

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

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

the class TouchEventPool method getNextFreeEvent.

/**
     * Fetches a touch event from the reuse pool
     *
     * @return a usable TouchEvent
     */
public TouchEvent getNextFreeEvent() {
    TouchEvent evt = null;
    int curSize = eventPool.size();
    while (curSize > 0) {
        evt = (TouchEvent) eventPool.pop();
        if (evt.isConsumed()) {
            break;
        } else {
            eventPool.push(evt);
            evt = null;
        }
        curSize--;
    }
    if (evt == null) {
        logger.warning("eventPool full of unconsumed events");
        evt = new TouchEvent();
    }
    return evt;
}
Also used : TouchEvent(com.jme3.input.event.TouchEvent)

Example 9 with TouchEvent

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

the class TouchEventPool method initialize.

public void initialize() {
    TouchEvent newEvent;
    while (!eventPool.isEmpty()) {
        eventPool.pop();
    }
    for (int i = 0; i < maxEvents; i++) {
        newEvent = new TouchEvent();
        newEvent.setConsumed();
        eventPool.push(newEvent);
    }
}
Also used : TouchEvent(com.jme3.input.event.TouchEvent)

Example 10 with TouchEvent

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

the class AndroidGestureProcessor method onFling.

@Override
public boolean onFling(MotionEvent startEvent, MotionEvent endEvent, float velocityX, float velocityY) {
    // Fling happens only once at the end of the gesture (all fingers up).
    // Fling returns the velocity of the finger movement in pixels/sec.
    // Therefore, the dX and dY values are actually velocity instead of distance values
    // Since this does not track the movement, use the start position and velocity values.
    //        logger.log(Level.INFO, "onFling pointerId: {0}, startAction: {1}, startX: {2}, startY: {3}, endAction: {4}, endX: {5}, endY: {6}, velocityX: {7}, velocityY: {8}",
    //                new Object[]{touchInput.getPointerId(startEvent), touchInput.getAction(startEvent), startEvent.getX(), startEvent.getY(), touchInput.getAction(endEvent), endEvent.getX(), endEvent.getY(), velocityX, velocityY});
    float jmeX = touchInput.getJmeX(startEvent.getX());
    float jmeY = touchInput.invertY(touchInput.getJmeY(startEvent.getY()));
    TouchEvent touchEvent = touchInput.getFreeTouchEvent();
    touchEvent.set(TouchEvent.Type.FLING, jmeX, jmeY, velocityX, velocityY);
    touchEvent.setPointerId(touchInput.getPointerId(endEvent));
    touchEvent.setTime(endEvent.getEventTime());
    touchEvent.setPressure(endEvent.getPressure());
    touchInput.addEvent(touchEvent);
    return true;
}
Also used : TouchEvent(com.jme3.input.event.TouchEvent)

Aggregations

TouchEvent (com.jme3.input.event.TouchEvent)20 Vector2f (com.jme3.math.Vector2f)4 InputEvent (com.jme3.input.event.InputEvent)2 KeyInputEvent (com.jme3.input.event.KeyInputEvent)2 MouseButtonEvent (com.jme3.input.event.MouseButtonEvent)2 MouseMotionEvent (com.jme3.input.event.MouseMotionEvent)2