From 89111059f9c5c6753ac876e77ad9a5b2d1b340fa Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 30 Dec 2024 23:24:59 +0100 Subject: [PATCH] feat: Added setting to disable hex editor highlights entirely --- plugins/builtin/romfs/lang/en_US.json | 1 + .../source/content/settings_entries.cpp | 1 + .../source/content/views/view_hex_editor.cpp | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index e50783bc2..0dce48a26 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -494,6 +494,7 @@ "hex.builtin.setting.hex_editor.pattern_parent_highlighting": "Highlight pattern parents on hover", "hex.builtin.setting.hex_editor.paste_behaviour": "Single-Byte Paste behaviour", "hex.builtin.setting.hex_editor.sync_scrolling": "Synchronize editor scroll position", + "hex.builtin.setting.hex_editor.show_highlights": "Show colorful highlightings", "hex.builtin.setting.hex_editor.show_selection": "Move selection display to hex editor footer", "hex.builtin.setting.imhex": "ImHex", "hex.builtin.setting.imhex.recent_files": "Recent Files", diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index d79f163b1..dec3ce61f 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -835,6 +835,7 @@ namespace hex::plugin::builtin { ContentRegistry::Settings::add("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.highlight_color", ImColor(0x80, 0x80, 0xC0, 0x60)); ContentRegistry::Settings::add("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.sync_scrolling", false); ContentRegistry::Settings::add("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.show_selection", false); + ContentRegistry::Settings::add("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.show_highlights", true); ContentRegistry::Settings::add("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.byte_padding", 0, 0, 50); ContentRegistry::Settings::add("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.char_padding", 0, 0, 50); diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index e480f8d9c..274dc4e09 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -154,9 +154,9 @@ namespace hex::plugin::builtin { u64 inputA = m_region.getStartAddress(); u64 inputB = m_region.getEndAddress(); - if (justOpened) { + if (m_justOpened) { ImGui::SetKeyboardFocusHere(); - justOpened = false; + m_justOpened = false; } ImGuiExt::InputHexadecimal("hex.builtin.view.hex_editor.select.offset.begin"_lang, &inputA, ImGuiInputTextFlags_AutoSelectAll); ImGuiExt::InputHexadecimal("hex.builtin.view.hex_editor.select.offset.end"_lang, &inputB, ImGuiInputTextFlags_AutoSelectAll); @@ -173,9 +173,9 @@ namespace hex::plugin::builtin { u64 inputA = m_region.getStartAddress(); u64 inputB = m_region.getSize(); - if (justOpened) { + if (m_justOpened) { ImGui::SetKeyboardFocusHere(); - justOpened = false; + m_justOpened = false; } ImGuiExt::InputHexadecimal("hex.builtin.view.hex_editor.select.offset.begin"_lang, &inputA, ImGuiInputTextFlags_AutoSelectAll); ImGuiExt::InputHexadecimal("hex.builtin.view.hex_editor.select.offset.size"_lang, &inputB, ImGuiInputTextFlags_AutoSelectAll); @@ -217,7 +217,7 @@ namespace hex::plugin::builtin { private: Region m_region = { 0, 1 }; - bool justOpened = true; + bool m_justOpened = true; }; class PopupBaseAddress : public ViewHexEditor::Popup { @@ -550,7 +550,15 @@ namespace hex::plugin::builtin { return result; }); + static bool showHighlights = true; + ContentRegistry::Settings::onChange("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.show_highlights", [](const ContentRegistry::Settings::SettingsValue &value) { + showHighlights = value.get(true); + }); + m_hexEditor.setBackgroundHighlightCallback([this](u64 address, const u8 *data, size_t size) -> std::optional { + if (!showHighlights) + return std::nullopt; + if (auto highlight = m_backgroundHighlights->find(address); highlight != m_backgroundHighlights->end()) { if (std::ranges::any_of(*m_hoverHighlights, [region = Region(address, size)](const Region &highlight) { return highlight.overlaps(region); })) return ImAlphaBlendColors(highlight->second, 0xA0FFFFFF);