From 609f23c64dc61d20a81617d591afd87af385d729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 1 Jul 2011 11:32:09 +0200 Subject: [PATCH] Make PlacedItem#matrix private and add getter / setter for it. --- src/item/PlacedItem.js | 18 +++++++++++++++++- src/item/PlacedSymbol.js | 10 +++++----- src/item/Raster.js | 14 +++++++------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/item/PlacedItem.js b/src/item/PlacedItem.js index 0cbe1d88..c1ed1f09 100644 --- a/src/item/PlacedItem.js +++ b/src/item/PlacedItem.js @@ -29,7 +29,23 @@ var PlacedItem = this.PlacedItem = Item.extend(/** @lends PlacedItem# */{ // In order to set the right context transformation when drawing the // raster, simply preconcatenate the internal matrix with the provided // one. - this.matrix.preConcatenate(matrix); + this._matrix.preConcatenate(matrix); + }, + + /** + * The item's transformation matrix, defining position and dimensions in the + * document. + * + * @type Matrix + * @bean + */ + getMatrix: function() { + return this._matrix; + }, + + setMatrix: function(matrix) { + this._matrix = matrix.clone(); + this._changed(Change.GEOMETRY); }, getStrokeBounds: function() { diff --git a/src/item/PlacedSymbol.js b/src/item/PlacedSymbol.js index 83ee3589..5bc91aca 100644 --- a/src/item/PlacedSymbol.js +++ b/src/item/PlacedSymbol.js @@ -64,7 +64,7 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol initialize: function(symbol, matrixOrOffset) { this.base(); this.symbol = symbol instanceof Symbol ? symbol : new Symbol(symbol); - this.matrix = matrixOrOffset !== undefined + this._matrix = matrixOrOffset !== undefined ? matrixOrOffset instanceof Matrix ? matrixOrOffset : new Matrix().translate(Point.read(arguments, 1)) @@ -79,23 +79,23 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol */ clone: function() { - return this._clone(new PlacedSymbol(this.symbol, this.matrix.clone())); + return this._clone(new PlacedSymbol(this.symbol, this._matrix.clone())); }, getBounds: function() { if (!this._bounds) this._bounds = this._createBounds( - this.symbol._definition.getStrokeBounds(this.matrix)) + this.symbol._definition.getStrokeBounds(this._matrix)) return this._bounds; }, draw: function(ctx, param) { if (param.selection) { Item.drawSelectedBounds(this.symbol._definition.getStrokeBounds(), - ctx, this.matrix); + ctx, this._matrix); } else { ctx.save(); - this.matrix.applyToContext(ctx); + this._matrix.applyToContext(ctx); Item.draw(this.symbol.getDefinition(), ctx, param); ctx.restore(); } diff --git a/src/item/Raster.js b/src/item/Raster.js index 2b3e8be8..caa83711 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -42,7 +42,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{ //#endif // BROWSER this.setImage(object); } - this.matrix = new Matrix(); + this._matrix = new Matrix(); }, clone: function() { @@ -54,7 +54,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{ image.getContext('2d').drawImage(this._canvas, 0, 0); } var copy = new Raster(image); - copy.matrix = this.matrix.clone(); + copy._matrix = this._matrix.clone(); return this._clone(copy); }, @@ -105,7 +105,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{ * @bean */ getPpi: function() { - var matrix = this.matrix, + var matrix = this._matrix, orig = new Point(0, 0).transform(matrix), u = new Point(1, 0).transform(matrix).subtract(orig), v = new Point(0, 1).transform(matrix).subtract(orig); @@ -251,7 +251,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{ if (path) path.draw(ctx, { clip: true }); // Now draw the image clipped into it. - this.matrix.applyToContext(ctx); + this._matrix.applyToContext(ctx); ctx.drawImage(this._canvas || this._image, -this._size.width / 2, -this._size.height / 2); ctx.restore(); @@ -370,7 +370,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{ getBounds: function() { if (!this._bounds) - this._bounds = this._createBounds(this.matrix._transformBounds( + this._bounds = this._createBounds(this._matrix._transformBounds( new Rectangle(this._size).setCenter(0, 0))); return this._bounds; }, @@ -378,10 +378,10 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{ draw: function(ctx, param) { if (param.selection) { var bounds = new Rectangle(this._size).setCenter(0, 0); - Item.drawSelectedBounds(bounds, ctx, this.matrix); + Item.drawSelectedBounds(bounds, ctx, this._matrix); } else { ctx.save(); - this.matrix.applyToContext(ctx); + this._matrix.applyToContext(ctx); ctx.drawImage(this._canvas || this._image, -this._size.width / 2, -this._size.height / 2); ctx.restore();