1 line
4.6 KiB
Plaintext
1 line
4.6 KiB
Plaintext
|
|
{"version":3,"file":"CanvasRenderTarget.mjs","sources":["../../src/media/CanvasRenderTarget.ts"],"sourcesContent":["import { settings } from '@pixi/settings';\n\nimport type { ICanvas, ICanvasRenderingContext2D } from '@pixi/settings';\n\n/**\n * Creates a Canvas element of the given size to be used as a target for rendering to.\n * @class\n * @memberof PIXI.utils\n */\nexport class CanvasRenderTarget\n{\n protected _canvas: ICanvas | null;\n\n protected _context: ICanvasRenderingContext2D | null;\n\n /**\n * The resolution / device pixel ratio of the canvas\n * @default 1\n */\n public resolution: number;\n\n /**\n * @param width - the width for the newly created canvas\n * @param height - the height for the newly created canvas\n * @param {number} [resolution=PIXI.settings.RESOLUTION] - The resolution / device pixel ratio of the canvas\n */\n constructor(width: number, height: number, resolution?: number)\n {\n this._canvas = settings.ADAPTER.createCanvas();\n\n this._context = this._canvas.getContext('2d');\n\n this.resolution = resolution || settings.RESOLUTION;\n\n this.resize(width, height);\n }\n\n /**\n * Clears the canvas that was created by the CanvasRenderTarget class.\n * @private\n */\n clear(): void\n {\n this._checkDestroyed();\n\n this._context.setTransform(1, 0, 0, 1, 0, 0);\n this._context.clearRect(0, 0, this._canvas.width, this._canvas.height);\n }\n\n /**\n * Resizes the canvas to the specified width and height.\n * @param desiredWidth - the desired width of the canvas\n * @param desiredHeight - the desired height of the canvas\n */\n resize(desiredWidth: number, desiredHeight: number): void\n {\n this._checkDestroyed();\n\n this._canvas.width = Math.round(desiredWidth * this.resolution);\n this._canvas.height = Math.round(desiredHeight * this.resolution);\n }\n\n /** Destroys this canvas. */\n destroy(): void\n {\n this._context = null;\n this._canvas = null;\n }\n\n /**\n * The width of the canvas buffer in pixels.\n * @member {number}\n */\n get width(): number\n {\n this._checkDestroyed();\n\n return this._canvas.width;\n }\n\n set width(val: number)\n {\n this._checkDestroyed();\n\n this._canvas.width = Math.round(val);\n }\n\n /**\n * The height of the canvas buffer in pixels.\n * @member {number}\n */\n get height(): number\n {\n this._checkDestroyed();\n\n return this._canvas.height;\n }\n\n set height(val: number)\n {\n this._checkDestroyed();\n\n this._canvas.height = Math.round(val);\n }\n\n /** The Canvas object that belongs to this CanvasRenderTarget. */\n public get canvas(): ICanvas\n {\n this._checkDestroyed();\n\n return this._canvas;\n }\n\n /** A CanvasRenderingContext2D object representing a two-dimensional rendering context. */\n public get context(): ICanvasRenderingContext2D\n {\n this._checkDestroyed();\n\n return this._context;\n }\n\n private _checkDestroyed(): asserts this is this & { _canvas: ICanvas; _context: ICanvasRenderingContext2D }\n {\n if (this._canvas === null)\n {\n if (process.env.DEBUG)\n {\n throw new TypeError('The CanvasRenderTarget has already been destroyed');\n }\n }\n }\n}\n"],"names":[],"mappings":";AASO,MAAM,mBACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBI,YAAY,OAAe,QAAgB,YAC3C;AACS,SAAA,UAAU,SAAS,QAAQ,gBAEhC,KAAK,WAAW,KAAK,QAAQ,WAAW,IAAI,GAE5C,KAAK,aAAa,cAAc,SAAS,YAEzC,KAAK,OAAO,OAAO,MAAM;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QACA;AACS,SAAA,gBAAA,GAEL,KAAK,SAAS,aAAa,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,GAC3C,KAAK,SAAS,UAAU,GAAG,GAAG,KAAK,QAAQ,OAAO,KAAK,QAAQ,MAAM;AAAA,EACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,cAAsB,eAC7B;AACI,SAAK,gBAEL,GAAA,KAAK,QAAQ,QAAQ,KAAK,MAAM,eAAe,KAAK,UAAU,GAC9D,KAAK,QAAQ,SAAS,KAAK,MAAM,gB
|