]> git.localhorst.tv Git - l2e.git/blob - src/app/Input.h
allow checking of multiple keys at once
[l2e.git] / src / app / Input.h
1 /*
2  * Input.h
3  *
4  *  Created on: Aug 6, 2012
5  *      Author: holy
6  */
7
8 #ifndef APP_INPUT_H_
9 #define APP_INPUT_H_
10
11 #include <SDL.h>
12 #include <map>
13
14 namespace app {
15
16 class Input {
17
18 public:
19         enum Button {
20                 PAD_UP = 1,
21                 PAD_RIGHT = 2,
22                 PAD_DOWN = 4,
23                 PAD_LEFT = 8,
24                 ACTION_A = 16,
25                 ACTION_B = 32,
26                 ACTION_X = 64,
27                 ACTION_Y = 128,
28                 START = 256,
29                 SELECT = 512,
30                 SHOULDER_RIGHT = 1024,
31                 SHOULDER_LEFT = 2048
32         };
33
34 public:
35         Input();
36
37 public:
38         bool IsDown(int b) const {
39                 return down & b;
40         }
41         bool JustPressed(int b) const {
42                 return pressed & b;
43         }
44         bool JustReleased(int b) const {
45                 return released & b;
46         }
47
48 public:
49         void ResetInteractiveState() {
50                 pressed = 0;
51                 released = 0;
52         }
53         void HandleKeyboardEvent(const SDL_KeyboardEvent &);
54
55 public:
56         void MapKey(SDLKey k, Button b) {
57                 mapping[k] = b;
58         }
59
60 private:
61         std::map<SDLKey, Button> mapping;
62         Uint16 down;
63         Uint16 pressed;
64         Uint16 released;
65
66 };
67
68 }
69
70 #endif /* APP_INPUT_H_ */