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.
This commit is contained in:
Richard Davey 2023-11-09 18:23:27 +00:00
parent 85a739d662
commit 921ff93ba0

View file

@ -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.
*