Some refactoring of ByteItem highlighting

This commit is contained in:
Nav
2022-07-30 22:44:53 +01:00
parent 1f4788b039
commit c410905395
4 changed files with 23 additions and 15 deletions

View File

@@ -10,7 +10,7 @@ namespace Bloom::Widgets
std::optional<std::uint32_t>& currentStackPointer, std::optional<std::uint32_t>& currentStackPointer,
ByteItem** hoveredByteItem, ByteItem** hoveredByteItem,
AnnotationItem** hoveredAnnotationItem, AnnotationItem** hoveredAnnotationItem,
std::set<std::uint32_t>& highlightedAddresses, std::set<ByteItem*>& highlightedByteItems,
const HexViewerWidgetSettings& settings const HexViewerWidgetSettings& settings
) )
: QGraphicsItem(nullptr) : QGraphicsItem(nullptr)
@@ -19,7 +19,7 @@ namespace Bloom::Widgets
, currentStackPointer(currentStackPointer) , currentStackPointer(currentStackPointer)
, hoveredByteItem(hoveredByteItem) , hoveredByteItem(hoveredByteItem)
, hoveredAnnotationItem(hoveredAnnotationItem) , hoveredAnnotationItem(hoveredAnnotationItem)
, highlightedAddresses(highlightedAddresses) , highlightedByteItems(highlightedByteItems)
, settings(settings) , settings(settings)
{ {
this->setCacheMode( this->setCacheMode(
@@ -129,7 +129,7 @@ namespace Bloom::Widgets
static const auto hoveredNeighbourBackgroundColor = QColor(0x8E, 0x8B, 0x83, 30); static const auto hoveredNeighbourBackgroundColor = QColor(0x8E, 0x8B, 0x83, 30);
if (this->isEnabled()) { if (this->isEnabled()) {
if (this->highlightedAddresses.contains(this->address)) { if (this->highlighted) {
return &(highlightedBackgroundColor); return &(highlightedBackgroundColor);
} }
@@ -165,7 +165,7 @@ namespace Bloom::Widgets
} }
} else { } else {
if (this->highlightedAddresses.contains(this->address)) { if (this->highlighted) {
return &(disabledHighlightedBackgroundColor); return &(disabledHighlightedBackgroundColor);
} }
@@ -210,7 +210,7 @@ namespace Bloom::Widgets
if ( if (
this->excludedMemoryRegion != nullptr this->excludedMemoryRegion != nullptr
|| this->settings.displayAsciiValues || this->settings.displayAsciiValues
|| (!this->highlightedAddresses.empty() && !this->highlightedAddresses.contains(this->address)) || (!this->highlightedByteItems.empty() && !this->highlighted)
) { ) {
return &(fadedStandardTextColor); return &(fadedStandardTextColor);
} }
@@ -218,10 +218,6 @@ namespace Bloom::Widgets
return &(standardTextColor); return &(standardTextColor);
} }
if (!this->highlightedAddresses.empty() && !this->highlightedAddresses.contains(this->address)) {
return &(fadedAsciiModeTextColor);
}
return &(asciiModeTextColor); return &(asciiModeTextColor);
} }

View File

@@ -33,6 +33,7 @@ namespace Bloom::Widgets
std::size_t currentRowIndex = 0; std::size_t currentRowIndex = 0;
std::size_t currentColumnIndex = 0; std::size_t currentColumnIndex = 0;
bool highlighted = false;
const FocusedMemoryRegion* focusedMemoryRegion = nullptr; const FocusedMemoryRegion* focusedMemoryRegion = nullptr;
const ExcludedMemoryRegion* excludedMemoryRegion = nullptr; const ExcludedMemoryRegion* excludedMemoryRegion = nullptr;
@@ -42,7 +43,7 @@ namespace Bloom::Widgets
std::optional<std::uint32_t>& currentStackPointer, std::optional<std::uint32_t>& currentStackPointer,
ByteItem** hoveredByteItem, ByteItem** hoveredByteItem,
AnnotationItem** hoveredAnnotationItem, AnnotationItem** hoveredAnnotationItem,
std::set<std::uint32_t>& highlightedAddresses, std::set<ByteItem*>& highlightedByteItems,
const HexViewerWidgetSettings& settings const HexViewerWidgetSettings& settings
); );
@@ -70,7 +71,7 @@ namespace Bloom::Widgets
ByteItem** hoveredByteItem; ByteItem** hoveredByteItem;
AnnotationItem** hoveredAnnotationItem; AnnotationItem** hoveredAnnotationItem;
std::optional<std::uint32_t>& currentStackPointer; std::optional<std::uint32_t>& currentStackPointer;
std::set<std::uint32_t>& highlightedAddresses; std::set<ByteItem*>& highlightedByteItems;
const QColor* getBackgroundColor(); const QColor* getBackgroundColor();
const QColor* getTextColor(); const QColor* getTextColor();

View File

@@ -41,7 +41,7 @@ namespace Bloom::Widgets
this->currentStackPointer, this->currentStackPointer,
&(this->hoveredByteWidget), &(this->hoveredByteWidget),
&(this->hoveredAnnotationItem), &(this->hoveredAnnotationItem),
this->highlightedAddresses, this->highlightedByteItems,
settings settings
); );
@@ -79,8 +79,19 @@ namespace Bloom::Widgets
} }
void ByteItemGraphicsScene::setHighlightedAddresses(const std::set<std::uint32_t>& highlightedAddresses) { void ByteItemGraphicsScene::setHighlightedAddresses(const std::set<std::uint32_t>& highlightedAddresses) {
this->highlightedAddresses = highlightedAddresses; this->highlightedByteItems.clear();
this->invalidateChildItemCaches();
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() { void ByteItemGraphicsScene::refreshRegions() {

View File

@@ -96,7 +96,7 @@ namespace Bloom::Widgets
ByteAddressContainer* byteAddressContainer = nullptr; ByteAddressContainer* byteAddressContainer = nullptr;
std::set<std::uint32_t> highlightedAddresses; std::set<ByteItem*> highlightedByteItems;
int getSceneWidth() { int getSceneWidth() {
/* /*