Qt: Expand palette view to GB
Jeffrey Pfau jeffrey@endrift.com
Sun, 28 Aug 2016 02:05:26 -0700
4 files changed,
108 insertions(+),
19 deletions(-)
M
src/platform/qt/PaletteView.cpp
→
src/platform/qt/PaletteView.cpp
@@ -14,7 +14,12 @@ #include <QFontDatabase>
extern "C" { #include "core/core.h" +#ifdef M_CORE_GBA #include "gba/extra/export.h" +#endif +#ifdef M_CORE_GB +#include "gb/gb.h" +#endif #include "util/vfs.h" }@@ -29,6 +34,16 @@
connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(updatePalette())); m_ui.bgGrid->setDimensions(QSize(16, 16)); m_ui.objGrid->setDimensions(QSize(16, 16)); + int count = 256; +#ifdef M_CORE_GB + if (controller->platform() == PLATFORM_GB) { + m_ui.bgGrid->setDimensions(QSize(4, 8)); + m_ui.objGrid->setDimensions(QSize(4, 8)); + m_ui.bgGrid->setSize(24); + m_ui.objGrid->setSize(24); + count = 32; + } +#endif m_ui.selected->setSize(64); m_ui.selected->setDimensions(QSize(1, 1)); updatePalette();@@ -43,9 +58,9 @@ m_ui.g->setFont(font);
m_ui.b->setFont(font); connect(m_ui.bgGrid, SIGNAL(indexPressed(int)), this, SLOT(selectIndex(int))); - connect(m_ui.objGrid, &Swatch::indexPressed, [this] (int index) { selectIndex(index + 256); }); - connect(m_ui.exportBG, &QAbstractButton::clicked, [this] () { exportPalette(0, 256); }); - connect(m_ui.exportOBJ, &QAbstractButton::clicked, [this] () { exportPalette(256, 256); }); + connect(m_ui.objGrid, &Swatch::indexPressed, [this, count] (int index) { selectIndex(index + count); }); + connect(m_ui.exportBG, &QAbstractButton::clicked, [this, count] () { exportPalette(0, count); }); + connect(m_ui.exportOBJ, &QAbstractButton::clicked, [this, count] () { exportPalette(count, count); }); connect(controller, SIGNAL(gameStopped(mCoreThread*)), this, SLOT(close())); }@@ -54,17 +69,49 @@ void PaletteView::updatePalette() {
if (!m_controller->thread() || !m_controller->thread()->core) { return; } - const uint16_t* palette = static_cast<GBA*>(m_controller->thread()->core->board)->video.palette; - for (int i = 0; i < 256; ++i) { + const uint16_t* palette; + size_t count; + switch (m_controller->platform()) { +#ifdef M_CORE_GBA + case PLATFORM_GBA: + palette = static_cast<GBA*>(m_controller->thread()->core->board)->video.palette; + count = 256; + break; +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: + palette = static_cast<GB*>(m_controller->thread()->core->board)->video.palette; + count = 32; + break; +#endif + default: + return; + } + for (int i = 0; i < count; ++i) { m_ui.bgGrid->setColor(i, palette[i]); - m_ui.objGrid->setColor(i, palette[i + 256]); + m_ui.objGrid->setColor(i, palette[i + count]); } m_ui.bgGrid->update(); m_ui.objGrid->update(); } void PaletteView::selectIndex(int index) { - uint16_t color = static_cast<GBA*>(m_controller->thread()->core->board)->video.palette[index]; + const uint16_t* palette; + switch (m_controller->platform()) { +#ifdef M_CORE_GBA + case PLATFORM_GBA: + palette = static_cast<GBA*>(m_controller->thread()->core->board)->video.palette; + break; +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: + palette = static_cast<GB*>(m_controller->thread()->core->board)->video.palette; + break; +#endif + default: + return; + } + uint16_t color = palette[index]; m_ui.selected->setColor(0, color); uint32_t r = GBA_R5(color); uint32_t g = GBA_G5(color);
M
src/platform/qt/PaletteView.ui
→
src/platform/qt/PaletteView.ui
@@ -6,7 +6,7 @@ <property name="geometry">
<rect> <x>0</x> <y>0</y> - <width>440</width> + <width>443</width> <height>397</height> </rect> </property>@@ -23,6 +23,12 @@ <item>
<spacer name="horizontalSpacer_2"> <property name="orientation"> <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> </property> </spacer> </item>@@ -52,11 +58,11 @@ <number>0</number>
</property> <item> <widget class="QGBA::Swatch" name="bgGrid" native="true"> - <property name="minimumSize"> - <size> - <width>175</width> - <height>175</height> - </size> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> </property> </widget> </item>@@ -67,6 +73,12 @@ <item>
<spacer name="horizontalSpacer"> <property name="orientation"> <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> </property> </spacer> </item>@@ -96,11 +108,11 @@ <number>0</number>
</property> <item> <widget class="QGBA::Swatch" name="objGrid" native="true"> - <property name="minimumSize"> - <size> - <width>175</width> - <height>175</height> - </size> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> </property> </widget> </item>@@ -112,6 +124,12 @@ <spacer name="horizontalSpacer_3">
<property name="orientation"> <enum>Qt::Horizontal</enum> </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> </spacer> </item> </layout>@@ -120,6 +138,12 @@ <item>
<spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> </property> </spacer> </item>@@ -284,6 +308,12 @@ <spacer name="horizontalSpacer_4">
<property name="orientation"> <enum>Qt::Horizontal</enum> </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> </spacer> </item> <item>@@ -298,6 +328,12 @@ <spacer name="horizontalSpacer_5">
<property name="orientation"> <enum>Qt::Horizontal</enum> </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> </spacer> </item> <item>@@ -311,6 +347,12 @@ <item>
<spacer name="horizontalSpacer_6"> <property name="orientation"> <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> </property> </spacer> </item>
M
src/platform/qt/Swatch.cpp
→
src/platform/qt/Swatch.cpp
@@ -34,6 +34,7 @@ m_colors.resize(elem);
for (int i = 0; i < elem; ++i) { updateFill(i); } + setMinimumSize(size * (m_size + 1) - QSize(1, 1)); } void Swatch::setColor(int index, uint16_t color) {
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -1329,7 +1329,6 @@
QAction* paletteView = new QAction(tr("View &palette..."), toolsMenu); connect(paletteView, SIGNAL(triggered()), this, SLOT(openPaletteWindow())); m_gameActions.append(paletteView); - m_gbaActions.append(paletteView); addControlledAction(toolsMenu, paletteView, "paletteWindow"); QAction* tileView = new QAction(tr("View &tiles..."), toolsMenu);