1 line
11 KiB
Plaintext
1 line
11 KiB
Plaintext
|
|
{"version":3,"file":"NineSlicePlane.mjs","sources":["../src/NineSlicePlane.ts"],"sourcesContent":["import { Texture } from '@pixi/core';\nimport { SimplePlane } from './SimplePlane';\n\nimport type { ITypedArray } from '@pixi/core';\n\nconst DEFAULT_BORDER_SIZE = 10;\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface NineSlicePlane extends GlobalMixins.NineSlicePlane {}\n\n/**\n * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful\n * for buttons with rounded corners for example) and the other areas will be scaled horizontally and or vertically\n *\n * <pre>\n * A B\n * +---+----------------------+---+\n * C | 1 | 2 | 3 |\n * +---+----------------------+---+\n * | | | |\n * | 4 | 5 | 6 |\n * | | | |\n * +---+----------------------+---+\n * D | 7 | 8 | 9 |\n * +---+----------------------+---+\n * When changing this objects width and/or height:\n * areas 1 3 7 and 9 will remain unscaled.\n * areas 2 and 8 will be stretched horizontally\n * areas 4 and 6 will be stretched vertically\n * area 5 will be stretched both horizontally and vertically\n * </pre>\n * @example\n * import { NineSlicePlane, Texture } from 'pixi.js';\n *\n * const plane9 = new NineSlicePlane(Texture.from('BoxWithRoundedCorners.png'), 15, 15, 15, 15);\n * @memberof PIXI\n */\nexport class NineSlicePlane extends SimplePlane\n{\n private _origWidth: number;\n private _origHeight: number;\n\n /**\n * The width of the left column (a).\n * @private\n */\n _leftWidth: number;\n\n /**\n * The width of the right column (b)\n * @private\n */\n _rightWidth: number;\n\n /**\n * The height of the top row (c)\n * @private\n */\n _topHeight: number;\n\n /**\n * The height of the bottom row (d)\n * @private\n */\n _bottomHeight: number;\n\n /**\n * @param texture - The texture to use on the NineSlicePlane.\n * @param {number} [leftWidth=10] - size of the left vertical bar (A)\n * @param {number} [topHeight=10] - size of the top horizontal bar (C)\n * @param {number} [rightWidth=10] - size of the right vertical bar (B)\n * @param {number} [bottomHeight=10] - size of the bottom horizontal bar (D)\n */\n constructor(\n texture: Texture,\n leftWidth?: number,\n topHeight?: number,\n rightWidth?: number,\n bottomHeight?: number\n )\n {\n super(Texture.WHITE, 4, 4);\n\n this._origWidth = texture.orig.width;\n this._origHeight = texture.orig.height;\n\n /** The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */\n this._width = this._origWidth;\n\n /** The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */\n this._height = this._origHeight;\n\n this._leftWidth = leftWidth ?? texture.defaultBorders?.left ?? DEFAULT_BORDER_SIZE;\n this._rightWidth = rightWidth ?? texture.defaultBorders?.right ?? DEFAULT_BORDER_SIZE;\n this._topHeight = topHeight ?? texture.defaultBorders?.top ?? DEFAULT_BORDER_SIZE;\n this._bottomHeight = bottomHeight ?? texture.defaultBorders?.bottom ?? DEFAULT_BORDER_SIZE;\n\n // lets call the setter to ensure all necessary updates are performed\n this.texture = texture;\n }\n\n public textureUpdated(): void\n {\n this._textureID = this.shader.texture._updateID;\n this._refresh();\n }\n\n get vertices(): ITypedArray\n {\n return this.geometry.getBuffer('aVertexPosition').data;\n }\n\n set vertices(value: ITypedArray)\n {\n this.geometry.getBuffer('aVertexPosition').data = value;\n }\n\n /** Updates the horizontal vertices. */\n public updateHorizontalVertices(): void\n {\n con
|