Skip to content

Commit

Permalink
Add new events for transformations (#4979)
Browse files Browse the repository at this point in the history
* before:transform event

* added more properties to transform events

* add some more events

* fix lint

* tests
  • Loading branch information
asturur authored May 19, 2018
1 parent ea13a2a commit ac804af
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 68 deletions.
25 changes: 21 additions & 4 deletions src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@
* @see {@link fabric.Canvas#initialize} for constructor definition
*
* @fires object:modified
* @fires object:rotated
* @fires object:scaled
* @fires object:moved
* @fires object:skewed
* @fires object:rotating
* @fires object:scaling
* @fires object:moving
* @fires object:skewing
* @fires object:selected this event is deprecated. use selection:created
*
* @fires before:transform
* @fires before:selection:cleared
* @fires selection:cleared
* @fires selection:updated
Expand All @@ -31,6 +37,9 @@
* @fires mouse:down
* @fires mouse:move
* @fires mouse:up
* @fires mouse:down:before
* @fires mouse:move:before
* @fires mouse:up:before
* @fires mouse:over
* @fires mouse:out
* @fires mouse:dblclick
Expand Down Expand Up @@ -695,6 +704,7 @@
};

this._resetCurrentTransform();
this._beforeTransform(e);
},

/**
Expand Down Expand Up @@ -1250,6 +1260,8 @@
* ignoreZoom true gives back coordinates after being processed
* by the viewportTransform ( sort of coordinates of what is displayed
* on the canvas where you are clicking.
* ignoreZoom true = HTMLElement coordinates relative to top,left
* ignoreZoom false, default = fabric space coordinates, the same used for shape position
* To interact with your shapes top and left you want to use ignoreZoom true
* most of the time, while ignoreZoom false will give you coordinates
* compatible with the object.oCoords system.
Expand All @@ -1258,11 +1270,17 @@
* @param {Boolean} ignoreZoom
* @return {Object} object with "x" and "y" number values
*/
getPointer: function (e, ignoreZoom, upperCanvasEl) {
if (!upperCanvasEl) {
upperCanvasEl = this.upperCanvasEl;
getPointer: function (e, ignoreZoom) {
// return cached values if we are in the event processing chain
if (this._absolutePointer && !ignoreZoom) {
return this._absolutePointer;
}
if (this._pointer && ignoreZoom) {
return this._pointer;
}

var pointer = getPointer(e),
upperCanvasEl = this.upperCanvasEl,
bounds = upperCanvasEl.getBoundingClientRect(),
boundsWidth = bounds.width || 0,
boundsHeight = bounds.height || 0,
Expand All @@ -1278,7 +1296,6 @@
}

this.calcOffset();

pointer.x = pointer.x - this._offset.left;
pointer.y = pointer.y - this._offset.top;
if (!ignoreZoom) {
Expand Down
Loading

0 comments on commit ac804af

Please sign in to comment.