summaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/classes')
-rw-r--r--src/newt/classes/com/jogamp/newt/event/GestureHandler.java12
-rw-r--r--src/newt/classes/com/jogamp/newt/event/PinchToZoomGesture.java44
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);
}
}
}