Gleam - v1.0.2
    Preparing search index...

    Class CanvasManager

    Tracks registered canvases and exposes the main 2D context. The width/height accessors and size getter all refer to the buffer dimensions (the canvas's width/height attributes — drawing-space pixels), while resizedSize and ratio describe the display size after CSS scaling.

    Owned by Game (game.canman). Lifecycle: subclass registers canvases via setupCanvas in its constructor, then preInit() calls finishSetup.

    Index

    Constructors

    Properties

    canvasBoundingClientRect: DOMRect

    Cached getBoundingClientRect() of the main canvas. Refreshed in resize. Used to map pointer client coords into canvas space.

    canvasHolder: Record<string, CanvasHolder> = {}

    Registry of every setupCanvas-registered canvas, keyed by selector.

    ratio: number = 1

    Display-to-buffer scale factor after the last resize (displayWidth / bufferWidth). 1 until the first resize.

    resizedSize: Vec2 = ...

    Display (CSS-pixel) size of the main canvas after the last resize. Independent of the buffer dimensions in width/height.

    Accessors

    • get canvas(): HTMLCanvasElement

      Main canvas element (the one registered with CANVAS_TYPES.MAIN).

      Returns HTMLCanvasElement

    • get canvasContext(): CanvasRenderingContext2D

      Main canvas 2D rendering context.

      Returns CanvasRenderingContext2D

    • get height(): number

      Main canvas buffer height (the drawing surface, not the CSS display size).

      Returns number

    • set height(height: number): void

      Main canvas buffer height (the drawing surface, not the CSS display size).

      Parameters

      • height: number

      Returns void

    • get width(): number

      Main canvas buffer width (the drawing surface, not the CSS display size).

      Returns number

    • set width(width: number): void

      Main canvas buffer width (the drawing surface, not the CSS display size).

      Parameters

      • width: number

      Returns void

    Methods

    • Finalize the canvas registry. Called once by Game.preInit(). Validates that exactly one CANVAS_TYPES.MAIN canvas is registered and that its buffer is non-zero, caches its bounding rect, and wires the "resized" listener if Settings.enableResize. Throws on duplicate calls or invalid registry state.

      Returns void

    • Rescale every opt-in canvas (holder.resize === true) to fit the window while preserving its buffer aspect ratio. Updates style.width/style.height only — buffer dimensions don't change. Refreshes canvasBoundingClientRect, resizedSize, and ratio from the main canvas.

      Returns void

    • Set the main context's font to ${size}px "${font}". Defaults the family to Settings.font.

      Parameters

      • size: number
      • font: string = Settings.font

      Returns void

    • Register a canvas at selector with the given role tag. Initializes its context (fillStyle/strokeStyle = white, font = 12px Arial) and returns the CanvasHolder. resize defaults to Settings.enableResize. Throws if the selector doesn't match an element or has already been registered.

      Parameters

      • canvasType: symbol
      • selector: string
      • resize: boolean = Settings.enableResize

      Returns CanvasHolder