From ac09295ac089be5dd5b74e077228824a1918bdbe Mon Sep 17 00:00:00 2001 From: Nathan Bruer Date: Mon, 2 Jul 2018 11:04:54 -0700 Subject: [PATCH] Fix Transformer with parent negative scale --- src/shapes/Transformer.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/shapes/Transformer.js b/src/shapes/Transformer.js index 424e65c2..9bdcb5f6 100644 --- a/src/shapes/Transformer.js +++ b/src/shapes/Transformer.js @@ -46,12 +46,17 @@ 'bottom-right': 135 }; - function getCursor(anchorName, rad) { + function getCursor(anchorName, rad, isMirrored) { if (anchorName === 'rotater') { return 'crosshair'; } rad += Konva.Util._degToRad(ANGLES[anchorName] || 0); + // If we are mirrored, we need to mirror the angle (this is not the same as + // rotate). + if (isMirrored) { + rad *= -1; + } var angle = (Konva.Util._radToDeg(rad) % 360 + 360) % 360; if ( @@ -334,8 +339,10 @@ // var dy = -pos.y + center.y; // var angle = -Math.atan2(-dy, dx) - Math.PI / 2; - - var cursor = getCursor(name, rad); + var scale = tr.getAbsoluteScale(); + // If scale.y < 0 xor scale.x < 0 we need to flip (not rotate). + var isMirrored = (scale.y * scale.x) < 0; + var cursor = getCursor(name, rad, isMirrored); anchor.getStage().content.style.cursor = cursor; layer.batchDraw(); });