2010-04-01 20:48:24 -06:00
|
|
|
#ifndef _CIFACE_SDL_H_
|
|
|
|
#define _CIFACE_SDL_H_
|
|
|
|
|
2013-06-16 18:07:10 -06:00
|
|
|
#include "../Device.h"
|
2010-04-01 20:48:24 -06:00
|
|
|
|
2011-04-01 17:57:06 -06:00
|
|
|
#include <list>
|
|
|
|
|
2013-02-05 14:32:13 -07:00
|
|
|
#include <SDL.h>
|
2010-04-01 20:48:24 -06:00
|
|
|
|
|
|
|
#if SDL_VERSION_ATLEAST(1, 3, 0)
|
|
|
|
#define USE_SDL_HAPTIC
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_SDL_HAPTIC
|
2013-02-05 14:32:13 -07:00
|
|
|
#include <SDL_haptic.h>
|
2010-04-01 20:48:24 -06:00
|
|
|
#define SDL_INIT_FLAGS SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC
|
|
|
|
#else
|
|
|
|
#define SDL_INIT_FLAGS SDL_INIT_JOYSTICK
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace ciface
|
|
|
|
{
|
|
|
|
namespace SDL
|
|
|
|
{
|
|
|
|
|
2013-06-16 18:07:10 -06:00
|
|
|
void Init( std::vector<Core::Device*>& devices );
|
2010-04-01 20:48:24 -06:00
|
|
|
|
2013-06-16 18:07:10 -06:00
|
|
|
class Joystick : public Core::Device
|
2010-04-01 20:48:24 -06:00
|
|
|
{
|
2011-03-13 19:20:11 -06:00
|
|
|
private:
|
2010-04-01 20:48:24 -06:00
|
|
|
|
|
|
|
#ifdef USE_SDL_HAPTIC
|
2011-03-13 19:20:11 -06:00
|
|
|
struct EffectIDState
|
2010-04-01 20:48:24 -06:00
|
|
|
{
|
2011-04-01 17:57:06 -06:00
|
|
|
EffectIDState() : effect(SDL_HapticEffect()), id(-1), changed(false) {}
|
2011-03-13 19:20:11 -06:00
|
|
|
|
2010-04-01 20:48:24 -06:00
|
|
|
SDL_HapticEffect effect;
|
|
|
|
int id;
|
|
|
|
bool changed;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2013-06-16 18:07:10 -06:00
|
|
|
class Button : public Core::Device::Input
|
2010-04-01 20:48:24 -06:00
|
|
|
{
|
|
|
|
public:
|
2013-10-28 23:34:26 -06:00
|
|
|
std::string GetName() const override;
|
2011-03-13 19:20:11 -06:00
|
|
|
Button(u8 index, SDL_Joystick* js) : m_js(js), m_index(index) {}
|
2013-10-28 23:34:26 -06:00
|
|
|
ControlState GetState() const override;
|
2011-03-13 19:20:11 -06:00
|
|
|
private:
|
|
|
|
SDL_Joystick* const m_js;
|
|
|
|
const u8 m_index;
|
2010-04-01 20:48:24 -06:00
|
|
|
};
|
2011-03-13 19:20:11 -06:00
|
|
|
|
2013-06-16 18:07:10 -06:00
|
|
|
class Axis : public Core::Device::Input
|
2010-04-01 20:48:24 -06:00
|
|
|
{
|
|
|
|
public:
|
2013-10-28 23:34:26 -06:00
|
|
|
std::string GetName() const override;
|
2011-03-13 19:20:11 -06:00
|
|
|
Axis(u8 index, SDL_Joystick* js, Sint16 range) : m_js(js), m_range(range), m_index(index) {}
|
2013-10-28 23:34:26 -06:00
|
|
|
ControlState GetState() const override;
|
2010-04-01 20:48:24 -06:00
|
|
|
private:
|
2011-03-13 19:20:11 -06:00
|
|
|
SDL_Joystick* const m_js;
|
|
|
|
const Sint16 m_range;
|
|
|
|
const u8 m_index;
|
2010-04-01 20:48:24 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
class Hat : public Input
|
|
|
|
{
|
|
|
|
public:
|
2013-10-28 23:34:26 -06:00
|
|
|
std::string GetName() const override;
|
2011-03-13 19:20:11 -06:00
|
|
|
Hat(u8 index, SDL_Joystick* js, u8 direction) : m_js(js), m_direction(direction), m_index(index) {}
|
2013-10-28 23:34:26 -06:00
|
|
|
ControlState GetState() const override;
|
2010-04-01 20:48:24 -06:00
|
|
|
private:
|
2011-03-13 19:20:11 -06:00
|
|
|
SDL_Joystick* const m_js;
|
|
|
|
const u8 m_direction;
|
|
|
|
const u8 m_index;
|
2010-04-01 20:48:24 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef USE_SDL_HAPTIC
|
|
|
|
class ConstantEffect : public Output
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string GetName() const;
|
2011-04-01 17:57:06 -06:00
|
|
|
ConstantEffect(EffectIDState& effect) : m_effect(effect) {}
|
2013-10-19 03:27:57 -06:00
|
|
|
void SetState(ControlState state);
|
2011-03-13 19:20:11 -06:00
|
|
|
private:
|
2011-04-01 17:57:06 -06:00
|
|
|
EffectIDState& m_effect;
|
2010-04-01 20:48:24 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
class RampEffect : public Output
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string GetName() const;
|
2011-04-01 17:57:06 -06:00
|
|
|
RampEffect(EffectIDState& effect) : m_effect(effect) {}
|
2013-10-19 03:27:57 -06:00
|
|
|
void SetState(ControlState state);
|
2011-03-13 19:20:11 -06:00
|
|
|
private:
|
2011-04-01 17:57:06 -06:00
|
|
|
EffectIDState& m_effect;
|
2010-04-01 20:48:24 -06:00
|
|
|
};
|
2012-07-11 14:48:15 -06:00
|
|
|
|
|
|
|
class SineEffect : public Output
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string GetName() const;
|
|
|
|
SineEffect(EffectIDState& effect) : m_effect(effect) {}
|
2013-10-19 03:27:57 -06:00
|
|
|
void SetState(ControlState state);
|
2012-07-11 14:48:15 -06:00
|
|
|
private:
|
|
|
|
EffectIDState& m_effect;
|
|
|
|
};
|
|
|
|
|
2013-08-15 14:18:40 -06:00
|
|
|
#ifdef SDL_HAPTIC_SQUARE
|
2012-07-11 14:48:15 -06:00
|
|
|
class SquareEffect : public Output
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string GetName() const;
|
|
|
|
SquareEffect(EffectIDState& effect) : m_effect(effect) {}
|
2013-10-19 03:27:57 -06:00
|
|
|
void SetState(ControlState state);
|
2012-07-11 14:48:15 -06:00
|
|
|
private:
|
|
|
|
EffectIDState& m_effect;
|
|
|
|
};
|
2013-08-15 14:18:40 -06:00
|
|
|
#endif // defined(SDL_HAPTIC_SQUARE)
|
2012-07-11 14:48:15 -06:00
|
|
|
|
|
|
|
class TriangleEffect : public Output
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string GetName() const;
|
|
|
|
TriangleEffect(EffectIDState& effect) : m_effect(effect) {}
|
2013-10-19 03:27:57 -06:00
|
|
|
void SetState(ControlState state);
|
2012-07-11 14:48:15 -06:00
|
|
|
private:
|
|
|
|
EffectIDState& m_effect;
|
|
|
|
};
|
2010-04-01 20:48:24 -06:00
|
|
|
#endif
|
|
|
|
|
2011-03-13 19:20:11 -06:00
|
|
|
public:
|
2013-10-28 23:34:26 -06:00
|
|
|
bool UpdateInput() override;
|
|
|
|
bool UpdateOutput() override;
|
2010-04-01 20:48:24 -06:00
|
|
|
|
2010-06-05 21:52:11 -06:00
|
|
|
Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsigned int index);
|
2010-04-01 20:48:24 -06:00
|
|
|
~Joystick();
|
|
|
|
|
2013-10-28 23:34:26 -06:00
|
|
|
std::string GetName() const override;
|
|
|
|
int GetId() const override;
|
|
|
|
std::string GetSource() const override;
|
2010-04-01 20:48:24 -06:00
|
|
|
|
|
|
|
private:
|
|
|
|
SDL_Joystick* const m_joystick;
|
2010-06-05 21:52:11 -06:00
|
|
|
const int m_sdl_index;
|
2010-04-01 20:48:24 -06:00
|
|
|
const unsigned int m_index;
|
|
|
|
|
|
|
|
#ifdef USE_SDL_HAPTIC
|
2011-04-01 17:57:06 -06:00
|
|
|
std::list<EffectIDState> m_state_out;
|
2010-04-01 20:48:24 -06:00
|
|
|
SDL_Haptic* m_haptic;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|