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, beans: true,
initialize: function(handlers, doc) { initialize: function(handlers, doc) {
@ -15,7 +22,7 @@ Tool = ToolHandler.extend({
var dragging = false; var dragging = false;
var events = { var events = {
dragstart: function(e) { dragstart: function(e) {
curPoint = new Point(e.offset); curPoint = viewToArtwork(e);//new Point(e.offset);
that.onHandleEvent('MOUSE_DOWN', curPoint, null, null); that.onHandleEvent('MOUSE_DOWN', curPoint, null, null);
if (that.onMouseDown) if (that.onMouseDown)
that._document.redraw(); that._document.redraw();
@ -24,7 +31,7 @@ Tool = ToolHandler.extend({
dragging = true; dragging = true;
}, },
drag: function(e) { drag: function(e) {
if (e) curPoint = new Point(e.offset); if (e) curPoint = viewToArtwork(e);//new Point(e.offset);
if (curPoint) { if (curPoint) {
that.onHandleEvent('MOUSE_DRAG', curPoint, null, null); that.onHandleEvent('MOUSE_DRAG', curPoint, null, null);
if (that.onMouseDrag) if (that.onMouseDrag)
@ -35,14 +42,14 @@ Tool = ToolHandler.extend({
curPoint = null; curPoint = null;
if (this.eventInterval != -1) if (this.eventInterval != -1)
clearInterval(this.intervalId); clearInterval(this.intervalId);
that.onHandleEvent('MOUSE_UP', new Point(e.offset), null, null); that.onHandleEvent('MOUSE_UP', viewToArtwork(e), null, null);
if (that.onMouseUp) if (that.onMouseUp)
that._document.redraw(); that._document.redraw();
dragging = false; dragging = false;
}, },
mousemove: function(e) { mousemove: function(e) {
if(!dragging) { if (!dragging) {
that.onHandleEvent('MOUSE_MOVE', new Point(e.offset), null, null); that.onHandleEvent('MOUSE_MOVE', viewToArtwork(e), null, null);
if (that.onMouseMove) if (that.onMouseMove)
that._document.redraw(); that._document.redraw();
} }
@ -71,4 +78,5 @@ Tool = ToolHandler.extend({
getDocument: function() { getDocument: function() {
return this._document; return this._document;
} }
};
}); });