]> git.localhorst.tv Git - blank.git/blob - src/ui/Keymap.hpp
basic message state
[blank.git] / src / ui / Keymap.hpp
1 #ifndef BLANK_UI_KEYMAP_HPP_
2 #define BLANK_UI_KEYMAP_HPP_
3
4 #include <iosfwd>
5 #include <string>
6 #include <SDL.h>
7
8
9 namespace blank {
10
11 class Keymap {
12
13 public:
14         enum Action {
15                 NONE,
16
17                 MOVE_FORWARD,
18                 MOVE_BACKWARD,
19                 MOVE_LEFT,
20                 MOVE_RIGHT,
21                 MOVE_UP,
22                 MOVE_DOWN,
23
24                 PRIMARY,
25                 SECONDARY,
26                 TERTIARY,
27
28                 INV_NEXT,
29                 INV_PREVIOUS,
30                 INV_1,
31                 INV_2,
32                 INV_3,
33                 INV_4,
34                 INV_5,
35                 INV_6,
36                 INV_7,
37                 INV_8,
38                 INV_9,
39                 INV_10,
40
41                 TOGGLE_AUDIO,
42                 TOGGLE_VIDEO,
43                 TOGGLE_HUD,
44                 TOGGLE_DEBUG,
45
46                 EXIT,
47         };
48
49         static constexpr unsigned int MAX_SCANCODE = 0xFF;
50         static constexpr unsigned int NUM_SCANCODES = MAX_SCANCODE + 1;
51
52 public:
53         Keymap();
54
55         void Map(SDL_Scancode scancode, Action);
56         Action Lookup(SDL_Scancode scancode) const;
57         Action Lookup(const SDL_Keysym &s) const { return Lookup(s.scancode); }
58         Action Lookup(const SDL_KeyboardEvent &e) const { return Lookup(e.keysym); }
59
60         void LoadDefault();
61
62         void Load(std::istream &);
63         void Save(std::ostream &);
64
65         static const char *ActionToString(Action);
66         static Action StringToAction(const std::string &);
67
68 private:
69         Action codemap[NUM_SCANCODES];
70
71 };
72
73 }
74
75 #endif