mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-03-15 17:29:52 -04: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
|
// In order to set the right context transformation when drawing the
|
||||||
// raster, simply preconcatenate the internal matrix with the provided
|
// raster, simply preconcatenate the internal matrix with the provided
|
||||||
// one.
|
// 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() {
|
getStrokeBounds: function() {
|
||||||
|
|
|
@ -64,7 +64,7 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol
|
||||||
initialize: function(symbol, matrixOrOffset) {
|
initialize: function(symbol, matrixOrOffset) {
|
||||||
this.base();
|
this.base();
|
||||||
this.symbol = symbol instanceof Symbol ? symbol : new Symbol(symbol);
|
this.symbol = symbol instanceof Symbol ? symbol : new Symbol(symbol);
|
||||||
this.matrix = matrixOrOffset !== undefined
|
this._matrix = matrixOrOffset !== undefined
|
||||||
? matrixOrOffset instanceof Matrix
|
? matrixOrOffset instanceof Matrix
|
||||||
? matrixOrOffset
|
? matrixOrOffset
|
||||||
: new Matrix().translate(Point.read(arguments, 1))
|
: new Matrix().translate(Point.read(arguments, 1))
|
||||||
|
@ -79,23 +79,23 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol
|
||||||
*/
|
*/
|
||||||
|
|
||||||
clone: function() {
|
clone: function() {
|
||||||
return this._clone(new PlacedSymbol(this.symbol, this.matrix.clone()));
|
return this._clone(new PlacedSymbol(this.symbol, this._matrix.clone()));
|
||||||
},
|
},
|
||||||
|
|
||||||
getBounds: function() {
|
getBounds: function() {
|
||||||
if (!this._bounds)
|
if (!this._bounds)
|
||||||
this._bounds = this._createBounds(
|
this._bounds = this._createBounds(
|
||||||
this.symbol._definition.getStrokeBounds(this.matrix))
|
this.symbol._definition.getStrokeBounds(this._matrix))
|
||||||
return this._bounds;
|
return this._bounds;
|
||||||
},
|
},
|
||||||
|
|
||||||
draw: function(ctx, param) {
|
draw: function(ctx, param) {
|
||||||
if (param.selection) {
|
if (param.selection) {
|
||||||
Item.drawSelectedBounds(this.symbol._definition.getStrokeBounds(),
|
Item.drawSelectedBounds(this.symbol._definition.getStrokeBounds(),
|
||||||
ctx, this.matrix);
|
ctx, this._matrix);
|
||||||
} else {
|
} else {
|
||||||
ctx.save();
|
ctx.save();
|
||||||
this.matrix.applyToContext(ctx);
|
this._matrix.applyToContext(ctx);
|
||||||
Item.draw(this.symbol.getDefinition(), ctx, param);
|
Item.draw(this.symbol.getDefinition(), ctx, param);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
//#endif // BROWSER
|
//#endif // BROWSER
|
||||||
this.setImage(object);
|
this.setImage(object);
|
||||||
}
|
}
|
||||||
this.matrix = new Matrix();
|
this._matrix = new Matrix();
|
||||||
},
|
},
|
||||||
|
|
||||||
clone: function() {
|
clone: function() {
|
||||||
|
@ -54,7 +54,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
image.getContext('2d').drawImage(this._canvas, 0, 0);
|
image.getContext('2d').drawImage(this._canvas, 0, 0);
|
||||||
}
|
}
|
||||||
var copy = new Raster(image);
|
var copy = new Raster(image);
|
||||||
copy.matrix = this.matrix.clone();
|
copy._matrix = this._matrix.clone();
|
||||||
return this._clone(copy);
|
return this._clone(copy);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
getPpi: function() {
|
getPpi: function() {
|
||||||
var matrix = this.matrix,
|
var matrix = this._matrix,
|
||||||
orig = new Point(0, 0).transform(matrix),
|
orig = new Point(0, 0).transform(matrix),
|
||||||
u = new Point(1, 0).transform(matrix).subtract(orig),
|
u = new Point(1, 0).transform(matrix).subtract(orig),
|
||||||
v = new Point(0, 1).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)
|
if (path)
|
||||||
path.draw(ctx, { clip: true });
|
path.draw(ctx, { clip: true });
|
||||||
// Now draw the image clipped into it.
|
// Now draw the image clipped into it.
|
||||||
this.matrix.applyToContext(ctx);
|
this._matrix.applyToContext(ctx);
|
||||||
ctx.drawImage(this._canvas || this._image,
|
ctx.drawImage(this._canvas || this._image,
|
||||||
-this._size.width / 2, -this._size.height / 2);
|
-this._size.width / 2, -this._size.height / 2);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
|
@ -370,7 +370,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
|
|
||||||
getBounds: function() {
|
getBounds: function() {
|
||||||
if (!this._bounds)
|
if (!this._bounds)
|
||||||
this._bounds = this._createBounds(this.matrix._transformBounds(
|
this._bounds = this._createBounds(this._matrix._transformBounds(
|
||||||
new Rectangle(this._size).setCenter(0, 0)));
|
new Rectangle(this._size).setCenter(0, 0)));
|
||||||
return this._bounds;
|
return this._bounds;
|
||||||
},
|
},
|
||||||
|
@ -378,10 +378,10 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
draw: function(ctx, param) {
|
draw: function(ctx, param) {
|
||||||
if (param.selection) {
|
if (param.selection) {
|
||||||
var bounds = new Rectangle(this._size).setCenter(0, 0);
|
var bounds = new Rectangle(this._size).setCenter(0, 0);
|
||||||
Item.drawSelectedBounds(bounds, ctx, this.matrix);
|
Item.drawSelectedBounds(bounds, ctx, this._matrix);
|
||||||
} else {
|
} else {
|
||||||
ctx.save();
|
ctx.save();
|
||||||
this.matrix.applyToContext(ctx);
|
this._matrix.applyToContext(ctx);
|
||||||
ctx.drawImage(this._canvas || this._image,
|
ctx.drawImage(this._canvas || this._image,
|
||||||
-this._size.width / 2, -this._size.height / 2);
|
-this._size.width / 2, -this._size.height / 2);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
|
|
Loading…
Reference in a new issue