]> git.localhorst.tv Git - blank.git/blob - src/ui/Keymap.hpp
runtime-selectable camera mode
[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                 CAMERA_NEXT,
46
47                 EXIT,
48         };
49
50         static constexpr unsigned int MAX_SCANCODE = 0xFF;
51         static constexpr unsigned int NUM_SCANCODES = MAX_SCANCODE + 1;
52
53 public:
54         Keymap();
55
56         void Map(SDL_Scancode scancode, Action);
57         Action Lookup(SDL_Scancode scancode) const;
58         Action Lookup(const SDL_Keysym &s) const { return Lookup(s.scancode); }
59         Action Lookup(const SDL_KeyboardEvent &e) const { return Lookup(e.keysym); }
60
61         void LoadDefault();
62
63         void Load(std::istream &);
64         void Save(std::ostream &);
65
66         static const char *ActionToString(Action);
67         static Action StringToAction(const std::string &);
68
69 private:
70         Action codemap[NUM_SCANCODES];
71
72 };
73
74 }
75
76 #endif