mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 04:14:52 +08:00
shadow logic is now applied to buffer context, not a newly created one each time drawScene is created
This commit is contained in:
38
src/Shape.js
38
src/Shape.js
@@ -104,12 +104,14 @@
|
|||||||
* element is the y component
|
* element is the y component
|
||||||
*/
|
*/
|
||||||
intersects: function() {
|
intersects: function() {
|
||||||
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments));
|
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
|
||||||
var stage = this.getStage();
|
stage = this.getStage(),
|
||||||
var hitCanvas = stage.hitCanvas;
|
bufferHitCanvas = stage.bufferHitCanvas,
|
||||||
hitCanvas.getContext().clear();
|
p;
|
||||||
this.drawScene(hitCanvas);
|
|
||||||
var p = hitCanvas.context.getImageData(pos.x | 0, pos.y | 0, 1, 1).data;
|
bufferHitCanvas.getContext().clear();
|
||||||
|
this.drawScene(bufferHitCanvas);
|
||||||
|
p = bufferHitCanvas.context.getImageData(pos.x | 0, pos.y | 0, 1, 1).data;
|
||||||
return p[3] > 0;
|
return p[3] > 0;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@@ -213,29 +215,27 @@
|
|||||||
context = canvas.getContext(),
|
context = canvas.getContext(),
|
||||||
drawFunc = this.getDrawFunc(),
|
drawFunc = this.getDrawFunc(),
|
||||||
applyShadow = this.hasShadow() && this.getShadowEnabled(),
|
applyShadow = this.hasShadow() && this.getShadowEnabled(),
|
||||||
stage, tempCanvas, tempContext;
|
stage, bufferCanvas, bufferContext;
|
||||||
|
|
||||||
if(drawFunc && this.isVisible()) {
|
if(drawFunc && this.isVisible()) {
|
||||||
if (applyShadow) {
|
if (applyShadow) {
|
||||||
stage = this.getStage();
|
stage = this.getStage();
|
||||||
tempCanvas = new Kinetic.SceneCanvas({
|
bufferCanvas = stage.bufferCanvas;
|
||||||
width: stage.getWidth(),
|
bufferContext = bufferCanvas.getContext();
|
||||||
height: stage.getHeight()
|
bufferContext.clear();
|
||||||
});
|
bufferContext.save();
|
||||||
tempContext = tempCanvas.getContext();
|
bufferContext._applyLineJoin(this);
|
||||||
tempContext.save();
|
bufferContext._applyAncestorTransforms(this);
|
||||||
tempContext._applyLineJoin(this);
|
drawFunc.call(this, bufferContext);
|
||||||
tempContext._applyAncestorTransforms(this);
|
bufferContext.restore();
|
||||||
drawFunc.call(this, tempContext);
|
|
||||||
tempContext.restore();
|
|
||||||
|
|
||||||
context.save();
|
context.save();
|
||||||
context.save();
|
context.save();
|
||||||
context._applyShadow(this);
|
context._applyShadow(this);
|
||||||
context.drawImage(tempCanvas._canvas, 0, 0);
|
context.drawImage(bufferCanvas._canvas, 0, 0);
|
||||||
context.restore();
|
context.restore();
|
||||||
context._applyOpacity(this);
|
context._applyOpacity(this);
|
||||||
context.drawImage(tempCanvas._canvas, 0, 0);
|
context.drawImage(bufferCanvas._canvas, 0, 0);
|
||||||
context.restore();
|
context.restore();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@@ -300,10 +300,10 @@
|
|||||||
this.content.style.width = width + PX;
|
this.content.style.width = width + PX;
|
||||||
this.content.style.height = height + PX;
|
this.content.style.height = height + PX;
|
||||||
|
|
||||||
this.bufferCanvas.setSize(width, height, 1);
|
this.bufferCanvas.setSize(width, height);
|
||||||
this.hitCanvas.setSize(width, height);
|
this.bufferHitCanvas.setSize(width, height);
|
||||||
|
|
||||||
// set pointer defined layer dimensions
|
// set layer dimensions
|
||||||
for(n = 0; n < len; n++) {
|
for(n = 0; n < len; n++) {
|
||||||
layer = layers[n];
|
layer = layers[n];
|
||||||
layer.getCanvas().setSize(width, height);
|
layer.getCanvas().setSize(width, height);
|
||||||
@@ -646,7 +646,7 @@
|
|||||||
container.appendChild(this.content);
|
container.appendChild(this.content);
|
||||||
|
|
||||||
this.bufferCanvas = new Kinetic.SceneCanvas();
|
this.bufferCanvas = new Kinetic.SceneCanvas();
|
||||||
this.hitCanvas = new Kinetic.HitCanvas();
|
this.bufferHitCanvas = new Kinetic.HitCanvas();
|
||||||
|
|
||||||
this._resizeDOM();
|
this._resizeDOM();
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user