Merge pull request #2269 from asturur/fix-rotated-poi

Fix rotated pointer
This commit is contained in:
Juriy Zaytsev 2015-06-10 11:59:22 -04:00
commit 0d83da0e29
2 changed files with 9 additions and 21 deletions

View file

@ -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,

View file

@ -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
};
},