Make gizmos work with translated/zoomed image

Added a new function that inverts the world transform and applies it to
a point. This allows the gizmo code to work in it's own space and not
need to know is the image has been zoomed or translated.
This commit is contained in:
Thomas Wilshaw
2020-06-21 19:31:40 +01:00
parent 1c6aebdcbe
commit ccb6efd6b6
2 changed files with 16 additions and 2 deletions
+14 -2
View File
@@ -197,10 +197,20 @@ QTransform ViewerDisplayWidget::GenerateWorldTransform()
return world;
}
QPoint ViewerDisplayWidget::TransformViewerSpaceToGizmoSpace(QPoint pos)
{
/*
* Inversion will only fail is the viewer has been scaled by 0 in any direction
* which I think should never happen. Also I don't know what we'd do if it does.
*/
return pos * GenerateWorldTransform().inverted();
}
void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
{
if (gizmos_
&& gizmos_->GizmoPress(gizmo_db_, event->pos(), QVector2D(GetTexturePosition(size())), size())) {
&& gizmos_->GizmoPress(gizmo_db_, TransformViewerSpaceToGizmoSpace(event->pos()),
QVector2D(GetTexturePosition(size())), size())) {
gizmo_click_ = true;
gizmo_drag_time_ = GetGizmoTime();
return;
@@ -246,7 +256,9 @@ void ViewerDisplayWidget::mouseMoveEvent(QMouseEvent *event)
}
if (gizmo_click_) {
gizmos_->GizmoMove(event->pos(), QVector2D(GetTexturePosition(size())), gizmo_drag_time_);
gizmos_->GizmoMove(TransformViewerSpaceToGizmoSpace(event->pos()),
QVector2D(GetTexturePosition(size())), gizmo_drag_time_);
update();
return;
}
+2
View File
@@ -93,6 +93,8 @@ public:
*/
QTransform GenerateWorldTransform();
QPoint TransformViewerSpaceToGizmoSpace(QPoint pos);
public slots:
/**
* @brief Set the transformation matrix to draw with