gizmos: correctly map cursor positions after new traversing implementation
This commit is contained in:
@@ -43,7 +43,7 @@ PointGizmo::PointGizmo(QObject *parent) :
|
||||
|
||||
void PointGizmo::Draw(QPainter *p) const
|
||||
{
|
||||
QRectF rect = GetDrawingRect(GetStandardRadius() / p->transform().m11());
|
||||
QRectF rect = GetDrawingRect(p->transform(), GetStandardRadius());
|
||||
|
||||
if (shape_ != kAnchorPoint) {
|
||||
p->setPen(Qt::NoPen);
|
||||
@@ -72,7 +72,7 @@ void PointGizmo::Draw(QPainter *p) const
|
||||
|
||||
QRectF PointGizmo::GetClickingRect(const QTransform &t) const
|
||||
{
|
||||
return GetDrawingRect(GetStandardRadius() / t.m11() * 1.5);
|
||||
return GetDrawingRect(t, GetStandardRadius());
|
||||
}
|
||||
|
||||
double PointGizmo::GetStandardRadius()
|
||||
@@ -80,20 +80,29 @@ double PointGizmo::GetStandardRadius()
|
||||
return QFontMetrics(qApp->font()).height() * 0.25;
|
||||
}
|
||||
|
||||
QRectF PointGizmo::GetDrawingRect(double radius) const
|
||||
QRectF PointGizmo::GetDrawingRect(const QTransform &transform, double radius) const
|
||||
{
|
||||
QRectF r(0,0, radius, radius);
|
||||
|
||||
r = transform.inverted().mapRect(r);
|
||||
|
||||
double width = r.width();
|
||||
double height = r.height();
|
||||
|
||||
if (shape_ == kAnchorPoint) {
|
||||
radius *= 2;
|
||||
width *= 2;
|
||||
height *= 2;
|
||||
}
|
||||
|
||||
if (smaller_) {
|
||||
radius *= 0.5;
|
||||
width *= 0.5;
|
||||
height *= 0.5;
|
||||
}
|
||||
|
||||
return QRectF(point_.x() - radius,
|
||||
point_.y() - radius,
|
||||
2*radius,
|
||||
2*radius);
|
||||
return QRectF(point_.x() - width,
|
||||
point_.y() - height,
|
||||
2*width,
|
||||
2*height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
private:
|
||||
static double GetStandardRadius();
|
||||
|
||||
QRectF GetDrawingRect(double radius) const;
|
||||
QRectF GetDrawingRect(const QTransform &transform, double radius) const;
|
||||
|
||||
Shape shape_;
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
} else if (event->button() == Qt::LeftButton && gizmos_
|
||||
&& (gizmo_last_draw_transform_inverted_ = gizmo_last_draw_transform_.inverted(),
|
||||
current_gizmo_ = TryGizmoPress(gizmo_db_, event->pos() * gizmo_last_draw_transform_inverted_))) {
|
||||
current_gizmo_ = TryGizmoPress(gizmo_db_, gizmo_last_draw_transform_inverted_.map(event->pos())))) {
|
||||
|
||||
// Handle gizmo click
|
||||
gizmo_start_drag_ = event->pos();
|
||||
@@ -736,8 +736,6 @@ QTransform ViewerDisplayWidget::GenerateGizmoTransform(NodeTraverser >, const
|
||||
{
|
||||
QTransform t = GenerateDisplayTransform();
|
||||
if (GetTimeTarget()) {
|
||||
t.translate(gizmo_params_.width()*0.5, gizmo_params_.height()*0.5);
|
||||
|
||||
Node *target = GetTimeTarget();
|
||||
if (ViewerOutput *v = dynamic_cast<ViewerOutput *>(target)) {
|
||||
if (Node *n = v->GetConnectedTextureOutput()) {
|
||||
@@ -748,8 +746,12 @@ QTransform ViewerDisplayWidget::GenerateGizmoTransform(NodeTraverser >, const
|
||||
QTransform nt;
|
||||
gt.Transform(&nt, gizmos_, target, range);
|
||||
|
||||
t.translate(gizmo_params_.width()*0.5, gizmo_params_.height()*0.5);
|
||||
t.scale(gizmo_params_.width(), gizmo_params_.height());
|
||||
|
||||
t = nt * t;
|
||||
|
||||
t.scale(1.0 / gizmo_params_.width(), 1.0 / gizmo_params_.height());
|
||||
t.translate(-gizmo_params_.width()*0.5, -gizmo_params_.height()*0.5);
|
||||
}
|
||||
|
||||
@@ -762,7 +764,7 @@ NodeGizmo *ViewerDisplayWidget::TryGizmoPress(const NodeValueRow &row, const QPo
|
||||
NodeGizmo *gizmo = *it;
|
||||
if (gizmo->IsVisible()) {
|
||||
if (PointGizmo *point = dynamic_cast<PointGizmo*>(gizmo)) {
|
||||
if (point->GetClickingRect(GenerateDisplayTransform()).contains(p)) {
|
||||
if (point->GetClickingRect(gizmo_last_draw_transform_).contains(p)) {
|
||||
return point;
|
||||
}
|
||||
} else if (PolygonGizmo *poly = dynamic_cast<PolygonGizmo*>(gizmo)) {
|
||||
|
||||
Reference in New Issue
Block a user