yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
memory_editor.cc
Go to the documentation of this file.
2
3#include "absl/strings/str_format.h"
4#include "app/gui/icons.h"
5#include "app/gui/style.h"
6#include "imgui/imgui.h"
7
8namespace yaze {
9namespace editor {
10
12 // Modern compact toolbar with icon-only buttons
13 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6, 4));
14 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 4));
15
16 if (ImGui::Button(ICON_MD_LOCATION_SEARCHING " Jump")) {
17 ImGui::OpenPopup("JumpToAddress");
18 }
19 if (ImGui::IsItemHovered()) {
20 ImGui::SetTooltip("Jump to specific address");
21 }
22
23 ImGui::SameLine();
24 if (ImGui::Button(ICON_MD_SEARCH " Search")) {
25 ImGui::OpenPopup("SearchPattern");
26 }
27 if (ImGui::IsItemHovered()) {
28 ImGui::SetTooltip("Search for hex pattern");
29 }
30
31 ImGui::SameLine();
32 if (ImGui::Button(ICON_MD_BOOKMARK " Bookmarks")) {
33 ImGui::OpenPopup("Bookmarks");
34 }
35 if (ImGui::IsItemHovered()) {
36 ImGui::SetTooltip("Manage address bookmarks");
37 }
38
39 ImGui::SameLine();
40 ImGui::Text(ICON_MD_MORE_VERT);
41 ImGui::SameLine();
42
43 // Show current address
44 if (current_address_ != 0) {
45 ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f),
47 }
48
49 ImGui::PopStyleVar(2);
50 ImGui::Separator();
51
55}
56
58 if (ImGui::BeginPopupModal("JumpToAddress", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
59 ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f),
60 ICON_MD_LOCATION_SEARCHING " Jump to Address");
61 ImGui::Separator();
62 ImGui::Spacing();
63
64 ImGui::SetNextItemWidth(200);
65 if (ImGui::InputText("##jump_addr", jump_address_, IM_ARRAYSIZE(jump_address_),
66 ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_EnterReturnsTrue)) {
67 // Parse and jump on Enter key
68 unsigned int addr;
69 if (sscanf(jump_address_, "%X", &addr) == 1) {
70 current_address_ = addr;
71 ImGui::CloseCurrentPopup();
72 }
73 }
74 ImGui::TextDisabled("Format: 0x1C800 or 1C800");
75
76 ImGui::Spacing();
77 ImGui::Separator();
78 ImGui::Spacing();
79
80 if (ImGui::Button(ICON_MD_CHECK " Go", ImVec2(120, 0))) {
81 unsigned int addr;
82 if (sscanf(jump_address_, "%X", &addr) == 1) {
83 current_address_ = addr;
84 }
85 ImGui::CloseCurrentPopup();
86 }
87 ImGui::SameLine();
88 if (ImGui::Button(ICON_MD_CANCEL " Cancel", ImVec2(120, 0))) {
89 ImGui::CloseCurrentPopup();
90 }
91 ImGui::EndPopup();
92 }
93}
94
96 if (ImGui::BeginPopupModal("SearchPattern", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
97 ImGui::TextColored(ImVec4(0.4f, 0.8f, 0.4f, 1.0f),
98 ICON_MD_SEARCH " Search Hex Pattern");
99 ImGui::Separator();
100 ImGui::Spacing();
101
102 ImGui::SetNextItemWidth(300);
103 if (ImGui::InputText("##search_pattern", search_pattern_, IM_ARRAYSIZE(search_pattern_),
104 ImGuiInputTextFlags_EnterReturnsTrue)) {
105 // TODO: Implement search
106 ImGui::CloseCurrentPopup();
107 }
108 ImGui::TextDisabled("Use ?? for wildcard (e.g. FF 00 ?? 12)");
109 ImGui::Spacing();
110
111 // Quick preset patterns
112 ImGui::Text(ICON_MD_LIST " Quick Patterns:");
113 if (ImGui::SmallButton("LDA")) {
114 snprintf(search_pattern_, sizeof(search_pattern_), "A9 ??");
115 }
116 ImGui::SameLine();
117 if (ImGui::SmallButton("STA")) {
118 snprintf(search_pattern_, sizeof(search_pattern_), "8D ?? ??");
119 }
120 ImGui::SameLine();
121 if (ImGui::SmallButton("JSR")) {
122 snprintf(search_pattern_, sizeof(search_pattern_), "20 ?? ??");
123 }
124
125 ImGui::Spacing();
126 ImGui::Separator();
127 ImGui::Spacing();
128
129 if (ImGui::Button(ICON_MD_SEARCH " Search", ImVec2(120, 0))) {
130 // TODO: Implement search using hex-search handler
131 ImGui::CloseCurrentPopup();
132 }
133 ImGui::SameLine();
134 if (ImGui::Button(ICON_MD_CANCEL " Cancel", ImVec2(120, 0))) {
135 ImGui::CloseCurrentPopup();
136 }
137 ImGui::EndPopup();
138 }
139}
140
142 if (ImGui::BeginPopupModal("Bookmarks", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
143 ImGui::TextColored(ImVec4(1.0f, 0.843f, 0.0f, 1.0f),
144 ICON_MD_BOOKMARK " Memory Bookmarks");
145 ImGui::Separator();
146 ImGui::Spacing();
147
148 if (bookmarks_.empty()) {
149 ImGui::TextDisabled(ICON_MD_INFO " No bookmarks yet");
150 ImGui::Spacing();
151 ImGui::Separator();
152 ImGui::Spacing();
153
154 if (ImGui::Button(ICON_MD_ADD " Add Current Address", ImVec2(250, 0))) {
155 Bookmark new_bookmark;
156 new_bookmark.address = current_address_;
157 new_bookmark.name = absl::StrFormat("Bookmark %zu", bookmarks_.size() + 1);
158 new_bookmark.description = "User-defined bookmark";
159 bookmarks_.push_back(new_bookmark);
160 }
161 } else {
162 // Bookmarks table
163 ImGui::BeginChild("##bookmarks_list", ImVec2(500, 300), true);
164 if (ImGui::BeginTable("##bookmarks_table", 3,
165 ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg |
166 ImGuiTableFlags_Resizable)) {
167 ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 150);
168 ImGui::TableSetupColumn("Address", ImGuiTableColumnFlags_WidthFixed, 100);
169 ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthStretch);
170 ImGui::TableHeadersRow();
171
172 for (size_t i = 0; i < bookmarks_.size(); ++i) {
173 const auto& bm = bookmarks_[i];
174 ImGui::PushID(static_cast<int>(i));
175
176 ImGui::TableNextRow();
177 ImGui::TableNextColumn();
178 if (ImGui::Selectable(bm.name.c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) {
179 current_address_ = bm.address;
180 ImGui::CloseCurrentPopup();
181 }
182
183 ImGui::TableNextColumn();
184 ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f), "0x%06X", bm.address);
185
186 ImGui::TableNextColumn();
187 ImGui::TextDisabled("%s", bm.description.c_str());
188
189 ImGui::PopID();
190 }
191 ImGui::EndTable();
192 }
193 ImGui::EndChild();
194
195 ImGui::Spacing();
196 if (ImGui::Button(ICON_MD_ADD " Add Bookmark", ImVec2(150, 0))) {
197 Bookmark new_bookmark;
198 new_bookmark.address = current_address_;
199 new_bookmark.name = absl::StrFormat("Bookmark %zu", bookmarks_.size() + 1);
200 new_bookmark.description = "User-defined bookmark";
201 bookmarks_.push_back(new_bookmark);
202 }
203 ImGui::SameLine();
204 if (ImGui::Button(ICON_MD_CLEAR_ALL " Clear All", ImVec2(150, 0))) {
205 bookmarks_.clear();
206 }
207 }
208
209 ImGui::Spacing();
210 ImGui::Separator();
211 ImGui::Spacing();
212
213 if (ImGui::Button(ICON_MD_CLOSE " Close", ImVec2(250, 0))) {
214 ImGui::CloseCurrentPopup();
215 }
216
217 ImGui::EndPopup();
218 }
219}
220
221} // namespace editor
222} // namespace yaze
#define ICON_MD_LOCATION_ON
Definition icons.h:1135
#define ICON_MD_LOCATION_SEARCHING
Definition icons.h:1137
#define ICON_MD_INFO
Definition icons.h:991
#define ICON_MD_CANCEL
Definition icons.h:362
#define ICON_MD_MORE_VERT
Definition icons.h:1241
#define ICON_MD_SEARCH
Definition icons.h:1671
#define ICON_MD_CHECK
Definition icons.h:395
#define ICON_MD_LIST
Definition icons.h:1092
#define ICON_MD_CLEAR_ALL
Definition icons.h:415
#define ICON_MD_ADD
Definition icons.h:84
#define ICON_MD_BOOKMARK
Definition icons.h:283
#define ICON_MD_CLOSE
Definition icons.h:416
Main namespace for the application.