mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
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:
parent
8cd47db046
commit
0eff286243
38
dist/kinetic-core.js
vendored
38
dist/kinetic-core.js
vendored
@ -2994,23 +2994,21 @@ Kinetic.Stage.prototype = {
|
|||||||
*/
|
*/
|
||||||
for(var n = layers.length - 1; n >= 0; n--) {
|
for(var n = layers.length - 1; n >= 0; n--) {
|
||||||
var layer = layers[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;
|
||||||
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
|
||||||
// this indicates that a buffer pixel may have been found
|
if(p[3] === 255) {
|
||||||
if(p[3] === 255) {
|
var colorKey = Kinetic.Type._rgbToHex(p[0], p[1], p[2]);
|
||||||
var colorKey = Kinetic.Type._rgbToHex(p[0], p[1], p[2]);
|
shape = Kinetic.Global.shapes[colorKey];
|
||||||
shape = Kinetic.Global.shapes[colorKey];
|
return {
|
||||||
return {
|
shape: shape,
|
||||||
shape: shape,
|
pixel: p
|
||||||
pixel: p
|
};
|
||||||
};
|
}
|
||||||
}
|
// if no shape mapped to that pixel, return pixel array
|
||||||
// if no shape mapped to that pixel, return pixel array
|
else if(p[0] > 0 || p[1] > 0 || p[2] > 0 || p[3] > 0) {
|
||||||
else if(p[0] > 0 || p[1] > 0 || p[2] > 0 || p[3] > 0) {
|
return {
|
||||||
return {
|
pixel: p
|
||||||
pixel: p
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3041,14 +3039,14 @@ Kinetic.Stage.prototype = {
|
|||||||
* @param {Layer} layer
|
* @param {Layer} layer
|
||||||
*/
|
*/
|
||||||
add: function(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.canvas.setSize(this.attrs.width, this.attrs.height);
|
||||||
layer.bufferCanvas.setSize(this.attrs.width, this.attrs.height);
|
layer.bufferCanvas.setSize(this.attrs.width, this.attrs.height);
|
||||||
|
|
||||||
// draw layer and append canvas to container
|
// draw layer and append canvas to container
|
||||||
layer.draw();
|
layer.draw();
|
||||||
this.content.appendChild(layer.canvas.element);
|
this.content.appendChild(layer.canvas.element);
|
||||||
|
|
||||||
// chainable
|
// chainable
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
@ -3580,9 +3578,11 @@ Kinetic.Layer.prototype = {
|
|||||||
Kinetic.Node.prototype.setVisible.call(this, visible);
|
Kinetic.Node.prototype.setVisible.call(this, visible);
|
||||||
if(visible) {
|
if(visible) {
|
||||||
this.canvas.element.style.display = 'block';
|
this.canvas.element.style.display = 'block';
|
||||||
|
this.bufferCanvas.element.style.display = 'block';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.canvas.element.style.display = 'none';
|
this.canvas.element.style.display = 'none';
|
||||||
|
this.bufferCanvas.element.style.display = 'none';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
moveToTop: function() {
|
moveToTop: function() {
|
||||||
|
6
dist/kinetic-core.min.js
vendored
6
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
@ -138,9 +138,11 @@ Kinetic.Layer.prototype = {
|
|||||||
Kinetic.Node.prototype.setVisible.call(this, visible);
|
Kinetic.Node.prototype.setVisible.call(this, visible);
|
||||||
if(visible) {
|
if(visible) {
|
||||||
this.canvas.element.style.display = 'block';
|
this.canvas.element.style.display = 'block';
|
||||||
|
this.bufferCanvas.element.style.display = 'block';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.canvas.element.style.display = 'none';
|
this.canvas.element.style.display = 'none';
|
||||||
|
this.bufferCanvas.element.style.display = 'none';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
moveToTop: function() {
|
moveToTop: function() {
|
||||||
|
36
src/Stage.js
36
src/Stage.js
@ -368,23 +368,21 @@ Kinetic.Stage.prototype = {
|
|||||||
*/
|
*/
|
||||||
for(var n = layers.length - 1; n >= 0; n--) {
|
for(var n = layers.length - 1; n >= 0; n--) {
|
||||||
var layer = layers[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;
|
||||||
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
|
||||||
// this indicates that a buffer pixel may have been found
|
if(p[3] === 255) {
|
||||||
if(p[3] === 255) {
|
var colorKey = Kinetic.Type._rgbToHex(p[0], p[1], p[2]);
|
||||||
var colorKey = Kinetic.Type._rgbToHex(p[0], p[1], p[2]);
|
shape = Kinetic.Global.shapes[colorKey];
|
||||||
shape = Kinetic.Global.shapes[colorKey];
|
return {
|
||||||
return {
|
shape: shape,
|
||||||
shape: shape,
|
pixel: p
|
||||||
pixel: p
|
};
|
||||||
};
|
}
|
||||||
}
|
// if no shape mapped to that pixel, return pixel array
|
||||||
// if no shape mapped to that pixel, return pixel array
|
else if(p[0] > 0 || p[1] > 0 || p[2] > 0 || p[3] > 0) {
|
||||||
else if(p[0] > 0 || p[1] > 0 || p[2] > 0 || p[3] > 0) {
|
return {
|
||||||
return {
|
pixel: p
|
||||||
pixel: p
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,14 +413,14 @@ Kinetic.Stage.prototype = {
|
|||||||
* @param {Layer} layer
|
* @param {Layer} layer
|
||||||
*/
|
*/
|
||||||
add: function(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.canvas.setSize(this.attrs.width, this.attrs.height);
|
||||||
layer.bufferCanvas.setSize(this.attrs.width, this.attrs.height);
|
layer.bufferCanvas.setSize(this.attrs.width, this.attrs.height);
|
||||||
|
|
||||||
// draw layer and append canvas to container
|
// draw layer and append canvas to container
|
||||||
layer.draw();
|
layer.draw();
|
||||||
this.content.appendChild(layer.canvas.element);
|
this.content.appendChild(layer.canvas.element);
|
||||||
|
|
||||||
// chainable
|
// chainable
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user