Ejemplo n.º 1
0
  private void showCursor() {
    if (cursorImage != null) {
      if (screenBackup == null) {
        screenBackup = new int[cursorImage.getWidth() * cursorImage.getHeight()];
      }

      // screenBackup = graphics.doGetPixels(cursorArea);
      final int cursorX = (int) cursorArea.getX();
      final int cursorY = (int) cursorArea.getY();
      final int maxY = Math.min(cursorY + cursorImage.getHeight(), graphics.getHeight());
      final int maxX = Math.min(cursorX + cursorImage.getWidth(), graphics.getWidth());
      final int width = cursorImage.getWidth();

      int index = 0;
      for (int y = cursorY; y < maxY; y++) {
        int lineIndex = index;
        for (int x = cursorX; x < maxX; x++) {
          screenBackup[lineIndex] = graphics.doGetPixel(x, y);
          lineIndex++;
        }

        index += width;
      }

      putPixels(cursorImage.getImage(), screenBackup);
    }
  }
Ejemplo n.º 2
0
  private void putPixels(int[] pixels, int[] background) {
    final int cursorX = (int) cursorArea.getX();
    final int cursorY = (int) cursorArea.getY();
    final int maxY = Math.min(cursorY + cursorImage.getHeight(), graphics.getHeight());
    final int maxX = Math.min(cursorX + cursorImage.getWidth(), graphics.getWidth());
    final int width = cursorImage.getWidth();

    int index = 0;
    for (int y = cursorY; y < maxY; y++) {
      int lineIndex = index;
      for (int x = cursorX; x < maxX; x++) {
        int color;
        if (background == null) {
          color = pixels[lineIndex];
        } else {
          final int c = pixels[lineIndex];
          final boolean isTransparent = (c == 0);
          color = isTransparent ? background[lineIndex] : c;
        }

        graphics.drawPixels(x, y, 1, color, Surface.PAINT_MODE);
        lineIndex++;
      }

      index += width;
    }
  }
Ejemplo n.º 3
0
  public void setCursorImage(HardwareCursor cursor) {
    if (cursor == null) {
      return;
    }

    try {
      final HardwareCursorImage cursImage = cursor.getImage(20, 20);

      if ((cursImage != null) && (this.cursorImage != cursImage)) {
        hideCursor();

        cursorArea.setSize(cursImage.getWidth(), cursImage.getHeight());
        if (cursorImage != null) {
          int newX =
              (int) (cursorArea.getX() + cursorImage.getHotSpotX() - cursImage.getHotSpotX());
          int newY =
              (int) (cursorArea.getY() + cursorImage.getHotSpotY() - cursImage.getHotSpotY());
          cursorArea.setLocation(newX, newY);
        }
        this.cursorImage = cursImage;

        showCursor();
      }
    } catch (Throwable t) {
      Unsafe.debugStackTrace("error in setCursorImage (" + t.getClass().getName() + ")", t);
    }
  }