private void limitPan() {
    final float aspectQuotient = mAspectQuotient.get();

    final float zoomX = mState.getZoomX(aspectQuotient);
    final float zoomY = mState.getZoomY(aspectQuotient);

    final float panMinX = .5f - getMaxPanDelta(zoomX);
    final float panMaxX = .5f + getMaxPanDelta(zoomX);
    final float panMinY = .5f - getMaxPanDelta(zoomY);
    final float panMaxY = .5f + getMaxPanDelta(zoomY);

    if (mState.getPanX() > panMaxX) {
      mState.setPanX(panMaxX);
    }

    if (mState.getPanX() < panMinX) {
      mState.setPanX(panMinX);
    }

    if (mState.getPanY() > panMaxY) {
      mState.setPanY(panMaxY);
    }

    if (mState.getPanY() < panMinY) {
      mState.setPanY(panMinY);
    }
  }
  public void pan(float dx, float dy) {
    final float aspectQuotient = mAspectQuotient.get();

    mState.setPanX(mState.getPanX() + dx / mState.getZoomX(aspectQuotient));
    mState.setPanY(mState.getPanY() + dy / mState.getZoomY(aspectQuotient));

    limitPan();

    mState.notifyObservers();
  }
  public void zoom(float f, float x, float y) {
    final float aspectQuotient = mAspectQuotient.get();

    final float prevZoomX = mState.getZoomX(aspectQuotient);
    final float prevZoomY = mState.getZoomY(aspectQuotient);

    mState.setZoom(mState.getZoom() * f);
    limitZoom();

    final float newZoomX = mState.getZoomX(aspectQuotient);
    final float newZoomY = mState.getZoomY(aspectQuotient);

    mState.setPanX(mState.getPanX() + (x - .5f) * (1f / prevZoomX - 1f / newZoomX));
    mState.setPanY(mState.getPanY() + (y - .5f) * (1f / prevZoomY - 1f / newZoomY));

    limitPan();

    mState.notifyObservers();
  }
Esempio n. 4
0
 private void resetZoomState() {
   mZoomState.setPanX(0.5f);
   mZoomState.setPanY(0.5f);
   mZoomState.setZoom(1f);
   mZoomState.notifyObservers();
 }