Remove duplicate code.
authorAlexandre Segura <mex.zktk@gmail.com>
Tue, 21 Feb 2017 14:35:19 +0100
changeset 331 74cdfdfa9f22
parent 330 64a8800e63eb
child 332 1670e5e1ed97
Remove duplicate code.
src_js/iconolab-bundle/src/components/editor/Canvas.vue
--- a/src_js/iconolab-bundle/src/components/editor/Canvas.vue	Mon Feb 20 23:56:15 2017 +0100
+++ b/src_js/iconolab-bundle/src/components/editor/Canvas.vue	Tue Feb 21 14:35:19 2017 +0100
@@ -365,20 +365,11 @@
                 var currentPosition = { x: 0, y: 0 };
                 var canDraw = false;
 
-                var computeOffset = (e) => {
-                    var rect = this.$refs.image.getBoundingClientRect();
-                    var zoomOffset = this.zoomOffset();
-                    var offsetX = (e.clientX - rect.left) / Math.min(zoomOffset.x, zoomOffset.y);
-                    var offsetY  = (e.clientY - rect.top) / Math.min(zoomOffset.x, zoomOffset.y);
-
-                    return { x: offsetX, y: offsetY };
-                }
-
                 this.paper.mousedown((e) => {
 
                     if (this.$refs.rect.width > 0 && this.$refs.rect.height > 0) { return; }
 
-                    startPosition = computeOffset(e);
+                    startPosition = this.computeOffset(e);
                     canDraw = true;
                 });
 
@@ -387,7 +378,7 @@
                     if (!canDraw) { return; }
 
                     var x, y;
-                    currentPosition = computeOffset(e);
+                    currentPosition = this.computeOffset(e);
 
                     /* bas -> droite */
                     var width = Math.abs(currentPosition.x - startPosition.x);
@@ -433,7 +424,7 @@
                     canDraw = false;
 
                     if (this.$refs.rect.width === 0 && this.$refs.rect.height === 0) {
-                        var currentPosition = computeOffset(e);
+                        var currentPosition = this.computeOffset(e);
                         Object.assign(this.$refs.rect, {
                             x: currentPosition.x,
                             y: currentPosition.y,