mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Support an optional argument 'dontLink' in getters that normalled return LinkedPoint and LinkedSize objects, for internal use.
This commit is contained in:
parent
8f8188a091
commit
c9eb538f7a
3 changed files with 25 additions and 12 deletions
|
@ -949,7 +949,12 @@ var LinkedPoint = Point.extend({
|
|||
},
|
||||
|
||||
statics: {
|
||||
create: function(owner, setter, x, y) {
|
||||
create: function(owner, setter, x, y, dontLink) {
|
||||
// Support creation of normal Points rather than LinkedPoints
|
||||
// through an optional parameter that can be passed to the getters.
|
||||
// See e.g. Rectangle#getPoint(true).
|
||||
if (dontLink)
|
||||
return Point.create(x, y);
|
||||
var point = new LinkedPoint(LinkedPoint.dont);
|
||||
point._x = x;
|
||||
point._y = y;
|
||||
|
|
|
@ -145,7 +145,10 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
* @bean
|
||||
*/
|
||||
getPoint: function() {
|
||||
return LinkedPoint.create(this, 'setPoint', this.x, this.y);
|
||||
// Pass on the optional argument dontLink which tells LinkedPoint to
|
||||
// produce a normal point instead. Used internally for speed reasons.
|
||||
return LinkedPoint.create(this, 'setPoint', this.x, this.y,
|
||||
arguments[0]);
|
||||
},
|
||||
|
||||
setPoint: function(point) {
|
||||
|
@ -162,7 +165,9 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
* @bean
|
||||
*/
|
||||
getSize: function() {
|
||||
return LinkedSize.create(this, 'setSize', this.width, this.height);
|
||||
// See Rectangle#getPoint() about arguments[0]
|
||||
return LinkedSize.create(this, 'setSize', this.width, this.height,
|
||||
arguments[0]);
|
||||
},
|
||||
|
||||
setSize: function(size) {
|
||||
|
@ -282,7 +287,7 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
*/
|
||||
getCenter: function() {
|
||||
return LinkedPoint.create(this, 'setCenter',
|
||||
this.getCenterX(), this.getCenterY());
|
||||
this.getCenterX(), this.getCenterY(), arguments[0]);
|
||||
},
|
||||
|
||||
setCenter: function(point) {
|
||||
|
@ -665,7 +670,7 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
set = 'set' + part;
|
||||
this[get] = function() {
|
||||
return LinkedPoint.create(this, set,
|
||||
this[getX](), this[getY]());
|
||||
this[getX](), this[getY](), arguments[0]);
|
||||
};
|
||||
this[set] = function(point) {
|
||||
point = Point.read(arguments);
|
||||
|
|
|
@ -535,13 +535,16 @@ var LinkedSize = Size.extend({
|
|||
},
|
||||
|
||||
statics: {
|
||||
create: function(owner, setter, width, height) {
|
||||
var point = new LinkedSize(LinkedSize.dont);
|
||||
point._width = width;
|
||||
point._height = height;
|
||||
point._owner = owner;
|
||||
point._setter = setter;
|
||||
return point;
|
||||
create: function(owner, setter, width, height, dontLink) {
|
||||
// See LinkedPoint.create() for an explanation about dontLink.
|
||||
if (dontLink)
|
||||
return Size.create(width, height);
|
||||
var size = new LinkedSize(LinkedSize.dont);
|
||||
size._width = width;
|
||||
size._height = height;
|
||||
size._owner = owner;
|
||||
size._setter = setter;
|
||||
return size;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue