diff options
author | Sven Gothel <[email protected]> | 2014-04-09 16:40:13 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-04-09 16:40:13 +0200 |
commit | 11021769c78343b842b723a432a08946a65a1ceb (patch) | |
tree | 2b161dc522979ffb36d165f9c118f806471c2b12 | |
parent | 38365e14977714df3f19fb6b5880dd6f4d4d5743 (diff) |
NEWT MouseEvent: Decouple pointerIds from single-pointer button, i.e. always use proper pointerId >= 0
In case of single-pointer mouse events, always use pointerId 0,
don't derive from button name.
Multiple pointer events still derive button name from the 'action' pointerId.
This allows applications to utilize pointerId equally for single and multiple
pointer events.
Passed all 'junit.run.newt.event' unit tests
3 files changed, 100 insertions, 114 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java index 84c78727e..fb74b5a09 100644 --- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java @@ -49,23 +49,17 @@ package com.jogamp.newt.event; * For example {@link #getX(int) e.getX(0)} at {@link #EVENT_MOUSE_PRESSED} returns the data of the pressed pointer, etc. * </p> * <p> - * A {@link #getButton() button value} of <code>0</code> denotes no button activity, i.e. {@link PointerType#Mouse} move. - * </p> - * <p> - * A {@link #getPointerId(int) pointer-ID} of -1 denotes no pointer/button activity, i.e. {@link PointerType#Mouse} move. + * Multiple-pointer event's {@link #getButton() button number} is mapped to the <i>first {@link #getPointerId(int) pointer ID}</i> + * triggering the event and the {@link InputEvent#BUTTON1_MASK button mask bits} in the {@link #getModifiers() modifiers} + * field represent the pressed pointer IDs. * </p> * <p> - * {@link #getButton() Button values} are mapped from and to {@link #getPointerId(int) pointer-IDs} as follows: - * <code> - * getPointerId(0) == getButton() - 1 - * </code>. + * Users can query the pressed button and pointer count via {@link InputEvent#getButtonDownCount()} + * or use the simple query {@link InputEvent#isAnyButtonDown()}. * </p> * <p> - * If representing a multiple-pointer event, the {@link #getButton() button number} is mapped to the <i>first {@link #getPointerId(int) pointer ID}</i> - * triggering the event and the {@link InputEvent#BUTTON1_MASK button mask bits} in the {@link #getModifiers() modifiers} - * field represent the pressed pointer IDs.<br> - * Hence users can query the pressed button count as well as the pressed pointer count via {@link InputEvent#getButtonDownCount()} - * or use the simple query {@link InputEvent#isAnyButtonDown()}. + * If representing a single-pointer {@link PointerType#Mouse} event, {@link #getPointerId(int) pointer-ID} is <code>0</code> + * and a {@link #getButton() button value} of <code>0</code> denotes no button activity, i.e. {@link PointerType#Mouse} move. * </p> */ @SuppressWarnings("serial") @@ -206,7 +200,7 @@ public class MouseEvent extends InputEvent this.pressure = constMousePressure0; } this.maxPressure= 1.0f; - this.pointerID = new short[] { (short)(button - 1) }; + this.pointerID = new short[] { (short)0 }; this.clickCount=clickCount; this.button=button; this.rotationXYZ = rotationXYZ; @@ -305,9 +299,6 @@ public class MouseEvent extends InputEvent * IDs start w/ 0 and are consecutive numbers. * </p> * <p> - * A pointer-ID of -1 may also denote no pointer/button activity, i.e. {@link PointerType#Mouse} move. - * </p> - * <p> * See details for <a href="#multiPtrEvent">multiple-pointer events</a>. * </p> */ @@ -556,12 +547,7 @@ public class MouseEvent extends InputEvent /** PointerType for each pointer (multiple pointer) */ private final PointerType pointerType[]; - /** - * Pointer-ID for each pointer (multiple pointer). IDs start w/ 0 and are consecutive numbers. - * <p> - * A pointer-ID of -1 may also denote no pointer/button activity, i.e. {@link PointerType#Mouse} move. - * </p> - */ + /** Pointer-ID for each pointer (multiple pointer). IDs start w/ 0 and are consecutive numbers. */ private final short pointerID[]; /** X-axis for each pointer (multiple pointer) */ private final int x[]; diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index d3f835e58..afb1ad020 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -2570,7 +2570,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer throw new NativeWindowException("Invalid mouse button number" + button); } doPointerEvent(enqueue, wait, constMousePointerTypes, eventType, modifiers, - 0 /*actionIdx*/, new short[] { (short)(button-1) }, + 0 /*actionIdx*/, new short[] { (short)0 }, button, new int[]{x}, new int[]{y}, new float[]{0f} /*pressure*/, 1f /*maxPressure*/, rotationXYZ, rotationScale); } @@ -2587,7 +2587,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer * Otherwise a simple <code>int</code> to <code>short</code> type cast is performed. * </p> * <p> - * See {@link #doPointerEvent(boolean, boolean, PointerType[], short, int, int, short[], int[], int[], float[], float, float[], float)} + * See {@link #doPointerEvent(boolean, boolean, PointerType[], short, int, int, short[], short, int[], int[], float[], float, float[], float)} * for details! * </p> * @@ -2638,7 +2638,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer pIDs[i] = (short)pNames[i]; } } - doPointerEvent(enqueue, wait, pTypes, eventType, modifiers, actionIdx, pIDs, + final short button = 0 < pCount ? (short) ( pIDs[0] + 1 ) : (short)0; + doPointerEvent(enqueue, wait, pTypes, eventType, modifiers, actionIdx, pIDs, button, pX, pY, pPressure, maxPressure, rotationXYZ, rotationScale); } @@ -2675,7 +2676,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer * @param modifiers * @param pActionIdx index of multiple-pointer arrays representing the pointer which triggered the event * @param pID Pointer ID for each pointer (multiple pointer). We assume consecutive pointerIDs starting w/ 0. - * A pointer-ID of -1 may also denote no pointer/button activity, i.e. {@link PointerType#Mouse} move. + * @param button Corresponding mouse-button, a button of 0 denotes no activity, i.e. {@link PointerType#Mouse} move. * @param pX X-axis for each pointer (multiple pointer) * @param pY Y-axis for each pointer (multiple pointer) * @param pPressure Pressure for each pointer (multiple pointer) @@ -2683,8 +2684,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer */ public final void doPointerEvent(final boolean enqueue, final boolean wait, final PointerType[] pTypes, final short eventType, int modifiers, - final int pActionIdx, final short[] pID, final int[] pX, final int[] pY, final float[] pPressure, - final float maxPressure, final float[] rotationXYZ, final float rotationScale) { + final int pActionIdx, final short[] pID, final short buttonIn, final int[] pX, final int[] pY, + final float[] pPressure, final float maxPressure, final float[] rotationXYZ, final float rotationScale) { final long when = System.currentTimeMillis(); final int pCount = pTypes.length; @@ -2717,12 +2718,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer pPressure[0] = aPress; } } - final short id = pID[0]; final short button; { - final int b = id + 1; - if( 0 <= b && b <= com.jogamp.newt.event.MouseEvent.BUTTON_COUNT ) { // we allow id==-1 -> button==0 for no button, i.e. mouse move - button = (short)b; + // validate button + if( 0 <= buttonIn && buttonIn <= com.jogamp.newt.event.MouseEvent.BUTTON_COUNT ) { // we allow button==0 for no button, i.e. mouse-ptr move + button = buttonIn; } else { button = com.jogamp.newt.event.MouseEvent.BUTTON1; } @@ -2736,7 +2736,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer int x = pX[0]; int y = pY[0]; final boolean insideWindow = x >= 0 && y >= 0 && x < getWidth() && y < getHeight(); - final Point movePositionP0 = pState1.getMovePosition(id); + final Point movePositionP0 = pState1.getMovePosition(pID[0]); switch( eventType ) { case MouseEvent.EVENT_MOUSE_EXITED: if( pState1.dragging ) { @@ -2918,7 +2918,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer /** * Consume the {@link MouseEvent}. * <p> - * Pointer/Mouse Processing Pass 2 (Pass 1 is performed in {@link #doPointerEvent(boolean, boolean, PointerType[], short, int, int, short[], int[], int[], float[], float, float[], float)}). + * Pointer/Mouse Processing Pass 2 (Pass 1 is performed in {@link #doPointerEvent(boolean, boolean, PointerType[], short, int, int, short[], short, int[], int[], float[], float, float[], float)}). * </p> * <p> * Invoked before dispatching the dequeued event. diff --git a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java index e5d667f3e..aef822262 100644 --- a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java +++ b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package jogamp.newt.driver.android.event; import jogamp.newt.Debug; @@ -39,7 +39,7 @@ import com.jogamp.newt.event.NEWTEvent; public class AndroidNewtEventFactory { private static final boolean DEBUG_MOUSE_EVENT = Debug.debug("Android.MouseEvent"); private static final boolean DEBUG_KEY_EVENT = Debug.debug("Android.KeyEvent"); - + /** API Level 12: {@link android.view.MotionEvent#ACTION_SCROLL} = {@value} */ private static final int ACTION_SCROLL = 8; @@ -53,35 +53,35 @@ public class AndroidNewtEventFactory { case MotionEvent.TOOL_TYPE_ERASER: return com.jogamp.newt.event.MouseEvent.PointerType.Pen; default: - return com.jogamp.newt.event.MouseEvent.PointerType.Undefined; + return com.jogamp.newt.event.MouseEvent.PointerType.Undefined; } } - + private static final short aMotionEventType2Newt(int aType) { switch( aType ) { - case android.view.MotionEvent.ACTION_DOWN: - case android.view.MotionEvent.ACTION_POINTER_DOWN: - return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED; - case android.view.MotionEvent.ACTION_UP: - case android.view.MotionEvent.ACTION_POINTER_UP: - case android.view.MotionEvent.ACTION_CANCEL: - return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED; - case android.view.MotionEvent.ACTION_MOVE: - return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_DRAGGED; - case android.view.MotionEvent.ACTION_OUTSIDE: - return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_MOVED; + case android.view.MotionEvent.ACTION_DOWN: + case android.view.MotionEvent.ACTION_POINTER_DOWN: + return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED; + case android.view.MotionEvent.ACTION_UP: + case android.view.MotionEvent.ACTION_POINTER_UP: + case android.view.MotionEvent.ACTION_CANCEL: + return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED; + case android.view.MotionEvent.ACTION_MOVE: + return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_DRAGGED; + case android.view.MotionEvent.ACTION_OUTSIDE: + return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_MOVED; // case ACTION_HOVER_MOVE case ACTION_SCROLL: // API Level 12 ! - return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_WHEEL_MOVED; + return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_WHEEL_MOVED; // case ACTION_HOVER_ENTER // case ACTION_HOVER_EXIT } return (short)0; } - + private static final short aAccessibilityEventType2Newt(int aType) { switch( aType ) { - case android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED: + case android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS; } return (short)0; @@ -89,7 +89,7 @@ public class AndroidNewtEventFactory { private static final short aKeyEventType2NewtEventType(int androidKeyAction) { switch(androidKeyAction) { - case android.view.KeyEvent.ACTION_DOWN: + case android.view.KeyEvent.ACTION_DOWN: case android.view.KeyEvent.ACTION_MULTIPLE: return com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED; case android.view.KeyEvent.ACTION_UP: @@ -97,22 +97,22 @@ public class AndroidNewtEventFactory { } return (short)0; } - + private static final short aKeyCode2NewtKeyCode(int androidKeyCode, boolean inclSysKeys) { if(android.view.KeyEvent.KEYCODE_0 <= androidKeyCode && androidKeyCode <= android.view.KeyEvent.KEYCODE_9) { - return (short) ( com.jogamp.newt.event.KeyEvent.VK_0 + ( androidKeyCode - android.view.KeyEvent.KEYCODE_0 ) ); + return (short) ( com.jogamp.newt.event.KeyEvent.VK_0 + ( androidKeyCode - android.view.KeyEvent.KEYCODE_0 ) ); } if(android.view.KeyEvent.KEYCODE_A <= androidKeyCode && androidKeyCode <= android.view.KeyEvent.KEYCODE_Z) { - return (short) ( com.jogamp.newt.event.KeyEvent.VK_A + ( androidKeyCode - android.view.KeyEvent.KEYCODE_A ) ); + return (short) ( com.jogamp.newt.event.KeyEvent.VK_A + ( androidKeyCode - android.view.KeyEvent.KEYCODE_A ) ); } if(android.view.KeyEvent.KEYCODE_F1 <= androidKeyCode && androidKeyCode <= android.view.KeyEvent.KEYCODE_F12) { - return (short) ( com.jogamp.newt.event.KeyEvent.VK_F1 + ( androidKeyCode - android.view.KeyEvent.KEYCODE_F1 ) ); + return (short) ( com.jogamp.newt.event.KeyEvent.VK_F1 + ( androidKeyCode - android.view.KeyEvent.KEYCODE_F1 ) ); } if(android.view.KeyEvent.KEYCODE_NUMPAD_0 <= androidKeyCode && androidKeyCode <= android.view.KeyEvent.KEYCODE_NUMPAD_9) { - return (short) ( com.jogamp.newt.event.KeyEvent.VK_NUMPAD0 + ( androidKeyCode - android.view.KeyEvent.KEYCODE_NUMPAD_0 ) ); - } + return (short) ( com.jogamp.newt.event.KeyEvent.VK_NUMPAD0 + ( androidKeyCode - android.view.KeyEvent.KEYCODE_NUMPAD_0 ) ); + } switch(androidKeyCode) { - case android.view.KeyEvent.KEYCODE_COMMA: return com.jogamp.newt.event.KeyEvent.VK_COMMA; + case android.view.KeyEvent.KEYCODE_COMMA: return com.jogamp.newt.event.KeyEvent.VK_COMMA; case android.view.KeyEvent.KEYCODE_PERIOD: return com.jogamp.newt.event.KeyEvent.VK_PERIOD; case android.view.KeyEvent.KEYCODE_ALT_LEFT: return com.jogamp.newt.event.KeyEvent.VK_ALT; case android.view.KeyEvent.KEYCODE_ALT_RIGHT: return com.jogamp.newt.event.KeyEvent.VK_ALT_GRAPH; @@ -137,7 +137,7 @@ public class AndroidNewtEventFactory { case android.view.KeyEvent.KEYCODE_ESCAPE: return com.jogamp.newt.event.KeyEvent.VK_ESCAPE; case android.view.KeyEvent.KEYCODE_CTRL_LEFT: return com.jogamp.newt.event.KeyEvent.VK_CONTROL; case android.view.KeyEvent.KEYCODE_CTRL_RIGHT: return com.jogamp.newt.event.KeyEvent.VK_CONTROL; // ?? - case android.view.KeyEvent.KEYCODE_BACK: + case android.view.KeyEvent.KEYCODE_BACK: if( inclSysKeys ) { // Note that manual mapping is performed, based on the keyboard state. // I.e. we map to VK_KEYBOARD_INVISIBLE if keyboard was visible and now becomes invisible! @@ -152,33 +152,33 @@ public class AndroidNewtEventFactory { return com.jogamp.newt.event.KeyEvent.VK_HOME; } break; - } + } return com.jogamp.newt.event.KeyEvent.VK_UNDEFINED; } - + private static final int aKeyModifiers2Newt(int androidMods) { int newtMods = 0; if ((androidMods & android.view.KeyEvent.META_SYM_ON) != 0) newtMods |= com.jogamp.newt.event.InputEvent.META_MASK; if ((androidMods & android.view.KeyEvent.META_SHIFT_ON) != 0) newtMods |= com.jogamp.newt.event.InputEvent.SHIFT_MASK; if ((androidMods & android.view.KeyEvent.META_ALT_ON) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_MASK; - + return newtMods; } - + public static com.jogamp.newt.event.WindowEvent createWindowEvent(android.view.accessibility.AccessibilityEvent event, com.jogamp.newt.Window newtSource) { final int aType = event.getEventType(); final short nType = aAccessibilityEventType2Newt(aType); - + if( (short)0 != nType) { return new com.jogamp.newt.event.WindowEvent(nType, ((null==newtSource)?null:(Object)newtSource), event.getEventTime()); } return null; // no mapping .. } - + public static com.jogamp.newt.event.KeyEvent createKeyEvent(android.view.KeyEvent aEvent, com.jogamp.newt.Window newtSource, boolean inclSysKeys) { final com.jogamp.newt.event.KeyEvent res; - final short newtType = aKeyEventType2NewtEventType(aEvent.getAction()); + final short newtType = aKeyEventType2NewtEventType(aEvent.getAction()); if( (short)0 != newtType) { final short newtKeyCode = aKeyCode2NewtKeyCode(aEvent.getKeyCode(), inclSysKeys); res = createKeyEventImpl(aEvent, newtType, newtKeyCode, newtSource); @@ -199,7 +199,7 @@ public class AndroidNewtEventFactory { } return res; } - + public static com.jogamp.newt.event.KeyEvent createKeyEvent(android.view.KeyEvent aEvent, short newtKeyCode, short newtType, com.jogamp.newt.Window newtSource) { final com.jogamp.newt.event.KeyEvent res = createKeyEventImpl(aEvent, newtType, newtKeyCode, newtSource); if(DEBUG_KEY_EVENT) { @@ -207,21 +207,21 @@ public class AndroidNewtEventFactory { } return res; } - + private static com.jogamp.newt.event.KeyEvent createKeyEventImpl(android.view.KeyEvent aEvent, short newtType, short newtKeyCode, com.jogamp.newt.Window newtSource) { if( (short)0 != newtType && com.jogamp.newt.event.KeyEvent.VK_UNDEFINED != newtKeyCode ) { final Object src = null==newtSource ? null : newtSource; final long unixTime = System.currentTimeMillis() + ( aEvent.getEventTime() - android.os.SystemClock.uptimeMillis() ); final int newtMods = aKeyModifiers2Newt(aEvent.getMetaState()); - + return com.jogamp.newt.event.KeyEvent.create( newtType, src, unixTime, newtMods, newtKeyCode, newtKeyCode, (char) aEvent.getUnicodeChar()); } return null; } - + private static float maxPressure = 0.7f; // experienced maximum value (Amazon HD = 0.8f) - + /** * Dynamic calibration of maximum MotionEvent pressure, starting from 0.7f * <p> @@ -235,49 +235,51 @@ public class AndroidNewtEventFactory { * <li>Amazon HD: Pressure always ≤ 0.8f</li> * </ul> * </p> - * + * * @return */ public static float getMaxPressure() { return maxPressure; } - - private final int touchSlop; + + private final int touchSlop; public AndroidNewtEventFactory(android.content.Context context, android.os.Handler handler) { final android.view.ViewConfiguration configuration = android.view.ViewConfiguration.get(context); touchSlop = configuration.getScaledTouchSlop(); final int doubleTapSlop = configuration.getScaledDoubleTapSlop(); if(DEBUG_MOUSE_EVENT) { - System.err.println("AndroidNewtEventFactory scrollSlop (scaled) "+touchSlop); - System.err.println("AndroidNewtEventFactory doubleTapSlop (scaled) "+doubleTapSlop); - } + System.err.println("AndroidNewtEventFactory scrollSlop (scaled) "+touchSlop); + System.err.println("AndroidNewtEventFactory doubleTapSlop (scaled) "+doubleTapSlop); + } } - - private static void collectPointerData(MotionEvent e, int idx, final int[] x, final int[] y, final float[] pressure, + + private static void collectPointerData(MotionEvent e, int count, final int[] x, final int[] y, final float[] pressure, final short[] pointerIds, final MouseEvent.PointerType[] pointerTypes) { - x[idx] = (int)e.getX(idx); - y[idx] = (int)e.getY(idx); - pressure[idx] = e.getPressure(idx); - pointerIds[idx] = (short)e.getPointerId(idx); - if( pressure[idx] > maxPressure ) { - maxPressure = pressure[idx]; - } - pointerTypes[idx] = aToolType2PointerType( e.getToolType(idx) ); - if(DEBUG_MOUSE_EVENT) { - System.err.println("createMouseEvent: ptr-data["+idx+"] "+x[idx]+"/"+y[idx]+", pressure "+pressure[idx]+", id "+pointerIds[idx]+", type "+pointerTypes[idx]); + for(int i=0; i < count; i++) { + x[i] = (int)e.getX(i); + y[i] = (int)e.getY(i); + pressure[i] = e.getPressure(i); + pointerIds[i] = (short)e.getPointerId(i); + if( pressure[i] > maxPressure ) { + maxPressure = pressure[i]; + } + pointerTypes[i] = aToolType2PointerType( e.getToolType(i) ); + if(DEBUG_MOUSE_EVENT) { + System.err.println("createMouseEvent: ptr-data["+i+"] "+x[i]+"/"+y[i]+", pressure "+pressure[i]+", id "+pointerIds[i]+", type "+pointerTypes[i]); + } } } - - public boolean sendPointerEvent(boolean enqueue, boolean wait, boolean setFocusOnDown, boolean isOnTouchEvent, + + public boolean sendPointerEvent(boolean enqueue, boolean wait, boolean setFocusOnDown, boolean isOnTouchEvent, android.view.MotionEvent event, jogamp.newt.driver.android.WindowDriver newtSource) { if(DEBUG_MOUSE_EVENT) { - System.err.println("createMouseEvent: isOnTouchEvent "+isOnTouchEvent+", "+event); + System.err.println("createMouseEvent: isOnTouchEvent "+isOnTouchEvent+", "+event); } if( event.getPressure() > maxPressure ) { maxPressure = event.getPressure(); } - + // // Prefilter Android Event (Gesture, ..) and determine final type // @@ -285,10 +287,10 @@ public class AndroidNewtEventFactory { final short nType = aMotionEventType2Newt(aType); final float rotationScale = touchSlop; final float[] rotationXYZ = new float[] { 0f, 0f, 0f }; - - if( (short)0 != nType ) { + + if( (short)0 != nType ) { int modifiers = 0; - + // // Determine SDK 12 SCROLL, newt-button and whether dedicated pointer is pressed // @@ -306,33 +308,33 @@ public class AndroidNewtEventFactory { } } break; - + case ACTION_SCROLL: if( AndroidVersion.SDK_INT >= 12 ) { // API Level 12 rotationXYZ[0] = event.getAxisValue(android.view.MotionEvent.AXIS_X) / rotationScale; rotationXYZ[1] = event.getAxisValue(android.view.MotionEvent.AXIS_Y) / rotationScale; - + if( rotationXYZ[0]*rotationXYZ[0] > rotationXYZ[1]*rotationXYZ[1] ) { // Horizontal modifiers |= com.jogamp.newt.event.InputEvent.SHIFT_MASK; } if(DEBUG_MOUSE_EVENT) { System.err.println("createMouseEvent: SDK-12 Scroll "+rotationXYZ[0]+"/"+rotationXYZ[1]+", "+rotationScale+", mods "+modifiers); - } + } } // Fall through intended! - + default: { pIndex = 0; button = com.jogamp.newt.event.MouseEvent.BUTTON1; } } final int pCount = event.getPointerCount(); // all - + switch( aType ) { case android.view.MotionEvent.ACTION_DOWN: - case android.view.MotionEvent.ACTION_POINTER_DOWN: - modifiers |= InputEvent.getButtonMask(button); + case android.view.MotionEvent.ACTION_POINTER_DOWN: + // modifier button-mask will be set on doPointerEvent(..) if( setFocusOnDown ) { newtSource.focusChanged(false, true); } @@ -350,12 +352,10 @@ public class AndroidNewtEventFactory { if(DEBUG_MOUSE_EVENT) { System.err.println("createMouseEvent: collect ptr-data [0.."+(pCount-1)+", count "+pCount+", action "+pIndex+"], aType "+aType+", button "+button); } - for(int i=0; i < pCount; i++) { - collectPointerData(event, i, x, y, pressure, pointerIds, pointerTypes); - } + collectPointerData(event, pCount, x, y, pressure, pointerIds, pointerTypes); } newtSource.doPointerEvent(enqueue, wait, pointerTypes, nType, modifiers, - pIndex, pointerIds, x, y, pressure, maxPressure, rotationXYZ, rotationScale); + pIndex, pointerIds, button, x, y, pressure, maxPressure, rotationXYZ, rotationScale); return true; } return false; // no mapping .. |