yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
shortcut_manager.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SYSTEM_SHORTCUT_MANAGER_H
2#define YAZE_APP_EDITOR_SYSTEM_SHORTCUT_MANAGER_H
3
4#include <functional>
5#include <string>
6#include <unordered_map>
7
8// Must define before including imgui.h
9#ifndef IMGUI_DEFINE_MATH_OPERATORS
10#define IMGUI_DEFINE_MATH_OPERATORS
11#endif
12
13#include "imgui/imgui.h"
14
15namespace yaze {
16namespace editor {
17
18struct Shortcut {
19 std::string name;
20 std::vector<ImGuiKey> keys;
21 std::function<void()> callback;
22};
23
24std::vector<ImGuiKey> ParseShortcut(const std::string &shortcut);
25
26std::string PrintShortcut(const std::vector<ImGuiKey> &keys);
27
29 public:
30 void RegisterShortcut(const std::string &name,
31 const std::vector<ImGuiKey> &keys) {
32 shortcuts_[name] = {name, keys};
33 }
34 void RegisterShortcut(const std::string &name,
35 const std::vector<ImGuiKey> &keys,
36 std::function<void()> callback) {
37 shortcuts_[name] = {name, keys, callback};
38 }
39
40 void RegisterShortcut(const std::string &name, ImGuiKey key,
41 std::function<void()> callback) {
42 shortcuts_[name] = {name, {key}, callback};
43 }
44
45 void ExecuteShortcut(const std::string &name) const {
46 shortcuts_.at(name).callback();
47 }
48
49 // Access the shortcut and print the readable name of the shortcut for menus
50 const Shortcut &GetShortcut(const std::string &name) const {
51 return shortcuts_.at(name);
52 }
53
54 // Get shortcut callback function
55 std::function<void()> GetCallback(const std::string &name) const {
56 return shortcuts_.at(name).callback;
57 }
58
59 const std::string GetKeys(const std::string &name) const {
60 return PrintShortcut(shortcuts_.at(name).keys);
61 }
62
63 auto GetShortcuts() const { return shortcuts_; }
64
65 private:
66 std::unordered_map<std::string, Shortcut> shortcuts_;
67};
68
69void ExecuteShortcuts(const ShortcutManager &shortcut_manager);
70
71} // namespace editor
72} // namespace yaze
73
74#endif // YAZE_APP_EDITOR_SYSTEM_SHORTCUT_MANAGER_H
const Shortcut & GetShortcut(const std::string &name) const
const std::string GetKeys(const std::string &name) const
void RegisterShortcut(const std::string &name, ImGuiKey key, std::function< void()> callback)
std::function< void()> GetCallback(const std::string &name) const
void RegisterShortcut(const std::string &name, const std::vector< ImGuiKey > &keys, std::function< void()> callback)
void ExecuteShortcut(const std::string &name) const
std::unordered_map< std::string, Shortcut > shortcuts_
void RegisterShortcut(const std::string &name, const std::vector< ImGuiKey > &keys)
std::vector< ImGuiKey > ParseShortcut(const std::string &shortcut)
std::string PrintShortcut(const std::vector< ImGuiKey > &keys)
void ExecuteShortcuts(const ShortcutManager &shortcut_manager)
Main namespace for the application.
std::function< void()> callback
std::vector< ImGuiKey > keys