Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix position jitter when flip enabled false #1659

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions src/shapes/Transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,6 @@ export class Transformer extends Group {
return;
}

const allowNegativeScale = this.flipEnabled();
var t = new Transform();
t.rotate(Konva.getAngle(this.rotation()));
if (
Expand All @@ -991,10 +990,6 @@ export class Transformer extends Group {
this._movingAnchorName = this._movingAnchorName.replace('left', 'right');
this._anchorDragOffset.x -= offset.x;
this._anchorDragOffset.y -= offset.y;
if (!allowNegativeScale) {
this.update();
return;
}
} else if (
this._movingAnchorName &&
newAttrs.width < 0 &&
Expand All @@ -1008,10 +1003,6 @@ export class Transformer extends Group {
this._anchorDragOffset.x -= offset.x;
this._anchorDragOffset.y -= offset.y;
newAttrs.width += this.padding() * 2;
if (!allowNegativeScale) {
this.update();
return;
}
}
if (
this._movingAnchorName &&
Expand All @@ -1028,10 +1019,6 @@ export class Transformer extends Group {
this._anchorDragOffset.x -= offset.x;
this._anchorDragOffset.y -= offset.y;
newAttrs.height += this.padding() * 2;
if (!allowNegativeScale) {
this.update();
return;
}
} else if (
this._movingAnchorName &&
newAttrs.height < 0 &&
Expand All @@ -1045,10 +1032,6 @@ export class Transformer extends Group {
this._anchorDragOffset.x -= offset.x;
this._anchorDragOffset.y -= offset.y;
newAttrs.height += this.padding() * 2;
if (!allowNegativeScale) {
this.update();
return;
}
}

if (this.boundBoxFunc()) {
Expand All @@ -1073,9 +1056,22 @@ export class Transformer extends Group {
oldTr.scale(oldAttrs.width / baseSize, oldAttrs.height / baseSize);

const newTr = new Transform();
newTr.translate(newAttrs.x, newAttrs.y);
newTr.rotate(newAttrs.rotation);
newTr.scale(newAttrs.width / baseSize, newAttrs.height / baseSize);
const newScaleX = newAttrs.width / baseSize;
const newScaleY = newAttrs.height / baseSize;

if (this.flipEnabled() === false) {
newTr.translate(newAttrs.x, newAttrs.y);
newTr.rotate(newAttrs.rotation);
newTr.translate(
newAttrs.width < 0 ? newAttrs.width : 0,
newAttrs.height < 0 ? newAttrs.height : 0
);
newTr.scale(Math.abs(newScaleX), Math.abs(newScaleY));
} else {
newTr.translate(newAttrs.x, newAttrs.y);
newTr.rotate(newAttrs.rotation);
newTr.scale(newScaleX, newScaleY);
}

// now lets think we had [old transform] and n ow we have [new transform]
// Now, the questions is: how can we transform "parent" to go from [old transform] into [new transform]
Expand Down
Loading