Qt: Expand palette view to GB

This commit is contained in:
Jeffrey Pfau 2016-08-28 02:05:26 -07:00
parent 68859f9fd8
commit e318d61a06
4 changed files with 108 additions and 19 deletions

View File

@ -14,7 +14,12 @@
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 @@ PaletteView::PaletteView(GameController* controller, QWidget* parent)
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 @@ PaletteView::PaletteView(GameController* controller, QWidget* parent)
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);

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>440</width>
<width>443</width>
<height>397</height>
</rect>
</property>
@ -24,6 +24,12 @@
<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>
@ -52,11 +58,11 @@
</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>
@ -68,6 +74,12 @@
<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>
@ -96,11 +108,11 @@
</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 @@
<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>
@ -121,6 +139,12 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
@ -284,6 +308,12 @@
<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 @@
<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>
@ -312,6 +348,12 @@
<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>

View File

@ -34,6 +34,7 @@ void Swatch::setDimensions(const QSize& size) {
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) {

View File

@ -1329,7 +1329,6 @@ void Window::setupMenu(QMenuBar* menubar) {
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);