mirror of
https://github.com/konvajs/konva.git
synced 2026-01-09 20:14:41 +08:00
Merge branch 'get-intersection-cache' of git://github.com/vmichnowicz/KineticJS into vmichnowicz-get-intersection-cache
Conflicts: src/Container.js src/Shape.js
This commit is contained in:
@@ -307,6 +307,9 @@
|
|||||||
cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
||||||
|
|
||||||
if (this.shouldDrawHit(canvas)) {
|
if (this.shouldDrawHit(canvas)) {
|
||||||
|
if (layer) {
|
||||||
|
layer.imageData = null; // Clear getImageData cache
|
||||||
|
}
|
||||||
if (cachedHitCanvas) {
|
if (cachedHitCanvas) {
|
||||||
this._drawCachedHitCanvas(context);
|
this._drawCachedHitCanvas(context);
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/Layer.js
27
src/Layer.js
@@ -92,8 +92,32 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Get ImageData.data array for an individual pixel on the hit canvas.
|
||||||
|
* Data is cached as getImageData is an expensive method to call often.
|
||||||
|
*
|
||||||
|
* @param {Number} x
|
||||||
|
* @param {Number} x
|
||||||
|
* @returns {Array} One-dimensional array containing the data in the RGBA order, with integer values between 0 and 255
|
||||||
|
*/
|
||||||
|
_getImageData: function(x, y) {
|
||||||
|
var width = this.hitCanvas.width || 1,
|
||||||
|
height = this.hitCanvas.height || 1,
|
||||||
|
index = (y * width ) + x;
|
||||||
|
|
||||||
|
if (!this.imageData) {
|
||||||
|
this.imageData = this.hitCanvas.context._context.getImageData(0, 0, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
this.imageData.data[4 * index + 0] , // Red
|
||||||
|
this.imageData.data[4 * index + 1], // Green
|
||||||
|
this.imageData.data[4 * index + 2], // Blue
|
||||||
|
this.imageData.data[4 * index + 3] // Alpha
|
||||||
|
];
|
||||||
|
},
|
||||||
_getIntersection: function(pos) {
|
_getIntersection: function(pos) {
|
||||||
var p = this.hitCanvas.context._context.getImageData(pos.x, pos.y, 1, 1).data,
|
var p = this._getImageData(pos.x, pos.y),
|
||||||
p3 = p[3],
|
p3 = p[3],
|
||||||
colorKey, shape;
|
colorKey, shape;
|
||||||
|
|
||||||
@@ -170,6 +194,7 @@
|
|||||||
clear: function(bounds) {
|
clear: function(bounds) {
|
||||||
this.getContext().clear(bounds);
|
this.getContext().clear(bounds);
|
||||||
this.getHitCanvas().getContext().clear(bounds);
|
this.getHitCanvas().getContext().clear(bounds);
|
||||||
|
this.imageData = null; // Clear getImageData cache
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
// extend Node.prototype.setVisible
|
// extend Node.prototype.setVisible
|
||||||
|
|||||||
@@ -209,7 +209,9 @@
|
|||||||
cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
||||||
|
|
||||||
if(this.shouldDrawHit(canvas)) {
|
if(this.shouldDrawHit(canvas)) {
|
||||||
|
if (layer) {
|
||||||
|
layer.imageData = null; // Clear getImageData cache
|
||||||
|
}
|
||||||
if (cachedHitCanvas) {
|
if (cachedHitCanvas) {
|
||||||
this._drawCachedHitCanvas(context);
|
this._drawCachedHitCanvas(context);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user