Skip to content

Commit

Permalink
Initial support for multitouch zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
ujhelyiz committed Feb 9, 2012
1 parent 249a26a commit f2e8d91
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
}
}
});
}

/**
Expand Down

0 comments on commit f2e8d91

Please sign in to comment.