Added color picker for Bookmarks and highlighting in the hex view
This commit is contained in:
parent
d3e47245d6
commit
4328a335ec
@ -13,14 +13,14 @@ namespace hex {
|
||||
|
||||
class ViewBookmarks : public View {
|
||||
public:
|
||||
explicit ViewBookmarks();
|
||||
explicit ViewBookmarks(std::list<Bookmark> &bookmarks);
|
||||
~ViewBookmarks() override;
|
||||
|
||||
void drawContent() override;
|
||||
void drawMenu() override;
|
||||
|
||||
private:
|
||||
std::list<Bookmark> m_bookmarks;
|
||||
std::list<Bookmark> &m_bookmarks;
|
||||
};
|
||||
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
#include "imgui_memory_editor.h"
|
||||
#include "ImGuiFileBrowser.h"
|
||||
|
||||
#include <list>
|
||||
#include <tuple>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
@ -20,7 +21,7 @@ namespace hex {
|
||||
|
||||
class ViewHexEditor : public View {
|
||||
public:
|
||||
ViewHexEditor(std::vector<lang::PatternData*> &patternData);
|
||||
ViewHexEditor(std::vector<lang::PatternData*> &patternData, const std::list<Bookmark> &bookmarks);
|
||||
~ViewHexEditor() override;
|
||||
|
||||
void drawContent() override;
|
||||
@ -32,6 +33,8 @@ namespace hex {
|
||||
imgui_addons::ImGuiFileBrowser m_fileBrowser;
|
||||
|
||||
std::vector<lang::PatternData*> &m_patternData;
|
||||
const std::list<Bookmark> &m_bookmarks;
|
||||
|
||||
std::map<u64, u32> m_highlightedBytes;
|
||||
|
||||
char m_searchStringBuffer[0xFFFF] = { 0 };
|
||||
|
@ -202,5 +202,6 @@ namespace hex {
|
||||
|
||||
std::vector<char> name;
|
||||
std::vector<char> comment;
|
||||
u32 color;
|
||||
};
|
||||
}
|
@ -28,9 +28,10 @@ int main(int argc, char **argv) {
|
||||
|
||||
// Shared Data
|
||||
std::vector<hex::lang::PatternData*> patternData;
|
||||
std::list<hex::Bookmark> bookmarks;
|
||||
|
||||
// Create views
|
||||
hex::ContentRegistry::Views::add<hex::ViewHexEditor>(patternData);
|
||||
hex::ContentRegistry::Views::add<hex::ViewHexEditor>(patternData, bookmarks);
|
||||
hex::ContentRegistry::Views::add<hex::ViewPattern>(patternData);
|
||||
hex::ContentRegistry::Views::add<hex::ViewPatternData>(patternData);
|
||||
hex::ContentRegistry::Views::add<hex::ViewDataInspector>();
|
||||
@ -38,7 +39,7 @@ int main(int argc, char **argv) {
|
||||
hex::ContentRegistry::Views::add<hex::ViewInformation>();
|
||||
hex::ContentRegistry::Views::add<hex::ViewStrings>();
|
||||
hex::ContentRegistry::Views::add<hex::ViewDisassembler>();
|
||||
hex::ContentRegistry::Views::add<hex::ViewBookmarks>();
|
||||
hex::ContentRegistry::Views::add<hex::ViewBookmarks>(bookmarks);
|
||||
hex::ContentRegistry::Views::add<hex::ViewPatches>();
|
||||
hex::ContentRegistry::Views::add<hex::ViewTools>();
|
||||
hex::ContentRegistry::Views::add<hex::ViewCommandPalette>();
|
||||
|
@ -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()) {
|
||||
|
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user