impr: Allow all highlights to overlap each other
This commit is contained in:
parent
c56af08c7e
commit
6e861001cf
@ -26,7 +26,7 @@
|
||||
#include <hex/helpers/utils_linux.hpp>
|
||||
#endif
|
||||
|
||||
struct ImVec2;
|
||||
#include <imgui.h>
|
||||
|
||||
namespace hex {
|
||||
|
||||
@ -340,4 +340,6 @@ namespace hex {
|
||||
*/
|
||||
[[nodiscard]] void* getContainingModule(void* symbol);
|
||||
|
||||
[[nodiscard]] std::optional<ImColor> blendColors(const std::optional<ImColor> &a, const std::optional<ImColor> &b);
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <hex/providers/buffered_reader.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
#include <windows.h>
|
||||
@ -844,4 +845,15 @@ namespace hex {
|
||||
#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());
|
||||
}
|
||||
|
||||
}
|
@ -65,11 +65,11 @@ namespace hex::plugin::builtin {
|
||||
// Check all bookmarks for potential overlaps with the current address
|
||||
std::optional<ImColor> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -569,14 +569,16 @@ namespace hex::plugin::builtin {
|
||||
|
||||
std::optional<color_t> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user