2017-02-08 22:15:43 -05:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#include "Common/Common.h"
|
2018-12-18 20:06:16 -06:00
|
|
|
#include "Common/MathUtil.h"
|
2017-02-08 22:15:43 -05: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 12:00:24 -08:00
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
2017-02-08 22:15:43 -05:00
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
2018-12-18 20:06:16 -06:00
|
|
|
AnalogStick::AnalogStick(const char* const name_, std::unique_ptr<StickGate>&& stick_gate)
|
|
|
|
: AnalogStick(name_, name_, std::move(stick_gate))
|
2017-02-08 22:15:43 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_,
|
2018-12-18 20:06:16 -06:00
|
|
|
std::unique_ptr<StickGate>&& stick_gate)
|
2018-12-29 16:06:03 -06:00
|
|
|
: ReshapableInput(name_, ui_name_, GroupType::Stick), m_stick_gate(std::move(stick_gate))
|
2017-02-08 22:15:43 -05:00
|
|
|
{
|
|
|
|
for (auto& named_direction : named_directions)
|
2018-04-10 17:22:30 +02:00
|
|
|
controls.emplace_back(std::make_unique<Input>(Translate, named_direction));
|
2017-02-08 22:15:43 -05:00
|
|
|
|
2018-04-10 17:22:30 +02:00
|
|
|
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Modifier")));
|
2018-12-18 20:06:16 -06:00
|
|
|
|
2018-12-29 16:06:03 -06:00
|
|
|
// Default input radius to that of the gate radius (no resizing)
|
|
|
|
// Default input shape to an octagon (no reshaping)
|
|
|
|
// Max deadzone to 50%
|
|
|
|
AddReshapingSettings(GetGateRadiusAtAngle(0.0), 0.0, 50);
|
2017-02-08 22:15:43 -05:00
|
|
|
}
|
|
|
|
|
2018-12-30 10:52:45 -06:00
|
|
|
AnalogStick::ReshapeData AnalogStick::GetReshapableState(bool adjusted)
|
2017-02-08 22:15:43 -05:00
|
|
|
{
|
2018-12-30 09:10:32 -06:00
|
|
|
const ControlState y = controls[0]->control_ref->State() - controls[1]->control_ref->State();
|
|
|
|
const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
2017-02-08 22:15:43 -05:00
|
|
|
|
2018-12-18 20:06:16 -06:00
|
|
|
// Return raw values. (used in UI)
|
|
|
|
if (!adjusted)
|
|
|
|
return {x, y};
|
2017-02-08 22:15:43 -05:00
|
|
|
|
2018-12-18 20:06:16 -06:00
|
|
|
const ControlState modifier = controls[4]->control_ref->State();
|
2018-12-29 16:06:03 -06:00
|
|
|
|
|
|
|
return Reshape(x, y, modifier);
|
2017-02-08 22:15:43 -05:00
|
|
|
}
|
2018-12-18 20:06:16 -06:00
|
|
|
|
2018-12-30 09:10:32 -06:00
|
|
|
AnalogStick::StateData AnalogStick::GetState()
|
|
|
|
{
|
|
|
|
return GetReshapableState(true);
|
|
|
|
}
|
|
|
|
|
2018-12-18 20:06:16 -06:00
|
|
|
ControlState AnalogStick::GetGateRadiusAtAngle(double ang) const
|
|
|
|
{
|
|
|
|
return m_stick_gate->GetRadiusAtAngle(ang);
|
|
|
|
}
|
|
|
|
|
|
|
|
OctagonAnalogStick::OctagonAnalogStick(const char* name, ControlState gate_radius)
|
|
|
|
: OctagonAnalogStick(name, name, gate_radius)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
OctagonAnalogStick::OctagonAnalogStick(const char* name, const char* ui_name,
|
|
|
|
ControlState gate_radius)
|
|
|
|
: AnalogStick(name, ui_name, std::make_unique<ControllerEmu::OctagonStickGate>(gate_radius))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-08 22:15:43 -05:00
|
|
|
} // namespace ControllerEmu
|