mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-08 15:20:45 +01:00
Merge pull request #13237 from AdmiralCurtiss/slider-mappings
DolphinQt/HacksWidget: Convert accuracy slider to ConfigSlider
This commit is contained in:
commit
b8921b1338
@ -1,6 +1,8 @@
|
|||||||
// Copyright 2017 Dolphin Emulator Project
|
// Copyright 2017 Dolphin Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
|
||||||
#include "DolphinQt/Config/ConfigControls/ConfigSlider.h"
|
#include "DolphinQt/Config/ConfigControls/ConfigSlider.h"
|
||||||
@ -24,14 +26,58 @@ ConfigSlider::ConfigSlider(int minimum, int maximum, const Config::Info<int>& se
|
|||||||
connect(this, &ConfigSlider::valueChanged, this, &ConfigSlider::Update);
|
connect(this, &ConfigSlider::valueChanged, this, &ConfigSlider::Update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigSlider::ConfigSlider(std::vector<int> tick_values, const Config::Info<int>& setting,
|
||||||
|
Config::Layer* layer)
|
||||||
|
: ConfigControl(Qt::Horizontal, setting.GetLocation(), layer), m_setting(setting),
|
||||||
|
m_tick_values(std::move(tick_values))
|
||||||
|
{
|
||||||
|
assert(!m_tick_values.empty());
|
||||||
|
setMinimum(0);
|
||||||
|
setMaximum(static_cast<int>(m_tick_values.size() - 1));
|
||||||
|
setPageStep(1);
|
||||||
|
setTickPosition(QSlider::TicksBelow);
|
||||||
|
OnConfigChanged();
|
||||||
|
|
||||||
|
connect(this, &ConfigSlider::valueChanged, this, &ConfigSlider::Update);
|
||||||
|
}
|
||||||
|
|
||||||
void ConfigSlider::Update(int value)
|
void ConfigSlider::Update(int value)
|
||||||
{
|
{
|
||||||
SaveValue(m_setting, value);
|
if (!m_tick_values.empty())
|
||||||
|
{
|
||||||
|
if (value >= 0 && static_cast<size_t>(value) < m_tick_values.size())
|
||||||
|
SaveValue(m_setting, m_tick_values[static_cast<size_t>(value)]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SaveValue(m_setting, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigSlider::OnConfigChanged()
|
void ConfigSlider::OnConfigChanged()
|
||||||
{
|
{
|
||||||
setValue(ReadValue(m_setting));
|
if (!m_tick_values.empty())
|
||||||
|
{
|
||||||
|
// re-enable in case it was disabled
|
||||||
|
setEnabled(true);
|
||||||
|
|
||||||
|
const int config_value = ReadValue(m_setting);
|
||||||
|
for (size_t i = 0; i < m_tick_values.size(); ++i)
|
||||||
|
{
|
||||||
|
if (m_tick_values[i] == config_value)
|
||||||
|
{
|
||||||
|
setValue(static_cast<int>(i));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we reach here than none of the options matched, disable the slider
|
||||||
|
setEnabled(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setValue(ReadValue(m_setting));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigSliderLabel::ConfigSliderLabel(const QString& text, ConfigSlider* slider)
|
ConfigSliderLabel::ConfigSliderLabel(const QString& text, ConfigSlider* slider)
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
@ -19,6 +21,11 @@ public:
|
|||||||
ConfigSlider(int minimum, int maximum, const Config::Info<int>& setting, Config::Layer* layer,
|
ConfigSlider(int minimum, int maximum, const Config::Info<int>& setting, Config::Layer* layer,
|
||||||
int tick = 0);
|
int tick = 0);
|
||||||
|
|
||||||
|
// Generates a slider with tick_values.size() ticks. Each tick corresponds to the integer at that
|
||||||
|
// index in the vector.
|
||||||
|
ConfigSlider(std::vector<int> tick_values, const Config::Info<int>& setting,
|
||||||
|
Config::Layer* layer);
|
||||||
|
|
||||||
void Update(int value);
|
void Update(int value);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -26,6 +33,9 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const Config::Info<int> m_setting;
|
const Config::Info<int> m_setting;
|
||||||
|
|
||||||
|
// Mappings for slider ticks to config values. Identity mapping is assumed if this is empty.
|
||||||
|
std::vector<int> m_tick_values;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConfigSliderLabel final : public QLabel
|
class ConfigSliderLabel final : public QLabel
|
||||||
|
@ -25,23 +25,18 @@
|
|||||||
HacksWidget::HacksWidget(GraphicsWindow* parent)
|
HacksWidget::HacksWidget(GraphicsWindow* parent)
|
||||||
{
|
{
|
||||||
CreateWidgets();
|
CreateWidgets();
|
||||||
LoadSettings();
|
|
||||||
ConnectWidgets();
|
ConnectWidgets();
|
||||||
AddDescriptions();
|
AddDescriptions();
|
||||||
|
|
||||||
connect(parent, &GraphicsWindow::BackendChanged, this, &HacksWidget::OnBackendChanged);
|
connect(parent, &GraphicsWindow::BackendChanged, this, &HacksWidget::OnBackendChanged);
|
||||||
OnBackendChanged(QString::fromStdString(Config::Get(Config::MAIN_GFX_BACKEND)));
|
OnBackendChanged(QString::fromStdString(Config::Get(Config::MAIN_GFX_BACKEND)));
|
||||||
connect(&Settings::Instance(), &Settings::ConfigChanged, this, &HacksWidget::LoadSettings);
|
connect(m_gpu_texture_decoding, &QCheckBox::toggled,
|
||||||
connect(m_gpu_texture_decoding, &QCheckBox::toggled, [this, parent] {
|
[this, parent] { emit parent->UseGPUTextureDecodingChanged(); });
|
||||||
SaveSettings();
|
|
||||||
emit parent->UseGPUTextureDecodingChanged();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HacksWidget::HacksWidget(GameConfigWidget* parent, Config::Layer* layer) : m_game_layer(layer)
|
HacksWidget::HacksWidget(GameConfigWidget* parent, Config::Layer* layer) : m_game_layer(layer)
|
||||||
{
|
{
|
||||||
CreateWidgets();
|
CreateWidgets();
|
||||||
LoadSettings();
|
|
||||||
ConnectWidgets();
|
ConnectWidgets();
|
||||||
AddDescriptions();
|
AddDescriptions();
|
||||||
}
|
}
|
||||||
@ -73,18 +68,15 @@ void HacksWidget::CreateWidgets()
|
|||||||
auto* texture_cache_layout = new QGridLayout();
|
auto* texture_cache_layout = new QGridLayout();
|
||||||
texture_cache_box->setLayout(texture_cache_layout);
|
texture_cache_box->setLayout(texture_cache_layout);
|
||||||
|
|
||||||
m_accuracy = new ToolTipSlider(Qt::Horizontal);
|
m_accuracy =
|
||||||
m_accuracy->setMinimum(0);
|
new ConfigSlider({0, 512, 128}, Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES, m_game_layer);
|
||||||
m_accuracy->setMaximum(2);
|
|
||||||
m_accuracy->setPageStep(1);
|
|
||||||
m_accuracy->setTickPosition(QSlider::TicksBelow);
|
|
||||||
m_gpu_texture_decoding = new ConfigBool(tr("GPU Texture Decoding"),
|
m_gpu_texture_decoding = new ConfigBool(tr("GPU Texture Decoding"),
|
||||||
Config::GFX_ENABLE_GPU_TEXTURE_DECODING, m_game_layer);
|
Config::GFX_ENABLE_GPU_TEXTURE_DECODING, m_game_layer);
|
||||||
|
|
||||||
auto* safe_label = new QLabel(tr("Safe"));
|
auto* safe_label = new QLabel(tr("Safe"));
|
||||||
safe_label->setAlignment(Qt::AlignRight);
|
safe_label->setAlignment(Qt::AlignRight);
|
||||||
|
|
||||||
m_accuracy_label = new QLabel(tr("Accuracy:"));
|
m_accuracy_label = new ConfigSliderLabel(tr("Accuracy:"), m_accuracy);
|
||||||
|
|
||||||
texture_cache_layout->addWidget(m_accuracy_label, 0, 0);
|
texture_cache_layout->addWidget(m_accuracy_label, 0, 0);
|
||||||
texture_cache_layout->addWidget(safe_label, 0, 1);
|
texture_cache_layout->addWidget(safe_label, 0, 1);
|
||||||
@ -158,7 +150,6 @@ void HacksWidget::OnBackendChanged(const QString& backend_name)
|
|||||||
|
|
||||||
void HacksWidget::ConnectWidgets()
|
void HacksWidget::ConnectWidgets()
|
||||||
{
|
{
|
||||||
connect(m_accuracy, &QSlider::valueChanged, [this](int) { SaveSettings(); });
|
|
||||||
connect(m_store_efb_copies, &QCheckBox::stateChanged,
|
connect(m_store_efb_copies, &QCheckBox::stateChanged,
|
||||||
[this](int) { UpdateDeferEFBCopiesEnabled(); });
|
[this](int) { UpdateDeferEFBCopiesEnabled(); });
|
||||||
connect(m_store_xfb_copies, &QCheckBox::stateChanged,
|
connect(m_store_xfb_copies, &QCheckBox::stateChanged,
|
||||||
@ -169,65 +160,6 @@ void HacksWidget::ConnectWidgets()
|
|||||||
[this](int) { UpdateSkipPresentingDuplicateFramesEnabled(); });
|
[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()
|
void HacksWidget::AddDescriptions()
|
||||||
{
|
{
|
||||||
static const char TR_SKIP_EFB_CPU_ACCESS_DESCRIPTION[] = QT_TR_NOOP(
|
static const char TR_SKIP_EFB_CPU_ACCESS_DESCRIPTION[] = QT_TR_NOOP(
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class ConfigBool;
|
class ConfigBool;
|
||||||
|
class ConfigSlider;
|
||||||
|
class ConfigSliderLabel;
|
||||||
class GameConfigWidget;
|
class GameConfigWidget;
|
||||||
class GraphicsWindow;
|
class GraphicsWindow;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
@ -24,9 +26,6 @@ public:
|
|||||||
HacksWidget(GameConfigWidget* parent, Config::Layer* layer);
|
HacksWidget(GameConfigWidget* parent, Config::Layer* layer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadSettings();
|
|
||||||
void SaveSettings();
|
|
||||||
|
|
||||||
void OnBackendChanged(const QString& backend_name);
|
void OnBackendChanged(const QString& backend_name);
|
||||||
|
|
||||||
// EFB
|
// EFB
|
||||||
@ -36,8 +35,8 @@ private:
|
|||||||
ConfigBool* m_defer_efb_copies;
|
ConfigBool* m_defer_efb_copies;
|
||||||
|
|
||||||
// Texture Cache
|
// Texture Cache
|
||||||
QLabel* m_accuracy_label;
|
ConfigSliderLabel* m_accuracy_label;
|
||||||
ToolTipSlider* m_accuracy;
|
ConfigSlider* m_accuracy;
|
||||||
ConfigBool* m_gpu_texture_decoding;
|
ConfigBool* m_gpu_texture_decoding;
|
||||||
|
|
||||||
// External Framebuffer
|
// External Framebuffer
|
||||||
|
Loading…
Reference in New Issue
Block a user