-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputManager.h
104 lines (83 loc) · 2.32 KB
/
InputManager.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
#ifndef _INPUT_SW_MAN_H
#define _INPUT_SW_MAN_H
#include <SDL_events.h>
#include <cstring>
const int JOYSTICK_THRESHOLD = 25000;
class InputSwitch
{
public:
InputSwitch(bool isup = false) : isup(isup) {}
virtual ~InputSwitch() {}
virtual const char *name() const = 0;
virtual int id() const = 0;
inline bool operator==(const InputSwitch &other) const {
return id() == other.id();
}
inline bool isUp() const { return isup; }
inline bool isDown() const { return !isup; }
/* Meta-Informations about the switch */
virtual bool isArrowUp() const { return false; }
virtual bool isArrowDown() const { return false; }
virtual bool isValidate() const { return false; }
virtual bool isCancel() const { return false; }
virtual bool isPause() const { return false; }
private:
bool isup;
};
void initControllers();
void closeControllers();
InputSwitch *switchForEvent(SDL_Event *e);
InputSwitch *waitInputSwitch();
InputSwitch *checkInputSwitch();
class KeyInputSwitch : public InputSwitch
{
public:
KeyInputSwitch(int keysym, bool isup);
const char *name() const;
int id() const;
virtual bool isArrowUp() const;
virtual bool isArrowDown() const;
virtual bool isValidate() const;
virtual bool isCancel() const;
virtual bool isPause() const;
private:
int keysym;
mutable char keyName[256];
};
class JoystickSwitch : public InputSwitch
{
private:
int which;
int button;
mutable char keyName[256];
public:
JoystickSwitch(int which, int button, bool isup);
const char *name() const;
int id() const;
virtual bool isValidate() const;
virtual bool isCancel() const;
};
class JoystickAxisSwitch : public InputSwitch
{
private:
int which;
int axis;
bool maximum;
mutable char keyName[256];
public:
JoystickAxisSwitch(int which, int axis, bool maximum, bool isup);
const char *name() const;
int id() const;
virtual bool isArrowUp() const;
virtual bool isArrowDown() const;
};
class InputFromIDAndName : public InputSwitch
{
int _id;
char _name[256];
public:
InputFromIDAndName(int _id, const char *_name) : _id(_id) {strcpy(this->_name, _name);}
const char *name() const { return _name; }
int id() const { return _id; }
};
#endif