Config: Add support for enums

This makes it possible to use enums as the config type.
Default values are now clearer and there's no need for casts
when calling Config::Get/Set anymore.

In order to add support for enums, the common code was updated to
handle enums by using the underlying type when loading/saving settings.

A copy constructor is also provided for conversions from
`ConfigInfo<Enum>` to `ConfigInfo<underlying_type<Enum>>`
so that enum settings can still easily work with code that doesn't care
about the actual enum values (like Graphics{Choice,Radio} in DolphinQt2
which only treat the setting as an integer).
This commit is contained in:
Léo Lam 2018-05-11 22:38:44 +02:00
commit 6763a3fce1
10 changed files with 87 additions and 54 deletions

View file

@ -6,11 +6,7 @@
#include <QComboBox>
namespace Config
{
template <typename T>
struct ConfigInfo;
}
#include "Common/Config/Config.h"
class GraphicsChoice : public QComboBox
{
@ -20,5 +16,5 @@ public:
private:
void Update(int choice);
const Config::ConfigInfo<int>& m_setting;
Config::ConfigInfo<int> m_setting;
};

View file

@ -6,11 +6,7 @@
#include <QRadioButton>
namespace Config
{
template <typename T>
struct ConfigInfo;
}
#include "Common/Config/Config.h"
class GraphicsRadioInt : public QRadioButton
{
@ -21,6 +17,6 @@ public:
private:
void Update();
const Config::ConfigInfo<int>& m_setting;
Config::ConfigInfo<int> m_setting;
int m_value;
};

View file

@ -279,8 +279,8 @@ void HotkeyScheduler::Run()
if (IsHotkey(HK_TOGGLE_AR))
{
show_msg(OSDMessage::ARToggled);
const auto aspect_ratio = (Config::Get(Config::GFX_ASPECT_RATIO) + 1) & 3;
Config::SetCurrent(Config::GFX_ASPECT_RATIO, aspect_ratio);
const int aspect_ratio = (static_cast<int>(Config::Get(Config::GFX_ASPECT_RATIO)) + 1) & 3;
Config::SetCurrent(Config::GFX_ASPECT_RATIO, static_cast<AspectMode>(aspect_ratio));
}
if (IsHotkey(HK_TOGGLE_EFBCOPIES))
{
@ -344,48 +344,47 @@ void HotkeyScheduler::Run()
// Stereoscopy
if (IsHotkey(HK_TOGGLE_STEREO_SBS) || IsHotkey(HK_TOGGLE_STEREO_TAB))
{
if (Config::Get(Config::GFX_STEREO_MODE) != static_cast<int>(StereoMode::SBS))
if (Config::Get(Config::GFX_STEREO_MODE) != StereoMode::SBS)
{
// Disable post-processing shader, as stereoscopy itself is currently a shader
if (Config::Get(Config::GFX_ENHANCE_POST_SHADER) == DUBOIS_ALGORITHM_SHADER)
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, "");
Config::SetCurrent(Config::GFX_STEREO_MODE, IsHotkey(HK_TOGGLE_STEREO_SBS) ?
static_cast<int>(StereoMode::SBS) :
static_cast<int>(StereoMode::TAB));
Config::SetCurrent(Config::GFX_STEREO_MODE,
IsHotkey(HK_TOGGLE_STEREO_SBS) ? StereoMode::SBS : StereoMode::TAB);
}
else
{
Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast<int>(StereoMode::Off));
Config::SetCurrent(Config::GFX_STEREO_MODE, StereoMode::Off);
}
}
if (IsHotkey(HK_TOGGLE_STEREO_ANAGLYPH))
{
if (Config::Get(Config::GFX_STEREO_MODE) != static_cast<int>(StereoMode::Anaglyph))
if (Config::Get(Config::GFX_STEREO_MODE) != StereoMode::Anaglyph)
{
Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast<int>(StereoMode::Anaglyph));
Config::SetCurrent(Config::GFX_STEREO_MODE, StereoMode::Anaglyph);
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, DUBOIS_ALGORITHM_SHADER);
}
else
{
Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast<int>(StereoMode::Off));
Config::SetCurrent(Config::GFX_STEREO_MODE, StereoMode::Off);
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, "");
}
}
if (IsHotkey(HK_TOGGLE_STEREO_3DVISION))
{
if (Config::Get(Config::GFX_STEREO_MODE) != static_cast<int>(StereoMode::Nvidia3DVision))
if (Config::Get(Config::GFX_STEREO_MODE) != StereoMode::Nvidia3DVision)
{
if (Config::Get(Config::GFX_ENHANCE_POST_SHADER) == DUBOIS_ALGORITHM_SHADER)
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, "");
Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast<int>(StereoMode::Nvidia3DVision));
Config::SetCurrent(Config::GFX_STEREO_MODE, StereoMode::Nvidia3DVision);
}
else
{
Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast<int>(StereoMode::Off));
Config::SetCurrent(Config::GFX_STEREO_MODE, StereoMode::Off);
}
}
}