Skip to content

Commit

Permalink
The code getViewScaleInverse assumes the m11 value is a scaling matri…
Browse files Browse the repository at this point in the history
…x but that's not guaranteed! We see the problem occur when the view has been rotated, which changes the matrix type so that it's no longer a pure scale factor. The fix is to create a new scaling matrix from the mScaling property and inverse that instead.
  • Loading branch information
MrStevns committed Jan 2, 2025
1 parent b6c8b3a commit f98f084
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core_lib/src/interface/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ LayerVisibility Editor::layerVisibility()

qreal Editor::viewScaleInversed()
{
return view()->getViewScaleInverse();
return view()->getScaleInversed();
}

void Editor::increaseLayerVisibilityIndex()
Expand Down
2 changes: 1 addition & 1 deletion core_lib/src/interface/scribblearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ void ScribbleArea::prepCameraPainter(int frame)
mEditor->playback()->isPlaying(),
mLayerVisibility,
mPrefs->getFloat(SETTING::LAYER_VISIBILITY_THRESHOLD),
mEditor->view()->getViewScaleInverse());
mEditor->view()->getScaleInversed());

OnionSkinPainterOptions onionSkinOptions;
onionSkinOptions.enabledWhilePlaying = mPrefs->getInt(SETTING::ONION_WHILE_PLAYBACK);
Expand Down
4 changes: 2 additions & 2 deletions core_lib/src/managers/viewmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ QTransform ViewManager::getViewInverse() const
return mViewCanvasInverse;
}

qreal ViewManager::getViewScaleInverse() const
qreal ViewManager::getScaleInversed() const
{
return mViewCanvasInverse.m11();
return QTransform::fromScale(mScaling, mScaling).inverted().m11();
}

void ViewManager::updateViewTransforms()
Expand Down
8 changes: 7 additions & 1 deletion core_lib/src/managers/viewmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ class ViewManager : public BaseManager

QTransform getView() const;
QTransform getViewInverse() const;
qreal getViewScaleInverse() const;

/**
* Creates a scaling matrix based on the current view scale and returns the inverted value
* @return The inverted scale value
*/
qreal getScaleInversed() const;

void resetView();

QPointF mapCanvasToScreen(QPointF p) const;
Expand Down
2 changes: 1 addition & 1 deletion core_lib/src/tool/cameratool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void CameraTool::updateUIAssists(const Layer* layer)

Camera* cam = camLayer->getLastCameraAtFrame(mEditor->currentFrame(), 0);
if (cam) {
mRotationHandlePoint = localRotationHandlePoint(cameraRect.topLeft(), localCamT, cam->scaling(), mEditor->view()->getViewScaleInverse());
mRotationHandlePoint = localRotationHandlePoint(cameraRect.topLeft(), localCamT, cam->scaling(), mEditor->view()->getScaleInversed());
}
}

Expand Down

0 comments on commit f98f084

Please sign in to comment.