Skip to content

Commit

Permalink
fix(): getLocalPointer
Browse files Browse the repository at this point in the history
moved to object_origin mixin
  • Loading branch information
ShaMan123 committed Feb 11, 2022
1 parent 1259773 commit 8bf7f92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
14 changes: 14 additions & 0 deletions src/mixins/object_origin.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@
return p2.subtractEquals(p);
},

/**
* Returns coordinates of a pointer relative to object's top left corner
* @param {Event} e Event to operate upon
* @param {Object} [pointer] Pointer to operate upon (instead of event)
* @return {Object} Coordinates of a pointer (x, y)
*/
getLocalPointer: function (e, pointer) {
pointer = pointer || this.canvas.getPointer(e);
return fabric.util.transformPoint(
new fabric.Point(pointer.x, pointer.y),
fabric.util.invertTransform(this.calcTransformMatrix())
).addEquals(new fabric.Point(this.width / 2, this.height / 2));
},

/**
* Returns the point in global coordinates
* @param {fabric.Point} The point relative to the local coordinate system
Expand Down
24 changes: 0 additions & 24 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1925,30 +1925,6 @@
return this;
},

/**
* Returns coordinates of a pointer relative to an object
* @param {Event} e Event to operate upon
* @param {Object} [pointer] Pointer to operate upon (instead of event)
* @return {Object} Coordinates of a pointer (x, y)
*/
getLocalPointer: function (e, pointer) {
pointer = pointer || this.canvas.getPointer(e);
var pClicked = new fabric.Point(pointer.x, pointer.y),
objectLeftTop = this._getLeftTopCoords(),
angle = this.getTotalAngle();
if (this.group) {
objectLeftTop = fabric.util.transformPoint(objectLeftTop, this.group.calcTransformMatrix());
}
if (this.angle) {
pClicked = fabric.util.rotatePoint(
pClicked, objectLeftTop, degreesToRadians(-angle));
}
return {
x: pClicked.x - objectLeftTop.x,
y: pClicked.y - objectLeftTop.y
};
},

/**
* Sets canvas globalCompositeOperation for specific object
* custom composition operation for the particular object can be specified using globalCompositeOperation property
Expand Down

0 comments on commit 8bf7f92

Please sign in to comment.