From 6e861001cf56cbb114b0d9347816284253d51913 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 4 Jan 2025 21:40:03 +0100 Subject: [PATCH] impr: Allow all highlights to overlap each other --- lib/libimhex/include/hex/helpers/utils.hpp | 4 +++- lib/libimhex/source/helpers/utils.cpp | 12 ++++++++++++ .../builtin/source/content/views/view_bookmarks.cpp | 8 ++++---- .../builtin/source/content/views/view_hex_editor.cpp | 10 ++++++---- .../source/content/views/view_pattern_editor.cpp | 5 +---- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/libimhex/include/hex/helpers/utils.hpp b/lib/libimhex/include/hex/helpers/utils.hpp index 0404ebf0f..b9a579624 100644 --- a/lib/libimhex/include/hex/helpers/utils.hpp +++ b/lib/libimhex/include/hex/helpers/utils.hpp @@ -26,7 +26,7 @@ #include #endif -struct ImVec2; +#include namespace hex { @@ -340,4 +340,6 @@ namespace hex { */ [[nodiscard]] void* getContainingModule(void* symbol); + [[nodiscard]] std::optional blendColors(const std::optional &a, const std::optional &b); + } diff --git a/lib/libimhex/source/helpers/utils.cpp b/lib/libimhex/source/helpers/utils.cpp index afef81b35..0bc7798fb 100644 --- a/lib/libimhex/source/helpers/utils.cpp +++ b/lib/libimhex/source/helpers/utils.cpp @@ -8,6 +8,7 @@ #include #include +#include #if defined(OS_WINDOWS) #include @@ -844,4 +845,15 @@ namespace hex { #endif } + std::optional blendColors(const std::optional &a, const std::optional &b) { + if (!a.has_value() && !b.has_value()) + return std::nullopt; + else if (a.has_value() && !b.has_value()) + return a; + else if (!a.has_value() && b.has_value()) + return b; + else + return ImAlphaBlendColors(a.value(), b.value()); + } + } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_bookmarks.cpp b/plugins/builtin/source/content/views/view_bookmarks.cpp index 9c54f5f3b..4a65625ed 100644 --- a/plugins/builtin/source/content/views/view_bookmarks.cpp +++ b/plugins/builtin/source/content/views/view_bookmarks.cpp @@ -65,11 +65,11 @@ namespace hex::plugin::builtin { // Check all bookmarks for potential overlaps with the current address std::optional color; for (const auto &bookmark : *m_bookmarks) { + if (!bookmark.highlightVisible) + continue; + if (Region { address, size }.isWithin(bookmark.entry.region)) { - if (color.has_value()) - color = ImAlphaBlendColors(*color, bookmark.entry.color); - else - color = bookmark.entry.color; + color = blendColors(color, bookmark.entry.color); } } diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 0d3603edf..952ea6403 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -569,14 +569,16 @@ namespace hex::plugin::builtin { std::optional result; for (const auto &[id, callback] : ImHexApi::HexEditor::impl::getBackgroundHighlightingFunctions()) { - if (auto color = callback(address, data, size, result.has_value()); color.has_value()) - result = color; + if (auto color = callback(address, data, size, result.has_value()); color.has_value()) { + result = blendColors(result, color); + } } if (!result.has_value()) { for (const auto &[id, highlighting] : ImHexApi::HexEditor::impl::getBackgroundHighlights()) { - if (highlighting.getRegion().overlaps({ address, size })) - return highlighting.getColor(); + if (highlighting.getRegion().overlaps({ address, size })) { + result = blendColors(result, highlighting.getColor()); + } } } diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 8e60af151..c9e5d597b 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -2212,10 +2212,7 @@ namespace hex::plugin::builtin { if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) { for (const auto &patternColor : runtime.getColorsAtAddress(address)) { - if (color.has_value()) - color = ImAlphaBlendColors(*color, patternColor); - else - color = patternColor; + color = blendColors(color, patternColor); } }