mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Add LinkedSize and use it in Rectangle#getSize().
This commit is contained in:
parent
10d56f318f
commit
818c847d73
2 changed files with 47 additions and 1 deletions
|
@ -82,7 +82,7 @@ var Rectangle = this.Rectangle = Base.extend({
|
|||
},
|
||||
|
||||
getSize: function() {
|
||||
return Size.create(this.width, this.height);
|
||||
return LinkedSize.create(this, 'setSize', this.width, this.height);
|
||||
},
|
||||
|
||||
setSize: function(size) {
|
||||
|
|
|
@ -130,3 +130,49 @@ var Size = this.Size = Base.extend({
|
|||
};
|
||||
}, {});
|
||||
});
|
||||
|
||||
/**
|
||||
* An internal version of Size that notifies its owner of each change through
|
||||
* setting itself again on the setter that corresponds to the getter that
|
||||
* produced this LinkedSize. See uses of LinkedSize.create()
|
||||
* Note: This prototype is not exported.
|
||||
*/
|
||||
var LinkedSize = Size.extend({
|
||||
beans: true,
|
||||
|
||||
set: function(width, height) {
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
this._owner[this._set](this);
|
||||
return this;
|
||||
},
|
||||
|
||||
getWidth: function() {
|
||||
return this._width;
|
||||
},
|
||||
|
||||
setWidth: function(width) {
|
||||
this._width = width;
|
||||
this._owner[this._set](this);
|
||||
},
|
||||
|
||||
getHeight: function() {
|
||||
return this._height;
|
||||
},
|
||||
|
||||
setHeight: function(height) {
|
||||
this._height = height;
|
||||
this._owner[this._set](this);
|
||||
},
|
||||
|
||||
statics: {
|
||||
create: function(owner, set, width, height) {
|
||||
var point = new LinkedSize(LinkedSize.dont);
|
||||
point._width = width;
|
||||
point._height = height;
|
||||
point._owner = owner;
|
||||
point._set = set;
|
||||
return point;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue