/** applies the next step in the pan-zoom animation, if any */ private void stepPanZoomAnimation() { if (zoomPanAnimationEndTime == 0) return; long now = System.currentTimeMillis(); if (now >= zoomPanAnimationEndTime) { zoom = zoomTo; drawOffset.x = panTo.x; drawOffset.y = panTo.y; stopPanZoomAnimation(); } else { long duration = zoomPanAnimationEndTime - zoomPanAnimationStartTime; long diff = zoomPanAnimationEndTime - now; float alpha = (float) Math.pow(diff / (float) duration, zoomPanAnimationInterpolationPower); float beta = 1.0f - alpha; zoom = (zoomFrom * alpha) + (zoomTo * beta); drawOffset.x = (int) ((panFrom.x * alpha) + (panTo.x * beta)); drawOffset.y = (int) ((panFrom.y * alpha) + (panTo.y * beta)); } }
/** * Starts a pan-zoom animation. * * @param toX what x coordinate to zoom to * @param toY what y coordinate to zoom to * @param zoomTo the new zoom factor * @param duration_msec how long to animate * @param zoomPanAnimationInterpolationPower 1 means a linear interpolation will be done between * the two animation endpoints. 2 would be quadratic, etc. A higher the number causes a faster * beginning and a slower and smoother the ending. */ public void startPanZoomAnimation( int toX, int toY, float zoomTo, long duration_msec, float zoomPanAnimationInterpolationPower) { this.zoomTo = zoomTo; this.panTo = new Vector2i(toX, toY); this.panFrom = drawOffset.clone(); this.zoomFrom = zoom; this.zoomPanAnimationStartTime = System.currentTimeMillis(); this.zoomPanAnimationEndTime = System.currentTimeMillis() + duration_msec; this.zoomPanAnimationInterpolationPower = zoomPanAnimationInterpolationPower; }
/** set the pan in progress to the specified amount */ public void setPanInProgress(int x, int y) { drawOffsetExtra.set(x, y); }
/** reset the pan to the origin and zoom to 1.0 */ public void resetView() { drawOffset.set(0, 0); setZoom(1.0f); }
/** pan up by the standard amount */ public void panUp() { drawOffset.y -= getHeight() / (DEFAULT_PAN_DIVISOR * zoom); }
/** apply the pan in progress */ public void applyPanInProgress() { drawOffset.add(drawOffsetExtra); drawOffsetExtra.set(0, 0); }
/** pan down by the standard amount */ public void panDown() { drawOffset.y += getHeight() / (DEFAULT_PAN_DIVISOR * zoom); }
/** pan right by the standard amount */ public void panRight() { drawOffset.x += getWidth() / (DEFAULT_PAN_DIVISOR * zoom); }
/** pan left by the standard amount */ public void panLeft() { drawOffset.x -= getWidth() / (DEFAULT_PAN_DIVISOR * zoom); }
/** set the aggregate y-axis pan */ public void setPanY(int y) { drawOffset.y = y; }
/** set the aggregate x-axis pan */ public void setPanX(int x) { drawOffset.x = x; }