mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Support PlacedSymbol opacity.
This commit is contained in:
parent
4fa293ec6d
commit
285f81f363
1 changed files with 29 additions and 3 deletions
|
@ -63,6 +63,16 @@ PlacedSymbol = Item.extend({
|
|||
if (this.blendMode != 'normal' && !param.ignoreBlendMode) {
|
||||
BlendMode.process(ctx, this, param);
|
||||
} else {
|
||||
var tempCanvas, originalCtx;
|
||||
if (this.opacity < 1) {
|
||||
originalCtx = ctx;
|
||||
// TODO: use strokeBounds for this, when implemented:
|
||||
tempCanvas = CanvasProvider.getCanvas(this.document.size);
|
||||
ctx = tempCanvas.getContext('2d');
|
||||
ctx.save();
|
||||
this.document.activeView.matrix.applyToContext(ctx);
|
||||
}
|
||||
|
||||
// TODO: we need to preserve strokewidth, but still transform the fill
|
||||
ctx.save();
|
||||
if (param.ignoreBlendMode !== true)
|
||||
|
@ -70,6 +80,22 @@ PlacedSymbol = Item.extend({
|
|||
param.ignoreBlendMode = false;
|
||||
this.symbol.definition.draw(ctx, param);
|
||||
ctx.restore();
|
||||
|
||||
if (tempCanvas) {
|
||||
// restore the activeView.matrix transformation,
|
||||
// so we can draw the image without transformation.
|
||||
originalCtx.restore();
|
||||
originalCtx.save();
|
||||
originalCtx.globalAlpha = this.opacity;
|
||||
originalCtx.drawImage(tempCanvas, 0, 0);
|
||||
originalCtx.restore();
|
||||
// apply the view transformation again.
|
||||
this.document.activeView.matrix.applyToContext(ctx, true);
|
||||
// Restore the state of the temp canvas:
|
||||
ctx.restore();
|
||||
// Return the temp canvas, so it can be reused
|
||||
CanvasProvider.returnCanvas(tempCanvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO:
|
||||
|
|
Loading…
Reference in a new issue