paper.js/src/item/PlacedSymbol.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2011-03-06 19:50:44 -05:00
/*
* Paper.js
*
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
* based on Scriptographer.org and designed to be largely API compatible.
2011-03-07 20:41:50 -05:00
* http://paperjs.org/
2011-03-06 19:50:44 -05:00
* http://scriptographer.org/
*
2011-03-07 20:41:50 -05:00
* Distributed under the MIT license. See LICENSE file for details.
*
2011-03-06 19:50:44 -05:00
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
2011-03-07 20:41:50 -05:00
* All rights reserved.
2011-03-06 19:50:44 -05:00
*/
var PlacedSymbol = this.PlacedSymbol = Item.extend({
beans: true,
initialize: function(symbol, matrixOrOffset) {
this.base();
2011-05-07 08:12:46 -04:00
this.symbol = symbol instanceof Symbol ? symbol : new Symbol(symbol);
this.matrix = matrixOrOffset !== undefined
? matrixOrOffset instanceof Matrix
? matrixOrOffset
: new Matrix().translate(Point.read(arguments, 1))
: new Matrix();
},
clone: function() {
return this._clone(new PlacedSymbol(symbol, this.matrix.clone()));
},
_transform: function(matrix, flags) {
// 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);
},
getBounds: function() {
2011-05-05 06:20:37 -04:00
var bounds = this.symbol._definition.getStrokeBounds(this.matrix);
return LinkedRectangle.create(this, 'setBounds',
bounds.x, bounds.y, bounds.width, bounds.height);
},
getStrokeBounds: function() {
return this.getBounds();
},
draw: function(ctx, param) {
2011-04-21 09:48:21 -04:00
if (param.selection) {
Item.drawSelectedBounds(this.symbol._definition.getStrokeBounds(),
2011-04-21 09:48:21 -04:00
ctx, this.matrix);
} else {
ctx.save();
this.matrix.applyToContext(ctx);
Item.draw(this.symbol.getDefinition(), ctx, param);
ctx.restore();
}
}
// TODO:
// embed()
2011-03-03 11:32:55 -05:00
});