From 746b87dfcb7dc2d5687720f661707672a0331661 Mon Sep 17 00:00:00 2001 From: sapics Date: Tue, 12 May 2015 10:48:58 +0900 Subject: [PATCH] add comment and some code style fix --- src/shapes/group.class.js | 58 +++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/src/shapes/group.class.js b/src/shapes/group.class.js index 88fee3d9095..2846fd1c85c 100644 --- a/src/shapes/group.class.js +++ b/src/shapes/group.class.js @@ -52,13 +52,18 @@ * Constructor * @param {Object} objects Group objects * @param {Object} [options] Options object + * @param {Boolean} [alreadyGrouped] if true, objects have been grouped already. * @return {Object} thisArg */ - initialize: function(objects, options, skipPropagation) { + initialize: function(objects, options, alreadyGrouped) { options = options || { }; this._objects = []; - skipPropagation && this.callSuper('initialize', options); + // if objects enclosed in a group have been grouped already, + // we cannot change properties of objects. + // Thus we need to set options to group without objects, + // because delegatedProperties propagate to objects. + alreadyGrouped && this.callSuper('initialize', options); this._objects = objects || []; for (var i = this._objects.length; i--; ) { @@ -74,18 +79,16 @@ this.originY = options.originY; } - if (!skipPropagation) { + if (alreadyGrouped) { + // do not change coordinate of objects enclosed in a group, + // because objects coordinate system have been group coodinate system already. + this._updateObjectsCoords(true); + } + else { this._calcBounds(); this._updateObjectsCoords(); this.callSuper('initialize', options); } - else { - for (i = this._objects.length; i--; ) { - this._objects[i].setCoords(); - this._objects[i].__origHasControls = this._objects[i].hasControls; - this._objects[i].hasControls = false; - } - } this.setCoords(); this.saveCoords(); @@ -93,25 +96,32 @@ /** * @private + * @param {Boolean} [unchangeCoords] if true, coordinates of objects enclosed in a group do not change */ - _updateObjectsCoords: function() { - this.forEachObject(this._updateObjectCoords, this); + _updateObjectsCoords: function(unchangeCoords) { + for (var i = this._objects.length; i--; ){ + this._updateObjectCoords(this._objects[i], unchangeCoords); + } }, /** * @private - */ - _updateObjectCoords: function(object) { - var objectLeft = object.getLeft(), - objectTop = object.getTop(), - center = this.getCenterPoint(); - - object.set({ - originalLeft: objectLeft, - originalTop: objectTop, - left: objectLeft - center.x, - top: objectTop - center.y - }); + * @param {Object} object + * @param {Boolean} [unchangeCoords] if true, coordinates of object dose not change + */ + _updateObjectCoords: function(object, unchangeCoords) { + if (!unchangeCoords) { + var objectLeft = object.getLeft(), + objectTop = object.getTop(), + center = this.getCenterPoint(); + + object.set({ + originalLeft: objectLeft, + originalTop: objectTop, + left: objectLeft - center.x, + top: objectTop - center.y + }); + } object.setCoords();