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:
@@ -197,10 +197,20 @@ QTransform ViewerDisplayWidget::GenerateWorldTransform()
|
|||||||
return world;
|
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)
|
void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (gizmos_
|
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_click_ = true;
|
||||||
gizmo_drag_time_ = GetGizmoTime();
|
gizmo_drag_time_ = GetGizmoTime();
|
||||||
return;
|
return;
|
||||||
@@ -246,7 +256,9 @@ void ViewerDisplayWidget::mouseMoveEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gizmo_click_) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
QTransform GenerateWorldTransform();
|
QTransform GenerateWorldTransform();
|
||||||
|
|
||||||
|
QPoint TransformViewerSpaceToGizmoSpace(QPoint pos);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
* @brief Set the transformation matrix to draw with
|
* @brief Set the transformation matrix to draw with
|
||||||
|
|||||||
Reference in New Issue
Block a user