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);
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 greyOutZeroes = true; // display null/zero bytes using the TextDisabled color.
87 std::string addrExpr;
88 std::string searchString;
89 unsigned currentAddr = 0;
90 int addrMode = CURSOR;
91 int searchType = static_cast<int>(SearchType::HEX);
92 int searchHighlight = static_cast<int>(SearchHighlight::SINGLE);
93 int searchDirection = static_cast<int>(SearchDirection::FWD);
94 int previewEndianess = LE;
95 ImGuiDataType previewDataType = ImGuiDataType_U8;
96
97 static constexpr auto persistentElements = std::tuple{
99 PersistentElementMax{"columns", &DebuggableEditor::columns, MAX_COLUMNS + 1},
100 PersistentElement {"showAscii", &DebuggableEditor::showAscii},
101 PersistentElement {"showAddress", &DebuggableEditor::showAddress},
102 PersistentElement {"showSearch", &DebuggableEditor::showSearch},
103 PersistentElement {"showDataPreview", &DebuggableEditor::showDataPreview},
104 PersistentElement {"greyOutZeroes", &DebuggableEditor::greyOutZeroes},
105 PersistentElement {"addrExpr", &DebuggableEditor::addrExpr},
106 PersistentElement {"searchString", &DebuggableEditor::searchString},
107 PersistentElement {"currentAddr", &DebuggableEditor::currentAddr},
108 PersistentElementMax{"addrMode", &DebuggableEditor::addrMode, 2},
109 PersistentElementMax{"searchType", &DebuggableEditor::searchType, 2},
110 PersistentElementMax{"searchHighlight", &DebuggableEditor::searchHighlight, 2},
111 PersistentElementMax{"searchDirection", &DebuggableEditor::searchDirection, 2},
112 PersistentElementMax{"previewEndianess", &DebuggableEditor::previewEndianess, 2},
113 PersistentElementMax{"previewDataType", &DebuggableEditor::previewDataType, 8}
114 };
115
116 // [Internal State]
117 std::string dataInput;
118 std::string addrStr;
119 std::optional<std::vector<uint8_t>> searchPattern;
120 std::optional<unsigned> searchResult;
121 enum EditType { HEX, ASCII };
122 EditType dataEditingActive = HEX;
123 bool dataEditingTakeFocus = true;
124 bool updateAddr = false;
125};
126
127} // namespace openmsx
128
129#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 >