openMSX
DebuggableEditor.hh
Go to the documentation of this file.
1#ifndef DEBUGGABLE_EDITOR_HH
2#define DEBUGGABLE_EDITOR_HH
3
4// Based on:
5// Mini memory editor for Dear ImGui (to embed in your game/tools)
6//
7// Get latest version at http://www.github.com/ocornut/imgui_club
8// (See there for documentation and the (old) Changelog).
9//
10// Licence: MIT
11
12#include "ImGuiPart.hh"
13
14#include <imgui.h>
15
16#include <optional>
17#include <string>
18#include <vector>
19
20namespace openmsx {
21
22class Debuggable;
23class ImGuiManager;
24class SymbolManager;
25
26class DebuggableEditor final : public ImGuiPart
27{
28 struct Sizes {
29 int addrDigitsCount = 0;
30 float lineHeight = 0.0f;
31 float glyphWidth = 0.0f;
32 float hexCellWidth = 0.0f;
33 float spacingBetweenMidCols = 0.0f;
34 float posHexStart = 0.0f;
35 float posAsciiStart = 0.0f;
36 float posAsciiEnd = 0.0f;
37 float windowWidth = 0.0f;
38 };
39
40public:
41 explicit DebuggableEditor(ImGuiManager& manager_, std::string debuggableName, size_t index);
42 [[nodiscard]] std::string_view getDebuggableName() const { return {title.data(), debuggableNameSize}; }
43
44 // ImGuiPart
45 [[nodiscard]] zstring_view iniName() const override { return title; }
46 void save(ImGuiTextBuffer& buf) override;
47 void loadLine(std::string_view name, zstring_view value) override;
48 void loadEnd() override;
49 void paint(MSXMotherBoard* motherBoard) override;
50
51public:
52 bool open = true;
53
54private:
55 [[nodiscard]] Sizes calcSizes(unsigned memSize) const;
56 [[nodiscard]] std::string formatAddr(const Sizes& s, unsigned addr) const;
57 void setStrings(const Sizes& s, Debuggable& debuggable);
58 bool setAddr(const Sizes& s, Debuggable& debuggable, unsigned memSize, unsigned addr);
59 void scrollAddr(const Sizes& s, Debuggable& debuggable, unsigned memSize, unsigned addr, bool forceScroll);
60
61 void drawContents(const Sizes& s, Debuggable& debuggable, unsigned memSize);
62 void drawSearch(const Sizes& s, Debuggable& debuggable, unsigned memSize);
63 void parseSearchString(std::string_view str);
64 void search(const Sizes& s, Debuggable& debuggable, unsigned memSize);
65 [[nodiscard]] bool match(Debuggable& debuggable, unsigned memSize, unsigned addr);
66 void drawPreviewLine(const Sizes& s, Debuggable& debuggable, unsigned memSize);
67
68private:
69 enum AddressMode : int {CURSOR, EXPRESSION};
70 enum class SearchType : int {HEX, ASCII};
71 enum class SearchHighlight : int {NONE, SINGLE, ALL};
72 enum class SearchDirection : int {FWD, BWD};
73 enum PreviewEndianess : int {LE, BE};
74
75 SymbolManager& symbolManager;
76 std::string title; // debuggableName + suffix
77 size_t debuggableNameSize;
78
79 // Settings
80 static constexpr int MAX_COLUMNS = 64;
81 int columns = 16; // number of columns to display.
82 bool showAscii = true; // display ASCII representation on the right side.
83 bool showAddress = true; // display the address bar (e.g. on small views it can make sense to hide this)
84 bool showSearch = false; // display search functionality
85 bool showDataPreview = false; // display a footer previewing the decimal/binary/hex/float representation of the currently selected bytes.
86 bool showSymbolInfo = false; // display symbol information and highlight known symbols in hex view
87 bool greyOutZeroes = true; // display null/zero bytes using the TextDisabled color.
88 std::string addrExpr;
89 std::string searchString;
90 unsigned currentAddr = 0;
91 int addrMode = CURSOR;
92 int searchType = static_cast<int>(SearchType::HEX);
93 int searchHighlight = static_cast<int>(SearchHighlight::SINGLE);
94 int searchDirection = static_cast<int>(SearchDirection::FWD);
95 int previewEndianess = LE;
96 ImGuiDataType previewDataType = ImGuiDataType_U8;
97
98 static constexpr auto persistentElements = std::tuple{
100 PersistentElementMax{"columns", &DebuggableEditor::columns, MAX_COLUMNS + 1},
101 PersistentElement {"showAscii", &DebuggableEditor::showAscii},
102 PersistentElement {"showAddress", &DebuggableEditor::showAddress},
103 PersistentElement {"showSearch", &DebuggableEditor::showSearch},
104 PersistentElement {"showDataPreview", &DebuggableEditor::showDataPreview},
105 PersistentElement {"showSymbolInfo", &DebuggableEditor::showSymbolInfo},
106 PersistentElement {"greyOutZeroes", &DebuggableEditor::greyOutZeroes},
107 PersistentElement {"addrExpr", &DebuggableEditor::addrExpr},
108 PersistentElement {"searchString", &DebuggableEditor::searchString},
109 PersistentElement {"currentAddr", &DebuggableEditor::currentAddr},
110 PersistentElementMax{"addrMode", &DebuggableEditor::addrMode, 2},
111 PersistentElementMax{"searchType", &DebuggableEditor::searchType, 2},
112 PersistentElementMax{"searchHighlight", &DebuggableEditor::searchHighlight, 2},
113 PersistentElementMax{"searchDirection", &DebuggableEditor::searchDirection, 2},
114 PersistentElementMax{"previewEndianess", &DebuggableEditor::previewEndianess, 2},
115 PersistentElementMax{"previewDataType", &DebuggableEditor::previewDataType, 8}
116 };
117
118 // [Internal State]
119 std::string dataInput;
120 std::string addrStr;
121 std::optional<std::vector<uint8_t>> searchPattern;
122 std::optional<unsigned> searchResult;
123 enum EditType { HEX, ASCII };
124 EditType dataEditingActive = HEX;
125 bool dataEditingTakeFocus = true;
126 bool updateAddr = false;
127};
128
129} // namespace openmsx
130
131#endif
void paint(MSXMotherBoard *motherBoard) override
zstring_view iniName() const override
std::string_view getDebuggableName() const
void loadLine(std::string_view name, zstring_view value) override
void save(ImGuiTextBuffer &buf) override
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
This file implemented 3 utility functions:
Definition Autofire.cc:11
PersistentElement(zstring_view, T C::*) -> PersistentElement< C, T >