From cc831757594ab74dd637b6804f617d2c19a48790 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 18 Aug 2018 23:21:16 +0200 Subject: [PATCH] fixed bug positioning group --- src/brushes/circle_brush.class.js | 2 +- src/brushes/spray_brush.class.js | 2 +- src/shapes/group.class.js | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/brushes/circle_brush.class.js b/src/brushes/circle_brush.class.js index c6cd6af9cfc..efa42a5d615 100644 --- a/src/brushes/circle_brush.class.js +++ b/src/brushes/circle_brush.class.js @@ -99,7 +99,7 @@ fabric.CircleBrush = fabric.util.createClass(fabric.BaseBrush, /** @lends fabric circles.push(circle); } - var group = new fabric.Group(circles, { originX: 'center', originY: 'center' }); + var group = new fabric.Group(circles); group.canvas = this.canvas; this.canvas.add(group); diff --git a/src/brushes/spray_brush.class.js b/src/brushes/spray_brush.class.js index 5fcb2b57cf3..531ce9ad7dc 100644 --- a/src/brushes/spray_brush.class.js +++ b/src/brushes/spray_brush.class.js @@ -109,7 +109,7 @@ fabric.SprayBrush = fabric.util.createClass( fabric.BaseBrush, /** @lends fabric rects = this._getOptimizedRects(rects); } - var group = new fabric.Group(rects, { originX: 'center', originY: 'center' }); + var group = new fabric.Group(rects); this.shadow && group.setShadow(this.shadow); this.canvas.add(group); this.canvas.fire('path:created', { path: group }); diff --git a/src/shapes/group.class.js b/src/shapes/group.class.js index abd562410f0..e67bcef57ec 100644 --- a/src/shapes/group.class.js +++ b/src/shapes/group.class.js @@ -78,6 +78,16 @@ if (!isAlreadyGrouped) { var center = options && options.centerPoint; + // we want to set origins before calculating the bounding box. + // so that the topleft can be set with that in mind. + // if specific top and left are passed, are overwritten later + // with the callSuper('initialize', options) + if (options.originX !== undefined) { + this.originX = options.originX; + } + if (options.originY !== undefined) { + this.originY = options.originY; + } // if coming from svg i do not want to calc bounds. // i assume width and height are passed along options center || this._calcBounds(); @@ -495,6 +505,8 @@ this.width = width; this.height = height; if (!onlyWidthHeight) { + // the bounding box always finds the topleft most corner. + // whatever is the group origin, we set up here the left/top position. this.setPositionByOrigin({ x: left, y: top }, 'left', 'top'); } },