-
Notifications
You must be signed in to change notification settings - Fork 59
/
CInput.h
134 lines (102 loc) · 3.03 KB
/
CInput.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
/////////////////////////////////////////
//
// OpenLieroX
//
// Auxiliary Software class library
//
// based on the work of JasonB
// enhanced by Dark Charlie and Albert Zeyer
//
// code under LGPL
//
/////////////////////////////////////////
// Input class
// Created 10/12/01
// By Jason Boettcher
#ifndef __CINPUT_H__
#define __CINPUT_H__
#include <string>
// Input variable types
#define INP_NOTUSED -1
#define INP_KEYBOARD 0
#define INP_MOUSE 1
#define INP_JOYSTICK1 2
#define INP_JOYSTICK2 3
// Joystick data
#define JOY_UP 0
#define JOY_DOWN 1
#define JOY_LEFT 2
#define JOY_RIGHT 3
#define JOY_BUTTON 4
#define JOY_TURN_LEFT 5
#define JOY_TURN_RIGHT 6
#define JOY_THROTTLE_LEFT 7
#define JOY_THROTTLE_RIGHT 8
struct KeyboardEvent;
class CInput {
friend void HandleNextEvent();
friend void HandleCInputs_UpdateDownOnceForNonKeyboard();
friend void HandleCInputs_UpdateUpForNonKeyboard();
friend void HandleCInputs_KeyEvent(const KeyboardEvent& ev);
public:
CInput();
~CInput();
private:
// Attributes
int Type; // keyboard, mouse or joystick
int Data;
int Extra;
std::string m_EventName;
bool resetEachFrame;
// HINT: currently these are only used for keyboard exept nDownOnce
// TODO: change this in HandleNextEvent() and here
int nDown;
int nDownOnce; // this is also updated for non-keyboards with currently the old code
int nUp;
bool bDown;
private:
int wasDown_withoutRepeats() const;
public:
// Methods
int Setup(const std::string& text);
static void InitJoysticksTemp(); // call this if CInput::Wait shall recognise joystick events
static void UnInitJoysticksTemp();
static int Wait(std::string& strText); // TODO: change this name. this function doesn't realy wait, it just checks the event-state
bool isUsed() { return Type >= 0; }
int getData() { return Data; }
int getType() { return Type; }
bool isJoystick() { return Type == INP_JOYSTICK1 || Type == INP_JOYSTICK2; }
bool isKeyboard() { return Type == INP_KEYBOARD; }
void setResetEachFrame(bool r) { resetEachFrame = r; }
bool getResetEachFrame() { return resetEachFrame; }
int getJoystickValue();
bool isJoystickAxis();
bool isJoystickThrottle();
bool isUp();
bool isDown() const;
bool isDownOnce();
int wasDown(bool withRepeats) const {
if(withRepeats) return wasDown();
else return wasDown_withoutRepeats();
}
int wasDown() const; // checks if there was such an event in the queue; returns the count of presses (down-events)
int wasUp(); // checks if there was an keyup-event; returns the count of up-events
std::string getEventName() { return m_EventName; }
// resets the current state
// this is called automatically if resetEachFrame
void reset();
};
// Keyboard structure
struct keys_t {
char text[16]; // Keep string local to speed up lookup.
int value;
static int keySymFromName(const std::string & name);
};
// Joystick structure
struct joystick_t {
char text[16]; // Keep string local to speed up lookup.
int value;
int extra;
int axis;
};
#endif // __CINPUT_H__