Added color picker for Bookmarks and highlighting in the hex view

This commit is contained in:
WerWolv
2021-01-13 14:11:23 +01:00
parent d3e47245d6
commit 4328a335ec
6 changed files with 39 additions and 11 deletions

View File

@@ -7,7 +7,7 @@
namespace hex {
ViewBookmarks::ViewBookmarks() : View("Bookmarks") {
ViewBookmarks::ViewBookmarks(std::list<Bookmark> &bookmarks) : View("Bookmarks"), m_bookmarks(bookmarks) {
View::subscribeEvent(Events::AddBookmark, [this](const void *userData) {
Bookmark bookmark = *reinterpret_cast<const Bookmark*>(userData);
bookmark.name.resize(64);
@@ -21,6 +21,8 @@ namespace hex {
if (bookmark.comment.empty())
std::memset(bookmark.comment.data(), 0x00, 0xF'FFFF);
bookmark.color = ImGui::GetColorU32(ImGuiCol_Header);
this->m_bookmarks.push_back(bookmark);
ProjectFile::markDirty();
});
@@ -52,8 +54,15 @@ namespace hex {
u32 id = 1;
std::list<Bookmark>::const_iterator bookmarkToRemove = this->m_bookmarks.end();
for (auto iter = this->m_bookmarks.begin(); iter != this->m_bookmarks.end(); iter++) {
auto &[region, name, comment] = *iter;
auto &[region, name, comment, color] = *iter;
auto headerColor = ImColor(color);
auto hoverColor = ImColor(color);
hoverColor.Value.w *= 1.3F;
ImGui::PushStyleColor(ImGuiCol_Header, color);
ImGui::PushStyleColor(ImGuiCol_HeaderActive, color);
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, u32(hoverColor));
if (ImGui::CollapsingHeader((std::string(name.data()) + "###" + std::to_string((u64)comment.data())).c_str())) {
ImGui::TextUnformatted("Information");
ImGui::Separator();
@@ -90,16 +99,22 @@ namespace hex {
ImGui::PushID(id);
ImGui::InputText("##nolabel", name.data(), 64);
ImGui::PopID();
ImGui::SameLine();
ImGui::PushID(id + 1);
ImGui::ColorEdit4("Color", (float*)&headerColor.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_NoAlpha);
color = headerColor;
ImGui::PopID();
ImGui::NewLine();
ImGui::TextUnformatted("Comment");
ImGui::Separator();
ImGui::PushID(id + 1);
ImGui::PushID(id + 2);
ImGui::InputTextMultiline("##nolabel", comment.data(), 0xF'FFFF);
ImGui::PopID();
ImGui::NewLine();
id += 2;
id += 3;
}
ImGui::PopStyleColor(3);
}
if (bookmarkToRemove != this->m_bookmarks.end()) {

View File

@@ -15,8 +15,8 @@
namespace hex {
ViewHexEditor::ViewHexEditor(std::vector<lang::PatternData*> &patternData)
: View("Hex Editor"), m_patternData(patternData) {
ViewHexEditor::ViewHexEditor(std::vector<lang::PatternData*> &patternData, const std::list<Bookmark> &bookmarks)
: View("Hex Editor"), m_patternData(patternData), m_bookmarks(bookmarks) {
this->m_memoryEditor.ReadFn = [](const ImU8 *data, size_t off) -> ImU8 {
auto provider = SharedData::currentProvider;
@@ -43,6 +43,14 @@ namespace hex {
ViewHexEditor *_this = (ViewHexEditor *) data;
std::optional<u32> currColor, prevColor;
for (const auto &[region, name, comment, color] : _this->m_bookmarks) {
if (off >= region.address && off < (region.address + region.size))
currColor = (color & 0x00FFFFFF) | 0x40000000;
if ((off - 1) >= region.address && (off - 1) < (region.address + region.size))
prevColor = (color & 0x00FFFFFF) | 0x40000000;;
}
if (_this->m_highlightedBytes.contains(off))
currColor = _this->m_highlightedBytes[off];
if (_this->m_highlightedBytes.contains(off - 1))