From 12859d7a24e0779d39440d20500710ea1490a0e2 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Mon, 28 Feb 2011 16:41:24 +0100 Subject: [PATCH 01/11] Item: pass on param object to Item#draw. --- src/item/Item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/item/Item.js b/src/item/Item.js index 450e6278..ad1545ef 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -547,7 +547,7 @@ Item = Base.extend({ var context = canvas.getContext('2d'); var matrix = new Matrix().scale(scale).translate(-bounds.x, -bounds.y); matrix.applyToContext(context); - this.draw(context); + this.draw(context, {}); var raster = new Raster(canvas); raster.position = this.bounds.center; raster.scale(1 / scale); From a7429205edd94e8e92144a04ee5c7075b6938640 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Mon, 28 Feb 2011 18:27:57 +0100 Subject: [PATCH 02/11] Allow Matrix#applyToContext to optionally reset the matrix transformation. --- src/basic/Matrix.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/basic/Matrix.js b/src/basic/Matrix.js index 8cfa6574..18130794 100644 --- a/src/basic/Matrix.js +++ b/src/basic/Matrix.js @@ -454,11 +454,18 @@ var Matrix = Base.extend({ /** * Applies this matrix to the specified Canvas Context. */ - applyToContext: function(context) { - context.setTransform( - this._m00, this._m01, this._m10, - this._m11, this._m02, this._m12 - ); + applyToContext: function(context, reset) { + if (reset) { + context.setTransform( + this._m00, this._m01, this._m10, + this._m11, this._m02, this._m12 + ); + } else { + context.transform( + this._m00, this._m01, this._m10, + this._m11, this._m02, this._m12 + ); + } }, statics: { From 84e31925b652904791f77f8c6008b76c6822d6b7 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Mon, 28 Feb 2011 18:28:16 +0100 Subject: [PATCH 03/11] Implement DocumentView. --- src/document/DocumentView.js | 97 ++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/document/DocumentView.js diff --git a/src/document/DocumentView.js b/src/document/DocumentView.js new file mode 100644 index 00000000..be914f1a --- /dev/null +++ b/src/document/DocumentView.js @@ -0,0 +1,97 @@ +DocumentView = Base.extend({ + beans: true, + + initialize: function(document) { + this.document = document; + this._bounds = this.document.bounds.clone(); + this.matrix = new Matrix(); + this._zoom = 1; + this._center = this._bounds.center; + }, + + // TODO: test this. + getCenter: function() { + return this._center; + }, + + setCenter: function() { + var center = Point.read(arguments); + if (center) { + var delta = center.subtract(this._center); + this.scrollBy(delta); + this._center = center; + } + }, + + getZoom: function() { + return this._zoom; + }, + + setZoom: function(zoom) { + // TODO: clamp the view between 1/32 and 64? + var mx = new Matrix(); + mx.scale(zoom / this._zoom, this.center); + this.transform(mx); + this._zoom = zoom; + }, + + scrollBy: function() { + var point = Point.read(arguments).negate(); + var mx = new Matrix().translate(point); + this.transform(mx); + }, + + getBounds: function() { + return this._bounds; + }, + + // TODO: + // setBounds: function(rect) { + // + // }, + + // TODO: getInvalidBounds + // TODO: invalidate(rect) + // TODO: style: artwork / preview / raster / opaque / ink + // TODO: getShowGrid + // TODO: getMousePoint + // TODO: artworkToView(rect) + artworkToView: function(point) { + return this.matrix.transform(point); + }, + + viewToArtwork: function(point) { + // TODO: cache the inverse matrix: + return this.matrix.createInverse().transform(point); + }, + + // TODO: inherit this code somehow? + transform: function(matrix, flags) { + var width = this.document.bounds.width; + var height = this.document.bounds.height; + var x = width * -0.5; + var y = height * -0.5; + var coords = [ + x, y, + x + width, y, + x + width, y + height, + x, y + height]; + this.matrix.preConcatenate(matrix); + this.matrix.createInverse().transform(coords, 0, coords, 0, 4); + var xMin = coords[0], xMax = coords[0]; + var yMin = coords[1], yMax = coords[1]; + for (var i = 2; i < 8; i += 2) { + var x = coords[i]; + var y = coords[i + 1]; + xMin = Math.min(x, xMin); + xMax = Math.max(x, xMax); + yMin = Math.min(y, yMin); + yMax = Math.max(y, yMax); + }; + var bounds = this._bounds; + bounds.x = xMin; + bounds.y = yMin; + bounds.width = xMax - xMin; + bounds.height = yMax - yMin; + } +}); \ No newline at end of file From 74f797a9dd0c0acf7d1fe2d0ddd9c2cc0d49c94a Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Mon, 28 Feb 2011 18:30:08 +0100 Subject: [PATCH 04/11] Clean up whitespace. --- src/item/Item.js | 4 ++-- src/item/Raster.js | 6 +++--- src/path/CompoundPath.js | 4 ++-- src/path/Path.Constructors.js | 2 +- src/path/Path.js | 6 +++--- src/util/CanvasProvider.js | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index ad1545ef..336f7c63 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -478,7 +478,7 @@ Item = Base.extend({ while(parent) { // Find group parents. Check for parent.parent, since don't want // top level layers, because they also inherit from Group - if(parent.parent + if (parent.parent && (parent instanceof Group || parent instanceof CompoundPath) && item.isDescendant(parent)) return true; @@ -538,7 +538,7 @@ Item = Base.extend({ // weird results on Scriptographer. Also we can't use antialiasing, since // Canvas doesn't support it yet. Document colorMode is also out of the // question for now. - if(!resolution) + if (!resolution) resolution = 72; // TODO: use strokebounds for this: var bounds = this.bounds; diff --git a/src/item/Raster.js b/src/item/Raster.js index 78c84bd1..80211bd0 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -164,7 +164,7 @@ Raster = Item.extend({ var xMin = coords[0], xMax = coords[0]; var yMin = coords[1], yMax = coords[1]; - for(var i = 2; i < 8; i += 2) { + for (var i = 2; i < 8; i += 2) { var x = coords[i]; var y = coords[i + 1]; xMin = Math.min(x, xMin); @@ -184,11 +184,11 @@ Raster = Item.extend({ }, draw: function(ctx, param) { - if(this.blendMode != 'normal' && !param.ignoreBlendMode) { + if (this.blendMode != 'normal' && !param.ignoreBlendMode) { BlendMode.process(ctx, this, param); } else { ctx.save(); - if(param.ignoreBlendMode !== true) + if (param.ignoreBlendMode !== true) this.matrix.applyToContext(ctx); ctx.drawImage(this._canvas || this._image, -this.size.width / 2, -this.size.height / 2); diff --git a/src/path/CompoundPath.js b/src/path/CompoundPath.js index 1833e942..43e24063 100644 --- a/src/path/CompoundPath.js +++ b/src/path/CompoundPath.js @@ -20,10 +20,10 @@ CompoundPath = PathItem.extend(new function() { }, draw: function(ctx, param) { - if(!this.visible) + if (!this.visible) return; if (this.children.length) { - if(this.blendMode != 'normal' && !param.ignoreBlendMode) { + if (this.blendMode != 'normal' && !param.ignoreBlendMode) { BlendMode.process(ctx, this, param); } else { var firstChild = this.children[0]; diff --git a/src/path/Path.Constructors.js b/src/path/Path.Constructors.js index 44b543fc..05532baa 100644 --- a/src/path/Path.Constructors.js +++ b/src/path/Path.Constructors.js @@ -110,7 +110,7 @@ Path.inject({ statics: new function() { var three = !(numSides % 3); var vector = new Point(0, three ? -radius : radius); var offset = three ? -1 : 0.5; - for(var i = 0; i < numSides; i++) { + for (var i = 0; i < numSides; i++) { var angle = (360 / numSides) * (i + offset); path.add(center.add(vector.rotate(angle))); } diff --git a/src/path/Path.js b/src/path/Path.js index 52ca16a8..bbb6fa6c 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -139,11 +139,11 @@ Path = PathItem.extend({ throw new Error('Nesting capacity exceeded in Path#getLenght()'); // Multiply by 3 again, as derivative was divided by 3 var length = 3 * integral; - if(goal == undefined || goal < 0 || goal >= length) + if (goal == undefined || goal < 0 || goal >= length) return length; var result = MathUtils.unsimpson(goal, ds, 0, goal / integral, 100 * MathUtils.EPSILON, integral, Math.sqrt(MathUtils.EPSILON), 1); - if(!result) + if (!result) throw new Error('Nesting capacity exceeded in computing arctime'); return -result.b; }, @@ -408,7 +408,7 @@ Path = PathItem.extend({ draw: function(ctx, param) { if (!this.visible) return; - if(this.blendMode != 'normal' && !param.ignoreBlendMode) { + if (this.blendMode != 'normal' && !param.ignoreBlendMode) { BlendMode.process(ctx, this, param); } else { param.ignoreBlendMode = false; diff --git a/src/util/CanvasProvider.js b/src/util/CanvasProvider.js index 0622bfbd..37e0e655 100644 --- a/src/util/CanvasProvider.js +++ b/src/util/CanvasProvider.js @@ -6,11 +6,11 @@ CanvasProvider = { canvases: [], getCanvas: function(size) { - if(this.canvases.length) { + if (this.canvases.length) { var canvas = this.canvases.pop(); // If they are not the same size, we don't need to clear them // using clearRect and visa versa. - if((canvas.width != size.width) || (canvas.height != size.height)) { + if ((canvas.width != size.width) || (canvas.height != size.height)) { canvas.width = size.width; canvas.height = size.height; } else { From 4fa293ec6d52f71905f1a9db9c09096252279800 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Mon, 28 Feb 2011 18:31:03 +0100 Subject: [PATCH 05/11] Have Tool convert points from view coordinates to artwork coordinates. --- src/tool/Tool.js | 146 +++++++++++++++++++++++++---------------------- 1 file changed, 77 insertions(+), 69 deletions(-) diff --git a/src/tool/Tool.js b/src/tool/Tool.js index 44dfeb2a..fada2019 100644 --- a/src/tool/Tool.js +++ b/src/tool/Tool.js @@ -1,74 +1,82 @@ -Tool = ToolHandler.extend({ - beans: true, +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) { - this.base(handlers); - if (Paper.document) - this.document = Paper.document; - }, - - setDocument: function(doc) { - if (this._document) - $(this._document.canvas).removeEvents(); - this._document = doc || Paper.document; - var that = this, curPoint; - var dragging = false; - var events = { - dragstart: function(e) { - curPoint = new Point(e.offset); - that.onHandleEvent('MOUSE_DOWN', curPoint, null, null); - if (that.onMouseDown) - that._document.redraw(); - if (that.eventInterval != -1) - this.intervalId = setInterval(events.drag, that.eventInterval); - dragging = true; - }, - drag: function(e) { - if (e) curPoint = new Point(e.offset); - if (curPoint) { - that.onHandleEvent('MOUSE_DRAG', curPoint, null, null); - if (that.onMouseDrag) + initialize: function(handlers, doc) { + this.base(handlers); + if (Paper.document) + this.document = Paper.document; + }, + + setDocument: function(doc) { + if (this._document) + $(this._document.canvas).removeEvents(); + this._document = doc || Paper.document; + var that = this, curPoint; + var dragging = false; + var events = { + dragstart: function(e) { + curPoint = viewToArtwork(e);//new Point(e.offset); + that.onHandleEvent('MOUSE_DOWN', curPoint, null, null); + if (that.onMouseDown) that._document.redraw(); - } - }, - dragend: function(e) { - curPoint = null; - if (this.eventInterval != -1) - clearInterval(this.intervalId); - that.onHandleEvent('MOUSE_UP', new Point(e.offset), 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); - if (that.onMouseMove) + if (that.eventInterval != -1) + this.intervalId = setInterval(events.drag, that.eventInterval); + dragging = true; + }, + drag: function(e) { + if (e) curPoint = viewToArtwork(e);//new Point(e.offset); + if (curPoint) { + that.onHandleEvent('MOUSE_DRAG', curPoint, null, null); + if (that.onMouseDrag) + that._document.redraw(); + } + }, + dragend: function(e) { + curPoint = null; + if (this.eventInterval != -1) + clearInterval(this.intervalId); + 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', viewToArtwork(e), null, null); + if (that.onMouseMove) + that._document.redraw(); + } } - } - }; - $(doc.canvas).addEvents(events); - }, - - /** - * The fixed time delay between each call to the {@link #onMouseDrag} - * 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: - * - * // Fire the onMouseDrag event once a second, - * // while the mouse button is down - * tool.eventInterval = 1000; - * - * - * @return the interval time in milliseconds - */ - eventInterval: -1, - - getDocument: function() { - return this._document; - } + }; + $(doc.canvas).addEvents(events); + }, + + /** + * The fixed time delay between each call to the {@link #onMouseDrag} + * 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: + * + * // Fire the onMouseDrag event once a second, + * // while the mouse button is down + * tool.eventInterval = 1000; + * + * + * @return the interval time in milliseconds + */ + eventInterval: -1, + + getDocument: function() { + return this._document; + } + }; }); \ No newline at end of file From 285f81f3637d65f5c6b90033ff9c2ec4036d4b6d Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Mon, 28 Feb 2011 18:31:51 +0100 Subject: [PATCH 06/11] Support PlacedSymbol opacity. --- src/item/PlacedSymbol.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/item/PlacedSymbol.js b/src/item/PlacedSymbol.js index 788d0e91..6adc1191 100644 --- a/src/item/PlacedSymbol.js +++ b/src/item/PlacedSymbol.js @@ -40,7 +40,7 @@ PlacedSymbol = Item.extend({ var xMin = coords[0], xMax = coords[0]; var yMin = coords[1], yMax = coords[1]; - for(var i = 2; i < 8; i += 2) { + for (var i = 2; i < 8; i += 2) { var x = coords[i]; var y = coords[i + 1]; xMin = Math.min(x, xMin); @@ -60,16 +60,42 @@ PlacedSymbol = Item.extend({ }, draw: function(ctx, param) { - if(this.blendMode != 'normal' && !param.ignoreBlendMode) { + if (this.blendMode != 'normal' && !param.ignoreBlendMode) { BlendMode.process(ctx, this, param); } else { + var tempCanvas, originalCtx; + if (this.opacity < 1) { + originalCtx = ctx; + // TODO: use strokeBounds for this, when implemented: + tempCanvas = CanvasProvider.getCanvas(this.document.size); + ctx = tempCanvas.getContext('2d'); + ctx.save(); + this.document.activeView.matrix.applyToContext(ctx); + } + // TODO: we need to preserve strokewidth, but still transform the fill ctx.save(); - if(param.ignoreBlendMode !== true) + if (param.ignoreBlendMode !== true) this.matrix.applyToContext(ctx); param.ignoreBlendMode = false; this.symbol.definition.draw(ctx, param); ctx.restore(); + + if (tempCanvas) { + // restore the activeView.matrix transformation, + // so we can draw the image without transformation. + originalCtx.restore(); + originalCtx.save(); + originalCtx.globalAlpha = this.opacity; + originalCtx.drawImage(tempCanvas, 0, 0); + originalCtx.restore(); + // apply the view transformation again. + this.document.activeView.matrix.applyToContext(ctx, true); + // Restore the state of the temp canvas: + ctx.restore(); + // Return the temp canvas, so it can be reused + CanvasProvider.returnCanvas(tempCanvas); + } } } // TODO: From fe9853852aae348b08717cae5ad6d01226b5c32d Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Mon, 28 Feb 2011 18:34:39 +0100 Subject: [PATCH 07/11] Implement new Doc(size) constructor, Doc#views / Doc#activeView and support DocumentView in Doc#redraw. --- src/document/Doc.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/document/Doc.js b/src/document/Doc.js index c62667a0..df2a5b58 100644 --- a/src/document/Doc.js +++ b/src/document/Doc.js @@ -2,17 +2,25 @@ Doc = Base.extend({ beans: true, initialize: function(canvas) { - if (canvas) { + if (canvas && canvas instanceof HTMLCanvasElement) { this.canvas = canvas; - this.ctx = this.canvas.getContext('2d'); this.size = new Size(canvas.offsetWidth, canvas.offsetHeight); + } else { + this.size = Size.read(arguments) || new Size(1024, 768); + this.canvas = document.createElement('canvas'); + this.canvas.width = this.size.width; + this.canvas.height = this.size.height; } + this.bounds = new Rectangle(new Point(0, 0), this.size); + this.ctx = this.canvas.getContext('2d'); Paper.documents.push(this); this.activate(); this.layers = []; this.activeLayer = new Layer(); this.currentStyle = null; this.symbols = []; + this.views = [new DocumentView(this)]; + this.activeView = this.views[0]; }, getCurrentStyle: function() { @@ -29,13 +37,18 @@ Doc = Base.extend({ redraw: function() { if (this.canvas) { - // Initial tests conclude that clearing the canvas is always - // faster than using clearRect: - // http://jsperf.com/clearrect-vs-setting-width/7 + // Initial tests conclude that clearing the canvas using clearRect + // is always faster than setting canvas.width = canvas.width + // http://jsperf.com/clearrect-vs-setting-width/ + var view = this.activeView; + var bounds = view.bounds; this.ctx.clearRect(0, 0, this.size.width + 1, this.size.height + 1); + this.ctx.save(); + view.matrix.applyToContext(this.ctx, true); for (var i = 0, l = this.layers.length; i < l; i++) { this.layers[i].draw(this.ctx, {}); } + this.ctx.restore(); } } }); From 0e011dee2a76513f357010c15aaf4437991708ea Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Mon, 28 Feb 2011 18:35:12 +0100 Subject: [PATCH 08/11] Support DocumentView in Group#draw. --- src/item/Group.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/item/Group.js b/src/item/Group.js index de88522e..3ce44968 100644 --- a/src/item/Group.js +++ b/src/item/Group.js @@ -18,7 +18,7 @@ Group = Item.extend({ // temporary canvas, and then draw that canvas onto ctx afterwards // with globalAlpha set. var tempCanvas, originalCtx; - if(this.blendMode != 'normal' && !param.ignoreBlendMode) { + if (this.blendMode != 'normal' && !param.ignoreBlendMode) { BlendMode.process(ctx, this, param); } else { param.ignoreBlendMode = false; @@ -27,6 +27,8 @@ Group = Item.extend({ // TODO: use strokeBounds for this, when implemented: tempCanvas = CanvasProvider.getCanvas(this.document.size); ctx = tempCanvas.getContext('2d'); + ctx.save(); + this.document.activeView.matrix.applyToContext(ctx); } for (var i = 0, l = this.children.length; i < l; i++) { this.children[i].draw(ctx, param); @@ -34,11 +36,18 @@ Group = Item.extend({ ctx.clip(); } if (tempCanvas) { + // restore the activeView.matrix transformation, + // so we can draw the image without transformation. + originalCtx.restore(); originalCtx.save(); originalCtx.globalAlpha = this.opacity; originalCtx.drawImage(tempCanvas, 0, 0); originalCtx.restore(); - // Return the canvas, so it can be reused + // apply the view transformation again. + this.document.activeView.matrix.applyToContext(ctx); + // Restore the state of the temp canvas: + ctx.restore(); + // Return the temp canvas, so it can be reused CanvasProvider.returnCanvas(tempCanvas); } } From eee5e63a7252ca3bf0dfcca1ce00d9ab5ddd8b30 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Mon, 28 Feb 2011 18:36:06 +0100 Subject: [PATCH 09/11] BlendMode: support DocumentView and return if an item's bounds is null. --- src/item/BlendMode.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/item/BlendMode.js b/src/item/BlendMode.js index 37f9fa3e..508f910a 100644 --- a/src/item/BlendMode.js +++ b/src/item/BlendMode.js @@ -30,15 +30,18 @@ BlendMode = { process: function(documentContext, item, param) { // TODO: use strokeBounds var itemBounds = item.bounds; + if (!itemBounds) + return; var top = Math.floor(itemBounds.top); var left = Math.floor(itemBounds.left); - var size = itemBounds.size.ceil(); + var size = itemBounds.size.ceil().add(1, 1); var width = size.width; var height = size.height; var itemCanvas = CanvasProvider.getCanvas(size); var itemContext = itemCanvas.getContext('2d'); - if(item.matrix) { + itemContext.save(); + if (item.matrix) { var matrix = item.matrix.clone(); var transMatrix = Matrix.getTranslateInstance(-left, -top); matrix.preConcatenate(transMatrix); @@ -210,6 +213,7 @@ BlendMode = { } } documentContext.putImageData(dstD, left, top); + itemContext.restore(); CanvasProvider.returnCanvas(itemCanvas); } }; \ No newline at end of file From 1261dc03df4a1093fb9ebba1dc757e8a7943f135 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Mon, 28 Feb 2011 18:41:46 +0100 Subject: [PATCH 10/11] Doc: point to the correct performance test url. --- src/document/Doc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/document/Doc.js b/src/document/Doc.js index df2a5b58..62a6a864 100644 --- a/src/document/Doc.js +++ b/src/document/Doc.js @@ -39,7 +39,7 @@ Doc = Base.extend({ if (this.canvas) { // Initial tests conclude that clearing the canvas using clearRect // is always faster than setting canvas.width = canvas.width - // http://jsperf.com/clearrect-vs-setting-width/ + // http://jsperf.com/clearrect-vs-setting-width/7 var view = this.activeView; var bounds = view.bounds; this.ctx.clearRect(0, 0, this.size.width + 1, this.size.height + 1); From 14b8452bad3c57c47548aadfec55b42e7ded4c83 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Mon, 28 Feb 2011 19:29:32 +0100 Subject: [PATCH 11/11] Fix mistakes in Tool.js --- src/tool/Tool.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/tool/Tool.js b/src/tool/Tool.js index fada2019..78e3349a 100644 --- a/src/tool/Tool.js +++ b/src/tool/Tool.js @@ -1,6 +1,6 @@ Tool = ToolHandler.extend(new function() { function viewToArtwork(event, document) { - var point = Point.read(event.offset.x, event.offset.y); + var point = Point.create(event.offset.x, event.offset.y); // TODO: always the active view? return document.activeView.viewToArtwork(point); }; @@ -22,7 +22,7 @@ Tool = ToolHandler.extend(new function() { var dragging = false; var events = { dragstart: function(e) { - curPoint = viewToArtwork(e);//new Point(e.offset); + curPoint = viewToArtwork(e, that._document); that.onHandleEvent('MOUSE_DOWN', curPoint, null, null); if (that.onMouseDown) that._document.redraw(); @@ -31,7 +31,7 @@ Tool = ToolHandler.extend(new function() { dragging = true; }, drag: function(e) { - if (e) curPoint = viewToArtwork(e);//new Point(e.offset); + if (e) curPoint = viewToArtwork(e, that._document); if (curPoint) { that.onHandleEvent('MOUSE_DRAG', curPoint, null, null); if (that.onMouseDrag) @@ -42,14 +42,16 @@ Tool = ToolHandler.extend(new function() { curPoint = null; if (this.eventInterval != -1) clearInterval(this.intervalId); - that.onHandleEvent('MOUSE_UP', viewToArtwork(e), null, null); + that.onHandleEvent('MOUSE_UP', + viewToArtwork(e, that._document), null, null); if (that.onMouseUp) that._document.redraw(); dragging = false; }, mousemove: function(e) { if (!dragging) { - that.onHandleEvent('MOUSE_MOVE', viewToArtwork(e), null, null); + that.onHandleEvent('MOUSE_MOVE', + viewToArtwork(e, that._document), null, null); if (that.onMouseMove) that._document.redraw(); }