From ef670bcd641840a414dd72e46fb90ec4d8a926ae Mon Sep 17 00:00:00 2001 From: HeCorr Date: Thu, 3 Aug 2023 15:54:55 -0300 Subject: [PATCH 1/6] invert action rotation direction if view is flipped see #1777 --- app/src/actioncommands.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index 6d1bac132..027f559ec 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -548,13 +548,29 @@ void ActionCommands::ZoomOut() void ActionCommands::rotateClockwise() { float currentRotation = mEditor->view()->rotation(); - mEditor->view()->rotate(currentRotation + 15.f); + // Invert rotation direction if view is flipped either vertically or horizontally + if (mEditor->view()->isFlipHorizontal() ^ mEditor->view()->isFlipVertical()) + { + mEditor->view()->rotate(currentRotation - 15.f); + } + else + { + mEditor->view()->rotate(currentRotation + 15.f); + } } void ActionCommands::rotateCounterClockwise() { float currentRotation = mEditor->view()->rotation(); - mEditor->view()->rotate(currentRotation - 15.f); + // Invert rotation direction if view is flipped either vertically or horizontally + if (mEditor->view()->isFlipHorizontal() ^ mEditor->view()->isFlipVertical()) + { + mEditor->view()->rotate(currentRotation + 15.f); + } + else + { + mEditor->view()->rotate(currentRotation - 15.f); + } } void ActionCommands::PlayStop() From 6fa1bd77ef48d090e343c97aa1d35fbe38213884 Mon Sep 17 00:00:00 2001 From: HeCorr Date: Thu, 3 Aug 2023 16:08:32 -0300 Subject: [PATCH 2/6] invert hand tool rotation direction if view is flipped see #1777 --- core_lib/src/tool/handtool.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core_lib/src/tool/handtool.cpp b/core_lib/src/tool/handtool.cpp index 5d3dc795d..33be74811 100644 --- a/core_lib/src/tool/handtool.cpp +++ b/core_lib/src/tool/handtool.cpp @@ -105,7 +105,16 @@ void HandTool::transformView(Qt::KeyboardModifiers keyMod, Qt::MouseButtons butt qreal angleOffset = static_cast(std::atan2(curV.y(), curV.x()) - std::atan2(startV.y(), startV.x())); angleOffset = qRadiansToDegrees(angleOffset); - float newAngle = viewMgr->rotation() + static_cast(angleOffset); + float newAngle = 0.0; + // Invert rotation direction if view is flipped either vertically or horizontally + if (viewMgr->isFlipHorizontal() ^ viewMgr->isFlipVertical()) + { + newAngle = viewMgr->rotation() - static_cast(angleOffset); + } + else + { + newAngle = viewMgr->rotation() + static_cast(angleOffset); + } viewMgr->rotate(newAngle); } else if (isScale) From bf93df6c98b313c108c567411e41e56dbca80248 Mon Sep 17 00:00:00 2001 From: HeCorr Date: Mon, 7 Aug 2023 10:28:53 -0300 Subject: [PATCH 3/6] create ViewManager::rotateRelative function similar to `rotate()` but doesn't require caller to know the current view rotation. --- core_lib/src/managers/viewmanager.cpp | 8 ++++++++ core_lib/src/managers/viewmanager.h | 1 + 2 files changed, 9 insertions(+) diff --git a/core_lib/src/managers/viewmanager.cpp b/core_lib/src/managers/viewmanager.cpp index fd79d3ea0..928d11d18 100644 --- a/core_lib/src/managers/viewmanager.cpp +++ b/core_lib/src/managers/viewmanager.cpp @@ -171,6 +171,14 @@ void ViewManager::rotate(float degree) emit viewChanged(); } +void ViewManager::rotateRelative(float delta) +{ + mRotation = mRotation + delta; + updateViewTransforms(); + + emit viewChanged(); +} + void ViewManager::resetRotation() { rotate(0); diff --git a/core_lib/src/managers/viewmanager.h b/core_lib/src/managers/viewmanager.h index 3a8d2d12d..1c0009c4d 100644 --- a/core_lib/src/managers/viewmanager.h +++ b/core_lib/src/managers/viewmanager.h @@ -58,6 +58,7 @@ class ViewManager : public BaseManager float rotation(); void rotate(float degree); + void rotateRelative(float delta); void resetRotation(); qreal scaling(); From 2e1be3a44ff1b0c048cbecf10d1a60439f940ebc Mon Sep 17 00:00:00 2001 From: HeCorr Date: Mon, 7 Aug 2023 10:31:09 -0300 Subject: [PATCH 4/6] replace XOR operator on HandTool::transformView as requested by MrStevns. --- core_lib/src/tool/handtool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core_lib/src/tool/handtool.cpp b/core_lib/src/tool/handtool.cpp index 33be74811..d9361cbef 100644 --- a/core_lib/src/tool/handtool.cpp +++ b/core_lib/src/tool/handtool.cpp @@ -107,7 +107,7 @@ void HandTool::transformView(Qt::KeyboardModifiers keyMod, Qt::MouseButtons butt angleOffset = qRadiansToDegrees(angleOffset); float newAngle = 0.0; // Invert rotation direction if view is flipped either vertically or horizontally - if (viewMgr->isFlipHorizontal() ^ viewMgr->isFlipVertical()) + if (viewMgr->isFlipHorizontal() == !viewMgr->isFlipVertical()) { newAngle = viewMgr->rotation() - static_cast(angleOffset); } From e1aa278a3ce3d21beefaff074d9e2b4de79c4f76 Mon Sep 17 00:00:00 2001 From: HeCorr Date: Mon, 7 Aug 2023 10:39:56 -0300 Subject: [PATCH 5/6] refactor ActionCommands rotation functions - replace XOR operators with `A == !B` - replace `if` with ternary operator - use rotateRelative() instead of rotate() - define a delta constant and call rotateRelative() once --- app/src/actioncommands.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index 027f559ec..343551737 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -547,30 +547,16 @@ void ActionCommands::ZoomOut() void ActionCommands::rotateClockwise() { - float currentRotation = mEditor->view()->rotation(); - // Invert rotation direction if view is flipped either vertically or horizontally - if (mEditor->view()->isFlipHorizontal() ^ mEditor->view()->isFlipVertical()) - { - mEditor->view()->rotate(currentRotation - 15.f); - } - else - { - mEditor->view()->rotate(currentRotation + 15.f); - } + // Rotation direction is inverted if view is flipped either vertically or horizontally + const float delta = mEditor->view()->isFlipHorizontal() == !mEditor->view()->isFlipVertical() ? -15.f : 15.f; + mEditor->view()->rotateRelative(delta); } void ActionCommands::rotateCounterClockwise() { - float currentRotation = mEditor->view()->rotation(); - // Invert rotation direction if view is flipped either vertically or horizontally - if (mEditor->view()->isFlipHorizontal() ^ mEditor->view()->isFlipVertical()) - { - mEditor->view()->rotate(currentRotation + 15.f); - } - else - { - mEditor->view()->rotate(currentRotation - 15.f); - } + // Rotation direction is inverted if view is flipped either vertically or horizontally + const float delta = mEditor->view()->isFlipHorizontal() == !mEditor->view()->isFlipVertical() ? 15.f : -15.f; + mEditor->view()->rotateRelative(delta); } void ActionCommands::PlayStop() From 8b5a55b423dd79055c02d9ef84dd19ba943e0df4 Mon Sep 17 00:00:00 2001 From: HeCorr Date: Mon, 7 Aug 2023 11:07:32 -0300 Subject: [PATCH 6/6] simplify rotation code in HandTool::transformView() - replace `if` with ternary operator - replace rotate() with rotateRelative() --- core_lib/src/tool/handtool.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/core_lib/src/tool/handtool.cpp b/core_lib/src/tool/handtool.cpp index d9361cbef..32e6e49ed 100644 --- a/core_lib/src/tool/handtool.cpp +++ b/core_lib/src/tool/handtool.cpp @@ -105,17 +105,10 @@ void HandTool::transformView(Qt::KeyboardModifiers keyMod, Qt::MouseButtons butt qreal angleOffset = static_cast(std::atan2(curV.y(), curV.x()) - std::atan2(startV.y(), startV.x())); angleOffset = qRadiansToDegrees(angleOffset); - float newAngle = 0.0; // Invert rotation direction if view is flipped either vertically or horizontally - if (viewMgr->isFlipHorizontal() == !viewMgr->isFlipVertical()) - { - newAngle = viewMgr->rotation() - static_cast(angleOffset); - } - else - { - newAngle = viewMgr->rotation() + static_cast(angleOffset); - } - viewMgr->rotate(newAngle); + const float delta = viewMgr->isFlipHorizontal() == !viewMgr->isFlipVertical() + ? static_cast(angleOffset * -1) : static_cast(angleOffset); + viewMgr->rotateRelative(delta); } else if (isScale) {