UNPKG

lazy-widgets

Version:

Typescript retained mode GUI for the HTML canvas API

48 lines 1.62 kB
import { BaseViewport } from "./BaseViewport.js"; import { Msg } from './Strings.js'; /** * A {@link Viewport} which inherits a rendering context from the closest parent * Viewport and paints {@link Widget | Widgets} by clipping them to the * Viewport's rectangle. * * @category Core */ export class ClippedViewport extends BaseViewport { get context() { if (this.parent === null) { throw Msg.PARENTLESS_CLIPVP; } return this.parent.context; } get effectiveScale() { if (this.parent === null) { throw Msg.PARENTLESS_CLIPVP; } return this.parent.effectiveScale; } constructor(child) { super(child, false); } paint(extraDirtyRects) { const wasDirty = extraDirtyRects.length > 0; const [vpX, vpY, vpW, vpH, _origXDst, _origYDst, _xDst, _yDst, wClipped, hClipped] = this.getClippedViewportRect(); // Abort if outside of bounds if (wClipped === 0 || hClipped === 0) { return wasDirty; } const ctx = this.context; ctx.save(); ctx.beginPath(); ctx.rect(vpX, vpY, vpW, vpH); ctx.clip(); this.child.paint(extraDirtyRects); ctx.restore(); return wasDirty; } // XXX clipped viewports don't care whether a rectangle was marked as dirty // or not, since they are always used in a viewport widget, which already // passes it along to the parent // eslint-disable-next-line @typescript-eslint/no-empty-function markDirtyRect(_rect) { } } //# sourceMappingURL=ClippedViewport.js.map