impr: Improve frame rate when lots of bytes are highlighted
This commit is contained in:
parent
440e2d91fc
commit
4d4f223357
@ -76,6 +76,8 @@ namespace hex::plugin::builtin {
|
||||
|
||||
PerProvider<std::optional<u64>> m_selectionStart, m_selectionEnd;
|
||||
PerProvider<float> m_scrollPosition;
|
||||
|
||||
PerProvider<std::map<u64, color_t>> m_foregroundHighlights, m_backgroundHighlights;
|
||||
};
|
||||
|
||||
}
|
@ -15,9 +15,11 @@ namespace hex::plugin::builtin {
|
||||
~ViewPatches() override = default;
|
||||
|
||||
void drawContent() override;
|
||||
void drawAlwaysVisible() override;
|
||||
|
||||
private:
|
||||
u64 m_selectedPatch = 0x00;
|
||||
PerProvider<u32> m_numPatches;
|
||||
};
|
||||
|
||||
}
|
@ -505,40 +505,50 @@ namespace hex::plugin::builtin {
|
||||
/* Hex Editor */
|
||||
|
||||
ViewHexEditor::ViewHexEditor() : View("hex.builtin.view.hex_editor.name") {
|
||||
this->m_hexEditor.setForegroundHighlightCallback([](u64 address, const u8 *data, size_t size) -> std::optional<color_t> {
|
||||
this->m_hexEditor.setForegroundHighlightCallback([this](u64 address, const u8 *data, size_t size) -> std::optional<color_t> {
|
||||
if (auto highlight = this->m_foregroundHighlights->find(address); highlight != this->m_foregroundHighlights->end())
|
||||
return highlight->second;
|
||||
|
||||
std::optional<color_t> result;
|
||||
for (const auto &[id, callback] : ImHexApi::HexEditor::impl::getForegroundHighlightingFunctions()) {
|
||||
if (auto color = callback(address, data, size, result.has_value()); color.has_value())
|
||||
result = color;
|
||||
}
|
||||
|
||||
if (result.has_value())
|
||||
return result;
|
||||
|
||||
for (const auto &[id, highlighting] : ImHexApi::HexEditor::impl::getForegroundHighlights()) {
|
||||
if (highlighting.getRegion().overlaps({ address, size }))
|
||||
return highlighting.getColor();
|
||||
if (!result.has_value()) {
|
||||
for (const auto &[id, highlighting] : ImHexApi::HexEditor::impl::getForegroundHighlights()) {
|
||||
if (highlighting.getRegion().overlaps({ address, size }))
|
||||
return highlighting.getColor();
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
if (result.has_value())
|
||||
this->m_foregroundHighlights->insert({ address, result.value() });
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
this->m_hexEditor.setBackgroundHighlightCallback([](u64 address, const u8 *data, size_t size) -> std::optional<color_t> {
|
||||
this->m_hexEditor.setBackgroundHighlightCallback([this](u64 address, const u8 *data, size_t size) -> std::optional<color_t> {
|
||||
if (auto highlight = this->m_backgroundHighlights->find(address); highlight != this->m_backgroundHighlights->end())
|
||||
return highlight->second;
|
||||
|
||||
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())
|
||||
return color.value();
|
||||
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 (result.has_value())
|
||||
return result;
|
||||
this->m_backgroundHighlights->insert({ address, result.value() });
|
||||
|
||||
for (const auto &[id, highlighting] : ImHexApi::HexEditor::impl::getBackgroundHighlights()) {
|
||||
if (highlighting.getRegion().overlaps({ address, size }))
|
||||
return highlighting.getColor();
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
return result;
|
||||
});
|
||||
|
||||
this->m_hexEditor.setTooltipCallback([](u64 address, const u8 *data, size_t size) {
|
||||
@ -573,8 +583,10 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
ViewHexEditor::~ViewHexEditor() {
|
||||
EventManager::unsubscribe<RequestSelectionChange>(this);
|
||||
EventManager::unsubscribe<EventProviderChanged>(this);
|
||||
EventManager::unsubscribe<EventProviderOpened>(this);
|
||||
EventManager::unsubscribe<EventHighlightingChanged>(this);
|
||||
}
|
||||
|
||||
void ViewHexEditor::drawPopup() {
|
||||
@ -931,6 +943,11 @@ namespace hex::plugin::builtin {
|
||||
ImHexApi::HexEditor::clearSelection();
|
||||
});
|
||||
|
||||
EventManager::subscribe<EventHighlightingChanged>(this, [this]{
|
||||
this->m_foregroundHighlights->clear();
|
||||
this->m_backgroundHighlights->clear();
|
||||
});
|
||||
|
||||
ProjectFile::registerPerProviderHandler({
|
||||
.basePath = "custom_encoding.tbl",
|
||||
.required = false,
|
||||
|
@ -117,4 +117,14 @@ namespace hex::plugin::builtin {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void ViewPatches::drawAlwaysVisible() {
|
||||
if (auto provider = ImHexApi::Provider::get(); provider != nullptr) {
|
||||
const auto &patches = provider->getPatches();
|
||||
if (this->m_numPatches.get(provider) != patches.size()) {
|
||||
this->m_numPatches.get(provider) = patches.size();
|
||||
EventManager::post<EventHighlightingChanged>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user