Qt: Show list of all sprites in sprite view
Vicki Pfau vi@endrift.com
Thu, 03 Oct 2019 20:31:24 -0700
4 files changed,
123 insertions(+),
43 deletions(-)
M
CHANGES
→
CHANGES
@@ -82,6 +82,7 @@ - Qt: Remove What's This icon from dialogs
- CMake: Don't use libzip on embedded platforms (fixes mgba.io/i/1527) - Qt: Printer quality of life improvements (fixes mgba.io/i/1540) - Qt: Add copy and QoL improvements to graphic views (closes mgba.io/i/1541) + - Qt: Show list of all sprites in sprite view 0.7.3: (2019-09-15) Emulation fixes:
M
src/platform/qt/ObjView.cpp
→
src/platform/qt/ObjView.cpp
@@ -11,6 +11,7 @@
#include <QAction> #include <QClipboard> #include <QFontDatabase> +#include <QListWidgetItem> #include <QTimer> #include "LogController.h"@@ -56,6 +57,13 @@ });
connect(m_ui.exportButton, &QAbstractButton::clicked, this, &ObjView::exportObj); connect(m_ui.copyButton, &QAbstractButton::clicked, this, &ObjView::copyObj); + connect(m_ui.objList, &QListWidget::currentItemChanged, [this]() { + QListWidgetItem* item = m_ui.objList->currentItem(); + if (item) { + selectObj(item->data(Qt::UserRole).toInt()); + } + }); + QAction* exportAction = new QAction(this); exportAction->setShortcut(QKeySequence::Save); connect(exportAction, &QAction::triggered, this, &ObjView::exportObj);@@ -69,6 +77,14 @@ }
void ObjView::selectObj(int obj) { m_objId = obj; + bool blocked = m_ui.objId->blockSignals(true); + m_ui.objId->setValue(m_objId); + m_ui.objId->blockSignals(blocked); + if (m_objs.size() > obj) { + blocked = m_ui.objList->blockSignals(true); + m_ui.objList->setCurrentItem(m_objs[obj]); + m_ui.objList->blockSignals(blocked); + } updateTiles(true); }@@ -83,6 +99,8 @@ void ObjView::updateTilesGBA(bool force) {
m_ui.objId->setMaximum(127); const GBA* gba = static_cast<const GBA*>(m_controller->thread()->core->board); const GBAObj* obj = &gba->video.oam.obj[m_objId]; + + updateObjList(128); ObjInfo newInfo; lookupObj(m_objId, &newInfo);@@ -165,6 +183,8 @@ void ObjView::updateTilesGB(bool force) {
m_ui.objId->setMaximum(39); const GB* gb = static_cast<const GB*>(m_controller->thread()->core->board); const GBObj* obj = &gb->video.oam.obj[m_objId]; + + updateObjList(40); ObjInfo newInfo; lookupObj(m_objId, &newInfo);@@ -212,6 +232,26 @@ m_ui.transform->setText(tr("N/A"));
m_ui.mode->setText(tr("N/A")); } #endif + +void ObjView::updateObjList(int maxObj) { + for (int i = 0; i < maxObj; ++i) { + if (m_objs.size() <= i) { + QListWidgetItem* item = new QListWidgetItem; + item->setText(QString::number(i)); + item->setData(Qt::UserRole, i); + item->setSizeHint(QSize(64, 96)); + if (m_objId == i) { + item->setSelected(true); + } + m_objs.append(item); + m_ui.objList->addItem(item); + } + QListWidgetItem* item = m_objs[i]; + ObjInfo info; + lookupObj(i, &info); + item->setIcon(QPixmap::fromImage(std::move(compositeObj(info)))); + } +} void ObjView::exportObj() { QString filename = GBAApp::app()->getSaveFileName(this, tr("Export sprite"),
M
src/platform/qt/ObjView.h
→
src/platform/qt/ObjView.h
@@ -9,7 +9,11 @@ #include "AssetView.h"
#include "ui_ObjView.h" +#include <QList> + #include <mgba/core/tile-cache.h> + +class QListWidgetItem; namespace QGBA {@@ -37,12 +41,16 @@ #ifdef M_CORE_GB
void updateTilesGB(bool force) override; #endif + void updateObjList(int maxObj); + Ui::ObjView m_ui; std::shared_ptr<CoreController> m_controller; mTileCacheEntry m_tileStatus[1024 * 32] = {}; // TODO: Correct size int m_objId = 0; ObjInfo m_objInfo = {}; + + QList<QListWidgetItem*> m_objs; int m_tileOffset; int m_boundary;
M
src/platform/qt/ObjView.ui
→
src/platform/qt/ObjView.ui
@@ -6,14 +6,21 @@ <property name="geometry">
<rect> <x>0</x> <y>0</y> - <width>641</width> - <height>470</height> + <width>800</width> + <height>730</height> </rect> </property> <property name="windowTitle"> <string>Sprites</string> </property> - <layout class="QGridLayout" name="gridLayout" columnstretch="0,0,1,1"> + <layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0,1" columnstretch="0,0,1,1"> + <item row="4" column="3"> + <widget class="QPushButton" name="copyButton"> + <property name="text"> + <string>Copy</string> + </property> + </widget> + </item> <item row="2" column="0"> <widget class="QGroupBox" name="groupBox"> <property name="title">@@ -151,6 +158,43 @@ </property>
</widget> </item> </layout> + </item> + </layout> + </widget> + </item> + <item row="0" column="2" rowspan="4" colspan="2"> + <widget class="QFrame" name="frame"> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item row="0" column="0" alignment="Qt::AlignHCenter|Qt::AlignVCenter"> + <widget class="QGBA::TilePainter" name="tiles" native="true"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>8</width> + <height>8</height> + </size> + </property> + </widget> </item> </layout> </widget>@@ -540,48 +584,35 @@ </widget>
</item> </layout> </item> - <item row="4" column="3"> - <widget class="QPushButton" name="copyButton"> - <property name="text"> - <string>Copy</string> + <item row="5" column="0" colspan="4"> + <widget class="QListWidget" name="objList"> + <property name="iconSize"> + <size> + <width>64</width> + <height>64</height> + </size> + </property> + <property name="flow"> + <enum>QListView::LeftToRight</enum> </property> - </widget> - </item> - <item row="0" column="2" rowspan="4" colspan="2"> - <widget class="QFrame" name="frame"> - <property name="frameShape"> - <enum>QFrame::StyledPanel</enum> + <property name="resizeMode"> + <enum>QListView::Adjust</enum> + </property> + <property name="gridSize"> + <size> + <width>64</width> + <height>96</height> + </size> + </property> + <property name="viewMode"> + <enum>QListView::IconMode</enum> + </property> + <property name="uniformItemSizes"> + <bool>true</bool> + </property> + <property name="itemAlignment"> + <set>Qt::AlignBottom|Qt::AlignHCenter</set> </property> - <layout class="QGridLayout" name="gridLayout_2"> - <property name="leftMargin"> - <number>0</number> - </property> - <property name="topMargin"> - <number>0</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> - <item row="0" column="0" alignment="Qt::AlignHCenter|Qt::AlignVCenter"> - <widget class="QGBA::TilePainter" name="tiles" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>8</width> - <height>8</height> - </size> - </property> - </widget> - </item> - </layout> </widget> </item> </layout>