UNPKG

gl2d

Version:

2D graphics package for WebGL

127 lines (126 loc) 5.19 kB
import { SurfaceMouseEvent } from '../event/mouse'; import { ScreenPoint } from '../event/screenpoint'; import { SurfaceWheelEvent } from '../event/scroll'; import { SurfaceTouchEvent } from '../event/touch'; import { Point, PointLike } from '../struct/point'; import { Vec2 } from '../struct/vec2'; import { Renderer } from './renderer'; /** * A rendering surface linked to an HTMLCanvasElement (the drawing buffer). */ export declare class Surface<R extends Renderer> { /** * The drawing buffer for this surface. */ drawingBuffer: HTMLCanvasElement; /** * The drawing buffer's bounding client rect. */ clientRect: ClientRect; /** * The renderer used to render this surface. */ renderer: R; /** * True if a request has been made to re-render this surface. */ hasRenderRequest: boolean; /** * Creates a new rendering surface. * @param drawingBuffer the canvas that serves as the drawing buffer for this surface. * @param renderer the renderer responsible for rendering the surface. */ constructor(drawingBuffer: HTMLCanvasElement, renderer: R); /** * Requests that this surface be re-rendered. */ requestRender(): void; /** * Re-renders this surface if it has a render request. */ onAnimationFrame(): void; /** * Resizes this surface if the specified width and height differ from the current width and height. * @param width the width to set on the surface. Defaults to the client width of the drawing buffer. * @param height the height to set on the surface. Defaults to the client height of the drawing buffer. */ resize(width?: number, height?: number): void; /** * Sends a request to offset the image displayed by this surface. * @param desiredOffset the desired offset, which is automatically adjusted according to the renderer's camera settings. * @returns the actual offset. */ offset(desiredOffset: Vec2): Vec2; /** * Sends a request to zoom into the image displayed by this surface. * @param desiredScaleFactor the desired scale factor, which is automatically adjusted according to the renderer's camera settings. * @returns the actual scale factor. */ zoomIn(desiredScaleFactor: number): number; /** * Sends a request to zoom out of the image displayed by this surface. * @param desiredScaleFactor the desired scale factor, which is automatically adjusted according to the renderer's camera settings. * @returns the actual scale factor. */ zoomOut(desiredScaleFactor: number): number; /** * Sends a request to zoom into the image displayed by this surface while fixing the specified focus point. * @param desiredScaleFactor the desired scale factor, which is automatically adjusted according to the renderer's camera settings. * @param focus the focus point. * @returns the actual scale factor and camera offset. */ zoomToPoint(desiredScaleFactor: number, focus: PointLike): { scaleFactor: number; offset: Vec2; }; /** * Maps a screen cordinate to canvas space. * @param screen the screen coordinate. * @param dst where to store the result. */ screenToCanvas(screenPoint: ScreenPoint, dst?: Point): Point; /** * Maps a screen coordinate to NDC space [0,1]. * @param screen the screen coordinate. * @param dst where to store the result. */ screenToNdc(screenPoint: ScreenPoint, dst?: Point): Point; /** * Maps a screen coordinate to clip space. * @param screen the screen coordinate. * @param dst where to store the result. */ screenToWorld(screenPoint: ScreenPoint, dst?: Point): Point; /** * Maps a canvas coordinate to NDC space [0,1]. * @param p the canvas coordinate. * @param dst where to store the result. */ canvasToNdc(canvasPoint: PointLike, dst?: Point): Point; /** * Maps a normalized device coordinate (NDC) to world space. * @param p the normalized device coordinate. * @param dst where to store the result. */ ndcToWorld(ndc: PointLike, dst?: Point): Point; /** * Invokes the specified callback whenever a mouse action occurs on this surface. */ onMouseEvent(callback: (action: SurfaceMouseEvent<this>) => void): void; private getSurfaceMouseEvent(event, status); /** * Invokes the specified callback whenever a touch action occurs on this surface. */ onTouchEvent(callback: (action: SurfaceTouchEvent<this>) => void): void; private getSurfaceTouchEvent(event, status); private getPointers(event); /** * Invokes the specified callback whenever a scroll action occurs on this surface. */ onWheelEvent(callback: (action: SurfaceWheelEvent<this>) => void): void; /** * From https://developer.mozilla.org/en-US/docs/Web/Events/wheel */ private getScrollSupport(); } export declare type _Surface = Surface<Renderer>;