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/AnalogStick.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#include "Common/Common.h"
|
2018-12-19 02:06:16 +00:00
|
|
|
#include "Common/MathUtil.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Input.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
2017-02-26 20:00:24 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
2018-12-19 02:06:16 +00:00
|
|
|
AnalogStick::AnalogStick(const char* const name_, std::unique_ptr<StickGate>&& stick_gate)
|
|
|
|
: AnalogStick(name_, name_, std::move(stick_gate))
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_,
|
2018-12-19 02:06:16 +00:00
|
|
|
std::unique_ptr<StickGate>&& stick_gate)
|
2018-12-29 22:06:03 +00:00
|
|
|
: ReshapableInput(name_, ui_name_, GroupType::Stick), m_stick_gate(std::move(stick_gate))
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
|
|
|
for (auto& named_direction : named_directions)
|
2019-10-27 16:04:08 +00:00
|
|
|
AddInput(Translate, named_direction);
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2019-10-27 16:04:08 +00:00
|
|
|
AddInput(Translate, _trans("Modifier"));
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 20:47:55 +00:00
|
|
|
AnalogStick::ReshapeData AnalogStick::GetReshapableState(bool adjusted) const
|
2017-02-09 03:15:43 +00:00
|
|
|
{
|
2020-02-09 02:36:26 +00:00
|
|
|
const ControlState y = controls[0]->GetState() - controls[1]->GetState();
|
|
|
|
const ControlState x = controls[3]->GetState() - controls[2]->GetState();
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2018-12-19 02:06:16 +00:00
|
|
|
// Return raw values. (used in UI)
|
|
|
|
if (!adjusted)
|
|
|
|
return {x, y};
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2022-01-04 20:09:50 +00:00
|
|
|
return Reshape(x, y, GetModifierInput()->GetState());
|
2017-02-09 03:15:43 +00:00
|
|
|
}
|
2018-12-19 02:06:16 +00:00
|
|
|
|
2021-05-04 20:47:55 +00:00
|
|
|
AnalogStick::StateData AnalogStick::GetState() const
|
2018-12-30 15:10:32 +00:00
|
|
|
{
|
|
|
|
return GetReshapableState(true);
|
|
|
|
}
|
|
|
|
|
2018-12-19 02:06:16 +00:00
|
|
|
ControlState AnalogStick::GetGateRadiusAtAngle(double ang) const
|
|
|
|
{
|
|
|
|
return m_stick_gate->GetRadiusAtAngle(ang);
|
|
|
|
}
|
|
|
|
|
2022-01-04 20:09:50 +00:00
|
|
|
Control* AnalogStick::GetModifierInput() const
|
|
|
|
{
|
|
|
|
return controls[4].get();
|
|
|
|
}
|
|
|
|
|
2020-07-31 23:17:23 +00:00
|
|
|
OctagonAnalogStick::OctagonAnalogStick(const char* name_, ControlState gate_radius)
|
|
|
|
: OctagonAnalogStick(name_, name_, gate_radius)
|
2018-12-19 02:06:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-31 23:17:23 +00:00
|
|
|
OctagonAnalogStick::OctagonAnalogStick(const char* name_, const char* ui_name_,
|
2018-12-19 02:06:16 +00:00
|
|
|
ControlState gate_radius)
|
2022-05-20 03:19:17 +00:00
|
|
|
: AnalogStick(name_, ui_name_, std::make_unique<ControllerEmu::OctagonStickGate>(1.0))
|
2018-12-19 02:06:16 +00:00
|
|
|
{
|
2020-10-29 22:11:34 +00:00
|
|
|
AddVirtualNotchSetting(&m_virtual_notch_setting, 45);
|
2022-05-20 03:19:17 +00:00
|
|
|
|
|
|
|
AddSetting(
|
|
|
|
&m_gate_size_setting,
|
|
|
|
{_trans("Gate Size"),
|
|
|
|
// i18n: The percent symbol.
|
|
|
|
_trans("%"),
|
|
|
|
// i18n: Refers to plastic shell of game controller (stick gate) that limits stick movements.
|
2022-05-20 03:33:15 +00:00
|
|
|
_trans("Adjusts target radius of simulated stick gate."), nullptr,
|
|
|
|
SettingVisibility::Advanced},
|
2022-05-20 03:19:17 +00:00
|
|
|
gate_radius * 100, 0.01, 100);
|
2020-10-29 22:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlState OctagonAnalogStick::GetVirtualNotchSize() const
|
|
|
|
{
|
|
|
|
return m_virtual_notch_setting.GetValue() * MathUtil::TAU / 360;
|
2018-12-19 02:06:16 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 03:19:17 +00:00
|
|
|
ControlState OctagonAnalogStick::GetGateRadiusAtAngle(double ang) const
|
|
|
|
{
|
|
|
|
return AnalogStick::GetGateRadiusAtAngle(ang) * m_gate_size_setting.GetValue() / 100;
|
|
|
|
}
|
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
} // namespace ControllerEmu
|