-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputHandler.h
More file actions
68 lines (50 loc) · 1.2 KB
/
InputHandler.h
File metadata and controls
68 lines (50 loc) · 1.2 KB
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
#pragma once
#include <array>
#include "sdl_includes.h"
#include "Vector2D.h"
/*
*
*/
class InputHandler {
public:
enum MOUSE_BUTTONS { LEFT, MIDDLE, RIGHT };
virtual ~InputHandler();
void update();
// keyboard
bool isAnyKeyDown(); // if a key change state to down in the last update
bool isAnyKeyUp(); // if a key change state to down in the last update
bool isKeyDown(SDL_Scancode key);
bool isKeyDown(SDL_Keycode key);
// mouse
const Vector2D& getMousePos();
int getMouseButtonState(int b);
// Joystick
// see:
// Chapter 4 of 'SDL Game Development' book
// Available online via https://biblioteca.ucm.es/
//
static InputHandler* getInstance() {
if ( instance_ == nullptr ) {
instance_ = new InputHandler();
}
return instance_;
}
private:
InputHandler();
// handle the events
void onKeyDown(SDL_Event &event);
void onKeyUp(SDL_Event &event);
void onMouseMotion(SDL_Event &event);
void onMouseButtonUp(SDL_Event &event);
void onMouseButtonDown(SDL_Event &event);
// reset the state
void clearState();
static InputHandler* instance_;
// keyboard
const Uint8 *kbState_;
bool keyDown_;
bool keyUp_;
// mouse
Vector2D mousePos_;
std::array<bool,3> mbState_;
};