2017-02-26 20:00:24 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-02-26 20:00:24 +00:00
|
|
|
|
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
|
|
|
|
2024-03-21 03:40:01 +00:00
|
|
|
#include <fmt/format.h>
|
2020-01-18 17:19:32 +00:00
|
|
|
|
2017-02-26 20:00:24 +00:00
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
2019-03-27 00:31:03 +00:00
|
|
|
NumericSettingBase::NumericSettingBase(const NumericSettingDetails& details) : m_details(details)
|
2017-02-26 20:00:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-03-21 03:40:01 +00:00
|
|
|
// Explicit instantiations so generic definitions can exist outside of the header.
|
|
|
|
template class NumericSetting<int>;
|
|
|
|
template class NumericSetting<double>;
|
|
|
|
template class NumericSetting<bool>;
|
|
|
|
|
2022-06-26 18:27:18 +00:00
|
|
|
const char* NumericSettingBase::GetININame() const
|
|
|
|
{
|
|
|
|
return m_details.ini_name;
|
|
|
|
}
|
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
const char* NumericSettingBase::GetUIName() const
|
2017-02-26 20:00:24 +00:00
|
|
|
{
|
2019-03-27 00:31:03 +00:00
|
|
|
return m_details.ui_name;
|
2017-02-26 20:00:24 +00:00
|
|
|
}
|
2019-03-27 00:31:03 +00:00
|
|
|
|
|
|
|
const char* NumericSettingBase::GetUISuffix() const
|
|
|
|
{
|
|
|
|
return m_details.ui_suffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* NumericSettingBase::GetUIDescription() const
|
|
|
|
{
|
|
|
|
return m_details.ui_description;
|
|
|
|
}
|
|
|
|
|
2022-05-20 03:47:30 +00:00
|
|
|
SettingVisibility NumericSettingBase::GetVisibility() const
|
|
|
|
{
|
|
|
|
return m_details.visibility;
|
|
|
|
}
|
|
|
|
|
2024-03-21 03:40:01 +00:00
|
|
|
template <typename T>
|
|
|
|
void NumericSetting<T>::SetExpressionFromValue()
|
2020-01-18 17:19:32 +00:00
|
|
|
{
|
2024-03-21 03:40:01 +00:00
|
|
|
// Always include -/+ sign to prevent CoalesceExpression binding.
|
|
|
|
// e.g. 1 is a valid input name for keyboard devices, +1 is not.
|
|
|
|
m_value.m_input.SetExpression(fmt::format("{:+g}", ControlState(GetValue())));
|
2020-01-18 17:19:32 +00:00
|
|
|
}
|
|
|
|
|
2024-03-21 03:40:01 +00:00
|
|
|
template <typename T>
|
|
|
|
void NumericSetting<T>::SimplifyIfPossible()
|
2020-01-18 17:19:32 +00:00
|
|
|
{
|
2024-03-21 03:40:01 +00:00
|
|
|
ValueType value;
|
|
|
|
if (TryParse(std::string(StripWhitespace(m_value.m_input.GetExpression())), &value))
|
|
|
|
m_value.SetValue(value);
|
2020-01-18 17:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
SettingType NumericSetting<int>::GetType() const
|
|
|
|
{
|
|
|
|
return SettingType::Int;
|
|
|
|
}
|
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
template <>
|
|
|
|
SettingType NumericSetting<double>::GetType() const
|
|
|
|
{
|
|
|
|
return SettingType::Double;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
SettingType NumericSetting<bool>::GetType() const
|
2017-02-26 20:00:24 +00:00
|
|
|
{
|
2019-03-27 00:31:03 +00:00
|
|
|
return SettingType::Bool;
|
2017-02-26 20:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ControllerEmu
|