Implement new selection drawing mechanism.

Using the new Item#globalMatrix.
This commit is contained in:
Jürg Lehni 2011-12-20 11:42:00 +01:00
parent 010209c70f
commit 93ede28f3b
4 changed files with 30 additions and 24 deletions

View file

@ -103,12 +103,12 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol
},
draw: function(ctx, param) {
if (param.selection) {
Item.drawSelectedBounds(this.symbol._definition.getBounds(), ctx,
this._matrix);
} else {
Item.draw(this.symbol._definition, ctx, param);
}
Item.draw(this.symbol._definition, ctx, param);
},
drawSelected: function(ctx, matrix) {
Item.drawSelectedBounds(this.symbol._definition.getBounds(), ctx,
matrix);
}
// TODO: PlacedSymbol#embed()

View file

@ -403,12 +403,12 @@ 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);
} else {
ctx.drawImage(this._canvas || this._image,
-this._size.width / 2, -this._size.height / 2);
}
ctx.drawImage(this._canvas || this._image,
-this._size.width / 2, -this._size.height / 2);
},
drawSelected: function(ctx, matrix) {
Item.drawSelectedBounds(new Rectangle(this._size).setCenter(0, 0), ctx,
matrix);
}
});

View file

@ -1434,17 +1434,12 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
// Prepare the canvas path if we have any situation that requires it
// to be defined.
if (param.compound || param.selection || this._clipMask || fillColor
if (param.compound || this._clipMask || fillColor
|| strokeColor && !hasDash) {
drawSegments(ctx, this);
}
// If we are drawing the selection of a path, stroke it and draw
// its handles:
if (param.selection) {
ctx.stroke();
drawHandles(ctx, this._segments);
} else if (this._clipMask) {
if (this._clipMask) {
ctx.clip();
} else if (!param.compound && (fillColor || strokeColor)) {
// If the path is part of a compound path or doesn't have a fill
@ -1464,6 +1459,14 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
}
ctx.restore();
}
},
drawSelected: function(ctx, matrix) {
ctx.beginPath();
drawSegments(ctx, this, matrix);
// Now stroke it and draw its handles:
ctx.stroke();
drawHandles(ctx, this._segments, matrix);
}
};
}, new function() { // Path Smoothing

View file

@ -272,10 +272,13 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
ctx.strokeWidth = 1;
// TODO: use Layer#color
ctx.strokeStyle = ctx.fillStyle = '#009dec';
param = { selection: true };
Base.each(this._selectedItems, function(item) {
item.draw(ctx, param);
});
for (var id in this._selectedItems) {
var item = this._selectedItems[id],
mx = item.getGlobalMatrix();
if (matrix)
mx.preConcatenate(matrix);
item.drawSelected(ctx, mx);
}
ctx.restore();
}
}