mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-27 08:44:42 +00:00
Merge pull request #857 from briefbanane/master
Allow toggling of flipX/Y to flip the whole group
This commit is contained in:
commit
aeaa5fcb00
1 changed files with 40 additions and 1 deletions
|
|
@ -134,6 +134,7 @@
|
|||
* @chainable
|
||||
*/
|
||||
removeWithUpdate: function(object) {
|
||||
this._moveFlippedObject(object);
|
||||
this._restoreObjectsState();
|
||||
// since _restoreObjectsState set objects inactive
|
||||
this.forEachObject(function(o){ o.set('active', true); o.group = this; }, this);
|
||||
|
|
@ -258,6 +259,44 @@
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Moves a flipped object to the position where it's displayed
|
||||
* @private
|
||||
* @param {fabric.Object} object
|
||||
* @return {fabric.Group} thisArg
|
||||
*/
|
||||
_moveFlippedObject: function(object) {
|
||||
var oldOriginX = object.get('originX');
|
||||
var oldOriginY = object.get('originY');
|
||||
var center = object.getCenterPoint();
|
||||
object.set({
|
||||
originX: 'center',
|
||||
originY: 'center',
|
||||
left: center.x,
|
||||
top: center.y
|
||||
});
|
||||
|
||||
if (this.flipX) {
|
||||
object.toggle('flipX');
|
||||
object.set('left', -object.get('left'));
|
||||
object.setAngle(-object.getAngle());
|
||||
}
|
||||
if (this.flipY) {
|
||||
object.toggle('flipY');
|
||||
object.set('top', -object.get('top'));
|
||||
object.setAngle(-object.getAngle());
|
||||
}
|
||||
|
||||
var newOrigin = object.getPointByOrigin(oldOriginX, oldOriginY);
|
||||
object.set({
|
||||
originX: oldOriginX,
|
||||
originY: oldOriginY,
|
||||
left: newOrigin.x,
|
||||
top: newOrigin.y
|
||||
});
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Restores original state of a specified object in group
|
||||
* @private
|
||||
|
|
@ -265,7 +304,6 @@
|
|||
* @return {fabric.Group} thisArg
|
||||
*/
|
||||
_restoreObjectState: function(object) {
|
||||
|
||||
var groupLeft = this.get('left'),
|
||||
groupTop = this.get('top'),
|
||||
groupAngle = this.getAngle() * (Math.PI / 180),
|
||||
|
|
@ -296,6 +334,7 @@
|
|||
* @chainable
|
||||
*/
|
||||
destroy: function() {
|
||||
this._objects.forEach(this._moveFlippedObject, this);
|
||||
return this._restoreObjectsState();
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue