aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-10-19 03:40:31 +0200
committerSven Gothel <[email protected]>2013-10-19 03:40:31 +0200
commit0ba264e878993d8f24254257d39a189b4ebf3937 (patch)
treedd2e0f39f8d08c31cdf621513729e7a28cdc4e31 /src/newt
parentfed660a69241a38535d26b54f8c81ec81edc3eff (diff)
PinchToZoomGesture: Add ctor arg 'allowMorePointer', should be false to be more stable (i.e. only 2 pointer pressed)v2.1.1
Diffstat (limited to 'src/newt')
-rw-r--r--src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java b/src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java
index b4e1341da..42f006f08 100644
--- a/src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java
+++ b/src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java
@@ -62,16 +62,22 @@ public class PinchToZoomGesture implements GestureHandler {
}
private final NativeSurface surface;
+ private final boolean allowMorePointer;
private float zoom;
private int zoomLastEdgeDist;
private boolean zoomFirstTouch;
private boolean zoomMode;
private ZoomEvent zoomEvent;
- private short[] pIds = new short[] { -1, -1 };
+ private final short[] pIds = new short[] { -1, -1 };
- public PinchToZoomGesture(NativeSurface surface) {
+ /**
+ * @param surface the {@link NativeSurface}, which size is used to compute the relative zoom factor
+ * @param allowMorePointer if false, allow only 2 pressed pointers (safe and recommended), otherwise accept other pointer to be pressed.
+ */
+ public PinchToZoomGesture(NativeSurface surface, boolean allowMorePointer) {
clear(true);
this.surface = surface;
+ this.allowMorePointer = allowMorePointer;
this.zoom = 1f;
}
@@ -135,11 +141,13 @@ public class PinchToZoomGesture implements GestureHandler {
return true;
}
final MouseEvent pe = (MouseEvent)in;
- if( pe.getPointerType(0).getPointerClass() != MouseEvent.PointerClass.Onscreen ) {
+ final int pointerDownCount = pe.getPointerCount();
+
+ if( pe.getPointerType(0).getPointerClass() != MouseEvent.PointerClass.Onscreen ||
+ ( !allowMorePointer && pointerDownCount > 2 ) ) {
return false;
}
- final int pointerDownCount = pe.getPointerCount();
final int eventType = pe.getEventType();
final boolean useY = surface.getWidth() >= surface.getHeight(); // use smallest dimension
switch ( eventType ) {
@@ -190,7 +198,7 @@ public class PinchToZoomGesture implements GestureHandler {
final int d = Math.abs(edge0-edge1);
final int dd = d - zoomLastEdgeDist;
final float screenEdge = useY ? surface.getHeight() : surface.getWidth();
- final float incr = (float)dd / screenEdge; // [-1..1]
+ final float incr = dd / screenEdge; // [-1..1]
if(DEBUG) {
System.err.println("XXX2: id0 "+pIds[0]+" -> idx0 "+p0Idx+", id1 "+pIds[1]+" -> idx1 "+p1Idx);
System.err.println("XXX3: d "+d+", ld "+zoomLastEdgeDist+", dd "+dd+", screen "+screenEdge+" -> incr "+incr+", zoom "+zoom+" -> "+(zoom+incr));