-
Notifications
You must be signed in to change notification settings - Fork 9
/
InputHandler.h
100 lines (71 loc) · 2.17 KB
/
InputHandler.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
#pragma once
#ifndef __InputHandler__
#define __InputHandler__
#include "SDL.h"
#include <vector>
#include "Vector2D.h"
enum mouse_buttons
{
LEFT = 0,
MIDDLE = 1,
RIGHT = 2
};
class InputHandler
{
InputHandler();
~InputHandler();
static InputHandler* s_pInstance;
std::vector<SDL_Joystick*> m_joysticks;
//a vector of pairs(one for each stick)
std::vector<std::pair<Vector2D*, Vector2D*>> m_joystickValues;
//a vector of vector(for each joystick and all of its buttons)
std::vector<std::vector<bool>> m_buttonStates;
//variable to account the sensitivity of the controller
const int m_joystickDeadZone = 10000;
bool m_bJoysticksInitialised;
//vector for mouse buttons(0 = left, 1 = middle, 2 = right)
std::vector<bool> m_mouseButtonStates;
//vector for mouse position
Vector2D* m_mousePosition;
//Pointer to the array returned by SDL_GetKeyboardState with "int* numkeys" arg
const Uint8* m_keystates;
//handle keyboard events
void onKeyDown();
void onKeyUp();
//handle mouse events
void onMouseMove(SDL_Event &event);
void onMouseButtonDown(SDL_Event &event);
void onMouseButtonUp(SDL_Event &event);
//handle joystick events
void onJoystickAxisMove(SDL_Event &event);
void onJoystickButtonDown(SDL_Event &event);
void onJoystickButtonUp(SDL_Event &event);
public:
static InputHandler* Instance()
{
if (s_pInstance == 0)
{
s_pInstance = new InputHandler();
}
return s_pInstance;
}
void initialiseJoysticks();
bool joysticksInitialised();
//Function to check if a specific button was pressed on a specific joystick
bool getButtonState(int joy, int buttonNumber);
//joy = Joystick identifier, stick = 1(left) and 2(right)
int xvalue(int joy, int stick);
int yvalue(int joy, int stick);
//Function to check if a specific mouse button was pressed
bool getMouseButtonState(int buttonNumber);
//Function to return mouse position
Vector2D* getMousePosition();
//Function to check if a key was pressed on the keyboard
bool isKeyDown(SDL_Scancode key);
//reset all mouse button states to false
void reset(); //required in PauseState
void update();
void clean();
};
typedef InputHandler TheInputHandler;
#endif //defined(__InputHandler__)