Have Tool convert points from view coordinates to artwork coordinates.

This commit is contained in:
Jonathan Puckey 2011-02-28 18:31:03 +01:00
parent 74f797a9dd
commit 4fa293ec6d

View file

@ -1,4 +1,11 @@
Tool = ToolHandler.extend({
Tool = ToolHandler.extend(new function() {
function viewToArtwork(event, document) {
var point = Point.read(event.offset.x, event.offset.y);
// TODO: always the active view?
return document.activeView.viewToArtwork(point);
};
return {
beans: true,
initialize: function(handlers, doc) {
@ -15,7 +22,7 @@ Tool = ToolHandler.extend({
var dragging = false;
var events = {
dragstart: function(e) {
curPoint = new Point(e.offset);
curPoint = viewToArtwork(e);//new Point(e.offset);
that.onHandleEvent('MOUSE_DOWN', curPoint, null, null);
if (that.onMouseDown)
that._document.redraw();
@ -24,7 +31,7 @@ Tool = ToolHandler.extend({
dragging = true;
},
drag: function(e) {
if (e) curPoint = new Point(e.offset);
if (e) curPoint = viewToArtwork(e);//new Point(e.offset);
if (curPoint) {
that.onHandleEvent('MOUSE_DRAG', curPoint, null, null);
if (that.onMouseDrag)
@ -35,14 +42,14 @@ Tool = ToolHandler.extend({
curPoint = null;
if (this.eventInterval != -1)
clearInterval(this.intervalId);
that.onHandleEvent('MOUSE_UP', new Point(e.offset), null, null);
that.onHandleEvent('MOUSE_UP', viewToArtwork(e), null, null);
if (that.onMouseUp)
that._document.redraw();
dragging = false;
},
mousemove: function(e) {
if (!dragging) {
that.onHandleEvent('MOUSE_MOVE', new Point(e.offset), null, null);
that.onHandleEvent('MOUSE_MOVE', viewToArtwork(e), null, null);
if (that.onMouseMove)
that._document.redraw();
}
@ -71,4 +78,5 @@ Tool = ToolHandler.extend({
getDocument: function() {
return this._document;
}
};
});