diff options
author | Sven Gothel <[email protected]> | 2013-10-17 07:57:02 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-10-17 07:57:02 +0200 |
commit | c9837ef133ff3465d9b06f1907a7a320181ec97c (patch) | |
tree | bf93947f79c0e21b01122e2ec0d9b4f9007d02d2 /src/newt | |
parent | a90bf31f8747dd38c61d518f8af4d4d4a64a8e90 (diff) |
PinchToZoomGesture: Validate pointer-IDs, skip if invalid.
Diffstat (limited to 'src/newt')
-rw-r--r-- | src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java b/src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java index 3a34c6253..eceea053d 100644 --- a/src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java +++ b/src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java @@ -177,31 +177,33 @@ public class PinchToZoomGesture implements GestureHandler { // same pointers final int p0Idx = pe.getPointerIdx(pIds[0]); final int p1Idx = pe.getPointerIdx(pIds[1]); - final int edge0 = useY ? pe.getY(p0Idx) : pe.getX(p0Idx); - final int edge1 = useY ? pe.getY(p1Idx) : pe.getX(p1Idx); - // Diff. 1:1 Zoom: finger-distance to screen-coord - if(zoomFirstTouch) { - zoomLastEdgeDist = Math.abs(edge0-edge1); - zoomFirstTouch=false; - zoomMode = true; - } else if( zoomMode ) { - 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] - 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)); - } - zoom += incr; - // clip value - if( 2f < zoom ) { - zoom = 2f; - } else if( 0 > zoom ) { - zoom = 0; + if( 0 <= p0Idx && 0 <= p1Idx ) { + final int edge0 = useY ? pe.getY(p0Idx) : pe.getX(p0Idx); + final int edge1 = useY ? pe.getY(p1Idx) : pe.getX(p1Idx); + // Diff. 1:1 Zoom: finger-distance to screen-coord + if(zoomFirstTouch) { + zoomLastEdgeDist = Math.abs(edge0-edge1); + zoomFirstTouch=false; + zoomMode = true; + } else if( zoomMode ) { + 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] + 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)); + } + zoom += incr; + // clip value + if( 2f < zoom ) { + zoom = 2f; + } else if( 0 > zoom ) { + zoom = 0; + } + zoomLastEdgeDist = d; + zoomEvent = new ZoomEvent(pe.getSource(), pe.getWhen(), pe.getModifiers(), this, pe, zoom); } - zoomLastEdgeDist = d; - zoomEvent = new ZoomEvent(pe.getSource(), pe.getWhen(), pe.getModifiers(), this, pe, zoom); } } if(DEBUG) { |