removed beforeDraw and afterDraw methods. you can now subscribe to draw events with .on('draw') or .on('beforeDraw'). Draw events also bubble

This commit is contained in:
Eric Rowell
2013-03-24 01:05:37 -07:00
parent 15a9f6165f
commit 13c540b969
3 changed files with 61 additions and 22 deletions

View File

@@ -27,25 +27,6 @@
// call super constructor
Kinetic.Container.call(this, config);
},
/**
* draw children nodes. this includes any groups
* or shapes
* @name draw
* @methodOf Kinetic.Layer.prototype
*/
draw: function() {
// before draw handler
if(this.beforeDrawFunc !== undefined) {
this.beforeDrawFunc.call(this);
}
Kinetic.Container.prototype.draw.call(this);
// after draw handler
if(this.afterDrawFunc !== undefined) {
this.afterDrawFunc.call(this);
}
},
toDataURL: function(config) {
config = config || {};
var mimeType = config.mimeType || null,

View File

@@ -18,7 +18,9 @@
MOUSELEAVE = 'mouseleave',
DEG = 'Deg',
ON = 'on',
OFF = 'off';
OFF = 'off',
BEFORE_DRAW = 'beforeDraw',
DRAW = 'draw';
/**
* Node constructor. Nodes are entities that can be transformed, layered,
@@ -945,7 +947,7 @@
},
_handleEvent: function(eventType, evt, compareShape) {
if(evt && this.nodeType === SHAPE) {
evt.shape = this;
evt.node = this;
}
var stage = this.getStage();
var el = this.eventListeners;
@@ -990,15 +992,20 @@
* the scene renderer
*/
draw: function() {
var layer = this.getLayer();
var layer = this.getLayer(),
evt = {
node: this
};
if(layer && layer.getClearBeforeDraw()) {
layer.getCanvas().clear();
layer.getHitCanvas().clear();
}
this.fire(BEFORE_DRAW, evt);
this.drawScene();
this.drawHit();
this.fire(DRAW, evt);
},
shouldDrawHit: function() {
return this.isVisible() && this.isListening() && !Kinetic.Global.isDragging();