コード例 #1
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);
    }
  }
コード例 #2
0
  public void setCursorPosition(int x, int y) {
    try {
      // x,y corresponds to the location of the cursor's hotspot on the
      // screen
      // it can be anywhere in the screen area (but some part of the
      // cursor might not be visible)
      x = Math.min(Math.max(x, 0), graphics.getWidth() - 1);
      y = Math.min(Math.max(y, 0), graphics.getHeight() - 1);

      if ((cursorArea.getX() != x) || (cursorArea.getY() != y)) {
        hideCursor();

        if (cursorImage != null) {
          int newX = (int) (x - cursorImage.getHotSpotX());
          int newY = (int) (y - cursorImage.getHotSpotY());
          cursorArea.setLocation(newX, newY);
        } else {
          cursorArea.setLocation(x, y);
        }

        showCursor();
      }
    } catch (Throwable t) {
      Unsafe.debugStackTrace("error in setCursorPosition", t);
    }
  }
コード例 #3
0
  public void setBitmapGraphics(BitmapGraphics graphics) {
    if (this.graphics != graphics) {
      hideCursor();

      this.graphics = graphics;
      if (cursorImage != null) {
        int newHotspotX =
            (int) Math.min(graphics.getWidth() - 1, cursorArea.getX() + cursorImage.getHotSpotX());
        int newHotspotY =
            (int) Math.min(graphics.getHeight() - 1, cursorArea.getY() + cursorImage.getHotSpotY());
        cursorArea.setLocation(
            newHotspotX - cursorImage.getHotSpotX(), newHotspotY - cursorImage.getHotSpotY());
      }

      // TODO test when screen resolution is changing
      showCursor();
    }
  }