fix #93 rather than detecting if a layer is listening or visible, I think it's cleaner to hide and show the buffer canvas along with the scene canvas inside the setVisible method

This commit is contained in:
ericdrowell 2012-10-02 23:33:53 -07:00
parent 8cd47db046
commit 0eff286243
4 changed files with 41 additions and 41 deletions

36
dist/kinetic-core.js vendored
View File

@ -2994,23 +2994,21 @@ Kinetic.Stage.prototype = {
*/
for(var n = layers.length - 1; n >= 0; n--) {
var layer = layers[n];
if(layer.isVisible() && layer.isListening()) {
var p = layer.bufferCanvas.context.getImageData(Math.round(pos.x), Math.round(pos.y), 1, 1).data;
// this indicates that a buffer pixel may have been found
if(p[3] === 255) {
var colorKey = Kinetic.Type._rgbToHex(p[0], p[1], p[2]);
shape = Kinetic.Global.shapes[colorKey];
return {
shape: shape,
pixel: p
};
}
// if no shape mapped to that pixel, return pixel array
else if(p[0] > 0 || p[1] > 0 || p[2] > 0 || p[3] > 0) {
return {
pixel: p
};
}
var p = layer.bufferCanvas.context.getImageData(Math.round(pos.x), Math.round(pos.y), 1, 1).data;
// this indicates that a buffer pixel may have been found
if(p[3] === 255) {
var colorKey = Kinetic.Type._rgbToHex(p[0], p[1], p[2]);
shape = Kinetic.Global.shapes[colorKey];
return {
shape: shape,
pixel: p
};
}
// if no shape mapped to that pixel, return pixel array
else if(p[0] > 0 || p[1] > 0 || p[2] > 0 || p[3] > 0) {
return {
pixel: p
};
}
}
@ -3041,7 +3039,7 @@ Kinetic.Stage.prototype = {
* @param {Layer} layer
*/
add: function(layer) {
Kinetic.Container.prototype.add.call(this, layer);
Kinetic.Container.prototype.add.call(this, layer);
layer.canvas.setSize(this.attrs.width, this.attrs.height);
layer.bufferCanvas.setSize(this.attrs.width, this.attrs.height);
@ -3580,9 +3578,11 @@ Kinetic.Layer.prototype = {
Kinetic.Node.prototype.setVisible.call(this, visible);
if(visible) {
this.canvas.element.style.display = 'block';
this.bufferCanvas.element.style.display = 'block';
}
else {
this.canvas.element.style.display = 'none';
this.bufferCanvas.element.style.display = 'none';
}
},
moveToTop: function() {

File diff suppressed because one or more lines are too long

View File

@ -138,9 +138,11 @@ Kinetic.Layer.prototype = {
Kinetic.Node.prototype.setVisible.call(this, visible);
if(visible) {
this.canvas.element.style.display = 'block';
this.bufferCanvas.element.style.display = 'block';
}
else {
this.canvas.element.style.display = 'none';
this.bufferCanvas.element.style.display = 'none';
}
},
moveToTop: function() {

View File

@ -368,23 +368,21 @@ Kinetic.Stage.prototype = {
*/
for(var n = layers.length - 1; n >= 0; n--) {
var layer = layers[n];
if(layer.isVisible() && layer.isListening()) {
var p = layer.bufferCanvas.context.getImageData(Math.round(pos.x), Math.round(pos.y), 1, 1).data;
// this indicates that a buffer pixel may have been found
if(p[3] === 255) {
var colorKey = Kinetic.Type._rgbToHex(p[0], p[1], p[2]);
shape = Kinetic.Global.shapes[colorKey];
return {
shape: shape,
pixel: p
};
}
// if no shape mapped to that pixel, return pixel array
else if(p[0] > 0 || p[1] > 0 || p[2] > 0 || p[3] > 0) {
return {
pixel: p
};
}
var p = layer.bufferCanvas.context.getImageData(Math.round(pos.x), Math.round(pos.y), 1, 1).data;
// this indicates that a buffer pixel may have been found
if(p[3] === 255) {
var colorKey = Kinetic.Type._rgbToHex(p[0], p[1], p[2]);
shape = Kinetic.Global.shapes[colorKey];
return {
shape: shape,
pixel: p
};
}
// if no shape mapped to that pixel, return pixel array
else if(p[0] > 0 || p[1] > 0 || p[2] > 0 || p[3] > 0) {
return {
pixel: p
};
}
}
@ -415,7 +413,7 @@ Kinetic.Stage.prototype = {
* @param {Layer} layer
*/
add: function(layer) {
Kinetic.Container.prototype.add.call(this, layer);
Kinetic.Container.prototype.add.call(this, layer);
layer.canvas.setSize(this.attrs.width, this.attrs.height);
layer.bufferCanvas.setSize(this.attrs.width, this.attrs.height);