Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Canvas

The Canvas object holds an HTMLCanvasElement reference and its 2d context, registers resize observers and can initiate render of Drawing

Hierarchy

  • Canvas

Index

Constructors

  • new Canvas(element?: HTMLCanvasElement | HTMLDivElement, width?: number, height?: number): Canvas
  • If no parameters are passed then a new canvas will be created and appended to <body>

    Parameters

    • Optional element: HTMLCanvasElement | HTMLDivElement

      Reference to an html <canvas> or <div> element, if a <div> element is passed, then a canvas will be created and appended

    • Optional width: number

      Passing a width will overwrite previously defined canvas width

    • Optional height: number

      Passing a height will overwrite previously defined canvas height

    Returns Canvas

Properties

canvasElement: HTMLCanvasElement

Reference to the bound <canvas> element

context: CanvasRenderingContext2D
currDrawing: Drawing

Drawing that is currently being rendered or paused

isCanvasCreated: boolean = false
offCanvasElement: HTMLCanvasElement | OffscreenCanvas

Reference to the created OffscreenCanvas used as hit-maps (if not supported, another <canvas> will be created)

offContext: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D

Accessors

  • get height(): number
  • get width(): number

Methods

  • dispose(): void
  • Stops rendering current drawing (see Canvas.currDrawing) (if any) and starts the one passed as argument

    Parameters

    • drawing: Drawing

      A Drawing object, which will be rendered by this canvas

    Returns void

  • resume(): void
  • stop(): void