2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-02-10 18:54:46 +00:00
|
|
|
|
|
|
|
#pragma once
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2013-02-05 21:32:13 +00:00
|
|
|
#include <SDL.h>
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
#if SDL_VERSION_ATLEAST(1, 3, 0)
|
|
|
|
#define USE_SDL_HAPTIC
|
|
|
|
#endif
|
|
|
|
|
2021-08-06 15:10:44 +00:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 14)
|
|
|
|
#define USE_SDL_GAMECONTROLLER
|
|
|
|
#endif
|
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
#ifdef USE_SDL_HAPTIC
|
2013-02-05 21:32:13 +00:00
|
|
|
#include <SDL_haptic.h>
|
2010-04-02 02:48:24 +00:00
|
|
|
#endif
|
|
|
|
|
2021-08-06 15:10:44 +00:00
|
|
|
#ifdef USE_SDL_GAMECONTROLLER
|
|
|
|
#include <SDL_gamecontroller.h>
|
|
|
|
#endif
|
|
|
|
|
2020-09-15 11:34:41 +00:00
|
|
|
#include "InputCommon/ControllerInterface/CoreDevice.h"
|
2022-10-22 21:13:35 +00:00
|
|
|
#include "InputCommon/ControllerInterface/InputBackend.h"
|
2017-11-09 22:06:58 +00:00
|
|
|
|
2019-06-17 20:39:24 +00:00
|
|
|
namespace ciface::SDL
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2022-10-22 21:13:35 +00:00
|
|
|
std::unique_ptr<ciface::InputBackend> CreateInputBackend(ControllerInterface* controller_interface);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2013-06-17 00:07:10 +00:00
|
|
|
class Joystick : public Core::Device
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2011-03-14 01:20:11 +00:00
|
|
|
private:
|
2013-06-17 00:07:10 +00:00
|
|
|
class Button : public Core::Device::Input
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-10-29 05:34:26 +00:00
|
|
|
std::string GetName() const override;
|
2011-03-14 01:20:11 +00:00
|
|
|
Button(u8 index, SDL_Joystick* js) : m_js(js), m_index(index) {}
|
2013-10-29 05:34:26 +00:00
|
|
|
ControlState GetState() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2011-03-14 01:20:11 +00:00
|
|
|
private:
|
|
|
|
SDL_Joystick* const m_js;
|
|
|
|
const u8 m_index;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-06-17 00:07:10 +00:00
|
|
|
class Axis : public Core::Device::Input
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-10-29 05:34:26 +00:00
|
|
|
std::string GetName() const override;
|
2011-03-14 01:20:11 +00:00
|
|
|
Axis(u8 index, SDL_Joystick* js, Sint16 range) : m_js(js), m_range(range), m_index(index) {}
|
2013-10-29 05:34:26 +00:00
|
|
|
ControlState GetState() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
private:
|
2011-03-14 01:20:11 +00:00
|
|
|
SDL_Joystick* const m_js;
|
|
|
|
const Sint16 m_range;
|
|
|
|
const u8 m_index;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
class Hat : public Input
|
|
|
|
{
|
|
|
|
public:
|
2013-10-29 05:34:26 +00:00
|
|
|
std::string GetName() const override;
|
2011-03-14 01:20:11 +00:00
|
|
|
Hat(u8 index, SDL_Joystick* js, u8 direction) : m_js(js), m_direction(direction), m_index(index)
|
|
|
|
{
|
|
|
|
}
|
2013-10-29 05:34:26 +00:00
|
|
|
ControlState GetState() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
private:
|
2011-03-14 01:20:11 +00:00
|
|
|
SDL_Joystick* const m_js;
|
|
|
|
const u8 m_direction;
|
|
|
|
const u8 m_index;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef USE_SDL_HAPTIC
|
2014-11-13 08:49:18 +00:00
|
|
|
class HapticEffect : public Output
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-08 16:25:13 +00:00
|
|
|
HapticEffect(SDL_Haptic* haptic);
|
|
|
|
~HapticEffect();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-11-13 08:49:18 +00:00
|
|
|
protected:
|
2019-01-08 16:25:13 +00:00
|
|
|
virtual bool UpdateParameters(s16 value) = 0;
|
|
|
|
static void SetDirection(SDL_HapticDirection* dir);
|
|
|
|
|
|
|
|
SDL_HapticEffect m_effect = {};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-01-08 16:25:13 +00:00
|
|
|
static constexpr u16 DISABLED_EFFECT_TYPE = 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-01-08 12:37:06 +00:00
|
|
|
private:
|
|
|
|
virtual void SetState(ControlState state) override final;
|
2019-01-08 16:25:13 +00:00
|
|
|
void UpdateEffect();
|
|
|
|
SDL_Haptic* const m_haptic;
|
|
|
|
int m_id = -1;
|
2014-11-13 08:49:18 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-11-13 08:49:18 +00:00
|
|
|
class ConstantEffect : public HapticEffect
|
|
|
|
{
|
|
|
|
public:
|
2019-01-08 16:25:13 +00:00
|
|
|
ConstantEffect(SDL_Haptic* haptic);
|
2014-03-08 00:54:44 +00:00
|
|
|
std::string GetName() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-01-08 15:17:29 +00:00
|
|
|
private:
|
2019-01-08 16:25:13 +00:00
|
|
|
bool UpdateParameters(s16 value) override;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-11-13 08:49:18 +00:00
|
|
|
class RampEffect : public HapticEffect
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-08 16:25:13 +00:00
|
|
|
RampEffect(SDL_Haptic* haptic);
|
2014-03-08 00:54:44 +00:00
|
|
|
std::string GetName() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-01-08 15:17:29 +00:00
|
|
|
private:
|
2019-01-08 16:25:13 +00:00
|
|
|
bool UpdateParameters(s16 value) override;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-01-08 16:25:13 +00:00
|
|
|
class PeriodicEffect : public HapticEffect
|
2015-01-06 19:17:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-08 16:25:13 +00:00
|
|
|
PeriodicEffect(SDL_Haptic* haptic, u16 waveform);
|
2015-01-06 19:17:43 +00:00
|
|
|
std::string GetName() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-01-08 15:17:29 +00:00
|
|
|
private:
|
2019-01-08 16:25:13 +00:00
|
|
|
bool UpdateParameters(s16 value) override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-01-08 16:25:13 +00:00
|
|
|
const u16 m_waveform;
|
2015-01-06 19:17:43 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-01-06 19:17:43 +00:00
|
|
|
class LeftRightEffect : public HapticEffect
|
|
|
|
{
|
|
|
|
public:
|
2019-01-17 16:13:32 +00:00
|
|
|
enum class Motor : u8
|
|
|
|
{
|
|
|
|
Weak,
|
|
|
|
Strong,
|
|
|
|
};
|
|
|
|
|
|
|
|
LeftRightEffect(SDL_Haptic* haptic, Motor motor);
|
2015-01-06 19:17:43 +00:00
|
|
|
std::string GetName() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-01-08 15:17:29 +00:00
|
|
|
private:
|
2019-01-08 16:25:13 +00:00
|
|
|
bool UpdateParameters(s16 value) override;
|
|
|
|
|
2019-01-17 16:13:32 +00:00
|
|
|
const Motor m_motor;
|
2015-01-06 19:17:43 +00:00
|
|
|
};
|
2010-04-02 02:48:24 +00:00
|
|
|
#endif
|
|
|
|
|
2021-08-06 15:10:44 +00:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 9)
|
|
|
|
class Motor : public Output
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit Motor(SDL_Joystick* js) : m_js(js){};
|
|
|
|
std::string GetName() const override;
|
|
|
|
void SetState(ControlState state) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SDL_Joystick* const m_js;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_SDL_GAMECONTROLLER
|
|
|
|
class MotionInput : public Input
|
|
|
|
{
|
|
|
|
public:
|
2022-11-24 20:49:11 +00:00
|
|
|
MotionInput(std::string name, SDL_GameController* gc, SDL_SensorType type, int index,
|
2021-08-06 15:10:44 +00:00
|
|
|
ControlState scale)
|
2022-11-24 20:49:11 +00:00
|
|
|
: m_name(std::move(name)), m_gc(gc), m_type(type), m_index(index), m_scale(scale){};
|
2021-08-06 15:10:44 +00:00
|
|
|
|
|
|
|
std::string GetName() const override { return m_name; };
|
|
|
|
bool IsDetectable() const override { return false; };
|
|
|
|
ControlState GetState() const override;
|
|
|
|
|
|
|
|
private:
|
2022-11-24 20:49:11 +00:00
|
|
|
std::string m_name;
|
2021-08-06 15:10:44 +00:00
|
|
|
|
|
|
|
SDL_GameController* const m_gc;
|
|
|
|
SDL_SensorType const m_type;
|
|
|
|
int const m_index;
|
|
|
|
|
|
|
|
ControlState const m_scale;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2011-03-14 01:20:11 +00:00
|
|
|
public:
|
2016-07-14 08:25:52 +00:00
|
|
|
Joystick(SDL_Joystick* const joystick, const int sdl_index);
|
2010-04-02 02:48:24 +00:00
|
|
|
~Joystick();
|
|
|
|
|
2013-10-29 05:34:26 +00:00
|
|
|
std::string GetName() const override;
|
|
|
|
std::string GetSource() const override;
|
2017-11-09 22:06:58 +00:00
|
|
|
SDL_Joystick* GetSDLJoystick() const;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SDL_Joystick* const m_joystick;
|
2017-11-09 22:04:31 +00:00
|
|
|
std::string m_name;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
#ifdef USE_SDL_HAPTIC
|
2022-04-16 16:00:00 +00:00
|
|
|
SDL_Haptic* m_haptic = nullptr;
|
2010-04-02 02:48:24 +00:00
|
|
|
#endif
|
2021-08-06 15:10:44 +00:00
|
|
|
|
|
|
|
#ifdef USE_SDL_GAMECONTROLLER
|
2022-04-16 16:00:00 +00:00
|
|
|
SDL_GameController* m_controller = nullptr;
|
2021-08-06 15:10:44 +00:00
|
|
|
#endif
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
2019-06-17 20:39:24 +00:00
|
|
|
} // namespace ciface::SDL
|