use of org.scijava.vecmath.Point2f in project TrakEM2 by trakem2.
the class DisplayCanvas method animateBrowsing.
/**
* Smoothly move the canvas from x0,y0,layer0 to x1,y1,layer1
*/
protected void animateBrowsing(final int dx, final int dy) {
// check preconditions
final float mag = (float) this.magnification;
final Rectangle startSrcRect = (Rectangle) this.srcRect.clone();
// The motion will be displaced by some screen pixels at every time step.
final Vector2f v = new Vector2f(dx, dy);
final float sqdist_to_travel = v.lengthSquared();
v.normalize();
v.scale(20 / mag);
// the current deltas
final Point2f cp = new Point2f(0, 0);
//
final ScheduledFuture<?>[] sf = new ScheduledFuture[1];
sf[0] = animate(new Runnable() {
@Override
public void run() {
cp.add(v);
// Utils.log2("advanced by x,y = " + cp.x + ", " + cp.y);
int x, y;
if (v.lengthSquared() >= sqdist_to_travel) {
// set target position
x = startSrcRect.x + dx;
y = startSrcRect.y + dy;
// quit animation
cancelAnimation(sf[0]);
} else {
// set position
x = startSrcRect.x + (int) (cp.x);
y = startSrcRect.y + (int) (cp.y);
}
setSrcRect(x, y, startSrcRect.width, startSrcRect.height);
display.repaintAll2();
}
}, 0, 50, TimeUnit.MILLISECONDS);
}
Aggregations