X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2FKeymap.hpp;fp=src%2Fui%2FKeymap.hpp;h=e96179ae9c4f8bce945251560163bb0125617fb1;hb=82ec71079e4763f2b2d66c0c210e37df40c89034;hp=0000000000000000000000000000000000000000;hpb=045a6ec084bf1fb4df3c6ade4a88932cf61bed23;p=blank.git diff --git a/src/ui/Keymap.hpp b/src/ui/Keymap.hpp new file mode 100644 index 0000000..e96179a --- /dev/null +++ b/src/ui/Keymap.hpp @@ -0,0 +1,72 @@ +#ifndef BLANK_UI_KEYMAP_HPP_ +#define BLANK_UI_KEYMAP_HPP_ + +#include +#include +#include + + +namespace blank { + +class Keymap { + +public: + enum Action { + NONE, + + MOVE_FORWARD, + MOVE_BACKWARD, + MOVE_LEFT, + MOVE_RIGHT, + MOVE_UP, + MOVE_DOWN, + + BLOCK_FACE, + BLOCK_TURN, + BLOCK_NEXT, + BLOCK_PREV, + + BLOCK_PLACE, + BLOCK_PICK, + BLOCK_REMOVE, + + TOGGLE_COLLISION, + TOGGLE_AUDIO, + TOGGLE_VISUAL, + TOGGLE_DEBUG, + + PRINT_BLOCK, + PRINT_CHUNK, + PRINT_LIGHT, + PRINT_SELECTION, + + EXIT, + }; + + static constexpr unsigned int MAX_SCANCODE = 0xFF; + static constexpr unsigned int NUM_SCANCODES = MAX_SCANCODE + 1; + +public: + Keymap(); + + void Map(SDL_Scancode scancode, Action); + Action Lookup(SDL_Scancode scancode); + Action Lookup(const SDL_Keysym &s) { return Lookup(s.scancode); } + Action Lookup(const SDL_KeyboardEvent &e) { return Lookup(e.keysym); } + + void LoadDefault(); + + void Load(std::istream &); + void Save(std::ostream &); + + static const char *ActionToString(Action); + static Action StringToAction(const std::string &); + +private: + Action codemap[NUM_SCANCODES]; + +}; + +} + +#endif