mirror of
https://github.com/konvajs/konva.git
synced 2026-03-03 16:58:33 +08:00
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:
11
src/Shape.js
11
src/Shape.js
@@ -215,10 +215,12 @@
|
|||||||
context = canvas.getContext(),
|
context = canvas.getContext(),
|
||||||
drawFunc = this.getDrawFunc(),
|
drawFunc = this.getDrawFunc(),
|
||||||
applyShadow = this.hasShadow() && this.getShadowEnabled(),
|
applyShadow = this.hasShadow() && this.getShadowEnabled(),
|
||||||
|
applyOpacity = this.getOpacity() !== 1,
|
||||||
stage, bufferCanvas, bufferContext;
|
stage, bufferCanvas, bufferContext;
|
||||||
|
|
||||||
if(drawFunc && this.isVisible()) {
|
if(drawFunc && this.isVisible()) {
|
||||||
if (applyShadow) {
|
// buffer canvas is needed to apply shadows or opacity
|
||||||
|
if (applyShadow || applyOpacity) {
|
||||||
stage = this.getStage();
|
stage = this.getStage();
|
||||||
bufferCanvas = stage.bufferCanvas;
|
bufferCanvas = stage.bufferCanvas;
|
||||||
bufferContext = bufferCanvas.getContext();
|
bufferContext = bufferCanvas.getContext();
|
||||||
@@ -230,14 +232,21 @@
|
|||||||
bufferContext.restore();
|
bufferContext.restore();
|
||||||
|
|
||||||
context.save();
|
context.save();
|
||||||
|
if (applyShadow) {
|
||||||
context.save();
|
context.save();
|
||||||
context._applyShadow(this);
|
context._applyShadow(this);
|
||||||
context.drawImage(bufferCanvas._canvas, 0, 0);
|
context.drawImage(bufferCanvas._canvas, 0, 0);
|
||||||
context.restore();
|
context.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (applyOpacity) {
|
||||||
context._applyOpacity(this);
|
context._applyOpacity(this);
|
||||||
|
}
|
||||||
|
|
||||||
context.drawImage(bufferCanvas._canvas, 0, 0);
|
context.drawImage(bufferCanvas._canvas, 0, 0);
|
||||||
context.restore();
|
context.restore();
|
||||||
}
|
}
|
||||||
|
// if buffer canvas is not needed
|
||||||
else {
|
else {
|
||||||
context.save();
|
context.save();
|
||||||
context._applyOpacity(this);
|
context._applyOpacity(this);
|
||||||
|
|||||||
@@ -1911,12 +1911,22 @@ suite('Node', function() {
|
|||||||
radius: 70,
|
radius: 70,
|
||||||
fill: 'green',
|
fill: 'green',
|
||||||
stroke: 'black',
|
stroke: 'black',
|
||||||
strokeWidth: 4
|
strokeWidth: 20,
|
||||||
|
draggable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
circle.setOpacity(0.5);
|
circle.setOpacity(0.5);
|
||||||
layer.add(circle);
|
layer.add(circle);
|
||||||
stage.add(layer);
|
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();');
|
||||||
});
|
});
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user