2011-02-20 12:34:38 -05:00
|
|
|
PlacedSymbol = Item.extend({
|
|
|
|
beans: true,
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
this.base();
|
|
|
|
if (arguments[0] instanceof Symbol) {
|
|
|
|
this.symbol = arguments[0];
|
|
|
|
} else {
|
|
|
|
this.symbol = new Symbol(arguments[0]);
|
|
|
|
}
|
|
|
|
if (arguments.length > 1) {
|
|
|
|
var arg = arguments[1];
|
|
|
|
if (arg instanceof Matrix) {
|
2011-02-21 13:04:51 -05:00
|
|
|
this.matrix = arguments[2];
|
2011-02-20 12:34:38 -05:00
|
|
|
} else {
|
|
|
|
var offset = Point.read(arguments, 1);
|
|
|
|
this.matrix = new Matrix().translate(offset);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.matrix = new Matrix();
|
|
|
|
}
|
|
|
|
this._bounds = this.symbol.definition.bounds.clone();
|
|
|
|
},
|
|
|
|
|
|
|
|
transformContent: function(matrix, flags) {
|
2011-02-25 18:58:54 -05:00
|
|
|
var width = this._size.width;
|
|
|
|
var height = this._size.height;
|
|
|
|
var x = width * -0.5;
|
|
|
|
var y = height * -0.5;
|
|
|
|
var coords = [
|
|
|
|
x, y,
|
|
|
|
x + width, y,
|
|
|
|
x + width, y + height,
|
|
|
|
x, y + height];
|
2011-02-20 12:34:38 -05:00
|
|
|
this.matrix.preConcatenate(matrix);
|
2011-02-25 18:58:54 -05:00
|
|
|
this.matrix.transform(coords, 0, coords, 0, 4);
|
|
|
|
|
|
|
|
var xMin = coords[0], xMax = coords[0];
|
|
|
|
var yMin = coords[1], yMax = coords[1];
|
|
|
|
for(var i = 2; i < 8; i += 2) {
|
|
|
|
var x = coords[i];
|
|
|
|
var y = coords[i + 1];
|
|
|
|
xMin = Math.min(x, xMin);
|
|
|
|
xMax = Math.max(x, xMax);
|
|
|
|
yMin = Math.min(y, yMin);
|
|
|
|
yMax = Math.max(y, yMax);
|
|
|
|
};
|
|
|
|
var bounds = this._bounds;
|
|
|
|
bounds.x = xMin;
|
|
|
|
bounds.y = yMin;
|
|
|
|
bounds.width = xMax - xMin;
|
|
|
|
bounds.height = yMax - yMin;
|
2011-02-20 12:34:38 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getBounds: function() {
|
|
|
|
return this._bounds;
|
|
|
|
},
|
|
|
|
|
2011-02-25 06:46:45 -05:00
|
|
|
draw: function(ctx, param) {
|
|
|
|
if(this.blendMode != 'normal' && !param.ignoreBlendMode) {
|
|
|
|
BlendMode.process(ctx, this, param);
|
|
|
|
} else {
|
|
|
|
// TODO: we need to preserve strokewidth, but still transform the fill
|
|
|
|
ctx.save();
|
2011-02-25 13:38:55 -05:00
|
|
|
if(param.ignoreBlendMode !== true)
|
|
|
|
this.matrix.applyToContext(ctx);
|
|
|
|
param.ignoreBlendMode = false;
|
2011-02-25 07:13:46 -05:00
|
|
|
this.symbol.definition.draw(ctx, param);
|
2011-02-25 06:46:45 -05:00
|
|
|
ctx.restore();
|
|
|
|
}
|
2011-02-20 12:34:38 -05:00
|
|
|
}
|
|
|
|
// TODO:
|
|
|
|
// embed()
|
|
|
|
});
|