Make Item#position a LinkedPoint and change the way it's transformed in #transform().

This commit is contained in:
Jürg Lehni 2011-05-16 11:19:19 +01:00
parent f92434ab54
commit f0b29e0e4d

View file

@ -512,9 +512,13 @@ var Item = this.Item = Base.extend({
*/
getPosition: function() {
// Cache position value
if (!this._position)
this._position = this.getBounds().getCenter();
return this._position.clone();
if (!this._position) {
// Center is a LinkedPoint as well, so we can use _x and _y
var center = this.getBounds().getCenter();
this._position = LinkedPoint.create(this, 'setPosition',
center._x, center._y);
}
return this._position;
},
setPosition: function(point) {
@ -534,9 +538,10 @@ var Item = this.Item = Base.extend({
// TODO: Call transform on chidren only if 'children' flag is provided
if (this._transform)
this._transform(matrix, flags);
// Transform position as well
// Transform position as well. Do not modify _position directly,
// since it's a LinkedPoint and would cause recursion!
if (this._position)
this._position = matrix._transformPoint(this._position);
matrix._transformPoint(this._position, this._position, true);
if (this._children) {
for (var i = 0, l = this._children.length; i < l; i++) {
var child = this._children[i];