when calling layer.hide() or show(), the physical canvas element is hidden and shown rather than clearing and redrawing the layer. This greatly improves hide and show performance for layers

This commit is contained in:
Eric Rowell 2012-09-18 09:25:16 -07:00
parent 0f2cee5499
commit d0a1b2870e
4 changed files with 42 additions and 5 deletions

20
dist/kinetic-core.js vendored
View File

@ -3,7 +3,7 @@
* http://www.kineticjs.com/
* Copyright 2012, Eric Rowell
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Sep 17 2012
* Date: Sep 18 2012
*
* Copyright (C) 2011 - 2012 by Eric Rowell
*
@ -3654,6 +3654,24 @@ Kinetic.Layer.prototype = {
clear: function() {
this.getCanvas().clear();
},
/**
* show layer
* @name show
* @methodOf Kinetic.Layer.prototype
*/
show: function() {
Kinetic.Node.prototype.show.call(this);
this.canvas.element.style.display = 'block';
},
/**
* hide layer. Hidden layers are no longer detectable
* @name hide
* @methodOf Kinetic.Layer.prototype
*/
hide: function() {
Kinetic.Node.prototype.hide.call(this);
this.canvas.element.style.display = 'none';
},
/**
* Creates a composite data URL. If MIME type is not
* specified, then "image/png" will result. For "image/jpeg", specify a quality

File diff suppressed because one or more lines are too long

View File

@ -139,6 +139,24 @@ Kinetic.Layer.prototype = {
clear: function() {
this.getCanvas().clear();
},
/**
* show layer
* @name show
* @methodOf Kinetic.Layer.prototype
*/
show: function() {
Kinetic.Node.prototype.show.call(this);
this.canvas.element.style.display = 'block';
},
/**
* hide layer. Hidden layers are no longer detectable
* @name hide
* @methodOf Kinetic.Layer.prototype
*/
hide: function() {
Kinetic.Node.prototype.hide.call(this);
this.canvas.element.style.display = 'none';
},
/**
* Creates a composite data URL. If MIME type is not
* specified, then "image/png" will result. For "image/jpeg", specify a quality

View File

@ -942,9 +942,10 @@ Test.prototype.tests = {
test(layer2.isVisible(), 'layer2 should be visible');
layer2.hide();
layer2.draw();
test(!layer2.isVisible(), 'layer2 should be invisible');
layer2.show();
test(layer2.isVisible(), 'layer2 should be visible');
},
'LAYER - beforeDraw and afterDraw': function(containerId) {
var stage = new Kinetic.Stage({