2015-02-17 15:49:30 +00:00
|
|
|
/**
|
2015-07-22 14:31:30 +00:00
|
|
|
* @author Mat Groves http://matgroves.com/
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2016-04-04 21:15:01 +00:00
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
2015-07-22 14:31:30 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
2015-02-17 15:49:30 +00:00
|
|
|
|
|
|
|
/**
|
2015-07-22 14:31:30 +00:00
|
|
|
* The Rounded Rectangle object is an area defined by its position and has nice rounded corners,
|
|
|
|
* as indicated by its top-left corner point (x, y) and by its width and its height.
|
|
|
|
*
|
|
|
|
* @class Phaser.RoundedRectangle
|
|
|
|
* @constructor
|
|
|
|
* @param {number} [x=0] - The x coordinate of the top-left corner of the Rectangle.
|
|
|
|
* @param {number} [y=0] - The y coordinate of the top-left corner of the Rectangle.
|
|
|
|
* @param {number} [width=0] - The width of the Rectangle. Should always be either zero or a positive value.
|
|
|
|
* @param {number} [height=0] - The height of the Rectangle. Should always be either zero or a positive value.
|
|
|
|
* @param {number} [radius=20] - Controls the radius of the rounded corners.
|
|
|
|
*/
|
2015-02-17 15:49:30 +00:00
|
|
|
Phaser.RoundedRectangle = function(x, y, width, height, radius)
|
|
|
|
{
|
2015-07-22 14:31:30 +00:00
|
|
|
if (x === undefined) { x = 0; }
|
|
|
|
if (y === undefined) { y = 0; }
|
|
|
|
if (width === undefined) { width = 0; }
|
|
|
|
if (height === undefined) { height = 0; }
|
|
|
|
if (radius === undefined) { radius = 20; }
|
|
|
|
|
2015-02-17 15:49:30 +00:00
|
|
|
/**
|
2015-07-22 14:31:30 +00:00
|
|
|
* @property {number} x - The x coordinate of the top-left corner of the Rectangle.
|
|
|
|
*/
|
|
|
|
this.x = x;
|
2015-02-17 15:49:30 +00:00
|
|
|
|
|
|
|
/**
|
2015-07-22 14:31:30 +00:00
|
|
|
* @property {number} y - The y coordinate of the top-left corner of the Rectangle.
|
|
|
|
*/
|
|
|
|
this.y = y;
|
2015-02-17 15:49:30 +00:00
|
|
|
|
|
|
|
/**
|
2015-07-22 14:31:30 +00:00
|
|
|
* @property {number} width - The width of the Rectangle. This value should never be set to a negative.
|
|
|
|
*/
|
|
|
|
this.width = width;
|
2015-02-17 15:49:30 +00:00
|
|
|
|
|
|
|
/**
|
2015-07-22 14:31:30 +00:00
|
|
|
* @property {number} height - The height of the Rectangle. This value should never be set to a negative.
|
|
|
|
*/
|
|
|
|
this.height = height;
|
2015-02-17 15:49:30 +00:00
|
|
|
|
|
|
|
/**
|
2015-07-22 14:31:30 +00:00
|
|
|
* @property {number} radius - The radius of the rounded corners.
|
|
|
|
*/
|
2015-02-17 15:49:30 +00:00
|
|
|
this.radius = radius || 20;
|
|
|
|
|
|
|
|
/**
|
2015-02-17 16:38:07 +00:00
|
|
|
* @property {number} type - The const type of this object.
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.type = Phaser.ROUNDEDRECTANGLE;
|
2015-02-17 15:49:30 +00:00
|
|
|
};
|
|
|
|
|
2016-10-07 02:32:37 +00:00
|
|
|
Phaser.RoundedRectangle.prototype.constructor = Phaser.RoundedRectangle;
|
|
|
|
|
2015-07-22 14:31:30 +00:00
|
|
|
Phaser.RoundedRectangle.prototype = {
|
2015-02-17 15:49:30 +00:00
|
|
|
|
2015-07-22 14:31:30 +00:00
|
|
|
/**
|
|
|
|
* Returns a new RoundedRectangle object with the same values for the x, y, width, height and
|
|
|
|
* radius properties as this RoundedRectangle object.
|
|
|
|
*
|
|
|
|
* @method Phaser.RoundedRectangle#clone
|
|
|
|
* @return {Phaser.RoundedRectangle}
|
|
|
|
*/
|
|
|
|
clone: function () {
|
2015-02-17 15:49:30 +00:00
|
|
|
|
2015-07-22 14:31:30 +00:00
|
|
|
return new Phaser.RoundedRectangle(this.x, this.y, this.width, this.height, this.radius);
|
2015-02-17 18:16:12 +00:00
|
|
|
|
2015-07-22 14:31:30 +00:00
|
|
|
},
|
2015-02-17 15:49:30 +00:00
|
|
|
|
2015-07-22 14:31:30 +00:00
|
|
|
/**
|
|
|
|
* Determines whether the specified coordinates are contained within the region defined by this Rounded Rectangle object.
|
|
|
|
*
|
|
|
|
* @method Phaser.RoundedRectangle#contains
|
|
|
|
* @param {number} x - The x coordinate of the point to test.
|
|
|
|
* @param {number} y - The y coordinate of the point to test.
|
|
|
|
* @return {boolean} A value of true if the RoundedRectangle Rectangle object contains the specified point; otherwise false.
|
|
|
|
*/
|
|
|
|
contains: function (x, y) {
|
|
|
|
|
|
|
|
if (this.width <= 0 || this.height <= 0)
|
2015-02-17 15:49:30 +00:00
|
|
|
{
|
2015-07-22 14:31:30 +00:00
|
|
|
return false;
|
2015-02-17 15:49:30 +00:00
|
|
|
}
|
2015-07-22 14:31:30 +00:00
|
|
|
|
|
|
|
var x1 = this.x;
|
|
|
|
|
|
|
|
if (x >= x1 && x <= x1 + this.width)
|
|
|
|
{
|
|
|
|
var y1 = this.y;
|
|
|
|
|
|
|
|
if (y >= y1 && y <= y1 + this.height)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
2015-02-17 15:49:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|