@kayahr/wastelib
    Preparing search index...

    Class Cursor

    Container for a single mouse cursor image.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    height: number

    The image height in pixels.

    width: number

    The image width in pixels.

    Methods

    • Draws the image onto the given rendering context.

      Parameters

      • ctx: CanvasContext2DLike

        The rendering context to draw the image to.

      • x: number = 0

        Optional horizontal target position. Defaults to 0.

      • y: number = 0

        Optional vertical target position. Defaults to 0.

      Returns void

    • Returns the RGBA color at the specified position.

      Parameters

      • x: number

        The horizontal pixel position.

      • y: number

        The vertical pixel position.

      Returns number

      The RGBA color at the specified position.

      RangeError if coordinates are outside of the image boundaries.

    • Resets the given canvas to the image size and fills the canvas with the image. This does not create a new canvas so any canvas implementation can be used and existing canvas objects can be re-used.

      In a browser you do this:

      const canvas = image.toCanvas(document.createElement("canvas"))`;
      

      In Node.js (with node-canvas) you do this:

      import { createCanvas} from "canvas";

      const canvas = image.toCanvas(createCanvas());

      Type Parameters

      Parameters

      • canvas: T

        The canvas to reset and fill.

      Returns T

      The passed canvas for method chaining.