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

Invert canvas rotation direction if view is flipped #1778

Merged
merged 6 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions app/src/actioncommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,16 @@ void ActionCommands::ZoomOut()

void ActionCommands::rotateClockwise()
{
float currentRotation = mEditor->view()->rotation();
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();
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()
Expand Down
8 changes: 8 additions & 0 deletions core_lib/src/managers/viewmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions core_lib/src/managers/viewmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ViewManager : public BaseManager

float rotation();
void rotate(float degree);
void rotateRelative(float delta);
void resetRotation();

qreal scaling();
Expand Down
6 changes: 4 additions & 2 deletions core_lib/src/tool/handtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ void HandTool::transformView(Qt::KeyboardModifiers keyMod, Qt::MouseButtons butt

qreal angleOffset = static_cast<qreal>(std::atan2(curV.y(), curV.x()) - std::atan2(startV.y(), startV.x()));
angleOffset = qRadiansToDegrees(angleOffset);
float newAngle = viewMgr->rotation() + static_cast<float>(angleOffset);
viewMgr->rotate(newAngle);
// Invert rotation direction if view is flipped either vertically or horizontally
const float delta = viewMgr->isFlipHorizontal() == !viewMgr->isFlipVertical()
? static_cast<float>(angleOffset * -1) : static_cast<float>(angleOffset);
viewMgr->rotateRelative(delta);
}
else if (isScale)
{
Expand Down