mirror of https://github.com/mgba-emu/mgba.git
Qt: Expand palette view to GB
This commit is contained in:
parent
68859f9fd8
commit
e318d61a06
|
@ -14,7 +14,12 @@
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
|
#ifdef M_CORE_GBA
|
||||||
#include "gba/extra/export.h"
|
#include "gba/extra/export.h"
|
||||||
|
#endif
|
||||||
|
#ifdef M_CORE_GB
|
||||||
|
#include "gb/gb.h"
|
||||||
|
#endif
|
||||||
#include "util/vfs.h"
|
#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()));
|
connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(updatePalette()));
|
||||||
m_ui.bgGrid->setDimensions(QSize(16, 16));
|
m_ui.bgGrid->setDimensions(QSize(16, 16));
|
||||||
m_ui.objGrid->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->setSize(64);
|
||||||
m_ui.selected->setDimensions(QSize(1, 1));
|
m_ui.selected->setDimensions(QSize(1, 1));
|
||||||
updatePalette();
|
updatePalette();
|
||||||
|
@ -43,9 +58,9 @@ PaletteView::PaletteView(GameController* controller, QWidget* parent)
|
||||||
m_ui.b->setFont(font);
|
m_ui.b->setFont(font);
|
||||||
|
|
||||||
connect(m_ui.bgGrid, SIGNAL(indexPressed(int)), this, SLOT(selectIndex(int)));
|
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.objGrid, &Swatch::indexPressed, [this, count] (int index) { selectIndex(index + count); });
|
||||||
connect(m_ui.exportBG, &QAbstractButton::clicked, [this] () { exportPalette(0, 256); });
|
connect(m_ui.exportBG, &QAbstractButton::clicked, [this, count] () { exportPalette(0, count); });
|
||||||
connect(m_ui.exportOBJ, &QAbstractButton::clicked, [this] () { exportPalette(256, 256); });
|
connect(m_ui.exportOBJ, &QAbstractButton::clicked, [this, count] () { exportPalette(count, count); });
|
||||||
|
|
||||||
connect(controller, SIGNAL(gameStopped(mCoreThread*)), this, SLOT(close()));
|
connect(controller, SIGNAL(gameStopped(mCoreThread*)), this, SLOT(close()));
|
||||||
}
|
}
|
||||||
|
@ -54,17 +69,49 @@ void PaletteView::updatePalette() {
|
||||||
if (!m_controller->thread() || !m_controller->thread()->core) {
|
if (!m_controller->thread() || !m_controller->thread()->core) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const uint16_t* palette = static_cast<GBA*>(m_controller->thread()->core->board)->video.palette;
|
const uint16_t* palette;
|
||||||
for (int i = 0; i < 256; ++i) {
|
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.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.bgGrid->update();
|
||||||
m_ui.objGrid->update();
|
m_ui.objGrid->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaletteView::selectIndex(int index) {
|
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);
|
m_ui.selected->setColor(0, color);
|
||||||
uint32_t r = GBA_R5(color);
|
uint32_t r = GBA_R5(color);
|
||||||
uint32_t g = GBA_G5(color);
|
uint32_t g = GBA_G5(color);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>440</width>
|
<width>443</width>
|
||||||
<height>397</height>
|
<height>397</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -24,6 +24,12 @@
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -52,11 +58,11 @@
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGBA::Swatch" name="bgGrid" native="true">
|
<widget class="QGBA::Swatch" name="bgGrid" native="true">
|
||||||
<property name="minimumSize">
|
<property name="sizePolicy">
|
||||||
<size>
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||||
<width>175</width>
|
<horstretch>0</horstretch>
|
||||||
<height>175</height>
|
<verstretch>0</verstretch>
|
||||||
</size>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -68,6 +74,12 @@
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -96,11 +108,11 @@
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGBA::Swatch" name="objGrid" native="true">
|
<widget class="QGBA::Swatch" name="objGrid" native="true">
|
||||||
<property name="minimumSize">
|
<property name="sizePolicy">
|
||||||
<size>
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||||
<width>175</width>
|
<horstretch>0</horstretch>
|
||||||
<height>175</height>
|
<verstretch>0</verstretch>
|
||||||
</size>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -112,6 +124,12 @@
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
@ -121,6 +139,12 @@
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -284,6 +308,12 @@
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -298,6 +328,12 @@
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -312,6 +348,12 @@
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
|
@ -34,6 +34,7 @@ void Swatch::setDimensions(const QSize& size) {
|
||||||
for (int i = 0; i < elem; ++i) {
|
for (int i = 0; i < elem; ++i) {
|
||||||
updateFill(i);
|
updateFill(i);
|
||||||
}
|
}
|
||||||
|
setMinimumSize(size * (m_size + 1) - QSize(1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Swatch::setColor(int index, uint16_t color) {
|
void Swatch::setColor(int index, uint16_t color) {
|
||||||
|
|
|
@ -1329,7 +1329,6 @@ void Window::setupMenu(QMenuBar* menubar) {
|
||||||
QAction* paletteView = new QAction(tr("View &palette..."), toolsMenu);
|
QAction* paletteView = new QAction(tr("View &palette..."), toolsMenu);
|
||||||
connect(paletteView, SIGNAL(triggered()), this, SLOT(openPaletteWindow()));
|
connect(paletteView, SIGNAL(triggered()), this, SLOT(openPaletteWindow()));
|
||||||
m_gameActions.append(paletteView);
|
m_gameActions.append(paletteView);
|
||||||
m_gbaActions.append(paletteView);
|
|
||||||
addControlledAction(toolsMenu, paletteView, "paletteWindow");
|
addControlledAction(toolsMenu, paletteView, "paletteWindow");
|
||||||
|
|
||||||
QAction* tileView = new QAction(tr("View &tiles..."), toolsMenu);
|
QAction* tileView = new QAction(tr("View &tiles..."), toolsMenu);
|
||||||
|
|
Loading…
Reference in New Issue