Inline Item.drawSelectedBounds() code.

This commit is contained in:
Jürg Lehni 2013-04-18 17:07:32 -07:00
parent 9ee8590a4d
commit 517b2ee27f
2 changed files with 15 additions and 19 deletions

View file

@ -2851,22 +2851,6 @@ var Item = this.Item = Base.extend(Callback, {
// Return the temporary context, so it can be reused
CanvasProvider.release(ctx);
}
},
statics: {
drawSelectedBounds: function(bounds, ctx, matrix) {
var coords = matrix._transformCorners(bounds);
ctx.beginPath();
for (var i = 0; i < 8; i++)
ctx[i == 0 ? 'moveTo' : 'lineTo'](coords[i], coords[++i]);
ctx.closePath();
ctx.stroke();
for (var i = 0; i < 8; i++) {
ctx.beginPath();
ctx.rect(coords[i] - 2, coords[++i] - 2, 4, 4);
ctx.fill();
}
}
}
}, Base.each(['down', 'drag', 'up', 'move'], function(name) {
this['removeOn' + Base.capitalize(name)] = function() {

View file

@ -317,11 +317,23 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
var mx = item._globalMatrix;
if (item.drawSelected)
item.drawSelected(ctx, mx);
if (item._boundsSelected)
if (item._boundsSelected) {
// We need to call the internal _getBounds, to get non-
// transformed bounds.
Item.drawSelectedBounds(item._getBounds('getBounds'),
ctx, mx);
var coords = mx._transformCorners(
item._getBounds('getBounds'));
ctx.beginPath();
for (var i = 0; i < 8; i++)
ctx[i === 0 ? 'moveTo' : 'lineTo'](
coords[i], coords[++i]);
ctx.closePath();
ctx.stroke();
for (var i = 0; i < 8; i++) {
ctx.beginPath();
ctx.rect(coords[i] - 2, coords[++i] - 2, 4, 4);
ctx.fill();
}
}
}
}
ctx.restore();