Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rotated pointer #2269

Merged
merged 1 commit into from
Jun 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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