Implement the ctrl-g texture goto popup

This commit is contained in:
baldurk
2016-10-10 16:41:48 +02:00
parent 7d73ad7c0e
commit a1e9554e66
11 changed files with 366 additions and 19 deletions
+39
View File
@@ -0,0 +1,39 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2016 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#include "RDDoubleSpinBox.h"
RDDoubleSpinBox::RDDoubleSpinBox(QWidget *parent) : QDoubleSpinBox(parent)
{
}
RDDoubleSpinBox::~RDDoubleSpinBox()
{
}
void RDDoubleSpinBox::keyPressEvent(QKeyEvent *e)
{
emit keyPress(e);
QDoubleSpinBox::keyPressEvent(e);
}
+42
View File
@@ -0,0 +1,42 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2016 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#pragma once
#include <QDoubleSpinBox>
class RDDoubleSpinBox : public QDoubleSpinBox
{
private:
Q_OBJECT
public:
explicit RDDoubleSpinBox(QWidget *parent = 0);
~RDDoubleSpinBox();
signals:
void keyPress(QKeyEvent *e);
private:
void keyPressEvent(QKeyEvent *e) override;
};
+118
View File
@@ -0,0 +1,118 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2016 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#include "TextureGoto.h"
#include <QApplication>
#include <QDebug>
#include <QFocusEvent>
#include <QGridLayout>
#include <QLabel>
#include "Widgets/RDDoubleSpinBox.h"
TextureGoto::TextureGoto(QWidget *parent, std::function<void(QPoint)> callback) : QDialog(parent)
{
m_Callback = callback;
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
QHBoxLayout *hbox = new QHBoxLayout(this);
hbox->setSpacing(5);
hbox->setMargin(0);
QFrame *frame = new QFrame(this);
frame->setGeometry(geometry());
frame->setFrameShadow(QFrame::Raised);
frame->setFrameStyle(QFrame::StyledPanel);
hbox->addWidget(frame);
QGridLayout *gridLayout = new QGridLayout(frame);
gridLayout->setSpacing(4);
gridLayout->setContentsMargins(3, 3, 3, 3);
QLabel *label = new QLabel(this);
label->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
label->setText(tr("Goto Location"));
label->setAlignment(Qt::AlignCenter);
gridLayout->addWidget(label, 0, 0, 1, 2);
m_X = new RDDoubleSpinBox(frame);
m_X->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
m_X->setMinimumSize(QSize(40, 0));
m_X->setDecimals(0);
m_X->setSingleStep(1.0);
m_X->setRange(0.0, 65536.0);
m_X->setValue(10);
gridLayout->addWidget(m_X, 1, 0, 1, 1);
m_Y = new RDDoubleSpinBox(frame);
m_Y->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
m_Y->setMinimumSize(QSize(40, 0));
m_Y->setDecimals(0);
m_Y->setSingleStep(1.0);
m_Y->setRange(0.0, 65536.0);
m_Y->setValue(20);
QObject::connect(m_X, &RDDoubleSpinBox::keyPress, this, &TextureGoto::location_keyPress);
QObject::connect(m_Y, &RDDoubleSpinBox::keyPress, this, &TextureGoto::location_keyPress);
gridLayout->addWidget(m_Y, 1, 1, 1, 1);
setTabOrder(m_X, m_Y);
setTabOrder(m_Y, m_X);
}
QPoint TextureGoto::point()
{
return QPoint(m_X->value(), m_Y->value());
}
void TextureGoto::show(QWidget *showParent, QPoint p)
{
m_X->setValue(p.x());
m_Y->setValue(p.y());
move(showParent->mapToGlobal(showParent->geometry().topLeft()) + showParent->rect().center() -
rect().center());
QDialog::show();
m_Y->setFocus(Qt::TabFocusReason);
m_X->setFocus(Qt::TabFocusReason);
}
void TextureGoto::leaveEvent(QEvent *event)
{
QDialog::hide();
}
void TextureGoto::location_keyPress(QKeyEvent *event)
{
if(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
{
m_Callback(point());
QDialog::hide();
}
}
+51
View File
@@ -0,0 +1,51 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2016 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#pragma once
#include <QDialog>
#include <functional>
class RDDoubleSpinBox;
class TextureGoto : public QDialog
{
Q_OBJECT
public:
explicit TextureGoto(QWidget *parent, std::function<void(QPoint)> callback);
QPoint point();
void show(QWidget *showParent, QPoint p);
signals:
public slots:
void location_keyPress(QKeyEvent *);
private:
void leaveEvent(QEvent *event) override;
RDDoubleSpinBox *m_X, *m_Y;
std::function<void(QPoint)> m_Callback;
};
-12
View File
@@ -78,9 +78,6 @@
<iconset resource="../resources.qrc">
<normaloff>:/Resources/find.png</normaloff>:/Resources/find.png</iconset>
</property>
<property name="shortcut">
<string>Ctrl+F</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
@@ -101,9 +98,6 @@
<iconset resource="../resources.qrc">
<normaloff>:/Resources/flag_green.png</normaloff>:/Resources/flag_green.png</iconset>
</property>
<property name="shortcut">
<string>Ctrl+G</string>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
@@ -118,9 +112,6 @@
<iconset resource="../resources.qrc">
<normaloff>:/Resources/time.png</normaloff>:/Resources/time.png</iconset>
</property>
<property name="shortcut">
<string>Ctrl+T</string>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
@@ -135,9 +126,6 @@
<iconset resource="../resources.qrc">
<normaloff>:/Resources/asterisk_orange.png</normaloff>:/Resources/asterisk_orange.png</iconset>
</property>
<property name="shortcut">
<string>Ctrl+B</string>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
+74 -4
View File
@@ -30,6 +30,7 @@
#include "3rdparty/toolwindowmanager/ToolWindowManagerArea.h"
#include "Code/CaptureContext.h"
#include "Widgets/ResourcePreview.h"
#include "Widgets/TextureGoto.h"
#include "FlowLayout.h"
#include "ui_TextureViewer.h"
@@ -402,6 +403,8 @@ TextureViewer::TextureViewer(CaptureContext *ctx, QWidget *parent)
ui->outputThumbs->setWindowTitle(tr("Outputs"));
ui->inputThumbs->setWindowTitle(tr("Inputs"));
m_Goto = new TextureGoto(this, [this](QPoint p) { GotoLocation(p.x(), p.y()); });
QVBoxLayout *vertical = new QVBoxLayout(this);
vertical->setSpacing(3);
@@ -478,12 +481,13 @@ TextureViewer::~TextureViewer()
void TextureViewer::RT_FetchCurrentPixel(uint32_t x, uint32_t y, PixelValue &pickValue,
PixelValue &realValue)
{
// FetchTexture tex = CurrentTexture;
FetchTexture *texptr = GetCurrentTexture();
// if (tex == null) return;
if(texptr == NULL)
return;
// if (m_TexDisplay.FlipY)
// y = (tex.height - 1) - y;
if(m_TexDisplay.FlipY)
y = (texptr->height - 1) - y;
m_Output->PickPixel(m_TexDisplay.texid, true, x, y, m_TexDisplay.sliceFace, m_TexDisplay.mip,
m_TexDisplay.sampleIdx, &pickValue);
@@ -1403,6 +1407,31 @@ void TextureViewer::UI_CreateThumbnails()
UI_CreateThumbnail(ui->inputThumbs);
}
void TextureViewer::GotoLocation(int x, int y)
{
if(!m_Ctx->LogLoaded())
return;
FetchTexture *tex = GetCurrentTexture();
if(tex == NULL)
return;
m_PickedPoint = QPoint(x, y);
uint32_t mipHeight = qMax(1U, tex->height >> (int)m_TexDisplay.mip);
if(m_Ctx->APIProps().pipelineType == eGraphicsAPI_OpenGL)
m_PickedPoint.setY((int)(mipHeight - 1) - m_PickedPoint.y());
if(m_TexDisplay.FlipY)
m_PickedPoint.setY((int)(mipHeight - 1) - m_PickedPoint.x());
if(m_Output != NULL)
INVOKE_MEMFN(RT_PickPixelsAndUpdate);
INVOKE_MEMFN(RT_UpdateAndDisplay);
UI_UpdateStatusText();
}
void TextureViewer::ViewTexture(ResourceId ID, bool focus)
{
if(QThread::currentThread() != QCoreApplication::instance()->thread())
@@ -2003,6 +2032,11 @@ void TextureViewer::render_keyPress(QKeyEvent *e)
if(!m_Ctx->LogLoaded())
return;
if((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_G)
{
ShowGotoPopup();
}
bool nudged = false;
int increment = 1 << (int)m_TexDisplay.mip;
@@ -2671,3 +2705,39 @@ void TextureViewer::on_sliceFace_currentIndexChanged(int index)
INVOKE_MEMFN(RT_UpdateAndDisplay);
}
void TextureViewer::on_locationGoto_clicked()
{
ShowGotoPopup();
}
void TextureViewer::ShowGotoPopup()
{
FetchTexture *texptr = GetCurrentTexture();
if(texptr)
{
QPoint p = m_PickedPoint;
uint32_t mipHeight = qMax(1U, texptr->height >> (int)m_TexDisplay.mip);
if(m_Ctx->APIProps().pipelineType == eGraphicsAPI_OpenGL)
p.setY((int)(mipHeight - 1) - p.y());
if(m_TexDisplay.FlipY)
p.setY((int)(mipHeight - 1) - p.y());
m_Goto->show(ui->render, p);
}
}
void TextureViewer::on_viewTexBuffer_clicked()
{
}
void TextureViewer::on_texListShow_clicked()
{
}
void TextureViewer::on_saveTex_clicked()
{
}
+11
View File
@@ -36,6 +36,7 @@ class TextureViewer;
class ResourcePreview;
class ThumbnailStrip;
class TextureGoto;
enum struct FollowType
{
@@ -127,6 +128,7 @@ public:
void OnLogfileClosed();
void OnEventSelected(uint32_t eventID);
void GotoLocation(int x, int y);
void ViewTexture(ResourceId ID, bool focus);
QVariant persistData();
@@ -173,6 +175,11 @@ private slots:
void channelsWidget_toggled(bool checked) { UI_UpdateChannels(); }
void channelsWidget_selected(int index) { UI_UpdateChannels(); }
void on_locationGoto_clicked();
void on_viewTexBuffer_clicked();
void on_texListShow_clicked();
void on_saveTex_clicked();
private:
void RT_FetchCurrentPixel(uint32_t x, uint32_t y, PixelValue &pickValue, PixelValue &realValue);
void RT_PickPixelsAndUpdate(IReplayRenderer *);
@@ -222,6 +229,8 @@ private:
FetchTexture *GetCurrentTexture();
void ShowGotoPopup();
void UI_UpdateFittedScale();
void UI_SetScale(float s);
void UI_SetScale(float s, int x, int y);
@@ -252,6 +261,8 @@ private:
ResourceId m_LockedId;
QMap<ResourceId, QWidget *> m_LockedTabs;
TextureGoto *m_Goto;
Ui::TextureViewer *ui;
CaptureContext *m_Ctx = NULL;
IReplayOutput *m_Output = NULL;
+1 -1
View File
@@ -454,7 +454,7 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="texListShow_2">
<widget class="QToolButton" name="locationGoto">
<property name="text">
<string/>
</property>
+6 -2
View File
@@ -96,7 +96,9 @@ SOURCES += Code/qrenderdoc.cpp \
Widgets/ResourcePreview.cpp \
Widgets/RDLabel.cpp \
Widgets/ThumbnailStrip.cpp \
Code/CommonPipelineState.cpp
Code/CommonPipelineState.cpp \
Widgets/TextureGoto.cpp \
Widgets/RDDoubleSpinBox.cpp
HEADERS += Windows/MainWindow.h \
Windows/EventBrowser.h \
@@ -114,7 +116,9 @@ HEADERS += Windows/MainWindow.h \
Widgets/ResourcePreview.h \
Widgets/RDLabel.h \
Widgets/ThumbnailStrip.h \
Code/CommonPipelineState.h
Code/CommonPipelineState.h \
Widgets/TextureGoto.h \
Widgets/RDDoubleSpinBox.h
FORMS += Windows/MainWindow.ui \
Windows/EventBrowser.ui \
+6
View File
@@ -282,18 +282,22 @@
<ClCompile Include="generated\moc_CaptureContext.cpp" />
<ClCompile Include="generated\moc_CustomPaintWidget.cpp" />
<ClCompile Include="generated\moc_EventBrowser.cpp" />
<ClCompile Include="generated\moc_RDDoubleSpinBox.cpp" />
<ClCompile Include="generated\moc_RDLabel.cpp" />
<ClCompile Include="generated\moc_RDLineEdit.cpp" />
<ClCompile Include="generated\moc_MainWindow.cpp" />
<ClCompile Include="generated\moc_ResourcePreview.cpp" />
<ClCompile Include="generated\moc_TextureGoto.cpp" />
<ClCompile Include="generated\moc_TextureViewer.cpp" />
<ClCompile Include="generated\moc_ThumbnailStrip.cpp" />
<ClCompile Include="generated\moc_ToolWindowManager.cpp" />
<ClCompile Include="generated\moc_ToolWindowManagerArea.cpp" />
<ClCompile Include="generated\moc_ToolWindowManagerWrapper.cpp" />
<ClCompile Include="generated\qrc_resources.cpp" />
<ClCompile Include="Widgets\RDDoubleSpinBox.cpp" />
<ClCompile Include="Widgets\RDLabel.cpp" />
<ClCompile Include="Widgets\ResourcePreview.cpp" />
<ClCompile Include="Widgets\TextureGoto.cpp" />
<ClCompile Include="Widgets\ThumbnailStrip.cpp" />
<ClCompile Include="Windows\AboutDialog.cpp" />
<ClCompile Include="Code\CaptureContext.cpp" />
@@ -326,8 +330,10 @@
<ClInclude Include="generated\ui_ResourcePreview.h" />
<ClInclude Include="generated\ui_TextureViewer.h" />
<ClInclude Include="generated\ui_ThumbnailStrip.h" />
<ClInclude Include="Widgets\RDDoubleSpinBox.h" />
<ClInclude Include="Widgets\RDLabel.h" />
<ClInclude Include="Widgets\ResourcePreview.h" />
<ClInclude Include="Widgets\TextureGoto.h" />
<ClInclude Include="Widgets\ThumbnailStrip.h" />
<ClInclude Include="Windows\AboutDialog.h" />
<ClInclude Include="Code\CaptureContext.h" />
@@ -136,6 +136,18 @@
<ClCompile Include="Code\PersistantConfig.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="Widgets\TextureGoto.cpp">
<Filter>Widgets</Filter>
</ClCompile>
<ClCompile Include="generated\moc_TextureGoto.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="generated\moc_RDDoubleSpinBox.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="Widgets\RDDoubleSpinBox.cpp">
<Filter>Widgets</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="3rdparty\flowlayout\FlowLayout.h">
@@ -195,6 +207,12 @@
<ClInclude Include="Code\PersistantConfig.h">
<Filter>Generated Files</Filter>
</ClInclude>
<ClInclude Include="Widgets\TextureGoto.h">
<Filter>Widgets</Filter>
</ClInclude>
<ClInclude Include="Widgets\RDDoubleSpinBox.h">
<Filter>Widgets</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="resources.qrc">