2017-03-02 02:05:33 +00:00
|
|
|
// Origin Component
|
2017-03-15 23:44:39 +00:00
|
|
|
// Values are normalized, given in the range 0 to 1.
|
|
|
|
// Display values contain the calculated pixel values.
|
2017-03-02 02:05:33 +00:00
|
|
|
|
|
|
|
var Origin = {
|
|
|
|
|
2017-03-15 23:08:59 +00:00
|
|
|
originX: 0.5,
|
|
|
|
originY: 0.5,
|
|
|
|
|
2017-08-17 05:26:25 +00:00
|
|
|
// READ ONLY
|
2017-10-08 22:15:56 +00:00
|
|
|
_displayOriginX: 0,
|
|
|
|
_displayOriginY: 0,
|
|
|
|
|
|
|
|
displayOriginX: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this._displayOriginX;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this._displayOriginX = value;
|
|
|
|
this.originX = (value === 0) ? 0 : this.width / value;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
displayOriginY: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this._displayOriginY;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this._displayOriginY = value;
|
|
|
|
this.originY = (value === 0) ? 0 : this.height / value;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2017-03-02 02:05:33 +00:00
|
|
|
|
|
|
|
setOrigin: function (x, y)
|
|
|
|
{
|
2017-03-15 23:08:59 +00:00
|
|
|
if (x === undefined) { x = 0.5; }
|
2017-03-02 02:05:33 +00:00
|
|
|
if (y === undefined) { y = x; }
|
|
|
|
|
|
|
|
this.originX = x;
|
|
|
|
this.originY = y;
|
|
|
|
|
2017-08-17 05:26:25 +00:00
|
|
|
return this.updateOrigin();
|
2017-03-02 02:05:33 +00:00
|
|
|
},
|
|
|
|
|
2017-03-16 15:37:43 +00:00
|
|
|
setDisplayOrigin: function (x, y)
|
|
|
|
{
|
|
|
|
if (x === undefined) { x = 0; }
|
|
|
|
if (y === undefined) { y = x; }
|
|
|
|
|
|
|
|
this.displayOriginX = x;
|
|
|
|
this.displayOriginY = y;
|
|
|
|
|
2017-08-17 05:26:25 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
updateOrigin: function ()
|
|
|
|
{
|
|
|
|
this.displayOriginX = Math.round(this.originX * this.width);
|
|
|
|
this.displayOriginY = Math.round(this.originY * this.height);
|
|
|
|
|
2017-03-15 23:44:39 +00:00
|
|
|
return this;
|
2017-03-02 02:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Origin;
|