From 22d5cf23136720e22966b80d7cab2b36367923f8 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 15 May 2020 20:50:55 +0100 Subject: [PATCH] Scroll selected pixel to centre on goto. Refs #1885 --- qrenderdoc/Widgets/TextureGoto.cpp | 3 +++ qrenderdoc/Windows/TextureViewer.cpp | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/qrenderdoc/Widgets/TextureGoto.cpp b/qrenderdoc/Widgets/TextureGoto.cpp index 866ccedda..d0d88093c 100644 --- a/qrenderdoc/Widgets/TextureGoto.cpp +++ b/qrenderdoc/Widgets/TextureGoto.cpp @@ -24,6 +24,7 @@ #include "TextureGoto.h" #include +#include #include #include #include @@ -101,6 +102,8 @@ void TextureGoto::show(QWidget *showParent, QPoint p) m_Y->setFocus(Qt::TabFocusReason); m_X->setFocus(Qt::TabFocusReason); + + QCursor::setPos(mapToGlobal(rect().bottomRight() - QPoint(2, 2))); } void TextureGoto::leaveEvent(QEvent *event) diff --git a/qrenderdoc/Windows/TextureViewer.cpp b/qrenderdoc/Windows/TextureViewer.cpp index 85a74fc85..7f18853b3 100644 --- a/qrenderdoc/Windows/TextureViewer.cpp +++ b/qrenderdoc/Windows/TextureViewer.cpp @@ -1979,13 +1979,22 @@ void TextureViewer::GotoLocation(int x, int y) if(tex == NULL) return; + x = qMin(x << m_TexDisplay.subresource.mip, int(tex->width - 1)); + y = qMin(y << m_TexDisplay.subresource.mip, int(tex->height - 1)); + m_PickedPoint = QPoint(x, y); - uint32_t mipHeight = qMax(1U, tex->height >> (int)m_TexDisplay.subresource.mip); if(m_Ctx.APIProps().pipelineType == GraphicsAPI::OpenGL) - m_PickedPoint.setY((int)(mipHeight - 1) - m_PickedPoint.y()); + m_PickedPoint.setY((int)(tex->height - 1) - m_PickedPoint.y()); if(m_TexDisplay.flipY) - m_PickedPoint.setY((int)(mipHeight - 1) - m_PickedPoint.x()); + m_PickedPoint.setY((int)(tex->height - 1) - m_PickedPoint.x()); + + // centre the picked point. + QPoint scrollPos; + scrollPos.setX(-m_PickedPoint.x() * m_TexDisplay.scale + realRenderWidth() / 2); + scrollPos.setY(-m_PickedPoint.y() * m_TexDisplay.scale + realRenderHeight() / 2); + + setScrollPosition(scrollPos); if(m_Output != NULL) INVOKE_MEMFN(RT_PickPixelsAndUpdate); @@ -3630,6 +3639,9 @@ void TextureViewer::ShowGotoPopup() { QPoint p = m_PickedPoint; + p.setX(p.x() >> (int)m_TexDisplay.subresource.mip); + p.setY(p.y() >> (int)m_TexDisplay.subresource.mip); + uint32_t mipHeight = qMax(1U, texptr->height >> (int)m_TexDisplay.subresource.mip); if(m_Ctx.APIProps().pipelineType == GraphicsAPI::OpenGL)