From f2e8d919f0c026e1ce81e54fd612368f088999a1 Mon Sep 17 00:00:00 2001 From: Zoltan Ujhelyi Date: Thu, 9 Feb 2012 23:22:39 +0100 Subject: [PATCH] Initial support for multitouch zoom --- .../org/eclipse/zest/core/widgets/Graph.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java b/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java index 2189a78f7..60d4f34dd 100644 --- a/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java +++ b/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java @@ -39,6 +39,8 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.events.GestureEvent; +import org.eclipse.swt.events.GestureListener; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.events.SelectionAdapter; @@ -61,6 +63,8 @@ */ public class Graph extends FigureCanvas implements IContainer { + private static final double MINIMUM_ZOOM = 0.1; + private static final double MAXIMUM_ZOOM = 10.0; // CLASS CONSTANTS public static final int ANIMATION_TIME = 500; public static final int FISHEYE_ANIMATION_TIME = 100; @@ -197,6 +201,29 @@ public void controlMoved(ControlEvent e) { // do nothing } }); + this.addGestureListener(new GestureListener() { + + double zoom = 1.0; + + public void gesture(GestureEvent e) { + switch (e.detail) { + case SWT.GESTURE_BEGIN: + zoom = getRootLayer().getScale(); + break; + case SWT.GESTURE_END: + break; + case SWT.GESTURE_MAGNIFY: + double newValue = zoom * e.magnification; + if (newValue >= MINIMUM_ZOOM && newValue <= MAXIMUM_ZOOM) { + getRootLayer().setScale(newValue); + getRootLayer().repaint(); + } + break; + default: + // Do nothing + } + } + }); } /**