added new beforeDraw() and afterDraw() event handlers for Layer

This commit is contained in:
Eric Rowell
2012-04-28 23:03:58 -07:00
parent 1dbe93a232
commit 7bcd34ec47
4 changed files with 87 additions and 4 deletions

View File

@@ -16,6 +16,8 @@ Kinetic.Layer = function(config) {
this.nodeType = 'Layer';
this.lastDrawTime = 0;
this.beforeDrawFunc = undefined;
this.afterDrawFunc = undefined;
this.canvas = document.createElement('canvas');
this.context = this.canvas.getContext('2d');
@@ -77,6 +79,18 @@ Kinetic.Layer.prototype = {
getThrottle: function() {
return this.attrs.throttle;
},
/**
* set before draw function handler
*/
beforeDraw: function(func) {
this.beforeDrawFunc = func;
},
/**
* set after draw function handler
*/
afterDraw: function(func) {
this.afterDrawFunc = func;
},
/**
* clears the canvas context tied to the layer. Clearing
* a layer does not remove its children. The nodes within
@@ -119,10 +133,20 @@ Kinetic.Layer.prototype = {
* private draw children
*/
_draw: function() {
// before draw handler
if(this.beforeDrawFunc !== undefined) {
this.beforeDrawFunc();
}
this.clear();
if(this.attrs.visible) {
this._drawChildren();
}
// after draw handler
if(this.afterDrawFunc !== undefined) {
this.afterDrawFunc();
}
}
};
// Extend Container and Node