Search in sources :

Example 1 with Point2f

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);
}
Also used : Point2f(org.scijava.vecmath.Point2f) Vector2f(org.scijava.vecmath.Vector2f) Rectangle(java.awt.Rectangle) ScheduledFuture(java.util.concurrent.ScheduledFuture) Point(java.awt.Point)

Aggregations

Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 Point2f (org.scijava.vecmath.Point2f)1 Vector2f (org.scijava.vecmath.Vector2f)1