2017-02-09 03:15:43 +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-09 03:15:43 +00:00
|
|
|
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Slider.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "Common/Common.h"
|
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Input.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
2017-12-19 10:21:27 +00:00
|
|
|
Slider::Slider(const std::string& name_, const std::string& ui_name_)
|
|
|
|
: ControlGroup(name_, ui_name_, GroupType::Slider)
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2019-10-27 16:04:08 +00:00
|
|
|
AddInput(Translate, _trans("Left"));
|
|
|
|
AddInput(Translate, _trans("Right"));
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2019-03-27 00:31:03 +00:00
|
|
|
AddDeadzoneSetting(&m_deadzone_setting, 50);
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 10:21:27 +00:00
|
|
|
Slider::Slider(const std::string& name_) : Slider(name_, name_)
|
2017-07-23 11:11:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-04 20:47:55 +00:00
|
|
|
Slider::StateData Slider::GetState() const
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2019-03-27 00:31:03 +00:00
|
|
|
const ControlState deadzone = m_deadzone_setting.GetValue() / 100;
|
2020-02-09 02:36:26 +00:00
|
|
|
const ControlState state = controls[1]->GetState() - controls[0]->GetState();
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2019-10-15 20:35:07 +00:00
|
|
|
return {std::clamp(ApplyDeadzone(state, deadzone), -1.0, 1.0)};
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
2021-03-21 19:27:00 +00:00
|
|
|
|
|
|
|
Slider::StateData Slider::GetState(const InputOverrideFunction& override_func) const
|
|
|
|
{
|
|
|
|
if (!override_func)
|
|
|
|
return GetState();
|
|
|
|
|
|
|
|
const ControlState deadzone = m_deadzone_setting.GetValue() / 100;
|
|
|
|
ControlState state = controls[1]->GetState() - controls[0]->GetState();
|
|
|
|
|
|
|
|
state = ApplyDeadzone(state, deadzone);
|
|
|
|
|
|
|
|
if (std::optional<ControlState> state_override = override_func(name, X_INPUT_OVERRIDE, state))
|
|
|
|
state = *state_override;
|
|
|
|
|
|
|
|
return {std::clamp(state, -1.0, 1.0)};
|
|
|
|
}
|
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
} // namespace ControllerEmu
|