diff options
author | Jon Santmyer <jon@jonsantmyer.com> | 2022-06-22 17:41:59 -0400 |
---|---|---|
committer | Jon Santmyer <jon@jonsantmyer.com> | 2022-06-22 17:41:59 -0400 |
commit | 5e3a2492c7bb73daa4e27398daaf490d09980ff3 (patch) | |
tree | 75178d823d596b6a898002c3f1d45b9ceede0e1e /include/keybind.hpp | |
download | systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.tar.gz systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.tar.bz2 systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.zip |
Base system viewer with data loaded from csv files
Diffstat (limited to 'include/keybind.hpp')
-rw-r--r-- | include/keybind.hpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/include/keybind.hpp b/include/keybind.hpp new file mode 100644 index 0000000..6541a21 --- /dev/null +++ b/include/keybind.hpp @@ -0,0 +1,71 @@ +#ifndef KEYBIND_HPP +#define KEYBIND_HPP 1 + +#include <string> +#include <vector> +#include <algorithm> +#include <unordered_map> + +#define CTX_GLOBAL "Global" +#define CTX_SYSTEMVIEW "System View" +#define CTX_TIMEMAN "Time Manager" + +#define BIND_G_QUIT "G_Quit" +#define BIND_G_NEXTWIN "G_NextWindow" +#define BIND_G_PREVWIN "G_PrevWindow" +#define BIND_G_EDITBINDS "G_EditBinds" +#define BIND_G_ESCAPE "G_Escape" +#define BIND_G_SELECT "G_Select" + +#define BIND_SYSTEMVIEW_PANUP "Systemview_PanUp" +#define BIND_SYSTEMVIEW_PANDOWN "Systemview_PanDown" +#define BIND_SYSTEMVIEW_PANLEFT "Systemview_PanLeft" +#define BIND_SYSTEMVIEW_PANRIGHT "Systemview_PanRight" +#define BIND_SYSTEMVIEW_DECSCALE "Systemview_DecScale" +#define BIND_SYSTEMVIEW_INCSCALE "Systemview_IncScale" +#define BIND_SYSTEMVIEW_SEARCH "Systemview_Search" + +#define BIND_SYSTEMVIEW_SEARCH_PREV "Systemview_Search_Prev" +#define BIND_SYSTEMVIEW_SEARCH_NEXT "Systemview_Search_Next" +#define BIND_SYSTEMVIEW_SEARCH_TOP "Systemview_Search_Top" +#define BIND_SYSTEMVIEW_SEARCH_BOTTOM "Systemview_Search_Bottom" +#define BIND_SYSTEMVIEW_SEARCH_COLLAPSE "Systemview_Search_Collapse" + +#define BIND_TIMEMAN_STEP "Timeman_Step" +#define BIND_TIMEMAN_INCSTEP "Timeman_IncStep" +#define BIND_TIMEMAN_DECSTEP "Timeman_DecStep" +#define BIND_TIMEMAN_TOGGLEAUTO "Timeman_ToggleAuto" + +class KeyMan { +public: + struct Bind { + int code; + std::string name; + std::string ctx; + std::string desc; + }; + + struct Binds { + std::vector<Bind> operator()() { + std::vector<Bind> bindList; + std::transform( + KeyMan::m_keybinds.begin(), + KeyMan::m_keybinds.end(), + std::back_inserter(bindList), [](auto &pair){return pair.second;}); + return bindList; + } + Bind &operator[](const std::string &name) { return KeyMan::m_keybinds[name]; } + }; + static Binds binds; + + static void registerBind(int def, const std::string &name, const std::string &context, const std::string &desc); + static void loadKeybindsFrom(const std::string &csvPath); + static void writeKeybindsTo(const std::string &csvPath); + static std::string translateCode(int code); + +private: + static std::unordered_map<std::string, Bind> m_keybinds; + static std::unordered_map<std::string, std::string> m_keybindContexts; +}; + +#endif |