1
0
mirror of synced 2025-01-10 21:41:53 +01:00

impr: Allow all highlights to overlap each other

This commit is contained in:
WerWolv 2025-01-04 21:40:03 +01:00
parent c56af08c7e
commit 6e861001cf
5 changed files with 26 additions and 13 deletions

View File

@ -26,7 +26,7 @@
#include <hex/helpers/utils_linux.hpp> #include <hex/helpers/utils_linux.hpp>
#endif #endif
struct ImVec2; #include <imgui.h>
namespace hex { namespace hex {
@ -340,4 +340,6 @@ namespace hex {
*/ */
[[nodiscard]] void* getContainingModule(void* symbol); [[nodiscard]] void* getContainingModule(void* symbol);
[[nodiscard]] std::optional<ImColor> blendColors(const std::optional<ImColor> &a, const std::optional<ImColor> &b);
} }

View File

@ -8,6 +8,7 @@
#include <hex/providers/buffered_reader.hpp> #include <hex/providers/buffered_reader.hpp>
#include <imgui.h> #include <imgui.h>
#include <imgui_internal.h>
#if defined(OS_WINDOWS) #if defined(OS_WINDOWS)
#include <windows.h> #include <windows.h>
@ -844,4 +845,15 @@ namespace hex {
#endif #endif
} }
std::optional<ImColor> blendColors(const std::optional<ImColor> &a, const std::optional<ImColor> &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());
}
} }

View File

@ -65,11 +65,11 @@ namespace hex::plugin::builtin {
// Check all bookmarks for potential overlaps with the current address // Check all bookmarks for potential overlaps with the current address
std::optional<ImColor> color; std::optional<ImColor> color;
for (const auto &bookmark : *m_bookmarks) { for (const auto &bookmark : *m_bookmarks) {
if (!bookmark.highlightVisible)
continue;
if (Region { address, size }.isWithin(bookmark.entry.region)) { if (Region { address, size }.isWithin(bookmark.entry.region)) {
if (color.has_value()) color = blendColors(color, bookmark.entry.color);
color = ImAlphaBlendColors(*color, bookmark.entry.color);
else
color = bookmark.entry.color;
} }
} }

View File

@ -569,14 +569,16 @@ namespace hex::plugin::builtin {
std::optional<color_t> result; std::optional<color_t> result;
for (const auto &[id, callback] : ImHexApi::HexEditor::impl::getBackgroundHighlightingFunctions()) { for (const auto &[id, callback] : ImHexApi::HexEditor::impl::getBackgroundHighlightingFunctions()) {
if (auto color = callback(address, data, size, result.has_value()); color.has_value()) if (auto color = callback(address, data, size, result.has_value()); color.has_value()) {
result = color; result = blendColors(result, color);
}
} }
if (!result.has_value()) { if (!result.has_value()) {
for (const auto &[id, highlighting] : ImHexApi::HexEditor::impl::getBackgroundHighlights()) { for (const auto &[id, highlighting] : ImHexApi::HexEditor::impl::getBackgroundHighlights()) {
if (highlighting.getRegion().overlaps({ address, size })) if (highlighting.getRegion().overlaps({ address, size })) {
return highlighting.getColor(); result = blendColors(result, highlighting.getColor());
}
} }
} }

View File

@ -2212,10 +2212,7 @@ namespace hex::plugin::builtin {
if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) { if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) {
for (const auto &patternColor : runtime.getColorsAtAddress(address)) { for (const auto &patternColor : runtime.getColorsAtAddress(address)) {
if (color.has_value()) color = blendColors(color, patternColor);
color = ImAlphaBlendColors(*color, patternColor);
else
color = patternColor;
} }
} }