Fix Transformer with parent negative scale

This commit is contained in:
Nathan Bruer 2018-07-02 11:04:54 -07:00
parent 1cac35652e
commit ac09295ac0

View File

@ -46,12 +46,17 @@
'bottom-right': 135 'bottom-right': 135
}; };
function getCursor(anchorName, rad) { function getCursor(anchorName, rad, isMirrored) {
if (anchorName === 'rotater') { if (anchorName === 'rotater') {
return 'crosshair'; return 'crosshair';
} }
rad += Konva.Util._degToRad(ANGLES[anchorName] || 0); 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; var angle = (Konva.Util._radToDeg(rad) % 360 + 360) % 360;
if ( if (
@ -334,8 +339,10 @@
// var dy = -pos.y + center.y; // var dy = -pos.y + center.y;
// var angle = -Math.atan2(-dy, dx) - Math.PI / 2; // var angle = -Math.atan2(-dy, dx) - Math.PI / 2;
var scale = tr.getAbsoluteScale();
var cursor = getCursor(name, rad); // 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; anchor.getStage().content.style.cursor = cursor;
layer.batchDraw(); layer.batchDraw();
}); });