mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-22 07:19:57 -05:00
Implement new selection drawing mechanism.
Using the new Item#globalMatrix.
This commit is contained in:
parent
010209c70f
commit
93ede28f3b
4 changed files with 30 additions and 24 deletions
|
@ -103,12 +103,12 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol
|
||||||
},
|
},
|
||||||
|
|
||||||
draw: function(ctx, param) {
|
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()
|
// TODO: PlacedSymbol#embed()
|
||||||
|
|
|
@ -403,12 +403,12 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
},
|
},
|
||||||
|
|
||||||
draw: function(ctx, param) {
|
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,
|
ctx.drawImage(this._canvas || this._image,
|
||||||
-this._size.width / 2, -this._size.height / 2);
|
-this._size.width / 2, -this._size.height / 2);
|
||||||
}
|
},
|
||||||
|
|
||||||
|
drawSelected: function(ctx, matrix) {
|
||||||
|
Item.drawSelectedBounds(new Rectangle(this._size).setCenter(0, 0), ctx,
|
||||||
|
matrix);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1434,17 +1434,12 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
|
|
||||||
// Prepare the canvas path if we have any situation that requires it
|
// Prepare the canvas path if we have any situation that requires it
|
||||||
// to be defined.
|
// to be defined.
|
||||||
if (param.compound || param.selection || this._clipMask || fillColor
|
if (param.compound || this._clipMask || fillColor
|
||||||
|| strokeColor && !hasDash) {
|
|| strokeColor && !hasDash) {
|
||||||
drawSegments(ctx, this);
|
drawSegments(ctx, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we are drawing the selection of a path, stroke it and draw
|
if (this._clipMask) {
|
||||||
// its handles:
|
|
||||||
if (param.selection) {
|
|
||||||
ctx.stroke();
|
|
||||||
drawHandles(ctx, this._segments);
|
|
||||||
} else if (this._clipMask) {
|
|
||||||
ctx.clip();
|
ctx.clip();
|
||||||
} else if (!param.compound && (fillColor || strokeColor)) {
|
} else if (!param.compound && (fillColor || strokeColor)) {
|
||||||
// If the path is part of a compound path or doesn't have a fill
|
// 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();
|
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
|
}, new function() { // Path Smoothing
|
||||||
|
|
|
@ -272,10 +272,13 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
|
||||||
ctx.strokeWidth = 1;
|
ctx.strokeWidth = 1;
|
||||||
// TODO: use Layer#color
|
// TODO: use Layer#color
|
||||||
ctx.strokeStyle = ctx.fillStyle = '#009dec';
|
ctx.strokeStyle = ctx.fillStyle = '#009dec';
|
||||||
param = { selection: true };
|
for (var id in this._selectedItems) {
|
||||||
Base.each(this._selectedItems, function(item) {
|
var item = this._selectedItems[id],
|
||||||
item.draw(ctx, param);
|
mx = item.getGlobalMatrix();
|
||||||
});
|
if (matrix)
|
||||||
|
mx.preConcatenate(matrix);
|
||||||
|
item.drawSelected(ctx, mx);
|
||||||
|
}
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue