diff options
author | Sven Gothel <[email protected]> | 2014-04-09 08:34:50 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-04-09 08:34:50 +0200 |
commit | f43b1f946159007b31162f765b1fa7b37991f940 (patch) | |
tree | 3dd145879f289cfed76180fa3cf93129cee1549a /src/newt/classes/com/jogamp | |
parent | 7ff2fcb36540aaed087e3a2ba2f0f84916bce2e2 (diff) |
PinchToZoomGesture: Add 'delta' value [-1..1], move 'InputEvent trigger' up to GestureHandler
Diffstat (limited to 'src/newt/classes/com/jogamp')
-rw-r--r-- | src/newt/classes/com/jogamp/newt/event/GestureHandler.java | 12 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java | 44 |
2 files changed, 44 insertions, 12 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/GestureHandler.java b/src/newt/classes/com/jogamp/newt/event/GestureHandler.java index 89f5e42d2..ea0f76fbb 100644 --- a/src/newt/classes/com/jogamp/newt/event/GestureHandler.java +++ b/src/newt/classes/com/jogamp/newt/event/GestureHandler.java @@ -52,6 +52,7 @@ public interface GestureHandler { public static final short EVENT_GESTURE_DETECTED = 400; private final GestureHandler handler; + private final InputEvent ie; /** * Creates a gesture event with default type {@link #EVENT_GESTURE_DETECTED}. @@ -60,10 +61,12 @@ public interface GestureHandler { * @param when * @param modifiers * @param handler + * @param trigger TODO */ - public GestureEvent(final Object source, final long when, final int modifiers, final GestureHandler handler) { + public GestureEvent(final Object source, final long when, final int modifiers, final GestureHandler handler, final InputEvent trigger) { super(EVENT_GESTURE_DETECTED, source, when, modifiers); this.handler = handler; + this.ie = trigger; } /** @@ -73,15 +76,20 @@ public interface GestureHandler { * @param when * @param modifiers * @param handler + * @param trigger TODO */ - public GestureEvent(final short event_type, final Object source, final long when, final int modifiers, final GestureHandler handler) { + public GestureEvent(final short event_type, final Object source, final long when, final int modifiers, final GestureHandler handler, final InputEvent trigger) { super(event_type, source, when, modifiers); this.handler = handler; + this.ie = trigger; } /** Return the {@link GestureHandler}, which produced the event. */ public final GestureHandler getHandler() { return handler; } + /** Triggering {@link InputEvent} */ + public final InputEvent getTrigger() { return ie; } + public String toString() { return "GestureEvent[handler "+handler+"]"; } diff --git a/src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java b/src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java index 42f006f08..7d22128cf 100644 --- a/src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java +++ b/src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java @@ -29,6 +29,8 @@ package com.jogamp.newt.event; import javax.media.nativewindow.NativeSurface; +import com.jogamp.newt.event.MouseEvent.PointerClass; + import jogamp.newt.Debug; /** @@ -48,17 +50,39 @@ public class PinchToZoomGesture implements GestureHandler { /** A {@link GestureHandler.GestureEvent} denominating zoom. */ @SuppressWarnings("serial") public static class ZoomEvent extends GestureEvent { - private final MouseEvent pe; private final float zoom; - public ZoomEvent(Object source, long when, int modifiers, GestureHandler handler, MouseEvent pe, float zoom) { - super(source, when, modifiers, handler); - this.pe = pe; + private final float delta; + private final float scale; + public ZoomEvent(final Object source, final long when, final int modifiers, final GestureHandler handler, final MouseEvent pe, + final float zoom, final float delta, final float scale) { + super(source, when, modifiers, handler, pe); this.zoom = zoom; + this.delta = delta; + this.scale = scale; } - /** Triggering {@link MouseEvent} */ - public final MouseEvent getTrigger() { return pe; } /** Zoom value lies within [0..2], with 1 as <i>1:1</i>. */ public final float getZoom() { return zoom; } + /** Delta to last zoom value lies within [-1..1]. */ + public final float getDelta() { return delta; } + /** + * Returns the scale used to determine the {@link #getZoom() zoom} + * and hence it's {@link #getDelta() delta} value, + * which semantics depends on the {@link #getPointerType() pointer type's} {@link PointerClass}. + * <p> + * For {@link PointerClass#Offscreen}, the scale is usually <code>1.0f</code> and denominates + * an abstract value without association to a physical value. + * </p> + * <p> + * For {@link PointerClass#Onscreen}, the scale varies and denominates + * the divisor of the distance the finger[s] have moved on the screen. + * Hence <code>scale * delta</code> reproduces the screen distance in pixels the finger[s] have moved. + * </p> + */ + public final float getScale() { return scale; } + + public final String toString() { + return "ZoomEvent[zoom "+zoom+", delta "+delta+", scale "+scale+", trigger "+getTrigger()+", handler "+getHandler()+"]"; + } } private final NativeSurface surface; @@ -198,12 +222,12 @@ 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 = dd / screenEdge; // [-1..1] + final float delta = 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)); + System.err.println("XXX3: d "+d+", ld "+zoomLastEdgeDist+", dd "+dd+", screen "+screenEdge+" -> incr "+delta+", zoom "+zoom+" -> "+(zoom+delta)); } - zoom += incr; + zoom += delta; // clip value if( 2f < zoom ) { zoom = 2f; @@ -211,7 +235,7 @@ public class PinchToZoomGesture implements GestureHandler { zoom = 0; } zoomLastEdgeDist = d; - zoomEvent = new ZoomEvent(pe.getSource(), pe.getWhen(), pe.getModifiers(), this, pe, zoom); + zoomEvent = new ZoomEvent(pe.getSource(), pe.getWhen(), pe.getModifiers(), this, pe, zoom, delta, screenEdge); } } } |