-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputHandler.h
89 lines (65 loc) · 1.72 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
#ifndef INPUT_HANDLER_H
#define INPUT_HANDLER_H
#include <SDL2/SDL.h>
#include <vector>
#include <utility>
#include <iostream>
#include "Game.h"
enum mouse_buttons
{
LEFT = 0,
MIDDLE = 1,
RIGHT = 2,
};
class InputHandler
{
public:
static InputHandler* instance();
void update();
void clean();
int xvalue(int joy, int stick);
int yvalue(int joy, int stick);
//Joystick Functions
void initialiseJoysticks();
bool joysticksInitialised(){ return m_bJoysticksInitialised;}
// JoyStick Button functions
bool getButtonState(int joy, int buttonNumber);
// Mouse Button functions
bool getMouseButtonState(int buttonNumber);
void reset();
// Mouse Motion functions
Vector2D* getMousePosition();
// Keyboard Button functions
bool isKeyDown(SDL_Scancode key);
private:
InputHandler();
~InputHandler() {}
static InputHandler* s_pInstance;
//Mouse Button Vars
std::vector<bool> m_mouseButtonStates;
//Mouse Motion vars
Vector2D* m_mousePosition;
//Keyboard Button Vars
const Uint8* m_keyStates;
//Joystick Vars
std::vector<SDL_Joystick*> m_joysticks;
std::vector<std::pair<Vector2D*, Vector2D*>> m_joystickValues;
bool m_bJoysticksInitialised;
const int m_joystickDeadZone = 10000;
//JoyStick button Vars
std::vector<std::vector<bool>> m_buttonStates;
// 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);
};
//defining singleton
typedef InputHandler TheInputHandler;
#endif //INPUT_HANDLER_H