mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-08 15:24:33 +00:00
Qt: Avoid extra string storage
This commit is contained in:
@@ -47,12 +47,6 @@ static void DecodeMSAAModeValue(const QVariant& userdata, uint* multisamples, bo
|
||||
*ssaa = (value & (1u << 31)) != 0u;
|
||||
}
|
||||
|
||||
static bool IsCustomAspectRatio(const DisplayAspectRatio& ratio)
|
||||
{
|
||||
return std::ranges::none_of(Settings::GetPredefinedDisplayAspectRatios(),
|
||||
[&ratio](const auto& it) { return (it == ratio); });
|
||||
}
|
||||
|
||||
GraphicsSettingsWidget::GraphicsSettingsWidget(SettingsWindow* dialog, QWidget* parent)
|
||||
: QWidget(parent), m_dialog(dialog)
|
||||
{
|
||||
@@ -966,6 +960,17 @@ void GraphicsSettingsWidget::populateUpscalingModes(QComboBox* const cb, int max
|
||||
}
|
||||
}
|
||||
|
||||
QVariant GraphicsSettingsWidget::packAspectRatio(DisplayAspectRatio ar)
|
||||
{
|
||||
return QVariant(static_cast<uint>(ar.numerator) << 16 | static_cast<uint>(ar.denominator));
|
||||
}
|
||||
|
||||
DisplayAspectRatio GraphicsSettingsWidget::unpackAspectRatio(const QVariant& var)
|
||||
{
|
||||
const uint packed = var.toUInt();
|
||||
return DisplayAspectRatio{static_cast<s16>(packed >> 16), static_cast<s16>(packed & 0xFFFFu)};
|
||||
}
|
||||
|
||||
void GraphicsSettingsWidget::createAspectRatioSetting(QComboBox* const cb, QSpinBox* const numerator,
|
||||
QLabel* const separator, QSpinBox* const denominator,
|
||||
SettingsInterface* const sif)
|
||||
@@ -984,7 +989,7 @@ void GraphicsSettingsWidget::createAspectRatioSetting(QComboBox* const cb, QSpin
|
||||
for (const DisplayAspectRatio& ratio : Settings::GetPredefinedDisplayAspectRatios())
|
||||
{
|
||||
cb->addItem(QtUtils::StringViewToQString(Settings::GetDisplayAspectRatioDisplayName(ratio)),
|
||||
QtUtils::StringViewToQString(Settings::GetDisplayAspectRatioName(ratio)));
|
||||
packAspectRatio(ratio));
|
||||
}
|
||||
cb->addItem(tr("Custom"));
|
||||
|
||||
@@ -999,7 +1004,8 @@ void GraphicsSettingsWidget::createAspectRatioSetting(QComboBox* const cb, QSpin
|
||||
Settings::ParseDisplayAspectRatio(sif ? sif->GetStringValue(CONFIG_SECTION, CONFIG_KEY) :
|
||||
Host::GetBaseStringSettingValue(CONFIG_SECTION, CONFIG_KEY))
|
||||
.value_or(Settings::DEFAULT_DISPLAY_ASPECT_RATIO);
|
||||
if ((is_custom_ar = IsCustomAspectRatio(ar)))
|
||||
if ((is_custom_ar = std::ranges::none_of(Settings::GetPredefinedDisplayAspectRatios(),
|
||||
[&ar](const auto& it) { return (it == ar); })))
|
||||
{
|
||||
cb->setCurrentIndex(cb->count() - 1);
|
||||
numerator->setValue(ar.numerator);
|
||||
@@ -1007,7 +1013,7 @@ void GraphicsSettingsWidget::createAspectRatioSetting(QComboBox* const cb, QSpin
|
||||
}
|
||||
else
|
||||
{
|
||||
cb->setCurrentIndex(cb->findData(QtUtils::StringViewToQString(Settings::GetDisplayAspectRatioName(ar))));
|
||||
cb->setCurrentIndex(cb->findData(packAspectRatio(ar)));
|
||||
}
|
||||
}
|
||||
numerator->setVisible(is_custom_ar);
|
||||
@@ -1027,8 +1033,7 @@ void GraphicsSettingsWidget::createAspectRatioSetting(QComboBox* const cb, QSpin
|
||||
}
|
||||
else
|
||||
{
|
||||
value_to_save.emplace(Settings::ParseDisplayAspectRatio(cb->currentData().toString().toStdString())
|
||||
.value_or(Settings::DEFAULT_DISPLAY_ASPECT_RATIO));
|
||||
value_to_save.emplace(unpackAspectRatio(cb->currentData()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include "ui_graphicssettingswidget.h"
|
||||
|
||||
#include "core/types.h"
|
||||
|
||||
#include "util/gpu_device.h"
|
||||
|
||||
enum class GPURenderer : u8;
|
||||
@@ -24,6 +26,9 @@ public:
|
||||
~GraphicsSettingsWidget();
|
||||
|
||||
static void populateUpscalingModes(QComboBox* const cb, int max_scale);
|
||||
|
||||
static QVariant packAspectRatio(DisplayAspectRatio ar);
|
||||
static DisplayAspectRatio unpackAspectRatio(const QVariant& var);
|
||||
static void createAspectRatioSetting(QComboBox* const cb, QSpinBox* const numerator, QLabel* const separator,
|
||||
QSpinBox* const denominator, SettingsInterface* const sif);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user