2017-02-08 22:15:43 -05:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
2017-04-04 15:37:31 -04:00
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
2017-02-08 22:15:43 -05:00
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
2018-12-18 20:06:16 -06:00
|
|
|
// An abstract class representing the plastic shell that limits an analog stick's movement.
|
|
|
|
class StickGate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Angle is in radians and should be non-negative
|
|
|
|
virtual ControlState GetRadiusAtAngle(double ang) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// An octagon-shaped stick gate is found on most Nintendo GC/Wii analog sticks.
|
|
|
|
class OctagonStickGate : public StickGate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit OctagonStickGate(ControlState radius);
|
|
|
|
ControlState GetRadiusAtAngle(double ang) const override;
|
|
|
|
|
|
|
|
static ControlState ComputeRadiusAtAngle(double ang);
|
|
|
|
|
|
|
|
const ControlState m_radius;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A round-shaped stick gate. Possibly found on 3rd-party accessories.
|
|
|
|
class RoundStickGate : public StickGate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit RoundStickGate(ControlState radius);
|
|
|
|
ControlState GetRadiusAtAngle(double ang) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const ControlState m_radius;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A square-shaped stick gate. e.g. keyboard input.
|
|
|
|
class SquareStickGate : public StickGate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit SquareStickGate(ControlState half_width);
|
|
|
|
ControlState GetRadiusAtAngle(double ang) const override;
|
|
|
|
|
|
|
|
static ControlState ComputeRadiusAtAngle(double ang);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const ControlState m_half_width;
|
|
|
|
};
|
|
|
|
|
2017-02-08 22:15:43 -05:00
|
|
|
class AnalogStick : public ControlGroup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
2018-12-18 20:06:16 -06:00
|
|
|
SETTING_INPUT_RADIUS,
|
|
|
|
SETTING_INPUT_SHAPE,
|
2017-02-08 22:15:43 -05:00
|
|
|
SETTING_DEADZONE,
|
|
|
|
};
|
|
|
|
|
2018-07-13 11:19:08 -04:00
|
|
|
struct StateData
|
|
|
|
{
|
|
|
|
ControlState x{};
|
|
|
|
ControlState y{};
|
|
|
|
};
|
|
|
|
|
2018-12-18 20:06:16 -06:00
|
|
|
AnalogStick(const char* name, std::unique_ptr<StickGate>&& stick_gate);
|
|
|
|
AnalogStick(const char* name, const char* ui_name, std::unique_ptr<StickGate>&& stick_gate);
|
|
|
|
|
|
|
|
StateData GetState(bool adjusted = true);
|
2017-02-08 22:15:43 -05:00
|
|
|
|
2018-12-18 20:06:16 -06:00
|
|
|
// Angle is in radians and should be non-negative
|
|
|
|
ControlState GetGateRadiusAtAngle(double ang) const;
|
|
|
|
ControlState GetDeadzoneRadiusAtAngle(double ang) const;
|
|
|
|
ControlState GetInputRadiusAtAngle(double ang) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ControlState CalculateInputShapeRadiusAtAngle(double ang) const;
|
|
|
|
|
|
|
|
std::unique_ptr<StickGate> m_stick_gate;
|
2017-02-08 22:15:43 -05:00
|
|
|
};
|
2018-12-18 20:06:16 -06:00
|
|
|
|
|
|
|
// An AnalogStick with an OctagonStickGate
|
|
|
|
class OctagonAnalogStick : public AnalogStick
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OctagonAnalogStick(const char* name, ControlState gate_radius);
|
|
|
|
OctagonAnalogStick(const char* name, const char* ui_name, ControlState gate_radius);
|
|
|
|
};
|
|
|
|
|
2017-02-08 22:15:43 -05:00
|
|
|
} // namespace ControllerEmu
|