From 11021769c78343b842b723a432a08946a65a1ceb Mon Sep 17 00:00:00 2001
From: Sven Gothel
- * A {@link #getButton() button value} of 0
denotes no button activity, i.e. {@link PointerType#Mouse} move.
- *
- * 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 first {@link #getPointerId(int) pointer ID} + * triggering the event and the {@link InputEvent#BUTTON1_MASK button mask bits} in the {@link #getModifiers() modifiers} + * field represent the pressed pointer IDs. *
*
- * {@link #getButton() Button values} are mapped from and to {@link #getPointerId(int) pointer-IDs} as follows:
- *
- * getPointerId(0) == getButton() - 1
- *
.
+ * Users can query the pressed button and pointer count via {@link InputEvent#getButtonDownCount()}
+ * or use the simple query {@link InputEvent#isAnyButtonDown()}.
*
- * If representing a multiple-pointer event, the {@link #getButton() button number} is mapped to the first {@link #getPointerId(int) pointer ID}
- * triggering the event and the {@link InputEvent#BUTTON1_MASK button mask bits} in the {@link #getModifiers() modifiers}
- * field represent the pressed pointer IDs.
- * 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 0
+ * and a {@link #getButton() button value} of 0
denotes no button activity, i.e. {@link PointerType#Mouse} move.
*
- * A pointer-ID of -1 may also denote no pointer/button activity, i.e. {@link PointerType#Mouse} move. - *
- ** See details for multiple-pointer events. *
*/ @@ -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. - *- * A pointer-ID of -1 may also denote no pointer/button activity, i.e. {@link PointerType#Mouse} move. - *
- */ + /** 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 simpleint
to short
type cast is performed.
*
* - * 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! *
* @@ -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}. *- * 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)}). *
** 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 *
@@ -235,49 +235,51 @@ public class AndroidNewtEventFactory { *