Skip to content

Commit

Permalink
Added rotation logic to getLocalPointer, removed no more usefull getL…
Browse files Browse the repository at this point in the history
…ocalRotatedPointer
  • Loading branch information
asturur committed Jun 8, 2015
1 parent 00b077c commit a745e41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
19 changes: 1 addition & 18 deletions src/mixins/itext_click_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 8 additions & 3 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
},

Expand Down

2 comments on commit a745e41

@boonkerz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? because the method is labeled as getLocal not as _gitLocal?

@asturur
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is wrong and there is a PR to fix it.
I did a bad copy paste before submitting. check #2278

Please sign in to comment.