Skip to content

Commit

Permalink
Qt/Debugger: Highlight selection on dump address
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Sep 9, 2024
1 parent c633a6b commit 936c945
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/duckstation-qt/debuggerwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ bool DebuggerWindow::scrollToMemoryAddress(VirtualMemoryAddress address)
setMemoryViewRegion(region.value());

const PhysicalMemoryAddress offset = phys_address - Bus::GetMemoryRegionStart(region.value());
m_ui.memoryView->scrolltoOffset(offset);
m_ui.memoryView->scrollToOffset(offset);
return true;
}

Expand Down
16 changes: 13 additions & 3 deletions src/duckstation-qt/memoryviewwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ void MemoryViewWidget::clearHighlightRange()
viewport()->update();
}

void MemoryViewWidget::scrolltoOffset(size_t offset)
void MemoryViewWidget::scrollToOffset(size_t offset, bool select /* = true */)
{
const unsigned row = static_cast<unsigned>(offset / m_bytes_per_line);
verticalScrollBar()->setSliderPosition(static_cast<int>(row));
horizontalScrollBar()->setSliderPosition(0);
if (select)
setSelection(offset, false);
}

void MemoryViewWidget::scrollToAddress(size_t address)
Expand Down Expand Up @@ -205,6 +207,7 @@ void MemoryViewWidget::paintEvent(QPaintEvent* event)
if (!m_data)
return;

const QColor alt_fill_color(40, 40, 40);
const QColor highlight_color(100, 100, 0);
const QColor selected_color = viewport()->palette().color(QPalette::Highlight);
const QColor text_color = viewport()->palette().color(QPalette::WindowText);
Expand All @@ -224,7 +227,9 @@ void MemoryViewWidget::paintEvent(QPaintEvent* event)
const size_t data_offset = m_start_offset + (row * m_bytes_per_line);
const unsigned row_address = static_cast<unsigned>(m_address_offset + data_offset);
const int draw_x = m_char_width / 2 - offsetX;
if (RangesOverlap(data_offset, data_offset + m_bytes_per_line, m_highlight_start, m_highlight_end))
if (RangesOverlap(data_offset, data_offset + m_bytes_per_line, m_selected_address, m_selected_address + 1))
painter.fillRect(0, y - m_char_height + 3, addressWidth(), m_char_height, selected_color);
else if (RangesOverlap(data_offset, data_offset + m_bytes_per_line, m_highlight_start, m_highlight_end))
painter.fillRect(0, y - m_char_height + 3, addressWidth(), m_char_height, highlight_color);

const QString address_text(QString::asprintf("%08X", row_address));
Expand All @@ -244,7 +249,7 @@ void MemoryViewWidget::paintEvent(QPaintEvent* event)
for (unsigned col = 0; col < m_bytes_per_line; col++)
{
if ((col % 2) != 0)
painter.fillRect(x, 0, HEX_CHAR_WIDTH, height(), viewport()->palette().color(QPalette::AlternateBase));
painter.fillRect(x, 0, HEX_CHAR_WIDTH, height(), alt_fill_color);

x += HEX_CHAR_WIDTH;
}
Expand Down Expand Up @@ -393,6 +398,11 @@ void MemoryViewWidget::updateSelectedByte(const QPoint& pos)
}
}

setSelection(new_selection, new_ascii);
}

void MemoryViewWidget::setSelection(size_t new_selection, bool new_ascii)
{
if (new_selection != m_selected_address || new_ascii != m_selection_was_ascii)
{
m_selected_address = new_selection;
Expand Down
3 changes: 2 additions & 1 deletion src/duckstation-qt/memoryviewwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MemoryViewWidget : public QAbstractScrollArea
void setData(size_t address_offset, void* data_ptr, size_t data_size, bool data_editable, EditCallback edit_callback);
void setHighlightRange(size_t start, size_t end);
void clearHighlightRange();
void scrolltoOffset(size_t offset);
void scrollToOffset(size_t offset, bool select = true);
void scrollToAddress(size_t address);
void setFont(const QFont& font);

Expand All @@ -49,6 +49,7 @@ private Q_SLOTS:
int asciiWidth() const;
void updateMetrics();
void updateSelectedByte(const QPoint& pos);
void setSelection(size_t new_selection, bool new_ascii);
void expandCurrentDataToInclude(size_t offset);

void* m_data;
Expand Down

0 comments on commit 936c945

Please sign in to comment.