Search in sources :

Example 1 with TouchEvent

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

the class AndroidGestureProcessor method onShowPress.

@Override
public void onShowPress(MotionEvent event) {
    //        logger.log(Level.INFO, "onShowPress 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.SHOWPRESS, jmeX, jmeY, 0, 0);
    touchEvent.setPointerId(touchInput.getPointerId(event));
    touchEvent.setTime(event.getEventTime());
    touchEvent.setPressure(event.getPressure());
    touchInput.addEvent(touchEvent);
}
Also used : TouchEvent(com.jme3.input.event.TouchEvent)

Example 2 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 3 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 4 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 5 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)

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