]> git.localhorst.tv Git - blank.git/blob - src/ui/Keymap.hpp
split composite model in template and instance
[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                 BLOCK_FACE,
25                 BLOCK_TURN,
26                 BLOCK_NEXT,
27                 BLOCK_PREV,
28
29                 BLOCK_PLACE,
30                 BLOCK_PICK,
31                 BLOCK_REMOVE,
32
33                 TOGGLE_COLLISION,
34                 TOGGLE_AUDIO,
35                 TOGGLE_VISUAL,
36                 TOGGLE_DEBUG,
37
38                 PRINT_BLOCK,
39                 PRINT_CHUNK,
40                 PRINT_LIGHT,
41                 PRINT_SELECTION,
42
43                 EXIT,
44         };
45
46         static constexpr unsigned int MAX_SCANCODE = 0xFF;
47         static constexpr unsigned int NUM_SCANCODES = MAX_SCANCODE + 1;
48
49 public:
50         Keymap();
51
52         void Map(SDL_Scancode scancode, Action);
53         Action Lookup(SDL_Scancode scancode);
54         Action Lookup(const SDL_Keysym &s) { return Lookup(s.scancode); }
55         Action Lookup(const SDL_KeyboardEvent &e) { return Lookup(e.keysym); }
56
57         void LoadDefault();
58
59         void Load(std::istream &);
60         void Save(std::ostream &);
61
62         static const char *ActionToString(Action);
63         static Action StringToAction(const std::string &);
64
65 private:
66         Action codemap[NUM_SCANCODES];
67
68 };
69
70 }
71
72 #endif