Skip to content

Commit 8bf7f92

Browse files
committed
fix(): getLocalPointer
moved to object_origin mixin
1 parent 1259773 commit 8bf7f92

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

src/mixins/object_origin.mixin.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@
151151
return p2.subtractEquals(p);
152152
},
153153

154+
/**
155+
* Returns coordinates of a pointer relative to object's top left corner
156+
* @param {Event} e Event to operate upon
157+
* @param {Object} [pointer] Pointer to operate upon (instead of event)
158+
* @return {Object} Coordinates of a pointer (x, y)
159+
*/
160+
getLocalPointer: function (e, pointer) {
161+
pointer = pointer || this.canvas.getPointer(e);
162+
return fabric.util.transformPoint(
163+
new fabric.Point(pointer.x, pointer.y),
164+
fabric.util.invertTransform(this.calcTransformMatrix())
165+
).addEquals(new fabric.Point(this.width / 2, this.height / 2));
166+
},
167+
154168
/**
155169
* Returns the point in global coordinates
156170
* @param {fabric.Point} The point relative to the local coordinate system

src/shapes/object.class.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,30 +1925,6 @@
19251925
return this;
19261926
},
19271927

1928-
/**
1929-
* Returns coordinates of a pointer relative to an object
1930-
* @param {Event} e Event to operate upon
1931-
* @param {Object} [pointer] Pointer to operate upon (instead of event)
1932-
* @return {Object} Coordinates of a pointer (x, y)
1933-
*/
1934-
getLocalPointer: function (e, pointer) {
1935-
pointer = pointer || this.canvas.getPointer(e);
1936-
var pClicked = new fabric.Point(pointer.x, pointer.y),
1937-
objectLeftTop = this._getLeftTopCoords(),
1938-
angle = this.getTotalAngle();
1939-
if (this.group) {
1940-
objectLeftTop = fabric.util.transformPoint(objectLeftTop, this.group.calcTransformMatrix());
1941-
}
1942-
if (this.angle) {
1943-
pClicked = fabric.util.rotatePoint(
1944-
pClicked, objectLeftTop, degreesToRadians(-angle));
1945-
}
1946-
return {
1947-
x: pClicked.x - objectLeftTop.x,
1948-
y: pClicked.y - objectLeftTop.y
1949-
};
1950-
},
1951-
19521928
/**
19531929
* Sets canvas globalCompositeOperation for specific object
19541930
* custom composition operation for the particular object can be specified using globalCompositeOperation property

0 commit comments

Comments
 (0)