diff --git a/src/platform/qt/TilePainter.cpp b/src/platform/qt/TilePainter.cpp index e78dd95c1..29b99df2f 100644 --- a/src/platform/qt/TilePainter.cpp +++ b/src/platform/qt/TilePainter.cpp @@ -13,10 +13,12 @@ using namespace QGBA; TilePainter::TilePainter(QWidget* parent) : QWidget(parent) + , m_size(8) { m_backing = QPixmap(256, 768); m_backing.fill(Qt::transparent); resize(256, 768); + setTileCount(3072); } void TilePainter::paintEvent(QPaintEvent* event) { @@ -25,30 +27,37 @@ void TilePainter::paintEvent(QPaintEvent* event) { } void TilePainter::resizeEvent(QResizeEvent* event) { - if (width() / 8 != m_backing.width() / 8) { - m_backing = QPixmap(width(), (3072 * 8) / (width() / 8)); + int calculatedHeight = (m_tileCount * m_size) / (width() / m_size) + m_size / 2; + if (width() / m_size != m_backing.width() / m_size || m_backing.height() != calculatedHeight) { + m_backing = QPixmap(width(), calculatedHeight); m_backing.fill(Qt::transparent); } } void TilePainter::mousePressEvent(QMouseEvent* event) { - int x = event->x() / 8; - int y = event->y() / 8; - emit indexPressed(y * (width() / 8) + x); + int x = event->x() / m_size; + int y = event->y() / m_size; + emit indexPressed(y * (width() / m_size) + x); } void TilePainter::setTile(int index, const uint16_t* data) { QPainter painter(&m_backing); - int w = width() / 8; + int w = width() / m_size; int x = index % w; int y = index / w; - QRect r(x * 8, y * 8, 8, 8); + QRect r(x * m_size, y * m_size, m_size, m_size); QImage tile(reinterpret_cast(data), 8, 8, QImage::Format_RGB555); - painter.fillRect(r, tile.rgbSwapped()); + painter.drawImage(r, tile.rgbSwapped()); update(r); } void TilePainter::setTileCount(int tiles) { - setMinimumSize(16, (tiles * 8) / (width() / 8)); + m_tileCount = tiles; + setMinimumSize(16, (tiles * m_size) / (width() / m_size)); resizeEvent(nullptr); } + +void TilePainter::setTileMagnification(int mag) { + m_size = mag * 8; + setTileCount(m_tileCount); +} diff --git a/src/platform/qt/TilePainter.h b/src/platform/qt/TilePainter.h index 8786aa206..1c61c5e97 100644 --- a/src/platform/qt/TilePainter.h +++ b/src/platform/qt/TilePainter.h @@ -21,6 +21,7 @@ public: public slots: void setTile(int index, const uint16_t*); void setTileCount(int tiles); + void setTileMagnification(int mag); signals: void indexPressed(int index); @@ -32,6 +33,8 @@ protected: private: QPixmap m_backing; + int m_size; + int m_tileCount; }; } diff --git a/src/platform/qt/TileView.cpp b/src/platform/qt/TileView.cpp index 8d74b8de0..599f23430 100644 --- a/src/platform/qt/TileView.cpp +++ b/src/platform/qt/TileView.cpp @@ -26,7 +26,7 @@ TileView::TileView(GameController* controller, QWidget* parent) m_ui.preview->setDimensions(QSize(8, 8)); m_updateTimer.setSingleShot(true); - m_updateTimer.setInterval(10); + m_updateTimer.setInterval(1); connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTiles())); const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); @@ -38,7 +38,12 @@ TileView::TileView(GameController* controller, QWidget* parent) connect(m_controller, SIGNAL(gameStopped(mCoreThread*)), this, SLOT(close())); connect(m_ui.tiles, SIGNAL(indexPressed(int)), this, SLOT(selectIndex(int))); connect(m_ui.paletteId, SIGNAL(valueChanged(int)), this, SLOT(updatePalette(int))); - connect(m_ui.palette256, SIGNAL(toggled(bool)), this, SLOT(updateTiles())); + connect(m_ui.palette256, &QAbstractButton::toggled, [this]() { + updateTiles(true); + }); + connect(m_ui.magnification, static_cast(&QSpinBox::valueChanged), [this]() { + updateTiles(true); + }); } TileView::~TileView() { @@ -131,5 +136,5 @@ void TileView::resizeEvent(QResizeEvent*) { } void TileView::showEvent(QShowEvent*) { - m_updateTimer.start(); + updateTiles(true); } diff --git a/src/platform/qt/TileView.ui b/src/platform/qt/TileView.ui index 87aa22833..fd4b88108 100644 --- a/src/platform/qt/TileView.ui +++ b/src/platform/qt/TileView.ui @@ -21,7 +21,7 @@ - + @@ -116,7 +116,7 @@ - + Qt::Vertical @@ -129,7 +129,7 @@ - + @@ -145,7 +145,7 @@ 0 0 - 271 + 290 768 @@ -185,6 +185,36 @@ + + + + + + + 0 + 0 + + + + × + + + 1 + + + 4 + + + + + + + Magnification + + + + + @@ -193,6 +223,9 @@ QWidget
TilePainter.h
1 + + setTileMagnification(int) + QGBA::Swatch @@ -219,5 +252,21 @@ + + magnification + valueChanged(int) + tiles + setTileMagnification(int) + + + 36 + 83 + + + 339 + 396 + + +