Moved current stack pointer out of HexViewerWidgetSettings - didn't belong there

This commit is contained in:
Nav
2021-12-25 03:10:46 +00:00
parent d69a8bcde5
commit a8e90f7b56
6 changed files with 25 additions and 12 deletions

View File

@@ -8,6 +8,7 @@ using namespace Bloom::Widgets;
ByteItem::ByteItem( ByteItem::ByteItem(
std::size_t byteIndex, std::size_t byteIndex,
std::uint32_t address, std::uint32_t address,
std::optional<std::uint32_t>& currentStackPointer,
std::optional<ByteItem*>& hoveredByteItem, std::optional<ByteItem*>& hoveredByteItem,
std::optional<AnnotationItem*>& hoveredAnnotationItem, std::optional<AnnotationItem*>& hoveredAnnotationItem,
const HexViewerWidgetSettings& settings const HexViewerWidgetSettings& settings
@@ -15,6 +16,7 @@ ByteItem::ByteItem(
QGraphicsItem(nullptr), QGraphicsItem(nullptr),
byteIndex(byteIndex), byteIndex(byteIndex),
address(address), address(address),
currentStackPointer(currentStackPointer),
hoveredByteItem(hoveredByteItem), hoveredByteItem(hoveredByteItem),
hoveredAnnotationItem(hoveredAnnotationItem), hoveredAnnotationItem(hoveredAnnotationItem),
settings(settings) settings(settings)
@@ -69,8 +71,8 @@ void ByteItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
// This byte is within a focused region // This byte is within a focused region
backgroundColor = focusedRegionBackgroundColor; backgroundColor = focusedRegionBackgroundColor;
} else if (this->settings.highlightStackMemory && this->settings.stackPointerAddress.has_value() } else if (this->settings.highlightStackMemory && this->currentStackPointer.has_value()
&& this->address > this->settings.stackPointerAddress && this->address > this->currentStackPointer
) { ) {
// This byte is within the stack memory // This byte is within the stack memory
backgroundColor = stackMemoryBackgroundColor; backgroundColor = stackMemoryBackgroundColor;

View File

@@ -37,6 +37,7 @@ namespace Bloom::Widgets
ByteItem( ByteItem(
std::size_t byteIndex, std::size_t byteIndex,
std::uint32_t address, std::uint32_t address,
std::optional<std::uint32_t>& currentStackPointer,
std::optional<ByteItem*>& hoveredByteItem, std::optional<ByteItem*>& hoveredByteItem,
std::optional<AnnotationItem*>& hoveredAnnotationItem, std::optional<AnnotationItem*>& hoveredAnnotationItem,
const HexViewerWidgetSettings& settings const HexViewerWidgetSettings& settings
@@ -66,5 +67,6 @@ namespace Bloom::Widgets
std::optional<ByteItem*>& hoveredByteItem; std::optional<ByteItem*>& hoveredByteItem;
std::optional<AnnotationItem*>& hoveredAnnotationItem; std::optional<AnnotationItem*>& hoveredAnnotationItem;
std::optional<std::uint32_t>& currentStackPointer;
}; };
} }

View File

@@ -3,7 +3,6 @@
#include <cmath> #include <cmath>
using namespace Bloom::Widgets; using namespace Bloom::Widgets;
using namespace Bloom::Exceptions;
using Bloom::Targets::TargetMemoryDescriptor; using Bloom::Targets::TargetMemoryDescriptor;
@@ -36,7 +35,15 @@ ByteItemGraphicsScene::ByteItemGraphicsScene(
for (std::uint32_t i = 0; i < memorySize; i++) { for (std::uint32_t i = 0; i < memorySize; i++) {
const auto address = startAddress + i; const auto address = startAddress + i;
auto* byteWidget = new ByteItem(i, address, this->hoveredByteWidget, this->hoveredAnnotationItem, settings); auto* byteWidget = new ByteItem(
i,
address,
this->currentStackPointer,
this->hoveredByteWidget,
this->hoveredAnnotationItem,
settings
);
this->byteItemsByAddress.insert(std::pair( this->byteItemsByAddress.insert(std::pair(
address, address,
byteWidget byteWidget
@@ -65,6 +72,11 @@ void ByteItemGraphicsScene::updateValues(const Targets::TargetMemoryBuffer& buff
this->lastValueBuffer = buffer; this->lastValueBuffer = buffer;
} }
void ByteItemGraphicsScene::updateStackPointer(std::uint32_t stackPointer) {
this->currentStackPointer = stackPointer;
this->invalidateChildItemCaches();
}
void ByteItemGraphicsScene::refreshRegions() { void ByteItemGraphicsScene::refreshRegions() {
for (auto& [byteAddress, byteWidget] : this->byteItemsByAddress) { for (auto& [byteAddress, byteWidget] : this->byteItemsByAddress) {
byteWidget->focusedMemoryRegion = nullptr; byteWidget->focusedMemoryRegion = nullptr;

View File

@@ -52,6 +52,7 @@ namespace Bloom::Widgets
); );
void updateValues(const Targets::TargetMemoryBuffer& buffer); void updateValues(const Targets::TargetMemoryBuffer& buffer);
void updateStackPointer(std::uint32_t stackPointer);
void refreshRegions(); void refreshRegions();
void adjustSize(bool forced = false); void adjustSize(bool forced = false);
void setEnabled(bool enabled); void setEnabled(bool enabled);
@@ -69,6 +70,8 @@ namespace Bloom::Widgets
std::vector<FocusedMemoryRegion>& focusedMemoryRegions; std::vector<FocusedMemoryRegion>& focusedMemoryRegions;
std::vector<ExcludedMemoryRegion>& excludedMemoryRegions; std::vector<ExcludedMemoryRegion>& excludedMemoryRegions;
std::optional<std::uint32_t> currentStackPointer;
Targets::TargetMemoryBuffer lastValueBuffer; Targets::TargetMemoryBuffer lastValueBuffer;
std::map<std::uint32_t, ByteItem*> byteItemsByAddress; std::map<std::uint32_t, ByteItem*> byteItemsByAddress;

View File

@@ -124,8 +124,7 @@ void HexViewerWidget::refreshRegions() {
} }
void HexViewerWidget::setStackPointer(std::uint32_t stackPointer) { void HexViewerWidget::setStackPointer(std::uint32_t stackPointer) {
this->settings.stackPointerAddress = stackPointer; this->byteItemGraphicsScene->updateStackPointer(stackPointer);
this->byteItemGraphicsScene->invalidateChildItemCaches();
} }
void HexViewerWidget::resizeEvent(QResizeEvent* event) { void HexViewerWidget::resizeEvent(QResizeEvent* event) {

View File

@@ -1,17 +1,12 @@
#pragma once #pragma once
#include <cstdint>
#include <optional>
namespace Bloom::Widgets namespace Bloom::Widgets
{ {
struct HexViewerWidgetSettings struct HexViewerWidgetSettings
{ {
bool highlightStackMemory = false; bool highlightStackMemory = false;
std::optional<std::uint32_t> stackPointerAddress;
bool highlightHoveredRowAndCol = false;
bool highlightFocusedMemory = false; bool highlightFocusedMemory = false;
bool highlightHoveredRowAndCol = false;
bool displayAsciiValues = false; bool displayAsciiValues = false;
}; };
} }