2014-02-10 18:54:46 +00:00
|
|
|
// Copyright 2014 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-04-01 23:57:06 +00:00
|
|
|
#include <list>
|
|
|
|
|
2013-02-05 21:32:13 +00:00
|
|
|
#include <SDL.h>
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
|
|
|
|
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
#if SDL_VERSION_ATLEAST(1, 3, 0)
|
|
|
|
#define USE_SDL_HAPTIC
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_SDL_HAPTIC
|
2013-02-05 21:32:13 +00:00
|
|
|
#include <SDL_haptic.h>
|
2014-02-17 04:51:41 +00:00
|
|
|
#define SDL_INIT_FLAGS SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC
|
2010-04-02 02:48:24 +00:00
|
|
|
#else
|
2014-02-17 04:51:41 +00:00
|
|
|
#define SDL_INIT_FLAGS SDL_INIT_JOYSTICK
|
2010-04-02 02:48:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace ciface
|
|
|
|
{
|
|
|
|
namespace SDL
|
|
|
|
{
|
|
|
|
|
2013-06-17 00:07:10 +00:00
|
|
|
void Init( std::vector<Core::Device*>& devices );
|
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:
|
2010-04-02 02:48:24 +00:00
|
|
|
|
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;
|
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
|
|
|
};
|
2011-03-14 01:20:11 +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;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
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:
|
2014-11-13 08:49:18 +00:00
|
|
|
HapticEffect(SDL_Haptic* haptic) : m_haptic(haptic), m_id(-1) {}
|
|
|
|
~HapticEffect() { m_effect.type = 0; Update(); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void Update();
|
|
|
|
|
|
|
|
SDL_HapticEffect m_effect;
|
|
|
|
SDL_Haptic* m_haptic;
|
|
|
|
int m_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConstantEffect : public HapticEffect
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ConstantEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
|
2014-03-08 00:54:44 +00:00
|
|
|
std::string GetName() const override;
|
|
|
|
void SetState(ControlState state) override;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
2014-11-13 08:49:18 +00:00
|
|
|
class RampEffect : public HapticEffect
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-11-13 08:49:18 +00:00
|
|
|
RampEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
|
2014-03-08 00:54:44 +00:00
|
|
|
std::string GetName() const override;
|
|
|
|
void SetState(ControlState state) override;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2011-03-14 01:20:11 +00:00
|
|
|
public:
|
2014-11-13 08:55:14 +00:00
|
|
|
void UpdateInput() override;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-06 03:52:11 +00:00
|
|
|
Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsigned int index);
|
2010-04-02 02:48:24 +00:00
|
|
|
~Joystick();
|
|
|
|
|
2013-10-29 05:34:26 +00:00
|
|
|
std::string GetName() const override;
|
|
|
|
int GetId() const override;
|
|
|
|
std::string GetSource() const override;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
private:
|
2014-02-09 23:29:13 +00:00
|
|
|
SDL_Joystick* const m_joystick;
|
|
|
|
const int m_sdl_index;
|
|
|
|
const unsigned int m_index;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
#ifdef USE_SDL_HAPTIC
|
2014-02-09 23:29:13 +00:00
|
|
|
SDL_Haptic* m_haptic;
|
2010-04-02 02:48:24 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|