mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
impr: Make highlight hovering more efficient
This commit is contained in:
@@ -493,16 +493,8 @@ namespace hex::plugin::builtin {
|
||||
});
|
||||
|
||||
m_hexEditor.setBackgroundHighlightCallback([this](u64 address, const u8 *data, size_t size) -> std::optional<color_t> {
|
||||
bool hovered = false;
|
||||
for (const auto &[id, hoverFunction] : ImHexApi::HexEditor::impl::getHoveringFunctions()) {
|
||||
if (hoverFunction(m_hexEditor.getProvider(), address, data, size)) {
|
||||
hovered = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (auto highlight = m_backgroundHighlights->find(address); highlight != m_backgroundHighlights->end()) {
|
||||
if (hovered)
|
||||
if (std::ranges::any_of(*m_hoverHighlights, [region = Region(address, size)](const Region &highlight) { return highlight.overlaps(region); }))
|
||||
return ImAlphaBlendColors(highlight->second, 0xA0FFFFFF);
|
||||
else
|
||||
return highlight->second;
|
||||
@@ -527,6 +519,14 @@ namespace hex::plugin::builtin {
|
||||
return result;
|
||||
});
|
||||
|
||||
m_hexEditor.setHoverChangedCallback([this](u64 address, size_t size) {
|
||||
m_hoverHighlights->clear();
|
||||
for (const auto &[id, hoverFunction] : ImHexApi::HexEditor::impl::getHoveringFunctions()) {
|
||||
auto highlightedAddresses = hoverFunction(m_hexEditor.getProvider(), address, size);
|
||||
m_hoverHighlights->merge(highlightedAddresses);
|
||||
}
|
||||
});
|
||||
|
||||
m_hexEditor.setTooltipCallback([](u64 address, const u8 *data, size_t size) {
|
||||
for (const auto &[id, callback] : ImHexApi::HexEditor::impl::getTooltipFunctions()) {
|
||||
callback(address, data, size);
|
||||
|
||||
@@ -37,8 +37,8 @@ namespace hex::plugin::builtin {
|
||||
(*m_patternDrawer)->jumpToPattern(pattern);
|
||||
});
|
||||
|
||||
ImHexApi::HexEditor::addHoverHighlightProvider([this](const prv::Provider *, u64 address, const u8 *, size_t size) {
|
||||
return m_hoveredPatternRegion.overlaps(Region { address, size });
|
||||
ImHexApi::HexEditor::addHoverHighlightProvider([this](const prv::Provider *, u64, size_t) -> std::set<Region> {
|
||||
return { m_hoveredPatternRegion };
|
||||
});
|
||||
|
||||
m_patternDrawer.setOnCreateCallback([this](const prv::Provider *provider, auto &drawer) {
|
||||
|
||||
@@ -1912,24 +1912,23 @@ namespace hex::plugin::builtin {
|
||||
return color;
|
||||
});
|
||||
|
||||
ImHexApi::HexEditor::addHoverHighlightProvider([this](const prv::Provider *provider, u64 address, const u8 *, size_t) {
|
||||
if (!m_parentHighlightingEnabled) return false;
|
||||
ImHexApi::HexEditor::addHoverHighlightProvider([this](const prv::Provider *, u64 address, size_t size) {
|
||||
std::set<Region> result;
|
||||
if (!m_parentHighlightingEnabled)
|
||||
return result;
|
||||
|
||||
const auto &runtime = ContentRegistry::PatternLanguage::getRuntime();
|
||||
|
||||
if (auto hoveredRegion = ImHexApi::HexEditor::getHoveredRegion(provider)) {
|
||||
for (const auto &pattern : runtime.getPatternsAtAddress(hoveredRegion->getStartAddress())) {
|
||||
const pl::ptrn::Pattern * checkPattern = pattern;
|
||||
if (auto parent = checkPattern->getParent(); parent != nullptr)
|
||||
checkPattern = parent;
|
||||
const auto hoveredRegion = Region { address, size };
|
||||
for (const auto &pattern : runtime.getPatternsAtAddress(hoveredRegion.getStartAddress())) {
|
||||
const pl::ptrn::Pattern * checkPattern = pattern;
|
||||
if (auto parent = checkPattern->getParent(); parent != nullptr)
|
||||
checkPattern = parent;
|
||||
|
||||
if (checkPattern->getOffset() <= address && checkPattern->getOffset() + checkPattern->getSize() > address) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result.emplace(checkPattern->getOffset(), checkPattern->getSize());
|
||||
}
|
||||
|
||||
return false;
|
||||
return result;
|
||||
});
|
||||
|
||||
ImHexApi::HexEditor::addTooltipProvider([this](u64 address, const u8 *data, size_t size) {
|
||||
|
||||
Reference in New Issue
Block a user