draw events no longer bubble. It was causing too much of a performance hit, and didn't provide a whole lot of value. Now, only layers fire draw events

This commit is contained in:
Eric Rowell
2013-08-09 20:22:51 -07:00
parent 992be5dd2e
commit 7700ecc70b
6 changed files with 58 additions and 38 deletions

View File

@@ -1,6 +1,8 @@
(function() {
// constants
var HASH = '#';
var HASH = '#',
BEFORE_DRAW ='beforeDraw',
DRAW = 'draw';
Kinetic.Util.addMethods(Kinetic.Layer, {
___init: function(config) {
@@ -51,11 +53,20 @@
drawScene: function(canvas) {
canvas = canvas || this.getCanvas();
this._fire(BEFORE_DRAW, {
node: this
});
if(this.getClearBeforeDraw()) {
canvas.clear();
}
Kinetic.Container.prototype.drawScene.call(this, canvas);
this._fire(DRAW, {
node: this
});
return this;
},
drawHit: function() {

View File

@@ -1117,7 +1117,7 @@
return this;
},
shouldDrawHit: function() {
return this.isVisible() && this.isListening() && !Kinetic.Global.isDragging();
return this.isListening() && this.isVisible() && !Kinetic.Global.isDragging();
},
isDraggable: function() {
return false;

View File

@@ -1,7 +1,4 @@
(function() {
var BEFORE_DRAW = 'beforeDraw',
DRAW = 'draw';
function _fillFunc(context) {
context.fill();
}
@@ -210,25 +207,11 @@
canvas._applyOpacity(this);
canvas._applyLineJoin(this);
canvas._applyAncestorTransforms(this);
this._fireBeforeDrawEvents();
drawFunc.call(this, canvas);
this._fireDrawEvents();
context.restore();
}
return this;
},
_fireBeforeDrawEvents: function() {
this._fireAndBubble(BEFORE_DRAW, {
node: this
});
},
_fireDrawEvents: function() {
this._fireAndBubble(DRAW, {
node: this
});
},
drawHit: function() {
var attrs = this.getAttrs(),
drawFunc = attrs.drawHitFunc || attrs.drawFunc,