Tool: add support for Tool#eventInterval

This commit is contained in:
Jonathan Puckey 2011-02-14 22:23:05 +01:00
parent a633b2a066
commit e36ea0c2e3

View file

@ -3,25 +3,37 @@ Tool = ToolHandler.extend({
initialize: function(handlers, doc) { initialize: function(handlers, doc) {
this.base(handlers); this.base(handlers);
if(Paper.document)
this.document = Paper.document;
}, },
setDocument: function(doc) { setDocument: function(doc) {
this._document = doc; this._document = doc;
var that = this; var that = this, curPoint;
$(doc.canvas).addEvents({ var events = {
mousedown: function(e) { mousedown: function(e) {
that.onHandleEvent('MOUSE_DOWN', new Point(e.offset), null, null); curPoint = new Point(e.offset);
that.onHandleEvent('MOUSE_DOWN', curPoint, null, null);
that._document.redraw(); that._document.redraw();
if(that.eventInterval != -1)
this.intervalId = setInterval(events.drag, that.eventInterval);
}, },
drag: function(e) { drag: function(e) {
that.onHandleEvent('MOUSE_DRAG', new Point(e.offset), null, null); if(e) curPoint = new Point(e.offset);
that._document.redraw(); if(curPoint) {
that.onHandleEvent('MOUSE_DRAG', curPoint, null, null);
that._document.redraw();
}
}, },
dragend: function(e) { dragend: function(e) {
curPoint = null;
if(this.eventInterval != -1)
clearInterval(this.intervalId);
that.onHandleEvent('MOUSE_UP', new Point(e.offset), null, null); that.onHandleEvent('MOUSE_UP', new Point(e.offset), null, null);
that._document.redraw(); that._document.redraw();
} }
}); };
$(doc.canvas).addEvents(events);
}, },
/** /**