mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-04 09:00:44 +00:00
Implement zooming and scaling
This commit is contained in:
@@ -24,6 +24,11 @@ void CustomPaintWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
emit mouseMove(e);
|
||||
}
|
||||
|
||||
void CustomPaintWidget::wheelEvent(QWheelEvent *e)
|
||||
{
|
||||
emit mouseWheel(e);
|
||||
}
|
||||
|
||||
void CustomPaintWidget::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
emit resize(e);
|
||||
@@ -33,7 +38,7 @@ void CustomPaintWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
if(m_Output)
|
||||
{
|
||||
m_Core->Renderer()->BlockInvoke([this](IReplayRenderer *r) { m_Output->Display(); });
|
||||
m_Core->Renderer()->AsyncInvoke([this](IReplayRenderer *r) { m_Output->Display(); });
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -22,10 +22,12 @@ signals:
|
||||
void clicked(QMouseEvent *e);
|
||||
void mouseMove(QMouseEvent *e);
|
||||
void resize(QResizeEvent *e);
|
||||
void mouseWheel(QWheelEvent *e);
|
||||
|
||||
private slots:
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void wheelEvent(QWheelEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -40,8 +40,13 @@ TextureViewer::TextureViewer(Core *core, QWidget *parent)
|
||||
|
||||
QObject::connect(ui->render, &CustomPaintWidget::clicked, this, &TextureViewer::render_mouseClick);
|
||||
QObject::connect(ui->render, &CustomPaintWidget::mouseMove, this, &TextureViewer::render_mouseMove);
|
||||
QObject::connect(ui->render, &CustomPaintWidget::mouseWheel, this,
|
||||
&TextureViewer::render_mouseWheel);
|
||||
QObject::connect(ui->render, &CustomPaintWidget::resize, this, &TextureViewer::render_resize);
|
||||
|
||||
QObject::connect(ui->zoomOption->lineEdit(), &QLineEdit::returnPressed, this,
|
||||
&TextureViewer::on_zoomOption_returnPressed);
|
||||
|
||||
ui->dockarea->addToolWindow(ui->renderContainer, ToolWindowManager::EmptySpace);
|
||||
ui->dockarea->setToolWindowProperties(renderContainer, ToolWindowManager::DisallowUserDocking |
|
||||
ToolWindowManager::HideCloseButton |
|
||||
@@ -150,6 +155,11 @@ TextureViewer::TextureViewer(Core *core, QWidget *parent)
|
||||
|
||||
ui->statusbar->addWidget(statusflowWidget);
|
||||
|
||||
ui->zoomOption->addItems({"10%", "25%", "50%", "75%", "100%", "200%", "400%", "800%"});
|
||||
|
||||
ui->zoomOption->setCurrentText("");
|
||||
ui->fitToWindow->toggle();
|
||||
|
||||
UI_UpdateTextureDetails();
|
||||
}
|
||||
|
||||
@@ -508,9 +518,24 @@ void TextureViewer::UI_UpdateTextureDetails()
|
||||
|
||||
void TextureViewer::UI_OnTextureSelectionChanged(bool newdraw)
|
||||
{
|
||||
UI_UpdateFittedScale();
|
||||
UI_UpdateTextureDetails();
|
||||
}
|
||||
|
||||
void TextureViewer::render_mouseWheel(QWheelEvent *e)
|
||||
{
|
||||
QPoint cursorPos = e->pos();
|
||||
|
||||
setFitToWindow(false);
|
||||
|
||||
// scroll in logarithmic scale
|
||||
double logScale = logf(m_TexDisplay.scale);
|
||||
logScale += e->delta() / 2500.0;
|
||||
UI_SetScale((float)expf(logScale), cursorPos.x(), cursorPos.y());
|
||||
|
||||
e->accept();
|
||||
}
|
||||
|
||||
void TextureViewer::render_mouseMove(QMouseEvent *e)
|
||||
{
|
||||
m_CurHoverPixel.setX(int(((float)e->x() - m_TexDisplay.offx) / m_TexDisplay.scale));
|
||||
@@ -586,7 +611,7 @@ void TextureViewer::render_mouseClick(QMouseEvent *e)
|
||||
|
||||
void TextureViewer::render_resize(QResizeEvent *e)
|
||||
{
|
||||
// UI_UpdateFittedScale();
|
||||
UI_UpdateFittedScale();
|
||||
UI_CalcScrollbars();
|
||||
|
||||
m_Core->Renderer()->AsyncInvoke([this](IReplayRenderer *) { RT_UpdateAndDisplay(); });
|
||||
@@ -623,8 +648,11 @@ QPoint TextureViewer::getScrollPosition()
|
||||
|
||||
void TextureViewer::setScrollPosition(const QPoint &pos)
|
||||
{
|
||||
m_TexDisplay.offx = qBound(CurMaxScrollX(), (float)pos.x(), 0.0f);
|
||||
m_TexDisplay.offy = qBound(CurMaxScrollY(), (float)pos.y(), 0.0f);
|
||||
m_TexDisplay.offx = qMax(CurMaxScrollX(), (float)pos.x());
|
||||
m_TexDisplay.offy = qMax(CurMaxScrollY(), (float)pos.y());
|
||||
|
||||
m_TexDisplay.offx = qMin(0.0f, m_TexDisplay.offx);
|
||||
m_TexDisplay.offy = qMin(0.0f, m_TexDisplay.offy);
|
||||
|
||||
if(ScrollUpdateScrollbars)
|
||||
{
|
||||
@@ -821,3 +849,115 @@ void TextureViewer::OnEventSelected(uint32_t eventID)
|
||||
// CurrentTexture.ID))
|
||||
UI_OnTextureSelectionChanged(true);
|
||||
}
|
||||
|
||||
float TextureViewer::GetFitScale()
|
||||
{
|
||||
FetchTexture *texptr = m_Core->GetTexture(m_TexDisplay.texid);
|
||||
|
||||
if(texptr == NULL)
|
||||
return 1.0f;
|
||||
|
||||
float xscale = (float)ui->render->width() / (float)texptr->width;
|
||||
float yscale = (float)ui->render->height() / (float)texptr->height;
|
||||
return qMin(xscale, yscale);
|
||||
}
|
||||
|
||||
void TextureViewer::UI_UpdateFittedScale()
|
||||
{
|
||||
if(ui->fitToWindow->isChecked())
|
||||
UI_SetScale(1.0f);
|
||||
}
|
||||
|
||||
void TextureViewer::UI_SetScale(float s)
|
||||
{
|
||||
UI_SetScale(s, ui->render->width() / 2, ui->render->height() / 2);
|
||||
}
|
||||
|
||||
void TextureViewer::UI_SetScale(float s, int x, int y)
|
||||
{
|
||||
if(ui->fitToWindow->isChecked())
|
||||
s = GetFitScale();
|
||||
|
||||
float prevScale = m_TexDisplay.scale;
|
||||
|
||||
m_TexDisplay.scale = qBound(0.1f, s, 256.0f);
|
||||
|
||||
m_Core->Renderer()->AsyncInvoke([this](IReplayRenderer *) { RT_UpdateAndDisplay(); });
|
||||
|
||||
float scaleDelta = (m_TexDisplay.scale / prevScale);
|
||||
|
||||
QPoint newPos = getScrollPosition();
|
||||
|
||||
newPos -= QPoint(x, y);
|
||||
newPos = QPoint((int)(newPos.x() * scaleDelta), (int)(newPos.y() * scaleDelta));
|
||||
newPos += QPoint(x, y);
|
||||
|
||||
setScrollPosition(newPos);
|
||||
|
||||
setCurrentZoomValue(m_TexDisplay.scale);
|
||||
|
||||
UI_CalcScrollbars();
|
||||
}
|
||||
|
||||
void TextureViewer::setCurrentZoomValue(float zoom)
|
||||
{
|
||||
ui->zoomOption->setCurrentText(QString::number(ceil(zoom * 100)) + "%");
|
||||
}
|
||||
|
||||
float TextureViewer::getCurrentZoomValue()
|
||||
{
|
||||
if(ui->fitToWindow->isChecked())
|
||||
return m_TexDisplay.scale;
|
||||
|
||||
QString zoomText = ui->zoomOption->currentText().replace('%', ' ');
|
||||
|
||||
bool ok = false;
|
||||
int zoom = zoomText.toInt(&ok);
|
||||
|
||||
if(!ok)
|
||||
zoom = 100;
|
||||
|
||||
return (float)(zoom) / 100.0f;
|
||||
}
|
||||
|
||||
void TextureViewer::setFitToWindow(bool checked)
|
||||
{
|
||||
if(checked)
|
||||
{
|
||||
UI_UpdateFittedScale();
|
||||
ui->fitToWindow->setChecked(true);
|
||||
}
|
||||
else if(!checked)
|
||||
{
|
||||
ui->fitToWindow->setChecked(false);
|
||||
float curScale = m_TexDisplay.scale;
|
||||
ui->zoomOption->setCurrentText("");
|
||||
setCurrentZoomValue(curScale);
|
||||
}
|
||||
}
|
||||
|
||||
void TextureViewer::on_fitToWindow_toggled(bool checked)
|
||||
{
|
||||
UI_UpdateFittedScale();
|
||||
}
|
||||
|
||||
void TextureViewer::on_zoomExactSize_clicked()
|
||||
{
|
||||
ui->fitToWindow->setChecked(false);
|
||||
UI_SetScale(1.0f);
|
||||
}
|
||||
|
||||
void TextureViewer::on_zoomOption_currentIndexChanged(int index)
|
||||
{
|
||||
if(index >= 0)
|
||||
{
|
||||
setFitToWindow(false);
|
||||
ui->zoomOption->setCurrentText(ui->zoomOption->itemText(index));
|
||||
UI_SetScale(getCurrentZoomValue());
|
||||
}
|
||||
}
|
||||
|
||||
void TextureViewer::on_zoomOption_returnPressed()
|
||||
{
|
||||
UI_SetScale(getCurrentZoomValue());
|
||||
}
|
||||
|
||||
@@ -26,10 +26,17 @@ public:
|
||||
private slots:
|
||||
void render_mouseClick(QMouseEvent *e);
|
||||
void render_mouseMove(QMouseEvent *e);
|
||||
void render_mouseWheel(QWheelEvent *e);
|
||||
void render_resize(QResizeEvent *e);
|
||||
|
||||
void on_renderHScroll_valueChanged(int position);
|
||||
void on_renderVScroll_valueChanged(int position);
|
||||
|
||||
void on_fitToWindow_toggled(bool checked);
|
||||
void on_zoomExactSize_clicked();
|
||||
void on_zoomOption_currentIndexChanged(int index);
|
||||
void on_zoomOption_returnPressed();
|
||||
|
||||
private:
|
||||
void RT_FetchCurrentPixel(uint32_t x, uint32_t y, PixelValue &pickValue, PixelValue &realValue);
|
||||
void RT_PickPixelsAndUpdate();
|
||||
@@ -40,14 +47,23 @@ private:
|
||||
void UI_UpdateTextureDetails();
|
||||
void UI_OnTextureSelectionChanged(bool newdraw);
|
||||
|
||||
void setFitToWindow(bool checked);
|
||||
|
||||
void setCurrentZoomValue(float zoom);
|
||||
float getCurrentZoomValue();
|
||||
|
||||
bool ScrollUpdateScrollbars = true;
|
||||
|
||||
float CurMaxScrollX();
|
||||
float CurMaxScrollY();
|
||||
|
||||
float GetFitScale();
|
||||
|
||||
QPoint getScrollPosition();
|
||||
void setScrollPosition(const QPoint &pos);
|
||||
|
||||
void UI_UpdateFittedScale();
|
||||
void UI_SetScale(float s);
|
||||
void UI_SetScale(float s, int x, int y);
|
||||
void UI_CalcScrollbars();
|
||||
|
||||
|
||||
@@ -187,8 +187,8 @@
|
||||
<widget class="QFrame" name="overlayToolbar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>200</x>
|
||||
<y>145</y>
|
||||
<x>240</x>
|
||||
<y>140</y>
|
||||
<width>129</width>
|
||||
<height>28</height>
|
||||
</rect>
|
||||
@@ -238,7 +238,7 @@
|
||||
<rect>
|
||||
<x>3</x>
|
||||
<y>145</y>
|
||||
<width>191</width>
|
||||
<width>221</width>
|
||||
<height>28</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -271,14 +271,39 @@
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="zoomLabel">
|
||||
<property name="text">
|
||||
<string>Zoom</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton_14">
|
||||
<widget class="QToolButton" name="zoomExactSize">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>1:1</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="fitToWindow">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fit</string>
|
||||
</property>
|
||||
@@ -301,10 +326,17 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_3"/>
|
||||
<widget class="QComboBox" name="zoomOption">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="insertPolicy">
|
||||
<enum>QComboBox::NoInsert</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton_15">
|
||||
<widget class="QToolButton" name="flip_y">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
|
||||
Reference in New Issue
Block a user