From 524e94edbf4360c5a12f8b189fa60fd7f6c80cdc Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Thu, 20 Oct 2016 17:36:09 -0700 Subject: [PATCH] Qt: Refactor tile viewer into its own class --- src/platform/qt/AssetTile.cpp | 94 ++++++++++++++++++++++ src/platform/qt/AssetTile.h | 46 +++++++++++ src/platform/qt/AssetTile.ui | 96 ++++++++++++++++++++++ src/platform/qt/CMakeLists.txt | 2 + src/platform/qt/TileView.cpp | 78 ++++++++++-------- src/platform/qt/TileView.h | 3 - src/platform/qt/TileView.ui | 142 +++++++++------------------------ 7 files changed, 320 insertions(+), 141 deletions(-) create mode 100644 src/platform/qt/AssetTile.cpp create mode 100644 src/platform/qt/AssetTile.h create mode 100644 src/platform/qt/AssetTile.ui diff --git a/src/platform/qt/AssetTile.cpp b/src/platform/qt/AssetTile.cpp new file mode 100644 index 000000000..77bc52eb5 --- /dev/null +++ b/src/platform/qt/AssetTile.cpp @@ -0,0 +1,94 @@ +/* Copyright (c) 2013-2016 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "AssetTile.h" + +#include "GBAApp.h" + +#include + +extern "C" { +#ifdef M_CORE_GBA +#include "gba/memory.h" +#endif +#ifdef M_CORE_GB +#include "gb/memory.h" +#endif +} + +using namespace QGBA; + +AssetTile::AssetTile(QWidget* parent) + : QGroupBox(parent) + , m_tileCache(nullptr) + , m_paletteId(0) + , m_paletteSet(0) + , m_index(0) +{ + m_ui.setupUi(this); + + m_ui.preview->setDimensions(QSize(8, 8)); + + const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); + + m_ui.tileId->setFont(font); + m_ui.address->setFont(font); +} + +void AssetTile::setController(GameController* controller) { + m_tileCache = controller->tileCache(); + switch (controller->platform()) { +#ifdef M_CORE_GBA + case PLATFORM_GBA: + m_addressWidth = 8; + m_addressBase = BASE_VRAM; + break; +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: + m_addressWidth = 4; + m_addressBase = GB_BASE_VRAM; + break; +#endif + default: + m_addressWidth = 0; + m_addressBase = 0; + break; + } +} + +void AssetTile::setPalette(int palette) { + m_paletteId = palette; + selectIndex(m_index); +} + +void AssetTile::setPaletteSet(int palette, int boundary, int max) { + if (m_index >= max) { + m_index = max - 1; + } + m_boundary = boundary; + m_paletteSet = palette; + selectIndex(m_index); +} + +void AssetTile::selectIndex(int index) { + m_index = index; + const uint16_t* data; + m_ui.tileId->setText(QString::number(index)); + + mTileCacheSetPalette(m_tileCache.get(), m_paletteSet); + unsigned bpp = 8 << m_tileCache->bpp; + m_ui.address->setText(tr("0x%0").arg(index * bpp | m_addressBase, m_addressWidth, 16, QChar('0'))); + if (index < m_boundary) { + data = mTileCacheGetTile(m_tileCache.get(), index, m_paletteId); + } else { + data = mTileCacheGetTile(m_tileCache.get(), index, m_paletteId + m_tileCache->count / 2); + } + for (int i = 0; i < 64; ++i) { + m_ui.preview->setColor(i, data[i]); + } + m_ui.preview->update(); +} + diff --git a/src/platform/qt/AssetTile.h b/src/platform/qt/AssetTile.h new file mode 100644 index 000000000..e0fc01f88 --- /dev/null +++ b/src/platform/qt/AssetTile.h @@ -0,0 +1,46 @@ +/* Copyright (c) 2013-2016 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef QGBA_ASSET_TILE +#define QGBA_ASSET_TILE + +#include "GameController.h" + +#include "ui_AssetTile.h" + +extern "C" { +#include "core/tile-cache.h" +} + +namespace QGBA { + +class AssetTile : public QGroupBox { +Q_OBJECT + +public: + AssetTile(QWidget* parent = nullptr); + void setController(GameController*); + +public slots: + void setPalette(int); + void setPaletteSet(int, int boundary, int max); + void selectIndex(int); + +private: + Ui::AssetTile m_ui; + + std::shared_ptr m_tileCache; + int m_paletteId; + int m_paletteSet; + int m_index; + + int m_addressWidth; + int m_addressBase; + int m_boundary; +}; + +} + +#endif diff --git a/src/platform/qt/AssetTile.ui b/src/platform/qt/AssetTile.ui new file mode 100644 index 000000000..dadc7080a --- /dev/null +++ b/src/platform/qt/AssetTile.ui @@ -0,0 +1,96 @@ + + + AssetTile + + + + 120 + 50 + 160 + 168 + + + + AssetTile + + + + 0 + 0 + + + + + 170 + 192 + + + + + + + + + + + 87 + 87 + + + + + + + + + + Tile # + + + + + + + 0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + Address + + + + + + + 0x06000000 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + QGBA::Swatch + QWidget +
Swatch.h
+ 1 +
+
+ + +
diff --git a/src/platform/qt/CMakeLists.txt b/src/platform/qt/CMakeLists.txt index cb98d95e9..6a58a0f96 100644 --- a/src/platform/qt/CMakeLists.txt +++ b/src/platform/qt/CMakeLists.txt @@ -69,6 +69,7 @@ endif() set(SOURCE_FILES AboutScreen.cpp ArchiveInspector.cpp + AssetTile.cpp AudioProcessor.cpp CheatsModel.cpp CheatsView.cpp @@ -113,6 +114,7 @@ set(SOURCE_FILES set(UI_FILES AboutScreen.ui ArchiveInspector.ui + AssetTile.ui CheatsView.ui GIFView.ui IOViewer.ui diff --git a/src/platform/qt/TileView.cpp b/src/platform/qt/TileView.cpp index 974c94ba7..4cd382669 100644 --- a/src/platform/qt/TileView.cpp +++ b/src/platform/qt/TileView.cpp @@ -24,22 +24,59 @@ TileView::TileView(GameController* controller, QWidget* parent) , m_paletteId(0) { m_ui.setupUi(this); + m_ui.tile->setController(controller); - m_ui.preview->setDimensions(QSize(8, 8)); m_updateTimer.setSingleShot(true); m_updateTimer.setInterval(1); connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTiles())); - const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); - - m_ui.tileId->setFont(font); - m_ui.address->setFont(font); - connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), &m_updateTimer, SLOT(start())); connect(m_controller, SIGNAL(gameStopped(mCoreThread*)), this, SLOT(close())); - connect(m_ui.tiles, SIGNAL(indexPressed(int)), this, SLOT(selectIndex(int))); + connect(m_ui.tiles, SIGNAL(indexPressed(int)), m_ui.tile, SLOT(selectIndex(int))); connect(m_ui.paletteId, SIGNAL(valueChanged(int)), this, SLOT(updatePalette(int))); - connect(m_ui.palette256, &QAbstractButton::toggled, [this]() { + + int max = 1024; + int boundary = 1024; + switch (m_controller->platform()) { +#ifdef M_CORE_GBA + case PLATFORM_GBA: + max = 3072; + boundary = 2048; + break; +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: + max = 1024; + boundary = 1024; + m_ui.palette256->setEnabled(false); + break; +#endif + default: + return; + } + m_ui.tile->setPaletteSet(0, boundary, max); + + connect(m_ui.palette256, &QAbstractButton::toggled, [this](bool selected) { + if (selected) { + m_ui.paletteId->setValue(0); + } + int max = 1024; + int boundary = 1024; + switch (m_controller->platform()) { +#ifdef M_CORE_GBA + case PLATFORM_GBA: + max = 3072 >> selected; + boundary = 2048 >> selected; + break; +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: + return; +#endif + default: + break; + } + m_ui.tile->setPaletteSet(selected, boundary, max); updateTiles(true); }); connect(m_ui.magnification, static_cast(&QSpinBox::valueChanged), [this]() { @@ -47,30 +84,6 @@ TileView::TileView(GameController* controller, QWidget* parent) }); } -void TileView::selectIndex(int index) { - const uint16_t* data; - m_ui.tileId->setText(QString::number(index)); - if (m_ui.palette256->isChecked()) { - m_ui.address->setText(tr("0x%0").arg(index * 64 | BASE_VRAM, 8, 16, QChar('0'))); - if (index < 1024) { - data = mTileCacheGetTile(m_tileCache.get(), index, 0); - } else { - data = mTileCacheGetTile(m_tileCache.get(), index, 1); - } - } else { - m_ui.address->setText(tr("0x%0").arg(index * 32 | BASE_VRAM, 8, 16, QChar('0'))); - if (index < 2048) { - data = mTileCacheGetTile(m_tileCache.get(), index, m_paletteId); - } else { - data = mTileCacheGetTile(m_tileCache.get(), index, m_paletteId + 16); - } - } - for (int i = 0; i < 64; ++i) { - m_ui.preview->setColor(i, data[i]); - } - m_ui.preview->update(); -} - void TileView::updateTiles(bool force) { if (!m_controller->thread() || !m_controller->thread()->core) { return; @@ -153,6 +166,7 @@ void TileView::updateTilesGB(bool force) { void TileView::updatePalette(int palette) { m_paletteId = palette; + m_ui.tile->setPalette(palette); updateTiles(true); } diff --git a/src/platform/qt/TileView.h b/src/platform/qt/TileView.h index eafd9a291..8d20635ec 100644 --- a/src/platform/qt/TileView.h +++ b/src/platform/qt/TileView.h @@ -28,9 +28,6 @@ public slots: void updateTiles(bool force = false); void updatePalette(int); -private slots: - void selectIndex(int); - protected: void resizeEvent(QResizeEvent*) override; void showEvent(QShowEvent*) override; diff --git a/src/platform/qt/TileView.ui b/src/platform/qt/TileView.ui index fd4b88108..0763f96f8 100644 --- a/src/platform/qt/TileView.ui +++ b/src/platform/qt/TileView.ui @@ -21,79 +21,6 @@ - - - - - 0 - 0 - - - - - 170 - 192 - - - - - - - - - - - 87 - 87 - - - - - - - - - - Tile # - - - - - - - 0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - Address - - - - - - - 0x06000000 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - @@ -129,6 +56,36 @@ + + + + + + + 0 + 0 + + + + × + + + 1 + + + 4 + + + + + + + Magnification + + + + + @@ -145,7 +102,7 @@ 0 0 - 290 + 286 768 @@ -185,35 +142,8 @@ - - - - - - - 0 - 0 - - - - × - - - 1 - - - 4 - - - - - - - Magnification - - - - + + @@ -228,9 +158,9 @@ - QGBA::Swatch - QWidget -
Swatch.h
+ QGBA::AssetTile + QGroupBox +
AssetTile.h
1