Example #1
0
  /**
   * Builds an image data that is based on the released image but has the pressed/enter key area
   * painted with data from the pressed/enter image
   *
   * @param key The pressed key
   * @param isEnter Whether the image being retrieved will be used for enter or pressed
   * @return An image data built the way described at method description
   */
  private ImageData getKeyImageData(IAndroidKey key, boolean isEnter) {

    ImageData resultingImage;
    ImageData releasedImage = getImageData(false, false);
    ImageData keyImage = isEnter ? getImageData(false, true) : getImageData(true, false);

    resultingImage = (ImageData) releasedImage.clone();

    Rectangle keyArea = key.getKeyArea();
    int resultingImageSize = resultingImage.width * keyArea.height;
    int[] keyPixelBuffer = new int[resultingImageSize];

    int startY = keyArea.y < 0 ? 0 : keyArea.y;

    keyImage.getPixels(0, startY, resultingImageSize, keyPixelBuffer, 0);

    for (int line = 0; line < keyArea.height; line++) {
      int pos = (line * resultingImage.width) + Math.abs(keyArea.x);
      int startX = Math.abs(keyArea.x);
      startY = (keyArea.y < 0 ? 0 : keyArea.y) + line;
      if (startY < 0) {
        continue;
      }

      int putWidth = keyArea.x < 0 ? keyArea.width - startX : keyArea.width;
      resultingImage.setPixels(startX, startY, putWidth, keyPixelBuffer, pos);
    }

    return resultingImage;
  }
Example #2
0
  /**
   * Performs the skin draw operation.
   *
   * @param gcUsedToDraw The gc object associated with the skin composite that is used to draw the
   *     images
   */
  private void drawSkin(GC gcUsedToDraw, IAndroidKey changedKey) {
    if (currentSkinImage == null) {
      IAndroidEmulatorInstance instance = UIHelper.getInstanceAssociatedToControl(this);
      ImageData initialSkinImage = getImageData(false, false);
      setSkinImage(initialSkinImage, null, false);
      applyLayout(instance.getCurrentLayout());

      if (scrollBarsUsed) {
        synchronizeScrollBars();
      }
    }

    if (displayRectangle != null) {
      int srcXPos, srcYPos, srcWidth, srcHeight;
      int destXPos, destYPos, destWidth, destHeight;
      if (changedKey == null) {
        srcXPos = displayRectangle.x;
        srcYPos = displayRectangle.y;
        srcWidth = displayRectangle.width;
        srcHeight = displayRectangle.height;
        destXPos = 0;
        destYPos = 0;
        destWidth = Math.min(currentSkinImage.getImageData().width, displayRectangle.width);
        destHeight = Math.min(currentSkinImage.getImageData().height, displayRectangle.height);
      } else {
        srcXPos =
            ((int) (changedKey.getKeyArea().x > 0 ? changedKey.getKeyArea().x * zoomFactor : 0));
        srcYPos =
            ((int) (changedKey.getKeyArea().y > 0 ? changedKey.getKeyArea().y * zoomFactor : 0));
        srcWidth = ((int) (changedKey.getKeyArea().width * zoomFactor));
        srcHeight = ((int) (changedKey.getKeyArea().height * zoomFactor));
        destXPos = srcXPos - displayRectangle.x;
        destYPos = srcYPos - displayRectangle.y;
        destWidth = srcWidth;
        destHeight = srcHeight;
      }

      gcUsedToDraw.drawImage(
          currentSkinImage,
          srcXPos,
          srcYPos,
          srcWidth,
          srcHeight,
          destXPos,
          destYPos,
          destWidth,
          destHeight);
    }
  }