mirror of https://github.com/mgba-emu/mgba.git
Qt: MemoryModel scrolling
This commit is contained in:
parent
0bc9d18bc7
commit
e3cc98e034
|
@ -11,6 +11,7 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
|
#include <QWheelEvent>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "gba/memory.h"
|
#include "gba/memory.h"
|
||||||
|
@ -33,9 +34,10 @@ MemoryModel::MemoryModel(QWidget* parent)
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||||
m_margins = QMargins(metrics.width("FFFFFF ") + 3, m_cellHeight + 1, metrics.width(" AAAAAAAAAAAAAAAA") + 3, 0);
|
m_margins = QMargins(metrics.width("FFFFFF ") + 3, m_cellHeight + 1, metrics.width(" AAAAAAAAAAAAAAAA") + 3, 0);
|
||||||
|
|
||||||
verticalScrollBar()->setRange(0, 0x01000000 - viewport()->size().height() / m_cellHeight);
|
verticalScrollBar()->setRange(0, 0x01000001 - viewport()->size().height() / m_cellHeight);
|
||||||
connect(verticalScrollBar(), &QSlider::sliderMoved, [this](int position) {
|
connect(verticalScrollBar(), &QSlider::sliderMoved, [this](int position) {
|
||||||
m_top = position;
|
m_top = position;
|
||||||
|
update();
|
||||||
});
|
});
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -45,7 +47,8 @@ void MemoryModel::setController(GameController* controller) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryModel::resizeEvent(QResizeEvent*) {
|
void MemoryModel::resizeEvent(QResizeEvent*) {
|
||||||
verticalScrollBar()->setRange(0, 0x01000000 - viewport()->size().height() / m_cellHeight);
|
verticalScrollBar()->setRange(0, 0x01000001 - viewport()->size().height() / m_cellHeight);
|
||||||
|
boundsCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryModel::paintEvent(QPaintEvent* event) {
|
void MemoryModel::paintEvent(QPaintEvent* event) {
|
||||||
|
@ -59,7 +62,7 @@ void MemoryModel::paintEvent(QPaintEvent* event) {
|
||||||
for (int x = 0; x < 16; ++x) {
|
for (int x = 0; x < 16; ++x) {
|
||||||
painter.drawText(QRectF(QPointF(cellSize.width() * x + m_margins.left(), 0), cellSize), Qt::AlignHCenter, QString::number(x, 16).toUpper());
|
painter.drawText(QRectF(QPointF(cellSize.width() * x + m_margins.left(), 0), cellSize), Qt::AlignHCenter, QString::number(x, 16).toUpper());
|
||||||
}
|
}
|
||||||
int height = (viewport()->size().height() - m_cellHeight + 1) / m_cellHeight;
|
int height = (viewport()->size().height() - m_cellHeight) / m_cellHeight;
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
int yp = m_cellHeight * y + m_margins.top();
|
int yp = m_cellHeight * y + m_margins.top();
|
||||||
QString data = QString("%0").arg(y + m_top, 6, 16, c0).toUpper();
|
QString data = QString("%0").arg(y + m_top, 6, 16, c0).toUpper();
|
||||||
|
@ -79,3 +82,19 @@ void MemoryModel::paintEvent(QPaintEvent* event) {
|
||||||
painter.drawLine(viewport()->size().width() - m_margins.right(), 0, viewport()->size().width() - m_margins.right(), viewport()->size().height());
|
painter.drawLine(viewport()->size().width() - m_margins.right(), 0, viewport()->size().width() - m_margins.right(), viewport()->size().height());
|
||||||
painter.drawLine(0, m_margins.top(), viewport()->size().width(), m_margins.top());
|
painter.drawLine(0, m_margins.top(), viewport()->size().width(), m_margins.top());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MemoryModel::wheelEvent(QWheelEvent* event) {
|
||||||
|
m_top -= event->angleDelta().y() / 8;
|
||||||
|
boundsCheck();
|
||||||
|
event->accept();
|
||||||
|
update();
|
||||||
|
QAbstractScrollArea::wheelEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MemoryModel::boundsCheck() {
|
||||||
|
if (m_top < 0) {
|
||||||
|
m_top = 0;
|
||||||
|
} else if (m_top > 0x01000001 - viewport()->size().height() / m_cellHeight) {
|
||||||
|
m_top = 0x01000001 - viewport()->size().height() / m_cellHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ protected:
|
||||||
void wheelEvent(QWheelEvent*) override;
|
void wheelEvent(QWheelEvent*) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void boundsCheck();
|
||||||
|
|
||||||
ARMCore* m_cpu;
|
ARMCore* m_cpu;
|
||||||
QFont m_font;
|
QFont m_font;
|
||||||
int m_cellHeight;
|
int m_cellHeight;
|
||||||
|
|
Loading…
Reference in New Issue