import { Canvas } from "./canvas.js"; import type { Canvas2DHeadless } from "./canvas2d-headless.js"; /** * Construction options for a {@linkcode Canvas2D}. */ export interface Canvas2DOptions { /** * Was this {@linkcode Canvas2D} created with the ability to copy the front buffer back into * the back buffer? */ readonly supportReadBack: boolean; } /** * The {@linkcode Canvas2D} is a double-buffered construct to help with drawing to a * {@linkcode !HTMLCanvasElement} with best possible performance. * We utilize an {@linkcode !OffscreenCanvas} with a {@linkcode !OffscreenCanvasRenderingContext2D} * to draw frames and expect to render them back to the DOM in regular intervals. */ export declare class Canvas2D extends Canvas { #private; /** * Retrieves the rendering context of the canvas. * @returns The rendering context of the canvas. */ get context(): OffscreenCanvasRenderingContext2D; /** * Our back buffer. */ buffer: Uint8ClampedArray; /** * The configuration that was used for this canvas. */ readonly options: Readonly>; /** * Constructs a new {@linkcode Canvas2D}. * @param canvas - The canvas to wrap. * @param options - The configuration for this canvas. */ constructor(canvas: HTMLCanvasElement, options?: Partial); /** * Recreate internal buffers in reaction to a change in our target {@linkcode !HTMLCanvasElement}. */ refreshCanvasNode(): void; /** * Draw FPS information onto the canvas. * @param frameTimes - Durations of previous frame draws. * @param frameTime - The duration of the previous frame draw. * @param timeDelta - The time elapsed since the last frame. */ renderFpsInfo(frameTimes: Array, frameTime: number, timeDelta: number): void; /** * Draws the back buffer onto the canvas. */ update(): void; /** * Draws the offscreen canvas into the DOM canvas. */ render(): void; /** * Draws a slightly transparent, black rectangle over the canvas, * and then reads the result back into the buffer. * @param color - The color to fade the buffer with. The alpha component of * the color defines how strong the fade is. `0` is not at all, `255` makes * it instantly black. */ fade(color?: number): void; /** * Reads the front buffer back into the back buffer. */ bufferReadBack(): void; /** * Returns the color of a pixel in the back buffer. * @param x - The X coordinate to retrieve. * @param y - The X coordinate to retrieve. * @returns The color of the pixel at the given local. */ getPixel32(x: number, y: number): number; /** * Colors a pixel in the back buffer. * @param x - The X coordinate to color. * @param y - The Y coordinate to color. * @param color - The color to place at the coordinate. */ setPixel32(x: number, y: number, color: number): void; /** * Fills the entire back buffer with the given color. * @param color - The color to fill the back buffer with. */ clearWith(color: number): void; /** * Fills the entire back buffer with the given color. * @param color - The color to fill the back buffer with. */ blendWith(color: number): void; } /** * Linearly blends a new pixel with an existing color value in a canvas. * * As this method is often called many times in render loops, only bounds * checking is applied to the given coordinates. * * The coordinates are **expected to already be integers**. Supplying numbers with fractions * has performance implications. Ensure you're working with integers, or truncate the * coordinates before passing them in. * * The `alpha` value is expected to be an integer in the range from `0` to `255`. * `0` meaning fully transparent, `255` meaning fully opaque. * @param canvas - The canvas to interact with. * @param x - The X coordinate at which to place the pixel. * @param y - The Y coordinate at which to place the pixel. * @param color - The color of the pixel. * @param alpha - The alpha value to use to blend the pixel with existing color at the location. */ export declare const putPixel32: (canvas: Canvas2D | Canvas2DHeadless, x: number, y: number, color: number, alpha: number) => void; /** * Additively blends a new pixel with an existing color value in a canvas. * * As this method is often called many times in render loops, only bounds * checking is applied to the given coordinates. * * The coordinates are **expected to already be integers**. Supplying numbers with fractions * has performance implications. Ensure you're working with integers, or truncate the * coordinates before passing them in. * * The `alpha` value is expected to be an integer in the range from `0` to `255`. * `0` meaning fully transparent, `255` meaning fully opaque. * @param canvas - The canvas to interact with. * @param x - The X coordinate at which to place the pixel. * @param y - The Y coordinate at which to place the pixel. * @param color - The color of the pixel. * @param alpha - The alpha value to use to blend the pixel with existing color at the location. */ export declare const putPixel32Add: (canvas: Canvas2D | Canvas2DHeadless, x: number, y: number, color: number, alpha: number) => void; /** * Subtractively blends a new pixel with an existing color value in a canvas. * * As this method is often called many times in render loops, only bounds * checking is applied to the given coordinates. * * The coordinates are **expected to already be integers**. Supplying numbers with fractions * has performance implications. Ensure you're working with integers, or truncate the * coordinates before passing them in. * * The `alpha` value is expected to be an integer in the range from `0` to `255`. * `0` meaning fully transparent, `255` meaning fully opaque. * @param canvas - The canvas to interact with. * @param x - The X coordinate at which to place the pixel. * @param y - The Y coordinate at which to place the pixel. * @param color - The color of the pixel. * @param alpha - The alpha value to use to blend the pixel with existing color at the location. */ export declare const putPixel32Sub: (canvas: Canvas2D | Canvas2DHeadless, x: number, y: number, color: number, alpha: number) => void; /** * Linearly blends a new pixel with an existing color value in a canvas. * Compared to {@linkcode putPixel32}, this function supports sub-pixel placement, but is dramatically slower. * @param canvas - The canvas to interact with. * @param x - The X coordinate at which to place the pixel. * @param y - The Y coordinate at which to place the pixel. * @param color - The color of the pixel. * @param alpha - The alpha value to use to blend the pixel with existing color at the location. */ export declare const putSubPixel32: (canvas: Canvas2D | Canvas2DHeadless, x: number, y: number, color: number, alpha: number) => void;