Class MouseCursor

All Implemented Interfaces:
IRenderable

public final class MouseCursor extends Object implements IRenderable

The visual representation of the Mouse in the LITIENGINE.

It controls the appearance of the rendered cursor and allows to specify offsets from the actual mouse location.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes a new instance of the MouseCursor class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the image currently used to render the cursor.
    int
    Gets the horizontal pixel offset from the actual mouse location to the rendered cursor.
    int
    Gets the vertical pixel offset from the actual mouse location to the rendered cursor.
    Gets the affine transform applied to the cursor image when it is rendered.
    void
    Hides the native system cursor by replacing it with an empty cursor on the game window.
    boolean
    Determines whether the cursor is currently visible (and will thereby be rendered), by checking the visible flag and whether the specified cursor image is null.
    void
    Renders the visual contents of this instance onto the provided graphics context.
    void
    set(Image img)
    Sets the cursor image, anchored at its top-left corner.
    void
    set(Image img, int offsetX, int offsetY)
    Sets the cursor image with the supplied pixel offsets.
    void
    set(Image img, Align hAlign, Valign vAlign)
    Sets the cursor image, computing the pixel offset so that the supplied alignment is anchored to the actual mouse location.
    void
    setOffset(int x, int y)
    Sets the cursor offsets.
    void
    setOffsetX(int cursorOffsetX)
    Sets the horizontal cursor offset.
    void
    setOffsetY(int cursorOffsetY)
    Sets the vertical cursor offset.
    void
    Sets the affine transform applied to the cursor image when it is rendered.
    void
    setVisible(boolean visible)
    Sets whether the cursor is visible.
    void
    Restores the native system cursor on the game window.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MouseCursor

      public MouseCursor()
      Initializes a new instance of the MouseCursor class.
  • Method Details

    • render

      public void render(Graphics2D g)
      Description copied from interface: IRenderable

      Renders the visual contents of this instance onto the provided graphics context.

      If an Entity implements this interface, this method will be called right after the entity was rendered from the environment. Allowing for a custom rendering mechanism.

      This interface can be implemented in general by anything that should be rendered to the game's screen.

      Specified by:
      render in interface IRenderable
      Parameters:
      g - The current graphics object onto which this instance will render its visual contents.
      See Also:
    • getImage

      public Image getImage()
      Gets the image currently used to render the cursor.
      Returns:
      the cursor image, or null if none is set
    • getTransform

      public AffineTransform getTransform()
      Gets the affine transform applied to the cursor image when it is rendered.
      Returns:
      the cursor transform
    • getOffsetX

      public int getOffsetX()
      Gets the horizontal pixel offset from the actual mouse location to the rendered cursor.
      Returns:
      the horizontal offset
    • getOffsetY

      public int getOffsetY()
      Gets the vertical pixel offset from the actual mouse location to the rendered cursor.
      Returns:
      the vertical offset
    • isVisible

      public boolean isVisible()
      Determines whether the cursor is currently visible (and will thereby be rendered), by checking the visible flag and whether the specified cursor image is null.
      Returns:
      True if the cursor is currently visible; otherwise false.
    • set

      public void set(Image img)
      Sets the cursor image, anchored at its top-left corner.
      Parameters:
      img - the cursor image
    • set

      public void set(Image img, int offsetX, int offsetY)
      Sets the cursor image with the supplied pixel offsets. If a non-null image is set, the native system cursor is hidden; otherwise it is restored (unless the mouse is grabbed).
      Parameters:
      img - the cursor image; may be null to clear the cursor
      offsetX - the horizontal offset
      offsetY - the vertical offset
    • set

      public void set(Image img, Align hAlign, Valign vAlign)
      Sets the cursor image, computing the pixel offset so that the supplied alignment is anchored to the actual mouse location.
      Parameters:
      img - the cursor image
      hAlign - the horizontal alignment of the anchor
      vAlign - the vertical alignment of the anchor
    • setOffset

      public void setOffset(int x, int y)
      Sets the cursor offsets.
      Parameters:
      x - the horizontal offset
      y - the vertical offset
    • setOffsetX

      public void setOffsetX(int cursorOffsetX)
      Sets the horizontal cursor offset.
      Parameters:
      cursorOffsetX - the horizontal offset
    • setOffsetY

      public void setOffsetY(int cursorOffsetY)
      Sets the vertical cursor offset.
      Parameters:
      cursorOffsetY - the vertical offset
    • setTransform

      public void setTransform(AffineTransform transform)
      Sets the affine transform applied to the cursor image when it is rendered.
      Parameters:
      transform - the transform
    • setVisible

      public void setVisible(boolean visible)
      Sets whether the cursor is visible.
      Parameters:
      visible - true to show the cursor
    • showDefaultCursor

      public void showDefaultCursor()
      Restores the native system cursor on the game window.
    • hideDefaultCursor

      public void hideDefaultCursor()
      Hides the native system cursor by replacing it with an empty cursor on the game window.