mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 10:48:38 -05:00
Clean up Group#draw and save/restore context state when drawing group with opacity.
This commit is contained in:
parent
dc51384a1a
commit
c929bacde8
1 changed files with 4 additions and 2 deletions
|
@ -17,10 +17,10 @@ Group = Item.extend({
|
||||||
// If the group has an opacity of less then 1, draw its children on a
|
// If the group has an opacity of less then 1, draw its children on a
|
||||||
// temporary canvas, and then draw that canvas onto ctx afterwards
|
// temporary canvas, and then draw that canvas onto ctx afterwards
|
||||||
// with globalAlpha set.
|
// with globalAlpha set.
|
||||||
|
var tempCanvas, originalCtx;
|
||||||
if (this.opacity < 1) {
|
if (this.opacity < 1) {
|
||||||
var originalCtx = ctx;
|
var originalCtx = ctx;
|
||||||
var size = this.document.size;
|
tempCanvas = CanvasProvider.getCanvas(this.document.size);
|
||||||
var tempCanvas = CanvasProvider.getCanvas(size.width, size.height);
|
|
||||||
ctx = tempCanvas.getContext('2d');
|
ctx = tempCanvas.getContext('2d');
|
||||||
}
|
}
|
||||||
for (var i = 0, l = this.children.length; i < l; i++) {
|
for (var i = 0, l = this.children.length; i < l; i++) {
|
||||||
|
@ -29,8 +29,10 @@ Group = Item.extend({
|
||||||
ctx.clip();
|
ctx.clip();
|
||||||
}
|
}
|
||||||
if (tempCanvas) {
|
if (tempCanvas) {
|
||||||
|
originalCtx.save();
|
||||||
originalCtx.globalAlpha = this.opacity;
|
originalCtx.globalAlpha = this.opacity;
|
||||||
originalCtx.drawImage(tempCanvas, 0, 0);
|
originalCtx.drawImage(tempCanvas, 0, 0);
|
||||||
|
originalCtx.restore();
|
||||||
// Return the canvas, so it can be reused
|
// Return the canvas, so it can be reused
|
||||||
CanvasProvider.returnCanvas(tempCanvas);
|
CanvasProvider.returnCanvas(tempCanvas);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue