Skip to content

Commit

Permalink
fix(controls): fixed the uniform scaling option (#6218)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Mar 17, 2020
1 parent ea2b86d commit 035eed8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
13 changes: 7 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

## [4.0.0-beta.8]

- fix(svg_parsers): Add support for empty <style/> tags [#6169](https://github.com/fabricjs/fabric.js/pull/)
- fix(SVG_export, text): Check font faces markup for objects within groups [#6195](https://github.com/fabricjs/fabric.js/pull/)
- feat(animation): Extend fabric.util.animate animating colors and other properties[#6191](https://github.com/fabricjs/fabric.js/pull/)
- fix(svg_export): remove extra space from svg export [#6209](https://github.com/fabricjs/fabric.js/pull/)
- fix(svg_import): ISSUE-6170 do not try to create missing clippath [#6210](https://github.com/fabricjs/fabric.js/pull/)
- fix(fabric.Object) Adding existence check for this.canvas on object stacking mixins [#6207](https://github.com/fabricjs/fabric.js/pull/)
- fix(fabric.Object): fix activeSelection toDataURL canvas restore [#6216](https://github.com/fabricjs/fabric.js/pull/6216)
- fix(svg_parsers): Add support for empty <style/> tags [#6169](https://github.com/fabricjs/fabric.js/pull/6169)
- fix(SVG_export, text): Check font faces markup for objects within groups [#6195](https://github.com/fabricjs/fabric.js/pull/6195)
- feat(animation): Extend fabric.util.animate animating colors and other properties[#6191](https://github.com/fabricjs/fabric.js/pull/6191)
- fix(svg_export): remove extra space from svg export [#6209](https://github.com/fabricjs/fabric.js/pull/6209)
- fix(svg_import): ISSUE-6170 do not try to create missing clippath [#6210](https://github.com/fabricjs/fabric.js/pull/6210)
- fix(fabric.Object) Adding existence check for this.canvas on object stacking mixins [#6207](https://github.com/fabricjs/fabric.js/pull/6207)

## [4.0.0-beta.7]

Expand Down
60 changes: 40 additions & 20 deletions src/controls.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,41 @@
target.fire(eventName, options);
}

function scaleCursorStyleHandler(eventData, corner, fabricObject) {
var canvas = fabricObject.canvas, uniScaleKey = canvas.uniScaleKey, notAllowed = 'not-allowed',
uniformIsToggled = eventData[uniScaleKey],
scaleIsProportional = (canvas.uniformScaling && !uniformIsToggled) ||
(!canvas.uniformScaling && uniformIsToggled);
function scaleIsProportional(eventData, fabricObject) {
var canvas = fabricObject.canvas, uniScaleKey = canvas.uniScaleKey,
uniformIsToggled = eventData[uniScaleKey];
return (canvas.uniformScaling && !uniformIsToggled) ||
(!canvas.uniformScaling && uniformIsToggled);
}

if (fabricObject.lockScalingX && fabricObject.lockScalingY) {
return notAllowed;
function scalingIsForbidden(fabricObject, by, scaleProportionally) {
var lockX = fabricObject.lockScalingX, lockY = fabricObject.lockScalingY;
if (lockX && lockY) {
return true;
}
if (corner.x !== 0 && fabricObject.lockScalingX && scaleIsProportional) {
return notAllowed;
if (!by && (lockX || lockY) && scaleProportionally) {
return true;
}
if (lockX && by === 'x') {
return true;
}
if (lockY && by === 'y') {
return true;
}
return false;
}

function scaleCursorStyleHandler(eventData, corner, fabricObject) {
var notAllowed = 'not-allowed',
scaleProportionally = scaleIsProportional(eventData, fabricObject),
by = '';
if (corner.x !== 0 && corner.y === 0) {
by = 'x';
}
else if (corner.x === 0 && corner.y !== 0) {
by = 'y';
}
if (corner.y !== 0 && fabricObject.lockScalingY && scaleIsProportional) {
if (scalingIsForbidden(fabricObject, by, scaleProportionally)) {
return notAllowed;
}
var n = findCornerQuadrant(fabricObject, corner);
Expand Down Expand Up @@ -341,23 +363,20 @@
function scaleObject(eventData, transform, x, y, options) {
options = options || {};
var target = transform.target,
uniScaleKey = target.canvas.uniScaleKey, isUniScalePressed = eventData[uniScaleKey],
lockScalingX = target.lockScalingX, lockScalingY = target.lockScalingY,
by = options.by, newPoint, scaleX, scaleY, dim;

if (!isUniScalePressed && (lockScalingX || lockScalingY)) {
return false;
}
by = options.by, newPoint, scaleX, scaleY, dim,
scaleProportionally = scaleIsProportional(eventData, target),
forbidScaling = scalingIsForbidden(target, by, scaleProportionally);

if (isUniScalePressed && lockScalingX && lockScalingY) {
if (forbidScaling) {
return false;
}

dim = target._getTransformedDimensions();
newPoint = getLocalPoint(target, transform.originX, transform.originY, x, y);

// missing detection of flip and logic to switch the origin
if (!isUniScalePressed && !by) {
if (scaleProportionally && !by) {
// uniform scaling
var distance = Math.abs(newPoint.x) + Math.abs(newPoint.y),
original = transform.original,
Expand All @@ -379,10 +398,11 @@
// minScale is taken are in the setter.
var oldScaleX = target.scaleX, oldScaleY = target.scaleY;
if (!by) {
target.set('scaleX', scaleX);
target.set('scaleY', scaleY);
!lockScalingX && target.set('scaleX', scaleX);
!lockScalingY && target.set('scaleY', scaleY);
}
else {
// forbidden cases already handled on top here.
by === 'x' && target.set('scaleX', scaleX);
by === 'y' && target.set('scaleY', scaleY);
}
Expand Down

0 comments on commit 035eed8

Please sign in to comment.