示例#1
0
文件: VncCanvas.java 项目: mzhou/bVNC
  /**
   * Pan by a number of pixels (relative pan)
   *
   * @param dX
   * @param dY
   * @return True if the pan changed the view (did not move view out of bounds); false otherwise
   */
  boolean pan(int dX, int dY) {

    // We only pan if the current scaling is able to pan.
    if (scaling != null && !scaling.isAbleToPan()) return false;

    double scale = getScale();

    double sX = (double) dX / scale;
    double sY = (double) dY / scale;

    if (absoluteXPosition + sX < 0)
      // dX = diff to 0
      sX = -absoluteXPosition;
    if (absoluteYPosition + sY < 0) sY = -absoluteYPosition;

    // Prevent panning right or below desktop image
    if (absoluteXPosition + getVisibleWidth() + sX > getImageWidth())
      sX = getImageWidth() - getVisibleWidth() - absoluteXPosition;
    if (absoluteYPosition + getVisibleHeight() + sY > getImageHeight())
      sY = getImageHeight() - getVisibleHeight() - absoluteYPosition;

    absoluteXPosition += sX;
    absoluteYPosition += sY;
    if (sX != 0.0 || sY != 0.0) {
      // scrollBy((int)sX, (int)sY);
      scrollToAbsolute();
      return true;
    }
    return false;
  }
示例#2
0
文件: VncCanvas.java 项目: mzhou/bVNC
  /** Make sure mouse is visible on displayable part of screen */
  public void panToMouse() {
    if (rfbconn == null) return;

    boolean panX = true;
    boolean panY = true;

    // Don't pan in a certain direction if dimension scaled is already less
    // than the dimension of the visible part of the screen.
    if (rfbconn.framebufferWidth() <= getVisibleWidth()) panX = false;
    if (rfbconn.framebufferHeight() <= getVisibleHeight()) panY = false;

    // We only pan if the current scaling is able to pan.
    if (scaling != null && !scaling.isAbleToPan()) return;

    int x = pointer.getX();
    int y = pointer.getY();
    boolean panned = false;
    int w = getVisibleWidth();
    int h = getVisibleHeight();
    int iw = getImageWidth();
    int ih = getImageHeight();
    int wthresh = 30;
    int hthresh = 30;

    int newX = absoluteXPosition;
    int newY = absoluteYPosition;

    if (x - absoluteXPosition >= w - wthresh) {
      newX = x - (w - wthresh);
      if (newX + w > iw) newX = iw - w;
    } else if (x < absoluteXPosition + wthresh) {
      newX = x - wthresh;
      if (newX < 0) newX = 0;
    }
    if (panX && newX != absoluteXPosition) {
      absoluteXPosition = newX;
      panned = true;
    }

    if (y - absoluteYPosition >= h - hthresh) {
      newY = y - (h - hthresh);
      if (newY + h > ih) newY = ih - h;
    } else if (y < absoluteYPosition + hthresh) {
      newY = y - hthresh;
      if (newY < 0) newY = 0;
    }
    if (panY && newY != absoluteYPosition) {
      absoluteYPosition = newY;
      panned = true;
    }

    if (panned) {
      // scrollBy(newX - absoluteXPosition, newY - absoluteYPosition);
      scrollToAbsolute();
    }
  }