Пример #1
0
  /**
   * 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
  /** 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();
    }
  }
Пример #3
0
 /* (non-Javadoc)
  * @see com.iiordanov.bVNC.AbstractScaling#setScaleTypeForActivity(com.iiordanov.bVNC.VncCanvasActivity)
  */
 @Override
 void setScaleTypeForActivity(RemoteCanvasActivity activity) {
   super.setScaleTypeForActivity(activity);
   RemoteCanvas canvas = activity.getCanvas();
   canvasXOffset = -canvas.getCenteredXOffset();
   canvasYOffset = -canvas.getCenteredYOffset();
   canvas.computeShiftFromFullToView();
   scaling = 1;
   resetMatrix();
   matrix.postScale(scaling, scaling);
   canvas.setImageMatrix(matrix);
   resolveZoom(canvas);
   // activity.vncCanvas.pan(0, 0);
   activity.zoomer.setIsZoomOutEnabled(false);
   activity.zoomer.setIsZoomInEnabled(false);
 }
 /**
  * Set modes on start to match what is specified in the ConnectionBean; color mode (already done)
  * scaling, input mode
  */
 void setModes() {
   AbstractInputHandler handler = getInputHandlerByName(connection.getInputMode());
   AbstractScaling.getByScaleType(connection.getScaleMode()).setScaleTypeForActivity(this);
   this.inputHandler = handler;
   showPanningState(false);
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    canvas.getKeyboard().setAfterMenu(true);
    switch (item.getItemId()) {
      case R.id.itemInfo:
        canvas.showConnectionInfo();
        return true;
      case R.id.itemSpecialKeys:
        showDialog(R.layout.metakey);
        return true;
      case R.id.itemColorMode:
        selectColorModel();
        return true;
        // Following sets one of the scaling options
      case R.id.itemZoomable:
      case R.id.itemOneToOne:
      case R.id.itemFitToScreen:
        AbstractScaling.getById(item.getItemId()).setScaleTypeForActivity(this);
        item.setChecked(true);
        showPanningState(false);
        return true;
      case R.id.itemCenterMouse:
        canvas
            .getPointer()
            .warpMouse(
                canvas.absoluteXPosition + canvas.getVisibleWidth() / 2,
                canvas.absoluteYPosition + canvas.getVisibleHeight() / 2);
        return true;
      case R.id.itemDisconnect:
        canvas.closeConnection();
        finish();
        return true;
      case R.id.itemEnterText:
        showDialog(R.layout.entertext);
        return true;
      case R.id.itemCtrlAltDel:
        canvas.getKeyboard().sendMetaKey(MetaKeyBean.keyCtrlAltDel);
        return true;
        /*        case R.id.itemFollowMouse:
                    boolean newFollow = !connection.getFollowMouse();
                    item.setChecked(newFollow);
                    connection.setFollowMouse(newFollow);
                    if (newFollow) {
                        vncCanvas.panToMouse();
                    }
                    connection.save(database.getWritableDatabase());
                    database.close();
                    return true;
                case R.id.itemFollowPan:
                    boolean newFollowPan = !connection.getFollowPan();
                    item.setChecked(newFollowPan);
                    connection.setFollowPan(newFollowPan);
                    connection.save(database.getWritableDatabase());
                    database.close();
                    return true;

                case R.id.itemArrowLeft:
                    vncCanvas.sendMetaKey(MetaKeyBean.keyArrowLeft);
                    return true;
                case R.id.itemArrowUp:
                    vncCanvas.sendMetaKey(MetaKeyBean.keyArrowUp);
                    return true;
                case R.id.itemArrowRight:
                    vncCanvas.sendMetaKey(MetaKeyBean.keyArrowRight);
                    return true;
                case R.id.itemArrowDown:
                    vncCanvas.sendMetaKey(MetaKeyBean.keyArrowDown);
                    return true;
        */
      case R.id.itemSendKeyAgain:
        sendSpecialKeyAgain();
        return true;
        // Disabling Manual/Wiki Menu item as the original does not correspond to this project
        // anymore.
        // case R.id.itemOpenDoc:
        //    Utils.showDocumentation(this);
        //    return true;
      case R.id.itemExtraKeys:
        if (connection.getExtraKeysToggleType() == Constants.EXTRA_KEYS_ON) {
          connection.setExtraKeysToggleType(Constants.EXTRA_KEYS_OFF);
          item.setTitle(R.string.extra_keys_enable);
          setExtraKeysVisibility(View.GONE, false);
        } else {
          connection.setExtraKeysToggleType(Constants.EXTRA_KEYS_ON);
          item.setTitle(R.string.extra_keys_disable);
          setExtraKeysVisibility(View.VISIBLE, false);
          extraKeysHidden = false;
        }
        setKeyStowDrawableAndVisibility();
        connection.save(database.getWritableDatabase());
        database.close();
        return true;
      case R.id.itemHelpInputMode:
        showDialog(R.id.itemHelpInputMode);
        return true;
      default:
        AbstractInputHandler input = getInputHandlerById(item.getItemId());
        if (input != null) {
          inputHandler = input;
          connection.setInputMode(input.getName());
          if (input.getName().equals(SimulatedTouchpadInputHandler.TOUCHPAD_MODE)) {
            connection.setFollowMouse(true);
            connection.setFollowPan(true);
          } else {
            connection.setFollowMouse(false);
            connection.setFollowPan(false);
          }

          item.setChecked(true);
          showPanningState(true);
          connection.save(database.getWritableDatabase());
          database.close();
          return true;
        }
    }
    return super.onOptionsItemSelected(item);
  }
Пример #6
0
 float getScale() {
   if (scaling == null) return 1;
   return scaling.getScale();
 }