algonim
    Preparing search index...

    Class Drawer

    Draws onto a Region of a CanvasRenderingContext2D.

    Index

    Constructors

    • Constructs a new drawer from a raw rendering context. This is likely not what you want, if you're just making a sequence.

      The rationale for there being two different regions is that it's convenient for some algorithms to have a well-defined area for them to draw their graphic in. Passing the clipping region itself to such algorithms would cause unexpected results when the clipping region itself has to be clipped within a parent drawer.

      Parameters

      • context: CanvasRenderingContext2D

        The rendering context to draw onto.

      • region: Region

        Area for drawing, in canvas coordinates.

      • clipRegion: Region

        Area where drawing is actually visible, in canvas coordinates.

      • origin: Point = ...

        The place where (0, 0) is within the drawing region.

      Returns Drawer

      gfx/Border.EllipseBorder.draw for an example of something that would behave unexpectedly.

    Methods

    • Creates a sub-drawer that draws to the same context as this one, but clipped to a lesser or equal region.

      Parameters

      • region: Region

        Area where the resulting sub-drawer will draw, in the coordinates of the current drawer's region. The sub-drawer's clipping region will be constrained to the clipping region of this instance.

      Returns Drawer

      constructor for why there is a separate drawing and clipping region.

    • Draws a line through multiple points. Line drawing only takes place if the iterable yields at least two points.

      Parameters

      Returns void

    • Draws the head of an arrow at the end of the specified line.

      A full arrow can be drawn by calling drawLine with the same points.

      A two-headed arrow can be drawn by calling this again, but with the start and end points swapped.

      Parameters

      Returns void

    • getImageData, but only within the clipping region of this drawer.

      Parameters

      • Optionalsettings: ImageDataSettings

      Returns ImageData

    • Escape hatch that gives you direct access to the underlying CanvasRenderingContext2D.

      SAFETY: The drawing state stack MUST NOT be different after your function returns! This is to prevent future drawing operations from being affected.

      Parameters

      • fn: (ctx: CanvasRenderingContext2D) => void

      Returns void

    • Gets the underlying canvas rendering context. Prefer not using this, since it defeats the whole purpose of being able to draw with styles and clipping. Here be dragons!

      Returns CanvasRenderingContext2D