Skip to content

Commit

Permalink
DolphinQt/HacksWidget: Convert accuracy slider to ConfigSlider
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiralCurtiss committed Dec 25, 2024
1 parent 0431675 commit 419436d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 76 deletions.
76 changes: 4 additions & 72 deletions Source/Core/DolphinQt/Config/Graphics/HacksWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,18 @@
HacksWidget::HacksWidget(GraphicsWindow* parent)
{
CreateWidgets();
LoadSettings();
ConnectWidgets();
AddDescriptions();

connect(parent, &GraphicsWindow::BackendChanged, this, &HacksWidget::OnBackendChanged);
OnBackendChanged(QString::fromStdString(Config::Get(Config::MAIN_GFX_BACKEND)));
connect(&Settings::Instance(), &Settings::ConfigChanged, this, &HacksWidget::LoadSettings);
connect(m_gpu_texture_decoding, &QCheckBox::toggled, [this, parent] {
SaveSettings();
emit parent->UseGPUTextureDecodingChanged();
});
connect(m_gpu_texture_decoding, &QCheckBox::toggled,
[this, parent] { emit parent->UseGPUTextureDecodingChanged(); });
}

HacksWidget::HacksWidget(GameConfigWidget* parent, Config::Layer* layer) : m_game_layer(layer)
{
CreateWidgets();
LoadSettings();
ConnectWidgets();
AddDescriptions();
}
Expand Down Expand Up @@ -73,11 +68,8 @@ void HacksWidget::CreateWidgets()
auto* texture_cache_layout = new QGridLayout();
texture_cache_box->setLayout(texture_cache_layout);

m_accuracy = new ToolTipSlider(Qt::Horizontal);
m_accuracy->setMinimum(0);
m_accuracy->setMaximum(2);
m_accuracy->setPageStep(1);
m_accuracy->setTickPosition(QSlider::TicksBelow);
m_accuracy =
new ConfigSlider({0, 512, 128}, Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES, m_game_layer);
m_gpu_texture_decoding = new ConfigBool(tr("GPU Texture Decoding"),
Config::GFX_ENABLE_GPU_TEXTURE_DECODING, m_game_layer);

Expand Down Expand Up @@ -158,7 +150,6 @@ void HacksWidget::OnBackendChanged(const QString& backend_name)

void HacksWidget::ConnectWidgets()
{
connect(m_accuracy, &QSlider::valueChanged, [this](int) { SaveSettings(); });
connect(m_store_efb_copies, &QCheckBox::stateChanged,
[this](int) { UpdateDeferEFBCopiesEnabled(); });
connect(m_store_xfb_copies, &QCheckBox::stateChanged,
Expand All @@ -169,65 +160,6 @@ void HacksWidget::ConnectWidgets()
[this](int) { UpdateSkipPresentingDuplicateFramesEnabled(); });
}

void HacksWidget::LoadSettings()
{
const QSignalBlocker blocker(m_accuracy);
auto samples = Config::Get(Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES);

// Re-enable the slider in case it was disabled because of a custom value
m_accuracy->setEnabled(true);

int slider_pos = 0;

switch (samples)
{
case 512:
slider_pos = 1;
break;
case 128:
slider_pos = 2;
break;
case 0:
slider_pos = 0;
break;
// Custom values, ought not to be touched
default:
m_accuracy->setEnabled(false);
}

m_accuracy->setValue(slider_pos);

QFont bf = m_accuracy_label->font();

bf.setBold(Config::GetActiveLayerForConfig(Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES) !=
Config::LayerType::Base);

m_accuracy_label->setFont(bf);
}

void HacksWidget::SaveSettings()
{
int slider_pos = m_accuracy->value();

if (m_accuracy->isEnabled())
{
int samples = 0;
switch (slider_pos)
{
case 0:
samples = 0;
break;
case 1:
samples = 512;
break;
case 2:
samples = 128;
}

Config::SetBaseOrCurrent(Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES, samples);
}
}

void HacksWidget::AddDescriptions()
{
static const char TR_SKIP_EFB_CPU_ACCESS_DESCRIPTION[] = QT_TR_NOOP(
Expand Down
6 changes: 2 additions & 4 deletions Source/Core/DolphinQt/Config/Graphics/HacksWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QWidget>

class ConfigBool;
class ConfigSlider;
class GameConfigWidget;
class GraphicsWindow;
class QLabel;
Expand All @@ -24,9 +25,6 @@ class HacksWidget final : public QWidget
HacksWidget(GameConfigWidget* parent, Config::Layer* layer);

private:
void LoadSettings();
void SaveSettings();

void OnBackendChanged(const QString& backend_name);

// EFB
Expand All @@ -37,7 +35,7 @@ class HacksWidget final : public QWidget

// Texture Cache
QLabel* m_accuracy_label;
ToolTipSlider* m_accuracy;
ConfigSlider* m_accuracy;
ConfigBool* m_gpu_texture_decoding;

// External Framebuffer
Expand Down

0 comments on commit 419436d

Please sign in to comment.