Do not usse LinkedPoint internally for PointText#point, since we're returning new instances each time now in #getPoint().

This commit is contained in:
Jürg Lehni 2011-08-02 16:08:00 +01:00
parent fe1b2ca8a0
commit 7c95eb7694

View file

@ -37,9 +37,8 @@ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
*/
initialize: function(point) {
this.base();
point = Point.read(arguments);
this._point = LinkedPoint.create(this, 'setPoint', point.x, point.y);
this._matrix = new Matrix().translate(point);
this._point = Point.read(arguments).clone();
this._matrix = new Matrix().translate(this._point);
},
clone: function() {
@ -56,13 +55,10 @@ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
* @bean
*/
getPoint: function() {
// this._point is a LinkedPoint, so we can use _x and _y.
// Do not cache LinkedPoints directly, since we would not be able to
// use them to calculate the difference in #setPoint, as when it is
// modified, it would hold new values already and only then cause the
// calling of #setPoint.
return LinkedPoint.create(this, 'setPoint', this._point._x,
this._point._y);
// Se Item#getPosition for an explanation why we create new LinkedPoint
// objects each time.
return LinkedPoint.create(this, 'setPoint',
this._point.x, this._point.y);
},
setPoint: function(point) {
@ -72,7 +68,8 @@ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
},
// TODO: Position should be the center point of the bounds but we currently
// don't support bounds for PointText.
// don't support bounds for PointText, so let's return the same as #point
// for the time being.
getPosition: function() {
return this.getPoint();
},
@ -83,10 +80,8 @@ var PointText = this.PointText = TextItem.extend(/** @lends PointText# */{
_transform: function(matrix, flags) {
this._matrix.preConcatenate(matrix);
// We need to transform the LinkedPoint, passing true for dontNotify so
// chaning it won't trigger calls of setPoint(), leading to an endless
// recursion.
matrix._transformPoint(this._point, this._point, true);
// Also transform _point:
matrix._transformPoint(this._point, this._point);
},
draw: function(ctx) {