mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Have Tool convert points from view coordinates to artwork coordinates.
This commit is contained in:
parent
74f797a9dd
commit
4fa293ec6d
1 changed files with 77 additions and 69 deletions
|
@ -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;
|
||||
}
|
||||
};
|
||||
});
|
Loading…
Reference in a new issue