/
SDL.h
163 lines (132 loc) · 3.36 KB
/
SDL.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright 2010 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <SDL.h>
#if SDL_VERSION_ATLEAST(1, 3, 0)
#define USE_SDL_HAPTIC
#endif
#ifdef USE_SDL_HAPTIC
#include <SDL_haptic.h>
#endif
#include "InputCommon/ControllerInterface/Device.h"
namespace ciface
{
namespace SDL
{
void Init();
void DeInit();
void PopulateDevices();
class Joystick : public Core::Device
{
private:
class Button : public Core::Device::Input
{
public:
std::string GetName() const override;
Button(u8 index, SDL_Joystick* js) : m_js(js), m_index(index) {}
ControlState GetState() const override;
private:
SDL_Joystick* const m_js;
const u8 m_index;
};
class Axis : public Core::Device::Input
{
public:
std::string GetName() const override;
Axis(u8 index, SDL_Joystick* js, Sint16 range) : m_js(js), m_range(range), m_index(index) {}
ControlState GetState() const override;
private:
SDL_Joystick* const m_js;
const Sint16 m_range;
const u8 m_index;
};
class Hat : public Input
{
public:
std::string GetName() const override;
Hat(u8 index, SDL_Joystick* js, u8 direction) : m_js(js), m_direction(direction), m_index(index)
{
}
ControlState GetState() const override;
private:
SDL_Joystick* const m_js;
const u8 m_direction;
const u8 m_index;
};
#ifdef USE_SDL_HAPTIC
class HapticEffect : public Output
{
public:
HapticEffect(SDL_Haptic* haptic) : m_haptic(haptic), m_id(-1) {}
~HapticEffect()
{
m_effect.type = 0;
Update();
}
protected:
void Update();
virtual void SetSDLHapticEffect(ControlState state) = 0;
SDL_HapticEffect m_effect;
SDL_Haptic* m_haptic;
int m_id;
private:
virtual void SetState(ControlState state) override final;
};
class ConstantEffect : public HapticEffect
{
public:
ConstantEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
std::string GetName() const override;
private:
void SetSDLHapticEffect(ControlState state) override;
};
class RampEffect : public HapticEffect
{
public:
RampEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
std::string GetName() const override;
private:
void SetSDLHapticEffect(ControlState state) override;
};
class SineEffect : public HapticEffect
{
public:
SineEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
std::string GetName() const override;
private:
void SetSDLHapticEffect(ControlState state) override;
};
class TriangleEffect : public HapticEffect
{
public:
TriangleEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
std::string GetName() const override;
private:
void SetSDLHapticEffect(ControlState state) override;
};
class LeftRightEffect : public HapticEffect
{
public:
LeftRightEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
std::string GetName() const override;
private:
void SetSDLHapticEffect(ControlState state) override;
};
#endif
public:
void UpdateInput() override;
Joystick(SDL_Joystick* const joystick, const int sdl_index);
~Joystick();
std::string GetName() const override;
std::string GetSource() const override;
SDL_Joystick* GetSDLJoystick() const;
private:
SDL_Joystick* const m_joystick;
std::string m_name;
#ifdef USE_SDL_HAPTIC
SDL_Haptic* m_haptic;
#endif
};
}
}