Qt: Better support for GB palettes

This commit is contained in:
Vicki Pfau 2017-09-26 18:22:51 -07:00
parent d3d7b9606c
commit 3914da27ad
8 changed files with 422 additions and 44 deletions

View File

@ -15,6 +15,7 @@ ColorPicker::ColorPicker() {
ColorPicker::ColorPicker(QWidget* parent, const QColor& defaultColor) ColorPicker::ColorPicker(QWidget* parent, const QColor& defaultColor)
: m_parent(parent) : m_parent(parent)
, m_defaultColor(defaultColor)
{ {
QPalette palette = parent->palette(); QPalette palette = parent->palette();
palette.setColor(parent->backgroundRole(), defaultColor); palette.setColor(parent->backgroundRole(), defaultColor);
@ -27,6 +28,7 @@ ColorPicker& ColorPicker::operator=(const ColorPicker& other) {
m_parent->removeEventFilter(this); m_parent->removeEventFilter(this);
} }
m_parent = other.m_parent; m_parent = other.m_parent;
m_defaultColor = other.m_defaultColor;
m_parent->installEventFilter(this); m_parent->installEventFilter(this);
return *this; return *this;
@ -45,8 +47,10 @@ bool ColorPicker::eventFilter(QObject* obj, QEvent* event) {
QColorDialog* colorPicker = new QColorDialog; QColorDialog* colorPicker = new QColorDialog;
colorPicker->setAttribute(Qt::WA_DeleteOnClose); colorPicker->setAttribute(Qt::WA_DeleteOnClose);
colorPicker->setCurrentColor(m_defaultColor);
colorPicker->open(); colorPicker->open();
connect(colorPicker, &QColorDialog::colorSelected, [this, swatch](const QColor& color) { connect(colorPicker, &QColorDialog::colorSelected, [this, swatch](const QColor& color) {
m_defaultColor = color;
QPalette palette = swatch->palette(); QPalette palette = swatch->palette();
palette.setColor(swatch->backgroundRole(), color); palette.setColor(swatch->backgroundRole(), color);
swatch->setPalette(palette); swatch->setPalette(palette);

View File

@ -5,9 +5,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#pragma once #pragma once
#include <QColor>
#include <QObject> #include <QObject>
class QColor;
class QWidget; class QWidget;
namespace QGBA { namespace QGBA {
@ -29,6 +29,7 @@ protected:
private: private:
QWidget* m_parent = nullptr; QWidget* m_parent = nullptr;
QColor m_defaultColor;
}; };
} }

View File

@ -70,9 +70,17 @@ OverrideView::OverrideView(ConfigController* config, QWidget* parent)
m_colorPickers[1] = ColorPicker(m_ui.color1, QColor(0xA8, 0xA8, 0xA8)); m_colorPickers[1] = ColorPicker(m_ui.color1, QColor(0xA8, 0xA8, 0xA8));
m_colorPickers[2] = ColorPicker(m_ui.color2, QColor(0x50, 0x50, 0x50)); m_colorPickers[2] = ColorPicker(m_ui.color2, QColor(0x50, 0x50, 0x50));
m_colorPickers[3] = ColorPicker(m_ui.color3, QColor(0x00, 0x00, 0x00)); m_colorPickers[3] = ColorPicker(m_ui.color3, QColor(0x00, 0x00, 0x00));
for (int colorId = 0; colorId < 4; ++colorId) { m_colorPickers[4] = ColorPicker(m_ui.color4, QColor(0xF8, 0xF8, 0xF8));
m_colorPickers[5] = ColorPicker(m_ui.color5, QColor(0xA8, 0xA8, 0xA8));
m_colorPickers[6] = ColorPicker(m_ui.color6, QColor(0x50, 0x50, 0x50));
m_colorPickers[7] = ColorPicker(m_ui.color7, QColor(0x00, 0x00, 0x00));
m_colorPickers[8] = ColorPicker(m_ui.color8, QColor(0xF8, 0xF8, 0xF8));
m_colorPickers[9] = ColorPicker(m_ui.color9, QColor(0xA8, 0xA8, 0xA8));
m_colorPickers[10] = ColorPicker(m_ui.color10, QColor(0x50, 0x50, 0x50));
m_colorPickers[11] = ColorPicker(m_ui.color11, QColor(0x00, 0x00, 0x00));
for (int colorId = 0; colorId < 12; ++colorId) {
connect(&m_colorPickers[colorId], &ColorPicker::colorChanged, this, [this, colorId](const QColor& color) { connect(&m_colorPickers[colorId], &ColorPicker::colorChanged, this, [this, colorId](const QColor& color) {
m_gbColors[colorId] = color.rgb(); m_gbColors[colorId] = color.rgb() | 0xFF000000;
}); });
} }
@ -161,12 +169,13 @@ void OverrideView::updateOverrides() {
std::unique_ptr<GBOverride> gb(new GBOverride); std::unique_ptr<GBOverride> gb(new GBOverride);
gb->override.mbc = s_mbcList[m_ui.mbc->currentIndex()]; gb->override.mbc = s_mbcList[m_ui.mbc->currentIndex()];
gb->override.model = s_gbModelList[m_ui.gbModel->currentIndex()]; gb->override.model = s_gbModelList[m_ui.gbModel->currentIndex()];
gb->override.gbColors[0] = m_gbColors[0]; bool hasColor = false;
gb->override.gbColors[1] = m_gbColors[1]; for (int i = 0; i < 12; ++i) {
gb->override.gbColors[2] = m_gbColors[2]; gb->override.gbColors[i] = m_gbColors[i];
gb->override.gbColors[3] = m_gbColors[3]; hasColor = hasColor || (m_gbColors[i] & 0xFF000000);
}
bool hasOverride = gb->override.mbc != GB_MBC_AUTODETECT || gb->override.model != GB_MODEL_AUTODETECT; bool hasOverride = gb->override.mbc != GB_MBC_AUTODETECT || gb->override.model != GB_MODEL_AUTODETECT;
hasOverride = hasOverride || (m_gbColors[0] | m_gbColors[1] | m_gbColors[2] | m_gbColors[3]); hasOverride = hasOverride || hasColor;
if (hasOverride) { if (hasOverride) {
m_controller->setOverride(std::move(gb)); m_controller->setOverride(std::move(gb));
} else { } else {

View File

@ -50,8 +50,8 @@ private:
bool m_savePending = false; bool m_savePending = false;
#ifdef M_CORE_GB #ifdef M_CORE_GB
uint32_t m_gbColors[4]{}; uint32_t m_gbColors[12]{};
ColorPicker m_colorPickers[4]; ColorPicker m_colorPickers[12];
static QList<enum GBModel> s_gbModelList; static QList<enum GBModel> s_gbModelList;
static QList<enum GBMemoryBankControllerType> s_mbcList; static QList<enum GBMemoryBankControllerType> s_mbcList;

View File

@ -344,7 +344,7 @@
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">
<string>Colors</string> <string>Background Colors</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -428,6 +428,180 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="3" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Sprite Colors 1</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Sprite Colors 2</string>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QFrame" name="color4">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="color5">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="color6">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="color7">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QFrame" name="color8">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="color9">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="color10">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="color11">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>

View File

@ -183,24 +183,38 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC
defaultColors.append(QColor(0xA8, 0xA8, 0xA8)); defaultColors.append(QColor(0xA8, 0xA8, 0xA8));
defaultColors.append(QColor(0x50, 0x50, 0x50)); defaultColors.append(QColor(0x50, 0x50, 0x50));
defaultColors.append(QColor(0x00, 0x00, 0x00)); defaultColors.append(QColor(0x00, 0x00, 0x00));
bool ok; defaultColors.append(QColor(0xF8, 0xF8, 0xF8));
if (m_controller->getOption("gb.pal[0]").toUInt(&ok) || ok) { defaultColors.append(QColor(0xA8, 0xA8, 0xA8));
defaultColors[0] = QColor::fromRgb(m_controller->getOption("gb.pal[0]").toUInt()); defaultColors.append(QColor(0x50, 0x50, 0x50));
} defaultColors.append(QColor(0x00, 0x00, 0x00));
if (m_controller->getOption("gb.pal[1]").toUInt(&ok) || ok) { defaultColors.append(QColor(0xF8, 0xF8, 0xF8));
defaultColors[1] = QColor::fromRgb(m_controller->getOption("gb.pal[1]").toUInt()); defaultColors.append(QColor(0xA8, 0xA8, 0xA8));
} defaultColors.append(QColor(0x50, 0x50, 0x50));
if (m_controller->getOption("gb.pal[2]").toUInt(&ok) || ok) { defaultColors.append(QColor(0x00, 0x00, 0x00));
defaultColors[2] = QColor::fromRgb(m_controller->getOption("gb.pal[2]").toUInt()); QList<QWidget*> colors{
} m_ui.color0,
if (m_controller->getOption("gb.pal[3]").toUInt(&ok) || ok) { m_ui.color1,
defaultColors[3] = QColor::fromRgb(m_controller->getOption("gb.pal[3]").toUInt()); m_ui.color2,
} m_ui.color3,
m_colorPickers[0] = ColorPicker(m_ui.color0, defaultColors[0]); m_ui.color4,
m_colorPickers[1] = ColorPicker(m_ui.color1, defaultColors[1]); m_ui.color5,
m_colorPickers[2] = ColorPicker(m_ui.color2, defaultColors[2]); m_ui.color6,
m_colorPickers[3] = ColorPicker(m_ui.color3, defaultColors[3]); m_ui.color7,
for (int colorId = 0; colorId < 4; ++colorId) { m_ui.color8,
m_ui.color9,
m_ui.color10,
m_ui.color11
};
for (int colorId = 0; colorId < 12; ++colorId) {
bool ok;
uint color = m_controller->getOption(QString("gb.pal[%0]").arg(colorId)).toUInt(&ok);
if (ok) {
defaultColors[colorId] = QColor::fromRgb(color);
m_gbColors[colorId] = color | 0xFF000000;
} else {
m_gbColors[colorId] = defaultColors[colorId].rgb() & ~0xFF000000;
}
m_colorPickers[colorId] = ColorPicker(colors[colorId], defaultColors[colorId]);
connect(&m_colorPickers[colorId], &ColorPicker::colorChanged, this, [this, colorId](const QColor& color) { connect(&m_colorPickers[colorId], &ColorPicker::colorChanged, this, [this, colorId](const QColor& color) {
m_gbColors[colorId] = color.rgb(); m_gbColors[colorId] = color.rgb();
}); });
@ -391,11 +405,13 @@ void SettingsView::updateConfig() {
GBModel modelCGB = s_gbModelList[m_ui.cgbModel->currentIndex()]; GBModel modelCGB = s_gbModelList[m_ui.cgbModel->currentIndex()];
m_controller->setOption("cgb.model", GBModelToName(modelCGB)); m_controller->setOption("cgb.model", GBModelToName(modelCGB));
if (m_gbColors[0] | m_gbColors[1] | m_gbColors[2] | m_gbColors[3]) { for (int colorId = 0; colorId < 12; ++colorId) {
m_controller->setOption("gb.pal[0]", m_gbColors[0]); if (!(m_gbColors[colorId] & 0xFF000000)) {
m_controller->setOption("gb.pal[1]", m_gbColors[1]); continue;
m_controller->setOption("gb.pal[2]", m_gbColors[2]); }
m_controller->setOption("gb.pal[3]", m_gbColors[3]); QString color = QString("gb.pal[%0]").arg(colorId);
m_controller->setOption(color.toUtf8().constData(), m_gbColors[colorId] & ~0xFF000000);
} }
#endif #endif

View File

@ -55,8 +55,8 @@ private:
ShaderSelector* m_shader = nullptr; ShaderSelector* m_shader = nullptr;
#ifdef M_CORE_GB #ifdef M_CORE_GB
uint32_t m_gbColors[4]{}; uint32_t m_gbColors[12]{};
ColorPicker m_colorPickers[4]; ColorPicker m_colorPickers[12];
static QList<enum GBModel> s_gbModelList; static QList<enum GBModel> s_gbModelList;
#endif #endif

View File

@ -1170,10 +1170,17 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2">
<widget class="Line" name="line_12">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="0"> <item row="4" column="0">
<widget class="QLabel" name="label_28"> <widget class="QLabel" name="label_28">
<property name="text"> <property name="text">
<string>Default colors:</string> <string>Default BG colors:</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -1258,27 +1265,107 @@
</layout> </layout>
</item> </item>
<item row="5" column="1"> <item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<widget class="QFrame" name="color4">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="color5">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="color6">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="color7">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="1">
<widget class="QCheckBox" name="sgbBorders"> <widget class="QCheckBox" name="sgbBorders">
<property name="text"> <property name="text">
<string>Super Game Boy borders</string> <string>Super Game Boy borders</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="0" colspan="2"> <item row="8" column="0" colspan="2">
<widget class="Line" name="line_11"> <widget class="Line" name="line_11">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="0"> <item row="9" column="0">
<widget class="QLabel" name="label_27"> <widget class="QLabel" name="label_27">
<property name="text"> <property name="text">
<string>Camera driver:</string> <string>Camera driver:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="9" column="1">
<widget class="QComboBox" name="cameraDriver"> <widget class="QComboBox" name="cameraDriver">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -1288,10 +1375,97 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="6" column="1">
<widget class="Line" name="line_12"> <layout class="QHBoxLayout" name="horizontalLayout_37">
<property name="orientation"> <item>
<enum>Qt::Horizontal</enum> <widget class="QFrame" name="color8">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="color9">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="color10">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="color11">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_69">
<property name="text">
<string>Default sprite colors 1:</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_70">
<property name="text">
<string>Default sprite colors 2:</string>
</property> </property>
</widget> </widget>
</item> </item>