mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-14 19:30:59 +00:00
fabric.Object.setAngle consider different originX/originY values other than "center"
Closes issue #1093
This commit is contained in:
parent
2c2ffb3187
commit
5ea264ae3d
2 changed files with 62 additions and 1 deletions
|
|
@ -198,6 +198,45 @@
|
|||
this.originX = to;
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Sets the origin/position of the object to it's center point
|
||||
* @return {void}
|
||||
*/
|
||||
_setOriginToCenter: function() {
|
||||
this._originalOriginX = this.originX;
|
||||
this._originalOriginY = this.originY;
|
||||
|
||||
var center = this.getCenterPoint();
|
||||
|
||||
this.originX = 'center';
|
||||
this.originY = 'center';
|
||||
|
||||
this.left = center.x;
|
||||
this.top = center.y;
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Resets the origin/position of the object to it's original origin
|
||||
* @return {void}
|
||||
*/
|
||||
_resetOrigin: function() {
|
||||
var originPoint = this.translateToOriginPoint(
|
||||
this.getCenterPoint(),
|
||||
this._originalOriginX,
|
||||
this._originalOriginY);
|
||||
|
||||
this.originX = this._originalOriginX;
|
||||
this.originY = this._originalOriginY;
|
||||
|
||||
this.left = originPoint.x;
|
||||
this.top = originPoint.y;
|
||||
|
||||
this._originalOriginX = null;
|
||||
this._originalOriginY = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1310,7 +1310,7 @@
|
|||
/**
|
||||
* Sets "color" of an instance (alias of `set('fill', …)`)
|
||||
* @param {String} color Color value
|
||||
* @return {fabric.Text} thisArg
|
||||
* @return {fabric.Object} thisArg
|
||||
* @chainable
|
||||
*/
|
||||
setColor: function(color) {
|
||||
|
|
@ -1318,6 +1318,28 @@
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets "angle" of an instance
|
||||
* @param {Number} angle Angle value
|
||||
* @return {fabric.Object} thisArg
|
||||
* @chainable
|
||||
*/
|
||||
setAngle: function(angle) {
|
||||
var shouldCenterOrigin = (this.originX !== 'center' || this.originY !== 'center') && this.centeredRotation;
|
||||
|
||||
if (shouldCenterOrigin) {
|
||||
this._setOriginToCenter();
|
||||
}
|
||||
|
||||
this.set('angle', angle);
|
||||
|
||||
if (shouldCenterOrigin) {
|
||||
this._resetOrigin();
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Centers object horizontally on canvas to which it was added last.
|
||||
* You might need to call `setCoords` on an object after centering, to update controls area.
|
||||
|
|
|
|||
Loading…
Reference in a new issue