| e8555c89 Andy McCall |
1 |
#ifndef IMGUI_SHORTCUTS_HH |
| 2 |
#define IMGUI_SHORTCUTS_HH |
| 3 |
|
| 4 |
#include "ImGuiUtils.hh" |
| 5 |
|
| 6 |
#include "enumerate.hh" |
| 7 |
#include "stl.hh" |
| 8 |
#include "zstring_view.hh" |
| 9 |
|
| 10 |
#include <cstdint> |
| 11 |
#include <optional> |
| 12 |
#include <string_view> |
| 13 |
|
| 14 |
namespace openmsx { |
| 15 |
|
| 16 |
class Shortcuts |
| 17 |
{ |
| 18 |
public: |
| 19 |
enum class ID : uint8_t { |
| 20 |
HEX_GOTO_ADDR, |
| 21 |
DEBUGGER_STEP_IN, |
| 22 |
DEBUGGER_STEP_OVER, |
| 23 |
DEBUGGER_STEP_OUT, |
| 24 |
DEBUGGER_STEP_BACK, |
| 25 |
DEBUGGER_BREAK_CONTINUE, |
| 26 |
DISASM_GOTO_ADDR, |
| 27 |
DISASM_RUN_TO_ADDR, |
| 28 |
DISASM_TOGGLE_BREAKPOINT, |
| 29 |
TRACE_ZOOM_TO_FIT, |
| 30 |
TRACE_ZOOM_IN, |
| 31 |
TRACE_ZOOM_OUT, |
| 32 |
TRACE_PREV_NEG_EDGE, |
| 33 |
TRACE_PREV_POS_EDGE, |
| 34 |
TRACE_PREV_EDGE, |
| 35 |
TRACE_NEXT_EDGE, |
| 36 |
TRACE_NEXT_POS_EDGE, |
| 37 |
TRACE_NEXT_NEG_EDGE, |
| 38 |
TRACE_ALT_PREV_NEG_EDGE, |
| 39 |
TRACE_ALT_PREV_POS_EDGE, |
| 40 |
TRACE_ALT_PREV_EDGE, |
| 41 |
TRACE_ALT_NEXT_EDGE, |
| 42 |
TRACE_ALT_NEXT_POS_EDGE, |
| 43 |
TRACE_ALT_NEXT_NEG_EDGE, |
| 44 |
TRACE_SHOW_MENU_BAR, |
| 45 |
|
| 46 |
NUM, |
| 47 |
INVALID = NUM |
| 48 |
}; |
| 49 |
enum class Type : uint8_t { |
| 50 |
LOCAL, |
| 51 |
GLOBAL, |
| 52 |
ALWAYS_LOCAL, |
| 53 |
ALWAYS_GLOBAL, |
| 54 |
}; |
| 55 |
struct Shortcut { |
| 56 |
ImGuiKeyChord keyChord = ImGuiKey_None; |
| 57 |
Type type = Type::LOCAL; |
| 58 |
|
| 59 |
[[nodiscard]] bool operator==(const Shortcut& other) const = default; |
| 60 |
}; |
| 61 |
struct ShortcutWithRepeat { |
| 62 |
ImGuiKeyChord keyChord = ImGuiKey_None; |
| 63 |
Type type = Type::LOCAL; |
| 64 |
bool repeat = false; |
| 65 |
}; |
| 66 |
|
| 67 |
public: |
| 68 |
Shortcuts(); |
| 69 |
Shortcuts(const Shortcuts&) = delete; |
| 70 |
Shortcuts(Shortcuts&&) = delete; |
| 71 |
Shortcuts& operator=(const Shortcuts&) = delete; |
| 72 |
Shortcuts& operator=(Shortcuts&&) = delete; |
| 73 |
~Shortcuts() = default; |
| 74 |
|
| 75 |
[[nodiscard]] static bool getShortcutRepeat(ID id); |
| 76 |
[[nodiscard]] static zstring_view getShortcutName(ID id); |
| 77 |
[[nodiscard]] static zstring_view getShortcutDescription(ID id); |
| 78 |
[[nodiscard]] static std::optional<ID> parseShortcutName(std::string_view name); |
| 79 |
[[nodiscard]] static std::optional<Type> parseType(std::string_view name); |
| 80 |
[[nodiscard]] static const Shortcut& getDefaultShortcut(ID id); |
| 81 |
|
| 82 |
[[nodiscard]] const Shortcut& getShortcut(ID id) const; |
| 83 |
void setShortcut(ID id, const Shortcut& shortcut); |
| 84 |
|
| 85 |
void setDefaultShortcuts(); |
| 86 |
|
| 87 |
[[nodiscard]] bool checkShortcut(const ShortcutWithRepeat& shortcut) const; |
| 88 |
[[nodiscard]] bool checkShortcut(ID id) const; |
| 89 |
|
| 90 |
template<typename XmlStream> |
| 91 |
void saveShortcuts(XmlStream& xml) const |
| 92 |
{ |
| 93 |
xml.with_tag("shortcuts", [&]{ |
| 94 |
for (auto [id_, shortcut] : enumerate(shortcuts)) { |
| 95 |
auto id = static_cast<ID>(id_); |
| 96 |
if (shortcut == getDefaultShortcut(id)) continue; |
| 97 |
xml.with_tag("shortcut", [&]{ |
| 98 |
xml.attribute("key", getKeyChordName(shortcut.keyChord)); |
| 99 |
|
| 100 |
if (shortcut.type == Type::GLOBAL) xml.attribute("type", "global"); |
| 101 |
xml.data(getShortcutName(id)); |
| 102 |
}); |
| 103 |
} |
| 104 |
}); |
| 105 |
} |
| 106 |
|
| 107 |
private: |
| 108 |
array_with_enum_index<ID, Shortcut> shortcuts; |
| 109 |
}; |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
#endif |