From e36ea0c2e39738c3de469e1c09faab9078d90b1f Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Mon, 14 Feb 2011 22:23:05 +0100 Subject: [PATCH] Tool: add support for Tool#eventInterval --- src/tool/Tool.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/tool/Tool.js b/src/tool/Tool.js index e2902617..30e82139 100644 --- a/src/tool/Tool.js +++ b/src/tool/Tool.js @@ -3,25 +3,37 @@ Tool = ToolHandler.extend({ initialize: function(handlers, doc) { this.base(handlers); + if(Paper.document) + this.document = Paper.document; }, setDocument: function(doc) { this._document = doc; - var that = this; - $(doc.canvas).addEvents({ + var that = this, curPoint; + var events = { 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(); + if(that.eventInterval != -1) + this.intervalId = setInterval(events.drag, that.eventInterval); }, drag: function(e) { - that.onHandleEvent('MOUSE_DRAG', new Point(e.offset), null, null); - that._document.redraw(); + if(e) curPoint = new Point(e.offset); + if(curPoint) { + that.onHandleEvent('MOUSE_DRAG', curPoint, null, null); + that._document.redraw(); + } }, dragend: function(e) { + curPoint = null; + if(this.eventInterval != -1) + clearInterval(this.intervalId); that.onHandleEvent('MOUSE_UP', new Point(e.offset), null, null); that._document.redraw(); } - }); + }; + $(doc.canvas).addEvents(events); }, /**