mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Make PlacedItem#matrix private and add getter / setter for it.
This commit is contained in:
parent
1cd7165ea2
commit
609f23c64d
3 changed files with 29 additions and 13 deletions
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue