mirror of https://github.com/mgba-emu/mgba.git
Qt: Memory view alignment adjustment
This commit is contained in:
parent
7ac49be6df
commit
28f174fb66
|
@ -23,6 +23,7 @@ MemoryModel::MemoryModel(QWidget* parent)
|
|||
: QAbstractScrollArea(parent)
|
||||
, m_cpu(nullptr)
|
||||
, m_top(0)
|
||||
, m_align(1)
|
||||
{
|
||||
m_font.setFamily("Source Code Pro");
|
||||
m_font.setStyleHint(QFont::Monospace);
|
||||
|
@ -74,6 +75,14 @@ void MemoryModel::setRegion(uint32_t base, uint32_t size, const QString& name) {
|
|||
viewport()->update();
|
||||
}
|
||||
|
||||
void MemoryModel::setAlignment(int width) {
|
||||
if (width != 1 && width != 2 && width != 4) {
|
||||
return;
|
||||
}
|
||||
m_align = width;
|
||||
viewport()->update();
|
||||
}
|
||||
|
||||
void MemoryModel::resizeEvent(QResizeEvent*) {
|
||||
verticalScrollBar()->setRange(0, (m_size >> 4) + 1 - viewport()->size().height() / m_cellHeight);
|
||||
boundsCheck();
|
||||
|
@ -95,9 +104,33 @@ void MemoryModel::paintEvent(QPaintEvent* event) {
|
|||
int yp = m_cellHeight * y + m_margins.top();
|
||||
QString data = QString("%0").arg((y + m_top) * 16 + m_base, 8, 16, c0).toUpper();
|
||||
painter.drawText(QRectF(QPointF(0, yp), QSizeF(m_margins.left(), m_cellHeight)), Qt::AlignHCenter, data);
|
||||
switch (m_align) {
|
||||
case 2:
|
||||
for (int x = 0; x < 16; x += 2) {
|
||||
uint16_t b = m_cpu->memory.load16(m_cpu, (y + m_top) * 16 + x + m_base, nullptr);
|
||||
painter.drawStaticText(QPointF(cellSize.width() * (x + 1.0) - 2 * m_letterWidth + m_margins.left(), yp), m_staticNumbers[(b >> 8) & 0xFF]);
|
||||
painter.drawStaticText(QPointF(cellSize.width() * (x + 1.0) + m_margins.left(), yp), m_staticNumbers[b & 0xFF]);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
for (int x = 0; x < 16; x += 4) {
|
||||
uint32_t b = m_cpu->memory.load32(m_cpu, (y + m_top) * 16 + x + m_base, nullptr);
|
||||
painter.drawStaticText(QPointF(cellSize.width() * (x + 2.0) - 4 * m_letterWidth + m_margins.left(), yp), m_staticNumbers[(b >> 24) & 0xFF]);
|
||||
painter.drawStaticText(QPointF(cellSize.width() * (x + 2.0) - 2 * m_letterWidth + m_margins.left(), yp), m_staticNumbers[(b >> 16) & 0xFF]);
|
||||
painter.drawStaticText(QPointF(cellSize.width() * (x + 2.0) + m_margins.left(), yp), m_staticNumbers[(b >> 8) & 0xFF]);
|
||||
painter.drawStaticText(QPointF(cellSize.width() * (x + 2.0) + 2 * m_letterWidth + m_margins.left(), yp), m_staticNumbers[b & 0xFF]);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
for (int x = 0; x < 16; ++x) {
|
||||
uint8_t b = m_cpu->memory.load8(m_cpu, (y + m_top) * 16 + x + m_base, nullptr);
|
||||
painter.drawStaticText(QPointF(cellSize.width() * (x + 0.5) - m_letterWidth + m_margins.left(), yp), m_staticNumbers[b]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
for (int x = 0; x < 16; ++x) {
|
||||
uint8_t b = m_cpu->memory.load8(m_cpu, (y + m_top) * 16 + x + m_base, nullptr);
|
||||
painter.drawStaticText(QPointF(cellSize.width() * (x + 0.5) - m_letterWidth + m_margins.left(), yp), m_staticNumbers[b]);
|
||||
painter.drawStaticText(QPointF(viewport()->size().width() - (16 - x) * m_margins.right() / 17.0 - m_letterWidth * 0.5, yp), b < 0x80 ? m_staticAscii[b] : m_staticAscii[0]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ public:
|
|||
void setController(GameController* controller);
|
||||
|
||||
void setRegion(uint32_t base, uint32_t size, const QString& name = QString());
|
||||
void setAlignment(int);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent*) override;
|
||||
|
@ -43,6 +44,7 @@ private:
|
|||
uint32_t m_base;
|
||||
uint32_t m_size;
|
||||
int m_top;
|
||||
int m_align;
|
||||
QMargins m_margins;
|
||||
QVector<QStaticText> m_staticNumbers;
|
||||
QVector<QStaticText> m_staticAscii;
|
||||
|
|
|
@ -24,6 +24,10 @@ MemoryView::MemoryView(GameController* controller, QWidget* parent)
|
|||
|
||||
connect(m_ui.regions, SIGNAL(currentIndexChanged(int)), this, SLOT(setIndex(int)));
|
||||
|
||||
connect(m_ui.width8, &QAbstractButton::clicked, [this]() { m_ui.hexfield->setAlignment(1); });
|
||||
connect(m_ui.width16, &QAbstractButton::clicked, [this]() { m_ui.hexfield->setAlignment(2); });
|
||||
connect(m_ui.width32, &QAbstractButton::clicked, [this]() { m_ui.hexfield->setAlignment(4); });
|
||||
|
||||
connect(controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(close()));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>527</width>
|
||||
<height>544</height>
|
||||
<width>550</width>
|
||||
<height>610</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -85,12 +85,6 @@
|
|||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -112,6 +106,69 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Set Alignment:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="width8">
|
||||
<property name="text">
|
||||
<string>1 Byte</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="width16">
|
||||
<property name="text">
|
||||
<string>2 Bytes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="width32">
|
||||
<property name="text">
|
||||
<string>4 Bytes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGBA::MemoryModel" name="hexfield" native="true">
|
||||
<property name="sizePolicy">
|
||||
|
|
Loading…
Reference in New Issue