From 2242b2a9948f05018b1fa169cad185925ba88c59 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sun, 10 Aug 2014 00:37:01 +0200 Subject: [PATCH 1/5] Update canvas.class.js Added lockScaleFlip variable to scale object method --- src/canvas.class.js | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/canvas.class.js b/src/canvas.class.js index 0a4f8a04..b73ac993 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -474,7 +474,8 @@ var t = this._currentTransform, target = t.target, lockScalingX = target.get('lockScalingX'), - lockScalingY = target.get('lockScalingY'); + lockScalingY = target.get('lockScalingY'), + lockScalingFlip = target.get('lockScalingFlip'); if (lockScalingX && lockScalingY) { return; @@ -487,7 +488,7 @@ this._setLocalMouse(localMouse, t); // Actually scale the object - this._setObjectScale(localMouse, t, lockScalingX, lockScalingY, by); + this._setObjectScale(localMouse, t, lockScalingX, lockScalingY, by, lockScalingFlip); // Make sure the constraints apply target.setPositionByOrigin(constraintPosition, t.originX, t.originY); @@ -496,32 +497,36 @@ /** * @private */ - _setObjectScale: function(localMouse, transform, lockScalingX, lockScalingY, by) { - var target = transform.target; + _setObjectScale: function(localMouse, transform, lockScalingX, lockScalingY, by, lockScalingFlip) { + var target = transform.target, forbidScalingX = false, forbidScalingY = false; - transform.newScaleX = target.scaleX; - transform.newScaleY = target.scaleY; + transform.newScaleX = localMouse.x / (target.width + target.strokeWidth); + transform.newScaleY = localMouse.y / (target.height + target.strokeWidth); + + if (lockScalingFlip && transform.newScaleX <= 0 && transform.newScaleX < target.scaleX) { + forbidScalingX = true; + } + + if (lockScalingFlip && transform.newScaleY <= 0 && transform.newScaleY < target.scaleY) { + forbidScalingY = true; + } if (by === 'equally' && !lockScalingX && !lockScalingY) { - this._scaleObjectEqually(localMouse, target, transform); + forbidScalingX || forbidScalingY || this._scaleObjectEqually(localMouse, target, transform); } else if (!by) { - transform.newScaleX = localMouse.x / (target.width + target.strokeWidth); - transform.newScaleY = localMouse.y / (target.height + target.strokeWidth); - - lockScalingX || target.set('scaleX', transform.newScaleX); - lockScalingY || target.set('scaleY', transform.newScaleY); + forbidScalingX || lockScalingX || target.set('scaleX', transform.newScaleX); + forbidScalingY || lockScalingY || target.set('scaleY', transform.newScaleY); } else if (by === 'x' && !target.get('lockUniScaling')) { - transform.newScaleX = localMouse.x / (target.width + target.strokeWidth); - lockScalingX || target.set('scaleX', transform.newScaleX); + forbidScalingX || lockScalingX || target.set('scaleX', transform.newScaleX); } else if (by === 'y' && !target.get('lockUniScaling')) { - transform.newScaleY = localMouse.y / (target.height + target.strokeWidth); - lockScalingY || target.set('scaleY', transform.newScaleY); + forbidScalingY || lockScalingY || target.set('scaleY', transform.newScaleY); } - this._flipObject(transform); + forbidScalingX || forbidScalingY || this._flipObject(transform); + }, /** From ebc1cf9604f5d843e6383f42b35bdc623ab9d66e Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sun, 10 Aug 2014 00:38:44 +0200 Subject: [PATCH 2/5] Update object.class.js added lockScalingFlip, if set to true you cannot flip by accident an objec while scaling it. --- src/shapes/object.class.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 7c433305..0a4a1b9a 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -658,6 +658,13 @@ */ lockUniScaling: false, + /** + * When `true`, object cannot be flipping by scaling with negative values + * @type Boolean + * @default + */ + + lockScalingFlip: false, /** * List of properties to consider when checking if state * of an object is changed (fabric.Object#hasStateChanged) From e8013f4964f1c14216731d4216db816f85610686 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sun, 10 Aug 2014 19:40:58 +0200 Subject: [PATCH 3/5] Update object.class.js Just grammar --- src/shapes/object.class.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 0a4a1b9a..cdf0cb44 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -659,7 +659,7 @@ lockUniScaling: false, /** - * When `true`, object cannot be flipping by scaling with negative values + * When `true`, object cannot be flipping by scaling into negative values * @type Boolean * @default */ From 66621bb37f0f1198c5a4a743af917ab6c2be2f2e Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Tue, 12 Aug 2014 23:02:55 +0200 Subject: [PATCH 4/5] Update canvas.class.js --- src/canvas.class.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/canvas.class.js b/src/canvas.class.js index b73ac993..e6fef510 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -504,11 +504,11 @@ transform.newScaleY = localMouse.y / (target.height + target.strokeWidth); if (lockScalingFlip && transform.newScaleX <= 0 && transform.newScaleX < target.scaleX) { - forbidScalingX = true; + forbidScalingX = true; } if (lockScalingFlip && transform.newScaleY <= 0 && transform.newScaleY < target.scaleY) { - forbidScalingY = true; + forbidScalingY = true; } if (by === 'equally' && !lockScalingX && !lockScalingY) { From 6cc42ca43c9fb81ee2fa937080f6026f99cfd8e4 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Tue, 12 Aug 2014 23:33:08 +0200 Subject: [PATCH 5/5] Update object.class.js --- src/shapes/object.class.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index cdf0cb44..97671aa3 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -659,7 +659,7 @@ lockUniScaling: false, /** - * When `true`, object cannot be flipping by scaling into negative values + * When `true`, object cannot be flipped by scaling into negative values * @type Boolean * @default */