2011-02-08 13:15:55 +01:00
|
|
|
Tool = ToolHandler.extend({
|
2011-02-11 14:40:36 +01:00
|
|
|
beans: true,
|
2011-02-13 18:52:17 +00:00
|
|
|
|
2011-02-08 13:15:55 +01:00
|
|
|
initialize: function(handlers, doc) {
|
|
|
|
this.base(handlers);
|
2011-02-21 03:32:39 +01:00
|
|
|
if (Paper.document)
|
2011-02-14 22:23:05 +01:00
|
|
|
this.document = Paper.document;
|
2011-02-08 13:15:55 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
setDocument: function(doc) {
|
2011-02-21 03:32:39 +01:00
|
|
|
if (this._document)
|
2011-02-15 00:01:56 +01:00
|
|
|
$(this._document.canvas).removeEvents();
|
|
|
|
this._document = doc || Paper.document;
|
2011-02-14 22:23:05 +01:00
|
|
|
var that = this, curPoint;
|
2011-02-26 13:00:55 +01:00
|
|
|
var dragging = false;
|
2011-02-14 22:23:05 +01:00
|
|
|
var events = {
|
2011-02-15 22:32:05 +00:00
|
|
|
dragstart: function(e) {
|
2011-02-14 22:23:05 +01:00
|
|
|
curPoint = new Point(e.offset);
|
|
|
|
that.onHandleEvent('MOUSE_DOWN', curPoint, null, null);
|
2011-02-21 03:32:39 +01:00
|
|
|
if (that.onMouseDown)
|
2011-02-15 00:01:56 +01:00
|
|
|
that._document.redraw();
|
2011-02-21 03:32:39 +01:00
|
|
|
if (that.eventInterval != -1)
|
2011-02-14 22:23:05 +01:00
|
|
|
this.intervalId = setInterval(events.drag, that.eventInterval);
|
2011-02-26 13:00:55 +01:00
|
|
|
dragging = true;
|
2011-02-08 13:15:55 +01:00
|
|
|
},
|
|
|
|
drag: function(e) {
|
2011-02-21 03:32:39 +01:00
|
|
|
if (e) curPoint = new Point(e.offset);
|
|
|
|
if (curPoint) {
|
2011-02-14 22:23:05 +01:00
|
|
|
that.onHandleEvent('MOUSE_DRAG', curPoint, null, null);
|
2011-02-21 03:32:39 +01:00
|
|
|
if (that.onMouseDrag)
|
2011-02-15 00:01:56 +01:00
|
|
|
that._document.redraw();
|
2011-02-14 22:23:05 +01:00
|
|
|
}
|
2011-02-08 13:15:55 +01:00
|
|
|
},
|
2011-02-14 20:08:19 +01:00
|
|
|
dragend: function(e) {
|
2011-02-14 22:23:05 +01:00
|
|
|
curPoint = null;
|
2011-02-21 03:32:39 +01:00
|
|
|
if (this.eventInterval != -1)
|
2011-02-14 22:23:05 +01:00
|
|
|
clearInterval(this.intervalId);
|
2011-02-08 13:15:55 +01:00
|
|
|
that.onHandleEvent('MOUSE_UP', new Point(e.offset), null, null);
|
2011-02-21 03:32:39 +01:00
|
|
|
if (that.onMouseUp)
|
2011-02-15 00:01:56 +01:00
|
|
|
that._document.redraw();
|
2011-02-26 13:00:55 +01:00
|
|
|
dragging = false;
|
|
|
|
},
|
|
|
|
mousemove: function(e) {
|
|
|
|
if(!dragging) {
|
|
|
|
that.onHandleEvent('MOUSE_MOVE', new Point(e.offset), null, null);
|
|
|
|
if (that.onMouseMove)
|
|
|
|
that._document.redraw();
|
|
|
|
}
|
2011-02-08 13:15:55 +01:00
|
|
|
}
|
2011-02-14 22:23:05 +01:00
|
|
|
};
|
|
|
|
$(doc.canvas).addEvents(events);
|
2011-02-08 13:15:55 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2011-02-11 14:40:36 +01:00
|
|
|
* The fixed time delay between each call to the {@link #onMouseDrag}
|
2011-02-08 13:15:55 +01:00
|
|
|
* event. Setting this to an interval means the {@link #onMouseDrag} event
|
|
|
|
* is called repeatedly after the initial {@link #onMouseDown} until the
|
|
|
|
* user releases the mouse.
|
|
|
|
*
|
|
|
|
* Sample code:
|
|
|
|
* <code>
|
|
|
|
* // Fire the onMouseDrag event once a second,
|
|
|
|
* // while the mouse button is down
|
|
|
|
* tool.eventInterval = 1000;
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* @return the interval time in milliseconds
|
|
|
|
*/
|
2011-02-11 14:40:36 +01:00
|
|
|
eventInterval: -1,
|
2011-02-08 13:15:55 +01:00
|
|
|
|
2011-02-11 14:40:36 +01:00
|
|
|
getDocument: function() {
|
|
|
|
return this._document;
|
2011-02-08 13:15:55 +01:00
|
|
|
}
|
2011-02-14 20:08:19 +01:00
|
|
|
});
|