hooked opacity rendering into the buffer canvas logic used for shadows so that strokes and fill opacities aren't applied separately

This commit is contained in:
Eric Rowell 2013-09-28 20:34:42 -07:00
parent e530a4697a
commit a8cbc2321d
2 changed files with 30 additions and 11 deletions

View File

@ -215,10 +215,12 @@
context = canvas.getContext(),
drawFunc = this.getDrawFunc(),
applyShadow = this.hasShadow() && this.getShadowEnabled(),
applyOpacity = this.getOpacity() !== 1,
stage, bufferCanvas, bufferContext;
if(drawFunc && this.isVisible()) {
if (applyShadow) {
// buffer canvas is needed to apply shadows or opacity
if (applyShadow || applyOpacity) {
stage = this.getStage();
bufferCanvas = stage.bufferCanvas;
bufferContext = bufferCanvas.getContext();
@ -230,20 +232,27 @@
bufferContext.restore();
context.save();
context.save();
context._applyShadow(this);
context.drawImage(bufferCanvas._canvas, 0, 0);
context.restore();
context._applyOpacity(this);
if (applyShadow) {
context.save();
context._applyShadow(this);
context.drawImage(bufferCanvas._canvas, 0, 0);
context.restore();
}
if (applyOpacity) {
context._applyOpacity(this);
}
context.drawImage(bufferCanvas._canvas, 0, 0);
context.restore();
}
// if buffer canvas is not needed
else {
context.save();
context._applyOpacity(this);
context._applyLineJoin(this);
context._applyAncestorTransforms(this);
drawFunc.call(this, context);
context._applyOpacity(this);
context._applyLineJoin(this);
context._applyAncestorTransforms(this);
drawFunc.call(this, context);
context.restore();
}
}

View File

@ -1911,12 +1911,22 @@ suite('Node', function() {
radius: 70,
fill: 'green',
stroke: 'black',
strokeWidth: 4
strokeWidth: 20,
draggable: true
});
circle.setOpacity(0.5);
layer.add(circle);
stage.add(layer);
var sceneTrace = layer.getContext().getTrace();
//console.log(sceneTrace);
var bufferTrace = stage.bufferCanvas.getContext().getTrace();
//console.log(bufferTrace);
assert.equal(sceneTrace, 'clearRect(0,0,578,200);save();globalAlpha=0.5;drawImage([object HTMLCanvasElement],0,0);restore();');
assert.equal(bufferTrace, 'clearRect(0,0,578,200);save();transform(1,0,0,1,289,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=20;strokeStyle=black;stroke();restore();');
});
// ======================================================