cooja: plugins/Visualizer: Implemented mouse wheel zooming with mouse coordinates as center
This commit is contained in:
parent
a1cd642e6e
commit
80b78ae6dd
|
@ -56,6 +56,8 @@ import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseMotionListener;
|
import java.awt.event.MouseMotionListener;
|
||||||
|
import java.awt.event.MouseWheelEvent;
|
||||||
|
import java.awt.event.MouseWheelListener;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -412,6 +414,20 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
canvas.addMouseWheelListener(new MouseWheelListener() {
|
||||||
|
public void mouseWheelMoved(MouseWheelEvent mwe) {
|
||||||
|
int x = mwe.getX();
|
||||||
|
int y = mwe.getY();
|
||||||
|
int rot = mwe.getWheelRotation();
|
||||||
|
|
||||||
|
if (rot > 0) {
|
||||||
|
zoomToFactor(zoomFactor() / 1.2, new Point(x, y));
|
||||||
|
} else {
|
||||||
|
zoomToFactor(zoomFactor() * 1.2, new Point(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/* Register mote menu actions */
|
/* Register mote menu actions */
|
||||||
registerMoteMenuAction(MoveMoteMenuAction.class);
|
registerMoteMenuAction(MoveMoteMenuAction.class);
|
||||||
|
@ -855,16 +871,16 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void zoomToFactor(double newZoom) {
|
private void zoomToFactor(double newZoom) {
|
||||||
Position center = transformPixelToPosition(
|
zoomToFactor(newZoom, new Point(canvas.getWidth()/2, canvas.getHeight()/2));
|
||||||
new Point(canvas.getWidth()/2, canvas.getHeight()/2)
|
}
|
||||||
);
|
|
||||||
|
private void zoomToFactor(double newZoom, Point zoomCenter) {
|
||||||
|
Position center = transformPixelToPosition(zoomCenter);
|
||||||
viewportTransform.setToScale(
|
viewportTransform.setToScale(
|
||||||
newZoom,
|
newZoom,
|
||||||
newZoom
|
newZoom
|
||||||
);
|
);
|
||||||
Position newCenter = transformPixelToPosition(
|
Position newCenter = transformPixelToPosition(zoomCenter);
|
||||||
new Point(canvas.getWidth()/2, canvas.getHeight()/2)
|
|
||||||
);
|
|
||||||
viewportTransform.translate(
|
viewportTransform.translate(
|
||||||
newCenter.getXCoordinate() - center.getXCoordinate(),
|
newCenter.getXCoordinate() - center.getXCoordinate(),
|
||||||
newCenter.getYCoordinate() - center.getYCoordinate()
|
newCenter.getYCoordinate() - center.getYCoordinate()
|
||||||
|
|
Loading…
Reference in a new issue