From ded080fd890c21b54ba1f96d84f9e355711dc88a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 24 Mar 2013 07:08:42 +0100 Subject: Newt/MouseEvent: Add 'float[3] getRotation()', getWheelScale() -> getRotationScale(), refinement of commit 18cb57246372eda72c25a5cd9a69a873bdf09489 Turns out the 'wheel' semantics are not generic enough and confining rotation values to one axis only satisfies the traditional mouse wheel. Widen the definition of 'rotation' and delivering 3-axis if supported. On NEWT/Android, we deliver the 2-axis for example, allowing to rotate around both or scrolling using both directions (-> GearsES2). --- .../classes/com/jogamp/newt/event/MouseEvent.java | 89 ++++++++++++++++++---- .../com/jogamp/newt/event/MouseListener.java | 15 +++- .../android/event/AndroidNewtEventFactory.java | 35 ++++----- .../opengl/test/junit/jogl/demos/es2/GearsES2.java | 19 ++--- 4 files changed, 107 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java index 87a9eeb7c..a40b0aa18 100644 --- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java @@ -52,7 +52,15 @@ public class MouseEvent extends InputEvent /** Type of pointer devices */ public static enum PointerType{ - Mouse(PointerClass.Offscreen), Pen(PointerClass.Onscreen), Touch(PointerClass.Onscreen), Undefined(PointerClass.Undefined); + /** {@link PointerClass#Offscreen} mouse. */ + Mouse(PointerClass.Offscreen), + /** {@link PointerClass#Offscreen} touch pad, usually using fingers. */ + TouchPad(PointerClass.Offscreen), + /** {@link PointerClass#Onscreen} touch screen, usually using fingers. */ + TouchScreen(PointerClass.Onscreen), + /** {@link PointerClass#Onscreen} pen on screen ?. */ + Pen(PointerClass.Onscreen), + Undefined(PointerClass.Undefined); public PointerClass getPointerClass() { return pc; } @@ -101,15 +109,20 @@ public class MouseEvent extends InputEvent this.pointerIDs = constMousePointerIDs; this.clickCount=clickCount; this.button=button; - this.wheelRotation = rotation; - this.wheelScale = 1f; + this.rotationXYZ = new float[] { 0f, 0f, 0f }; + if( isShiftDown() ) { + this.rotationXYZ[0] = rotation; + } else { + this.rotationXYZ[1] = rotation; + } + this.rotationScale = 1f; this.pointerTypes = constMousePointerTypes; } /** Constructor for multi-touch pointer events. */ public MouseEvent(short eventType, Object source, long when, int modifiers, int[] x, int[] y, float[] pressure, float maxPressure, PointerType pointerTypes[], short[] pointerids, short clickCount, - short button, float rotation, float rotationScale) + short button, float[] rotationXYZ, float rotationScale) { super(eventType, source, when, modifiers); this.x = x; @@ -127,8 +140,8 @@ public class MouseEvent extends InputEvent this.pointerIDs = pointerids; this.clickCount=clickCount; this.button=button; - this.wheelRotation = rotation; - this.wheelScale = rotationScale; + this.rotationXYZ = rotationXYZ; + this.rotationScale = rotationScale; this.pointerTypes = pointerTypes; } @@ -252,18 +265,62 @@ public class MouseEvent extends InputEvent *

*

* The button number refers to the wheel number. - *

- * @return + *

+ * @deprecated Use {@link #getRotation()} */ public float getWheelRotation() { - return wheelRotation; + return isShiftDown() ? rotationXYZ[0] : rotationXYZ[1] ; } + /** + * Returns a 3-component float array filled with the values of the rotational axis + * in the following order: horizontal-, vertical- and z-axis. + *

+ * A vertical rotation of > 0.0f is up and < 0.0f is down. + *

+ *

+ * A horizontal rotation of > 0.0f is left and < 0.0f is right. + *

+ *

+ * A z-axis rotation of > 0.0f is back and < 0.0f is front. + *

+ *

+ * However, on some OS this might be flipped due to the OS default behavior. + * The latter is true for OS X 10.7 (Lion) for example. + *

+ *

+ * On PointerClass {@link PointerClass#Onscreen onscreen} devices, i.e. {@link PointerType#TouchScreen touch screens}, + * rotation events are usually produced by a 2-finger movement, where horizontal and vertical rotation values are filled. + *

+ *

+ * On PointerClass {@link PointerClass#Offscreen offscreen} devices, i.e. {@link PointerType#Mouse mouse}, + * either the horizontal or the vertical rotation value is filled. + *

+ *

+ * The {@link InputEvent#SHIFT_MASK} modifier is set in case |horizontal| > |vertical| value.
+ * This can be utilized to implement only one 2d rotation direction, you may use {@link #isShiftDown()} to query it. + *

+ *

+ * In case the pointer type is {@link PointerType#Mouse mouse}, + * events are usually send in steps of one, ie. -1.0f and 1.0f. + * Higher values may result due to fast scrolling. + * Fractional values may result due to slow scrolling with high resolution devices.
+ * Here the button number refers to the wheel number. + *

+ *

+ * In case the pointer type is of class {@link PointerClass#Onscreen}, e.g. {@link PointerType#TouchScreen touch screen}, + * see {@link #getRotationScale()} for semantics. + *

+ */ + public float[] getRotation() { + return rotationXYZ; + } + /** - * Returns the scale used to determine the {@link #getWheelRotation() wheel rotation}, + * Returns the scale used to determine the {@link #getRotation() rotation value}, * which semantics depends on the {@link #getPointerType() pointer type's} {@link PointerClass}. *

- * For {@link PointerClass#Offscreen}, the scale is always 1.0f and denominates + * For {@link PointerClass#Offscreen}, the scale is usually 1.0f and denominates * an abstract value without association to a physical value. *

*

@@ -272,8 +329,8 @@ public class MouseEvent extends InputEvent * Hence scale * rotation reproduces the screen distance in pixels the finger[s] have moved. *

*/ - public float getWheelScale() { - return wheelScale; + public float getRotationScale() { + return rotationScale; } public String toString() { @@ -287,7 +344,7 @@ public class MouseEvent extends InputEvent sb.append("MouseEvent[").append(getEventTypeString(getEventType())) .append(", ").append(x).append("/").append(y) .append(", button ").append(button).append(", count ") - .append(clickCount).append(", wheel rotation ").append(wheelRotation).append(" * ").append(wheelScale); + .append(clickCount).append(", rotation [").append(rotationXYZ[0]).append(", ").append(rotationXYZ[1]).append(", ").append(rotationXYZ[2]).append("] * ").append(rotationScale); if(pointerIDs.length>0) { sb.append(", pointer<").append(pointerIDs.length).append(">["); for(int i=0; i + * Triggered for any rotational pointer events, see + * {@link MouseEvent#getRotation()} and {@link MouseEvent#getRotationScale()}. + *

+ */ public void mouseWheelMoved(MouseEvent e); } 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 83d3e7d90..21f552fdb 100644 --- a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java +++ b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java @@ -45,7 +45,7 @@ public class AndroidNewtEventFactory { private static final com.jogamp.newt.event.MouseEvent.PointerType aToolType2PointerType(int aToolType) { switch( aToolType ) { case MotionEvent.TOOL_TYPE_FINGER: - return com.jogamp.newt.event.MouseEvent.PointerType.Touch; + return com.jogamp.newt.event.MouseEvent.PointerType.TouchScreen; case MotionEvent.TOOL_TYPE_MOUSE: return com.jogamp.newt.event.MouseEvent.PointerType.Mouse; case MotionEvent.TOOL_TYPE_STYLUS: @@ -288,7 +288,8 @@ public class AndroidNewtEventFactory { // final int aType; final short nType; - float[] rotationXY = null; + final float rotationScale = touchSlop; + final float[] rotationXYZ = new float[] { 0f, 0f, 0f }; int rotationSource = 0; // 1 - Gesture, 2 - ACTION_SCROLL { final int aType0 = event.getActionMasked(); @@ -314,7 +315,9 @@ public class AndroidNewtEventFactory { } if( gesture2FingerScrl.isWithinGesture() ) { - rotationXY = gesture2FingerScrl.getScrollDistanceXY(); + final float[] rot = gesture2FingerScrl.getScrollDistanceXY(); + rotationXYZ[0] = rot[0] / rotationScale; + rotationXYZ[1] = rot[1] / rotationScale; aType = ACTION_SCROLL; // 8 rotationSource = 1; } else { @@ -327,30 +330,20 @@ public class AndroidNewtEventFactory { final short clickCount = 1; int modifiers = 0; - if( null == rotationXY && AndroidVersion.SDK_INT >= 12 && ACTION_SCROLL == aType ) { // API Level 12 - rotationXY = new float[] { event.getAxisValue(android.view.MotionEvent.AXIS_X), - event.getAxisValue(android.view.MotionEvent.AXIS_Y) }; + if( 0 == rotationSource && AndroidVersion.SDK_INT >= 12 && ACTION_SCROLL == aType ) { // API Level 12 + rotationXYZ[0] = event.getAxisValue(android.view.MotionEvent.AXIS_X) / rotationScale; + rotationXYZ[1] = event.getAxisValue(android.view.MotionEvent.AXIS_Y) / rotationScale; rotationSource = 2; } - final float rotation; - final float rotationScale = touchSlop; - if( null != rotationXY ) { - final float _rotation; - if( rotationXY[0]*rotationXY[0] > rotationXY[1]*rotationXY[1] ) { + if( 0 != rotationSource ) { + if( rotationXYZ[0]*rotationXYZ[0] > rotationXYZ[1]*rotationXYZ[1] ) { // Horizontal modifiers |= com.jogamp.newt.event.InputEvent.SHIFT_MASK; - _rotation = rotationXY[0]; - } else { - // Vertical - _rotation = rotationXY[1]; } - rotation = _rotation / rotationScale; if(DEBUG_MOUSE_EVENT) { - System.err.println("createMouseEvent: Scroll "+rotationXY[0]+"/"+rotationXY[1]+" -> "+_rotation+" / "+rotationScale+" -> "+rotation+" scaled -- mods "+modifiers+", source "+rotationSource); + System.err.println("createMouseEvent: Scroll "+rotationXYZ[0]+"/"+rotationXYZ[1]+", "+rotationScale+", mods "+modifiers+", source "+rotationSource); } - } else { - rotation = 0.0f; } // @@ -414,14 +407,14 @@ public class AndroidNewtEventFactory { final com.jogamp.newt.event.MouseEvent me1 = new com.jogamp.newt.event.MouseEvent( nType, src, unixTime, modifiers, x, y, pressure, maxPressure, pointerTypes, pointerIds, - clickCount, button, rotation, rotationScale); + clickCount, button, rotationXYZ, rotationScale); if( com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED == nType ) { return new com.jogamp.newt.event.MouseEvent[] { me1, new com.jogamp.newt.event.MouseEvent( com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_CLICKED, src, unixTime, modifiers, x, y, pressure, maxPressure, pointerTypes, pointerIds, - clickCount, button, rotation, rotationScale) }; + clickCount, button, rotationXYZ, rotationScale) }; } else { return new com.jogamp.newt.event.MouseEvent[] { me1 }; } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java index c239a949b..06635f2d5 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java @@ -420,23 +420,16 @@ public class GearsES2 implements GLEventListener { @Override public void mouseWheelMoved(MouseEvent e) { - float r = e.getWheelRotation() * 0.5f; + float[] rot = e.getRotation(); if( e.isControlDown() ) { // alternative zoom - panZ += r; - if( e.isShiftDown() ) { - panZ += r; - } - System.err.println("panZ.2: incr "+r+", dblZoom "+e.isShiftDown()+" -> "+panZ); + final float incr = e.isShiftDown() ? rot[0] : rot[1] * 0.5f ; + panZ += incr; + System.err.println("panZ.2: incr "+incr+", dblZoom "+e.isShiftDown()+" -> "+panZ); } else { // panning - if( e.isShiftDown() ) { - // horizontal - panX -= r; // positive -> left - } else { - // vertical - panY += r; // positive -> up - } + panX -= rot[0]; // positive -> left + panY += rot[1]; // positive -> up } } -- cgit v1.2.3