2023-06-12 23:05:30 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2023-06-11 05:40:39 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-06-22 03:41:06 +02:00
|
|
|
#include <limits>
|
2023-06-11 05:40:39 +02:00
|
|
|
#include <map>
|
|
|
|
#include <optional>
|
2023-06-18 09:52:41 +02:00
|
|
|
#include <stdexcept>
|
2023-06-11 05:40:39 +02:00
|
|
|
#include <string>
|
|
|
|
#include <typeindex>
|
|
|
|
#include <typeinfo>
|
2023-09-13 19:31:46 +02:00
|
|
|
#include <fmt/core.h>
|
2023-06-11 05:40:39 +02:00
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/settings_common.h"
|
|
|
|
#include "common/settings_enums.h"
|
|
|
|
|
|
|
|
namespace Settings {
|
|
|
|
|
|
|
|
/** The Setting class is a simple resource manager. It defines a label and default value
|
|
|
|
* alongside the actual value of the setting for simpler and less-error prone use with frontend
|
|
|
|
* configurations. Specifying a default value and label is required. A minimum and maximum range
|
|
|
|
* can be specified for sanitization.
|
|
|
|
*/
|
|
|
|
template <typename Type, bool ranged = false>
|
|
|
|
class Setting : public BasicSetting {
|
|
|
|
protected:
|
|
|
|
Setting() = default;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Sets a default value, label, and setting value.
|
|
|
|
*
|
|
|
|
* @param linkage Setting registry
|
|
|
|
* @param default_val Initial value of the setting, and default value of the setting
|
|
|
|
* @param name Label for the setting
|
|
|
|
* @param category_ Category of the setting AKA INI group
|
2023-07-18 21:44:27 +02:00
|
|
|
* @param specialization_ Suggestion for how frontend implementations represent this in a config
|
2023-07-18 21:36:20 +02:00
|
|
|
* @param save_ Suggests that this should or should not be saved to a frontend config file
|
|
|
|
* @param runtime_modifiable_ Suggests whether this is modifiable while a guest is loaded
|
|
|
|
* @param other_setting_ A second Setting to associate to this one in metadata
|
2023-06-11 05:40:39 +02:00
|
|
|
*/
|
|
|
|
explicit Setting(Linkage& linkage, const Type& default_val, const std::string& name,
|
2023-07-18 21:42:59 +02:00
|
|
|
Category category_, u32 specialization_ = Specialization::Default,
|
2023-06-21 10:32:13 +02:00
|
|
|
bool save_ = true, bool runtime_modifiable_ = false,
|
2023-06-21 21:38:30 +02:00
|
|
|
BasicSetting* other_setting_ = nullptr)
|
2023-06-11 05:40:39 +02:00
|
|
|
requires(!ranged)
|
2023-06-21 21:38:30 +02:00
|
|
|
: BasicSetting(linkage, name, category_, save_, runtime_modifiable_, specialization_,
|
|
|
|
other_setting_),
|
2023-06-21 09:23:36 +02:00
|
|
|
value{default_val}, default_value{default_val} {}
|
2023-06-11 05:40:39 +02:00
|
|
|
virtual ~Setting() = default;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a default value, minimum value, maximum value, and label.
|
|
|
|
*
|
|
|
|
* @param linkage Setting registry
|
|
|
|
* @param default_val Initial value of the setting, and default value of the setting
|
|
|
|
* @param min_val Sets the minimum allowed value of the setting
|
|
|
|
* @param max_val Sets the maximum allowed value of the setting
|
|
|
|
* @param name Label for the setting
|
|
|
|
* @param category_ Category of the setting AKA INI group
|
2023-07-18 21:44:27 +02:00
|
|
|
* @param specialization_ Suggestion for how frontend implementations represent this in a config
|
2023-07-18 21:36:20 +02:00
|
|
|
* @param save_ Suggests that this should or should not be saved to a frontend config file
|
|
|
|
* @param runtime_modifiable_ Suggests whether this is modifiable while a guest is loaded
|
|
|
|
* @param other_setting_ A second Setting to associate to this one in metadata
|
2023-06-11 05:40:39 +02:00
|
|
|
*/
|
|
|
|
explicit Setting(Linkage& linkage, const Type& default_val, const Type& min_val,
|
2023-07-18 21:42:59 +02:00
|
|
|
const Type& max_val, const std::string& name, Category category_,
|
2023-06-21 21:38:30 +02:00
|
|
|
u32 specialization_ = Specialization::Default, bool save_ = true,
|
|
|
|
bool runtime_modifiable_ = false, BasicSetting* other_setting_ = nullptr)
|
2023-06-11 05:40:39 +02:00
|
|
|
requires(ranged)
|
2023-06-21 21:38:30 +02:00
|
|
|
: BasicSetting(linkage, name, category_, save_, runtime_modifiable_, specialization_,
|
|
|
|
other_setting_),
|
2023-06-21 09:23:36 +02:00
|
|
|
value{default_val}, default_value{default_val}, maximum{max_val}, minimum{min_val} {}
|
2023-06-11 05:40:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a reference to the setting's value.
|
|
|
|
*
|
|
|
|
* @returns A reference to the setting
|
|
|
|
*/
|
|
|
|
[[nodiscard]] virtual const Type& GetValue() const {
|
|
|
|
return value;
|
|
|
|
}
|
2023-12-11 02:10:36 +01:00
|
|
|
[[nodiscard]] virtual const Type& GetValue(bool need_global) const {
|
|
|
|
return value;
|
|
|
|
}
|
2023-06-11 05:40:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the setting to the given value.
|
|
|
|
*
|
|
|
|
* @param val The desired value
|
|
|
|
*/
|
|
|
|
virtual void SetValue(const Type& val) {
|
|
|
|
Type temp{ranged ? std::clamp(val, minimum, maximum) : val};
|
|
|
|
std::swap(value, temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the value that this setting was created with.
|
|
|
|
*
|
|
|
|
* @returns A reference to the default value
|
|
|
|
*/
|
|
|
|
[[nodiscard]] const Type& GetDefault() const {
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] constexpr bool IsEnum() const override {
|
2023-07-18 21:36:20 +02:00
|
|
|
return std::is_enum_v<Type>;
|
2023-06-11 05:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2023-07-18 21:36:20 +02:00
|
|
|
[[nodiscard]] std::string ToString(const Type& value_) const {
|
|
|
|
if constexpr (std::is_same_v<Type, std::string>) {
|
2023-06-11 05:40:39 +02:00
|
|
|
return value_;
|
2023-07-18 21:36:20 +02:00
|
|
|
} else if constexpr (std::is_same_v<Type, std::optional<u32>>) {
|
2023-06-11 05:40:39 +02:00
|
|
|
return value_.has_value() ? std::to_string(*value_) : "none";
|
2023-07-18 21:36:20 +02:00
|
|
|
} else if constexpr (std::is_same_v<Type, bool>) {
|
2023-06-11 05:40:39 +02:00
|
|
|
return value_ ? "true" : "false";
|
2023-09-13 21:59:44 +02:00
|
|
|
} else if constexpr (std::is_same_v<Type, AudioEngine>) {
|
|
|
|
// Compatibility with old AudioEngine setting being a string
|
|
|
|
return CanonicalizeEnum(value_);
|
2023-09-13 19:31:46 +02:00
|
|
|
} else if constexpr (std::is_floating_point_v<Type>) {
|
|
|
|
return fmt::format("{:f}", value_);
|
|
|
|
} else if constexpr (std::is_enum_v<Type>) {
|
|
|
|
return std::to_string(static_cast<u32>(value_));
|
2023-06-11 05:40:39 +02:00
|
|
|
} else {
|
2023-09-13 19:31:46 +02:00
|
|
|
return std::to_string(value_);
|
2023-06-11 05:40:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Converts the value of the setting to a std::string. Respects the global state if the setting
|
|
|
|
* has one.
|
|
|
|
*
|
|
|
|
* @returns The current setting as a std::string
|
|
|
|
*/
|
2023-07-18 21:36:20 +02:00
|
|
|
[[nodiscard]] std::string ToString() const override {
|
2023-06-11 05:40:39 +02:00
|
|
|
return ToString(this->GetValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the default value of the setting as a std::string.
|
|
|
|
*
|
|
|
|
* @returns The default value as a string.
|
|
|
|
*/
|
2023-07-18 21:36:20 +02:00
|
|
|
[[nodiscard]] std::string DefaultToString() const override {
|
2023-06-11 05:40:39 +02:00
|
|
|
return ToString(default_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assigns a value to the setting.
|
|
|
|
*
|
|
|
|
* @param val The desired setting value
|
|
|
|
*
|
|
|
|
* @returns A reference to the setting
|
|
|
|
*/
|
|
|
|
virtual const Type& operator=(const Type& val) {
|
|
|
|
Type temp{ranged ? std::clamp(val, minimum, maximum) : val};
|
|
|
|
std::swap(value, temp);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a reference to the setting.
|
|
|
|
*
|
|
|
|
* @returns A reference to the setting
|
|
|
|
*/
|
|
|
|
explicit virtual operator const Type&() const {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts the given value to the Setting's type of value. Uses SetValue to enter the setting,
|
|
|
|
* thus respecting its constraints.
|
|
|
|
*
|
|
|
|
* @param input The desired value
|
|
|
|
*/
|
2023-07-18 21:36:20 +02:00
|
|
|
void LoadString(const std::string& input) override final {
|
2023-06-11 05:40:39 +02:00
|
|
|
if (input.empty()) {
|
|
|
|
this->SetValue(this->GetDefault());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
2023-07-18 21:36:20 +02:00
|
|
|
if constexpr (std::is_same_v<Type, std::string>) {
|
2023-06-11 05:40:39 +02:00
|
|
|
this->SetValue(input);
|
2023-07-18 21:36:20 +02:00
|
|
|
} else if constexpr (std::is_same_v<Type, std::optional<u32>>) {
|
2023-06-11 05:40:39 +02:00
|
|
|
this->SetValue(static_cast<u32>(std::stoul(input)));
|
2023-07-18 21:36:20 +02:00
|
|
|
} else if constexpr (std::is_same_v<Type, bool>) {
|
2023-06-11 05:40:39 +02:00
|
|
|
this->SetValue(input == "true");
|
2023-09-13 19:31:46 +02:00
|
|
|
} else if constexpr (std::is_same_v<Type, float>) {
|
|
|
|
this->SetValue(std::stof(input));
|
2023-09-26 04:20:24 +02:00
|
|
|
} else if constexpr (std::is_same_v<Type, AudioEngine>) {
|
|
|
|
this->SetValue(ToEnum<AudioEngine>(input));
|
2023-06-11 05:40:39 +02:00
|
|
|
} else {
|
|
|
|
this->SetValue(static_cast<Type>(std::stoll(input)));
|
|
|
|
}
|
2023-06-18 23:58:07 +02:00
|
|
|
} catch (std::invalid_argument&) {
|
2023-06-11 05:40:39 +02:00
|
|
|
this->SetValue(this->GetDefault());
|
2023-09-13 19:31:46 +02:00
|
|
|
} catch (std::out_of_range&) {
|
|
|
|
this->SetValue(this->GetDefault());
|
2023-06-11 05:40:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-10 02:58:47 +02:00
|
|
|
[[nodiscard]] std::string Canonicalize() const override final {
|
2023-07-18 21:36:20 +02:00
|
|
|
if constexpr (std::is_enum_v<Type>) {
|
2023-06-11 05:40:39 +02:00
|
|
|
return CanonicalizeEnum(this->GetValue());
|
2023-06-11 06:41:14 +02:00
|
|
|
} else {
|
|
|
|
return ToString(this->GetValue());
|
2023-06-11 05:40:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gives us another way to identify the setting without having to go through a string.
|
|
|
|
*
|
|
|
|
* @returns the type_index of the setting's type
|
|
|
|
*/
|
2023-07-18 21:36:20 +02:00
|
|
|
[[nodiscard]] std::type_index TypeId() const override final {
|
2023-06-11 05:40:39 +02:00
|
|
|
return std::type_index(typeid(Type));
|
|
|
|
}
|
|
|
|
|
2023-07-18 21:36:20 +02:00
|
|
|
[[nodiscard]] constexpr u32 EnumIndex() const override final {
|
|
|
|
if constexpr (std::is_enum_v<Type>) {
|
2023-06-22 03:41:06 +02:00
|
|
|
return EnumMetadata<Type>::Index();
|
|
|
|
} else {
|
|
|
|
return std::numeric_limits<u32>::max();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-13 19:31:46 +02:00
|
|
|
[[nodiscard]] constexpr bool IsFloatingPoint() const final {
|
|
|
|
return std::is_floating_point_v<Type>;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] constexpr bool IsIntegral() const final {
|
|
|
|
return std::is_integral_v<Type>;
|
|
|
|
}
|
|
|
|
|
2023-07-18 21:36:20 +02:00
|
|
|
[[nodiscard]] std::string MinVal() const override final {
|
2023-09-13 19:31:46 +02:00
|
|
|
if constexpr (std::is_arithmetic_v<Type> && !ranged) {
|
|
|
|
return this->ToString(std::numeric_limits<Type>::min());
|
|
|
|
} else {
|
|
|
|
return this->ToString(minimum);
|
|
|
|
}
|
2023-06-11 05:40:39 +02:00
|
|
|
}
|
2023-07-18 21:36:20 +02:00
|
|
|
[[nodiscard]] std::string MaxVal() const override final {
|
2023-09-13 19:31:46 +02:00
|
|
|
if constexpr (std::is_arithmetic_v<Type> && !ranged) {
|
|
|
|
return this->ToString(std::numeric_limits<Type>::max());
|
|
|
|
} else {
|
|
|
|
return this->ToString(maximum);
|
|
|
|
}
|
2023-06-11 05:40:39 +02:00
|
|
|
}
|
|
|
|
|
2023-07-18 21:36:20 +02:00
|
|
|
[[nodiscard]] constexpr bool Ranged() const override {
|
2023-06-14 01:37:54 +02:00
|
|
|
return ranged;
|
|
|
|
}
|
|
|
|
|
2023-06-11 05:40:39 +02:00
|
|
|
protected:
|
2023-06-12 23:05:30 +02:00
|
|
|
Type value{}; ///< The setting
|
|
|
|
const Type default_value{}; ///< The default value
|
|
|
|
const Type maximum{}; ///< Maximum allowed value of the setting
|
|
|
|
const Type minimum{}; ///< Minimum allowed value of the setting
|
2023-06-11 05:40:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The SwitchableSetting class is a slightly more complex version of the Setting class. This adds a
|
|
|
|
* custom setting to switch to when a guest application specifically requires it. The effect is that
|
|
|
|
* other components of the emulator can access the setting's intended value without any need for the
|
|
|
|
* component to ask whether the custom or global setting is needed at the moment.
|
|
|
|
*
|
|
|
|
* By default, the global setting is used.
|
|
|
|
*/
|
|
|
|
template <typename Type, bool ranged = false>
|
|
|
|
class SwitchableSetting : virtual public Setting<Type, ranged> {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Sets a default value, label, and setting value.
|
|
|
|
*
|
|
|
|
* @param linkage Setting registry
|
|
|
|
* @param default_val Initial value of the setting, and default value of the setting
|
|
|
|
* @param name Label for the setting
|
|
|
|
* @param category_ Category of the setting AKA INI group
|
2023-07-18 21:44:27 +02:00
|
|
|
* @param specialization_ Suggestion for how frontend implementations represent this in a config
|
2023-07-18 21:36:20 +02:00
|
|
|
* @param save_ Suggests that this should or should not be saved to a frontend config file
|
|
|
|
* @param runtime_modifiable_ Suggests whether this is modifiable while a guest is loaded
|
|
|
|
* @param other_setting_ A second Setting to associate to this one in metadata
|
2023-06-11 05:40:39 +02:00
|
|
|
*/
|
2023-08-10 02:58:47 +02:00
|
|
|
template <typename T = BasicSetting>
|
2023-06-11 05:40:39 +02:00
|
|
|
explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const std::string& name,
|
2023-06-21 21:38:30 +02:00
|
|
|
Category category_, u32 specialization_ = Specialization::Default,
|
2023-06-21 10:32:13 +02:00
|
|
|
bool save_ = true, bool runtime_modifiable_ = false,
|
2023-08-10 02:58:47 +02:00
|
|
|
typename std::enable_if<!ranged, T*>::type other_setting_ = nullptr)
|
2023-06-21 10:32:13 +02:00
|
|
|
: Setting<Type, false>{
|
2023-06-21 21:38:30 +02:00
|
|
|
linkage, default_val, name, category_, specialization_,
|
|
|
|
save_, runtime_modifiable_, other_setting_} {
|
2023-06-11 05:40:39 +02:00
|
|
|
linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); });
|
|
|
|
}
|
|
|
|
virtual ~SwitchableSetting() = default;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a default value, minimum value, maximum value, and label.
|
|
|
|
*
|
|
|
|
* @param linkage Setting registry
|
|
|
|
* @param default_val Initial value of the setting, and default value of the setting
|
|
|
|
* @param min_val Sets the minimum allowed value of the setting
|
|
|
|
* @param max_val Sets the maximum allowed value of the setting
|
|
|
|
* @param name Label for the setting
|
|
|
|
* @param category_ Category of the setting AKA INI group
|
2023-07-18 21:44:27 +02:00
|
|
|
* @param specialization_ Suggestion for how frontend implementations represent this in a config
|
2023-07-18 21:36:20 +02:00
|
|
|
* @param save_ Suggests that this should or should not be saved to a frontend config file
|
|
|
|
* @param runtime_modifiable_ Suggests whether this is modifiable while a guest is loaded
|
|
|
|
* @param other_setting_ A second Setting to associate to this one in metadata
|
2023-06-11 05:40:39 +02:00
|
|
|
*/
|
2023-08-10 02:58:47 +02:00
|
|
|
template <typename T = BasicSetting>
|
2023-06-11 05:40:39 +02:00
|
|
|
explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const Type& min_val,
|
2023-06-18 09:52:41 +02:00
|
|
|
const Type& max_val, const std::string& name, Category category_,
|
2023-06-21 21:38:30 +02:00
|
|
|
u32 specialization_ = Specialization::Default, bool save_ = true,
|
2023-06-21 11:04:21 +02:00
|
|
|
bool runtime_modifiable_ = false,
|
2023-08-10 02:58:47 +02:00
|
|
|
typename std::enable_if<ranged, T*>::type other_setting_ = nullptr)
|
2023-06-21 21:38:30 +02:00
|
|
|
: Setting<Type, true>{linkage, default_val, min_val,
|
|
|
|
max_val, name, category_,
|
|
|
|
specialization_, save_, runtime_modifiable_,
|
|
|
|
other_setting_} {
|
2023-06-11 05:40:39 +02:00
|
|
|
linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); });
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tells this setting to represent either the global or custom setting when other member
|
|
|
|
* functions are used.
|
|
|
|
*
|
|
|
|
* @param to_global Whether to use the global or custom setting.
|
|
|
|
*/
|
2023-07-18 21:36:20 +02:00
|
|
|
void SetGlobal(bool to_global) override final {
|
2023-06-11 05:40:39 +02:00
|
|
|
use_global = to_global;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether this setting is using the global setting or not.
|
|
|
|
*
|
|
|
|
* @returns The global state
|
|
|
|
*/
|
2023-07-18 21:36:20 +02:00
|
|
|
[[nodiscard]] bool UsingGlobal() const override final {
|
2023-06-11 05:40:39 +02:00
|
|
|
return use_global;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns either the global or custom setting depending on the values of this setting's global
|
|
|
|
* state or if the global value was specifically requested.
|
|
|
|
*
|
|
|
|
* @param need_global Request global value regardless of setting's state; defaults to false
|
|
|
|
*
|
|
|
|
* @returns The required value of the setting
|
|
|
|
*/
|
2023-07-18 21:36:20 +02:00
|
|
|
[[nodiscard]] const Type& GetValue() const override final {
|
2023-06-11 05:40:39 +02:00
|
|
|
if (use_global) {
|
|
|
|
return this->value;
|
|
|
|
}
|
|
|
|
return custom;
|
|
|
|
}
|
2023-12-11 02:10:36 +01:00
|
|
|
[[nodiscard]] const Type& GetValue(bool need_global) const override final {
|
2023-06-11 05:40:39 +02:00
|
|
|
if (use_global || need_global) {
|
|
|
|
return this->value;
|
|
|
|
}
|
|
|
|
return custom;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the current setting value depending on the global state.
|
|
|
|
*
|
|
|
|
* @param val The new value
|
|
|
|
*/
|
2023-07-18 21:36:20 +02:00
|
|
|
void SetValue(const Type& val) override final {
|
2023-06-11 05:40:39 +02:00
|
|
|
Type temp{ranged ? std::clamp(val, this->minimum, this->maximum) : val};
|
|
|
|
if (use_global) {
|
|
|
|
std::swap(this->value, temp);
|
|
|
|
} else {
|
|
|
|
std::swap(custom, temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-18 21:36:20 +02:00
|
|
|
[[nodiscard]] constexpr bool Switchable() const override final {
|
2023-06-11 05:40:39 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-07-18 21:36:20 +02:00
|
|
|
[[nodiscard]] std::string ToStringGlobal() const override final {
|
2023-06-11 05:40:39 +02:00
|
|
|
return this->ToString(this->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assigns the current setting value depending on the global state.
|
|
|
|
*
|
|
|
|
* @param val The new value
|
|
|
|
*
|
|
|
|
* @returns A reference to the current setting value
|
|
|
|
*/
|
2023-07-18 21:36:20 +02:00
|
|
|
const Type& operator=(const Type& val) override final {
|
2023-06-11 05:40:39 +02:00
|
|
|
Type temp{ranged ? std::clamp(val, this->minimum, this->maximum) : val};
|
|
|
|
if (use_global) {
|
|
|
|
std::swap(this->value, temp);
|
|
|
|
return this->value;
|
|
|
|
}
|
|
|
|
std::swap(custom, temp);
|
|
|
|
return custom;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current setting value depending on the global state.
|
|
|
|
*
|
|
|
|
* @returns A reference to the current setting value
|
|
|
|
*/
|
2023-07-18 21:36:20 +02:00
|
|
|
explicit operator const Type&() const override final {
|
2023-06-11 05:40:39 +02:00
|
|
|
if (use_global) {
|
|
|
|
return this->value;
|
|
|
|
}
|
|
|
|
return custom;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool use_global{true}; ///< The setting's global state
|
|
|
|
Type custom{}; ///< The custom value of the setting
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Settings
|