From c4109053953665e8c2c25808edd139a238c88636 Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 30 Jul 2022 22:44:53 +0100 Subject: [PATCH] Some refactoring of ByteItem highlighting --- .../HexViewerWidget/ByteItem.cpp | 14 +++++--------- .../HexViewerWidget/ByteItem.hpp | 5 +++-- .../HexViewerWidget/ByteItemGraphicsScene.cpp | 17 ++++++++++++++--- .../HexViewerWidget/ByteItemGraphicsScene.hpp | 2 +- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.cpp index 0a36870f..9341cc7e 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.cpp @@ -10,7 +10,7 @@ namespace Bloom::Widgets std::optional& currentStackPointer, ByteItem** hoveredByteItem, AnnotationItem** hoveredAnnotationItem, - std::set& highlightedAddresses, + std::set& highlightedByteItems, const HexViewerWidgetSettings& settings ) : QGraphicsItem(nullptr) @@ -19,7 +19,7 @@ namespace Bloom::Widgets , currentStackPointer(currentStackPointer) , hoveredByteItem(hoveredByteItem) , hoveredAnnotationItem(hoveredAnnotationItem) - , highlightedAddresses(highlightedAddresses) + , highlightedByteItems(highlightedByteItems) , settings(settings) { this->setCacheMode( @@ -129,7 +129,7 @@ namespace Bloom::Widgets static const auto hoveredNeighbourBackgroundColor = QColor(0x8E, 0x8B, 0x83, 30); if (this->isEnabled()) { - if (this->highlightedAddresses.contains(this->address)) { + if (this->highlighted) { return &(highlightedBackgroundColor); } @@ -165,7 +165,7 @@ namespace Bloom::Widgets } } else { - if (this->highlightedAddresses.contains(this->address)) { + if (this->highlighted) { return &(disabledHighlightedBackgroundColor); } @@ -210,7 +210,7 @@ namespace Bloom::Widgets if ( this->excludedMemoryRegion != nullptr || this->settings.displayAsciiValues - || (!this->highlightedAddresses.empty() && !this->highlightedAddresses.contains(this->address)) + || (!this->highlightedByteItems.empty() && !this->highlighted) ) { return &(fadedStandardTextColor); } @@ -218,10 +218,6 @@ namespace Bloom::Widgets return &(standardTextColor); } - if (!this->highlightedAddresses.empty() && !this->highlightedAddresses.contains(this->address)) { - return &(fadedAsciiModeTextColor); - } - return &(asciiModeTextColor); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.hpp index c867fcd0..ff45bb13 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItem.hpp @@ -33,6 +33,7 @@ namespace Bloom::Widgets std::size_t currentRowIndex = 0; std::size_t currentColumnIndex = 0; + bool highlighted = false; const FocusedMemoryRegion* focusedMemoryRegion = nullptr; const ExcludedMemoryRegion* excludedMemoryRegion = nullptr; @@ -42,7 +43,7 @@ namespace Bloom::Widgets std::optional& currentStackPointer, ByteItem** hoveredByteItem, AnnotationItem** hoveredAnnotationItem, - std::set& highlightedAddresses, + std::set& highlightedByteItems, const HexViewerWidgetSettings& settings ); @@ -70,7 +71,7 @@ namespace Bloom::Widgets ByteItem** hoveredByteItem; AnnotationItem** hoveredAnnotationItem; std::optional& currentStackPointer; - std::set& highlightedAddresses; + std::set& highlightedByteItems; const QColor* getBackgroundColor(); const QColor* getTextColor(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp index ad9b8c6d..13990a21 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp @@ -41,7 +41,7 @@ namespace Bloom::Widgets this->currentStackPointer, &(this->hoveredByteWidget), &(this->hoveredAnnotationItem), - this->highlightedAddresses, + this->highlightedByteItems, settings ); @@ -79,8 +79,19 @@ namespace Bloom::Widgets } void ByteItemGraphicsScene::setHighlightedAddresses(const std::set& highlightedAddresses) { - this->highlightedAddresses = highlightedAddresses; - this->invalidateChildItemCaches(); + this->highlightedByteItems.clear(); + + for (auto& [address, byteItem] : this->byteItemsByAddress) { + if (highlightedAddresses.contains(address)) { + byteItem->highlighted = true; + this->highlightedByteItems.insert(byteItem); + + } else { + byteItem->highlighted = false; + } + + byteItem->update(); + } } void ByteItemGraphicsScene::refreshRegions() { diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.hpp index e100305a..969eb7a8 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.hpp @@ -96,7 +96,7 @@ namespace Bloom::Widgets ByteAddressContainer* byteAddressContainer = nullptr; - std::set highlightedAddresses; + std::set highlightedByteItems; int getSceneWidth() { /*