mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -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,
|
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;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
});
|
});
|
Loading…
Reference in a new issue