From b4b2c41b3484acccea10e239b38b23b6a166e838 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 17 Jun 2021 23:42:43 +0200 Subject: [PATCH] patterns: Added `hidden` attribute --- .../include/hex/lang/pattern_data.hpp | 22 ++++++++++++++++--- plugins/libimhex/source/lang/evaluator.cpp | 2 ++ source/views/view_hexeditor.cpp | 3 ++- source/views/view_pattern_data.cpp | 2 +- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/plugins/libimhex/include/hex/lang/pattern_data.hpp b/plugins/libimhex/include/hex/lang/pattern_data.hpp index 455d0edfe..cd8b85fef 100644 --- a/plugins/libimhex/include/hex/lang/pattern_data.hpp +++ b/plugins/libimhex/include/hex/lang/pattern_data.hpp @@ -92,6 +92,7 @@ namespace hex::lang { } virtual std::map getHighlightedAddresses() { + if (this->isHidden()) return { }; if (this->m_highlightedAddresses.empty()) { for (u64 i = 0; i < this->getSize(); i++) this->m_highlightedAddresses.insert({ this->getOffset() + i, this->getColor() }); @@ -154,8 +155,22 @@ namespace hex::lang { return false; } + void draw(prv::Provider *provider) { + if (isHidden()) return; + + this->createEntry(provider); + } + static void resetPalette() { SharedData::patternPaletteOffset = 0; } + void setHidden(bool hidden) { + this->m_hidden = hidden; + } + + bool isHidden() const { + return this->m_hidden; + } + protected: void createDefaultEntry(std::string_view value) const { ImGui::TableNextRow(); @@ -190,6 +205,7 @@ namespace hex::lang { protected: std::endian m_endian = std::endian::native; std::map m_highlightedAddresses; + bool m_hidden = false; private: u64 m_offset; @@ -599,7 +615,7 @@ namespace hex::lang { if (open) { for (auto &member : this->m_entries) - member->createEntry(provider); + member->draw(provider); ImGui::TreePop(); } @@ -681,7 +697,7 @@ namespace hex::lang { if (open) { for (auto &member : this->m_sortedMembers) - member->createEntry(provider); + member->draw(provider); ImGui::TreePop(); } @@ -782,7 +798,7 @@ namespace hex::lang { if (open) { for (auto &member : this->m_sortedMembers) - member->createEntry(provider); + member->draw(provider); ImGui::TreePop(); } diff --git a/plugins/libimhex/source/lang/evaluator.cpp b/plugins/libimhex/source/lang/evaluator.cpp index ab79d0e3c..6969c6222 100644 --- a/plugins/libimhex/source/lang/evaluator.cpp +++ b/plugins/libimhex/source/lang/evaluator.cpp @@ -432,6 +432,8 @@ namespace hex::lang { currPattern->setVariableName(value->data()); else if (attribute == "comment" && value.has_value()) currPattern->setComment(value->data()); + else if (attribute == "hidden" && value.has_value()) + currPattern->setHidden(true); else this->getConsole().abortEvaluation("unknown or invalid attribute"); diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index be908c949..1ff42570f 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -162,8 +162,9 @@ namespace hex { EventManager::subscribe(this, [this]() { this->m_highlightedBytes.clear(); - for (const auto &pattern : SharedData::patternData) + for (const auto &pattern : SharedData::patternData) { this->m_highlightedBytes.merge(pattern->getHighlightedAddresses()); + } }); EventManager::subscribe(this, [this](std::string name) { diff --git a/source/views/view_pattern_data.cpp b/source/views/view_pattern_data.cpp index c34b949a7..e5d87c2c3 100644 --- a/source/views/view_pattern_data.cpp +++ b/source/views/view_pattern_data.cpp @@ -57,7 +57,7 @@ namespace hex { if (this->m_sortedPatternData.size() > 0) { for (auto &patternData : this->m_sortedPatternData) - patternData->createEntry(provider); + patternData->draw(provider); }