From 921ff93ba0a7cf0326a3ba23309d843dfd0021a3 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 9 Nov 2023 18:23:27 +0000 Subject: [PATCH] Added `setScale9` method and `scale9` and `is3Slice` boolean properties * `Frame.setScale9` is a new method that allows you to set the scale9 data associated with the given Frame. This is used internally by the Texture Packer parsers, but can also be called directly. * `Frame.scale9` is a new read-only boolean property that returns `true` if the Frame has scale9 data associated with it. * `Frame.is3Slice` is a new read-only boolean property that returns `true` if the Frame has scale9 data associated with it that is 3-slice instead of 9-slice. --- src/textures/Frame.js | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/textures/Frame.js b/src/textures/Frame.js index d83e3a274..d7616d63e 100644 --- a/src/textures/Frame.js +++ b/src/textures/Frame.js @@ -332,6 +332,14 @@ var Frame = new Class({ y: 0, width: 0, height: 0 + }, + is3Slice: false, + scale9: false, + scale9Borders: { + x: 0, + y: 0, + w: 0, + h: 0 } }; @@ -451,6 +459,38 @@ var Frame = new Class({ return this.updateUVs(); }, + /** + * Sets the scale9 center rectangle values. + * + * Scale9 is a feature of Texture Packer, allowing you to define a nine-slice scaling grid. + * + * This is set automatically by the JSONArray and JSONHash parsers. + * + * @method Phaser.Textures.Frame#setScale9 + * @since 3.61.0 + * + * @param {number} x - The left coordinate of the center scale9 rectangle. + * @param {number} y - The top coordinate of the center scale9 rectangle. + * @param {number} width - The width of the center scale9 rectangle. + * @param {number} height - The height coordinate of the center scale9 rectangle. + * + * @return {this} This Frame object. + */ + setScale9: function (x, y, width, height) + { + var data = this.data; + + data.scale9 = true; + data.is3Slice = (y === 0 && height === this.height); + + data.scale9Borders.x = x; + data.scale9Borders.y = y; + data.scale9Borders.w = width; + data.scale9Borders.h = height; + + return this; + }, + /** * Takes a crop data object and, based on the rectangular region given, calculates the * required UV coordinates in order to crop this Frame for WebGL and Canvas rendering. @@ -829,6 +869,40 @@ var Frame = new Class({ }, + /** + * Does the Frame have scale9 border data? + * + * @name Phaser.Textures.Frame#scale9 + * @type {boolean} + * @readonly + * @since 3.61.0 + */ + scale9: { + + get: function () + { + return this.data.scale9; + } + + }, + + /** + * If the Frame has scale9 border data, is it 3-slice or 9-slice data? + * + * @name Phaser.Textures.Frame#is3Slice + * @type {boolean} + * @readonly + * @since 3.61.0 + */ + is3Slice: { + + get: function () + { + return this.data.is3Slice; + } + + }, + /** * The Canvas drawImage data object. *