mirror of
https://github.com/konvajs/konva.git
synced 2025-12-04 19:08:24 +08:00
added new beforeDraw() and afterDraw() event handlers for Layer
This commit is contained in:
24
src/Layer.js
24
src/Layer.js
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user