From a745e4184926040250b650be3ca46b319bf797fb Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 8 Jun 2015 07:40:58 +0200 Subject: [PATCH] Added rotation logic to getLocalPointer, removed no more usefull getLocalRotatedPointer --- src/mixins/itext_click_behavior.mixin.js | 19 +------------------ src/shapes/object.class.js | 11 ++++++++--- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/mixins/itext_click_behavior.mixin.js b/src/mixins/itext_click_behavior.mixin.js index fc3b8d17a4b..9ef853aa449 100644 --- a/src/mixins/itext_click_behavior.mixin.js +++ b/src/mixins/itext_click_behavior.mixin.js @@ -156,30 +156,13 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot } }, - /** - * @private - * @param {Event} e Event object - * @return {Object} Coordinates of a pointer (x, y) - */ - _getLocalRotatedPointer: function(e) { - var pointer = this.canvas.getPointer(e), - - pClicked = new fabric.Point(pointer.x, pointer.y), - pLeftTop = new fabric.Point(this.left, this.top), - - rotated = fabric.util.rotatePoint( - pClicked, pLeftTop, fabric.util.degreesToRadians(-this.angle)); - - return this.getLocalPointer(e, rotated); - }, - /** * Returns index of a character corresponding to where an object was clicked * @param {Event} e Event object * @return {Number} Index of a character */ getSelectionStartFromPointer: function(e) { - var mouseOffset = this._getLocalRotatedPointer(e), + var mouseOffset = this._getLocalPointer(e), prevWidth = 0, width = 0, height = 0, diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index b7ae836c9cb..00ccfbc67c0 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -1464,10 +1464,15 @@ */ getLocalPointer: function(e, pointer) { pointer = pointer || this.canvas.getPointer(e); - var objectLeftTop = this.translateToOriginPoint(this.getCenterPoint(), 'left', 'top'); + var pClicked = new fabric.Point(pointer.x, pointer.y), + objectLeftTop = this._getLeftTopCoords(); + if (this.angle) { + pClicked = fabric.util.rotatePoint( + pClicked, objectLeftTop, fabric.util.degreesToRadians(-this.angle)); + } return { - x: pointer.x - objectLeftTop.x, - y: pointer.y - objectLeftTop.y + x: pClicked.x - objectLeftTop.x, + y: pClicked.y - objectLeftTop.y }; },