From 3914da27adbd216e7020461bb214c63ff579a5b0 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 26 Sep 2017 18:22:51 -0700 Subject: [PATCH] Qt: Better support for GB palettes --- src/platform/qt/ColorPicker.cpp | 4 + src/platform/qt/ColorPicker.h | 3 +- src/platform/qt/OverrideView.cpp | 23 ++-- src/platform/qt/OverrideView.h | 4 +- src/platform/qt/OverrideView.ui | 176 +++++++++++++++++++++++++++- src/platform/qt/SettingsView.cpp | 62 ++++++---- src/platform/qt/SettingsView.h | 4 +- src/platform/qt/SettingsView.ui | 190 +++++++++++++++++++++++++++++-- 8 files changed, 422 insertions(+), 44 deletions(-) diff --git a/src/platform/qt/ColorPicker.cpp b/src/platform/qt/ColorPicker.cpp index 7351286e4..18782a5dc 100644 --- a/src/platform/qt/ColorPicker.cpp +++ b/src/platform/qt/ColorPicker.cpp @@ -15,6 +15,7 @@ ColorPicker::ColorPicker() { ColorPicker::ColorPicker(QWidget* parent, const QColor& defaultColor) : m_parent(parent) + , m_defaultColor(defaultColor) { QPalette palette = parent->palette(); palette.setColor(parent->backgroundRole(), defaultColor); @@ -27,6 +28,7 @@ ColorPicker& ColorPicker::operator=(const ColorPicker& other) { m_parent->removeEventFilter(this); } m_parent = other.m_parent; + m_defaultColor = other.m_defaultColor; m_parent->installEventFilter(this); return *this; @@ -45,8 +47,10 @@ bool ColorPicker::eventFilter(QObject* obj, QEvent* event) { QColorDialog* colorPicker = new QColorDialog; colorPicker->setAttribute(Qt::WA_DeleteOnClose); + colorPicker->setCurrentColor(m_defaultColor); colorPicker->open(); connect(colorPicker, &QColorDialog::colorSelected, [this, swatch](const QColor& color) { + m_defaultColor = color; QPalette palette = swatch->palette(); palette.setColor(swatch->backgroundRole(), color); swatch->setPalette(palette); diff --git a/src/platform/qt/ColorPicker.h b/src/platform/qt/ColorPicker.h index 5bc4bee20..1e94933c8 100644 --- a/src/platform/qt/ColorPicker.h +++ b/src/platform/qt/ColorPicker.h @@ -5,9 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #pragma once +#include #include -class QColor; class QWidget; namespace QGBA { @@ -29,6 +29,7 @@ protected: private: QWidget* m_parent = nullptr; + QColor m_defaultColor; }; } diff --git a/src/platform/qt/OverrideView.cpp b/src/platform/qt/OverrideView.cpp index 940d46077..c9e68c68c 100644 --- a/src/platform/qt/OverrideView.cpp +++ b/src/platform/qt/OverrideView.cpp @@ -70,9 +70,17 @@ OverrideView::OverrideView(ConfigController* config, QWidget* parent) m_colorPickers[1] = ColorPicker(m_ui.color1, QColor(0xA8, 0xA8, 0xA8)); m_colorPickers[2] = ColorPicker(m_ui.color2, QColor(0x50, 0x50, 0x50)); 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) { - m_gbColors[colorId] = color.rgb(); + m_gbColors[colorId] = color.rgb() | 0xFF000000; }); } @@ -161,12 +169,13 @@ void OverrideView::updateOverrides() { std::unique_ptr gb(new GBOverride); gb->override.mbc = s_mbcList[m_ui.mbc->currentIndex()]; gb->override.model = s_gbModelList[m_ui.gbModel->currentIndex()]; - gb->override.gbColors[0] = m_gbColors[0]; - gb->override.gbColors[1] = m_gbColors[1]; - gb->override.gbColors[2] = m_gbColors[2]; - gb->override.gbColors[3] = m_gbColors[3]; + bool hasColor = false; + for (int i = 0; i < 12; ++i) { + gb->override.gbColors[i] = m_gbColors[i]; + hasColor = hasColor || (m_gbColors[i] & 0xFF000000); + } 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) { m_controller->setOverride(std::move(gb)); } else { diff --git a/src/platform/qt/OverrideView.h b/src/platform/qt/OverrideView.h index c144350e5..5a877b174 100644 --- a/src/platform/qt/OverrideView.h +++ b/src/platform/qt/OverrideView.h @@ -50,8 +50,8 @@ private: bool m_savePending = false; #ifdef M_CORE_GB - uint32_t m_gbColors[4]{}; - ColorPicker m_colorPickers[4]; + uint32_t m_gbColors[12]{}; + ColorPicker m_colorPickers[12]; static QList s_gbModelList; static QList s_mbcList; diff --git a/src/platform/qt/OverrideView.ui b/src/platform/qt/OverrideView.ui index 9ab598a8e..108622ffc 100644 --- a/src/platform/qt/OverrideView.ui +++ b/src/platform/qt/OverrideView.ui @@ -344,7 +344,7 @@ - Colors + Background Colors @@ -428,6 +428,180 @@ + + + + Sprite Colors 1 + + + + + + + Sprite Colors 2 + + + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + diff --git a/src/platform/qt/SettingsView.cpp b/src/platform/qt/SettingsView.cpp index 0a587371a..d17134563 100644 --- a/src/platform/qt/SettingsView.cpp +++ b/src/platform/qt/SettingsView.cpp @@ -183,24 +183,38 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC defaultColors.append(QColor(0xA8, 0xA8, 0xA8)); defaultColors.append(QColor(0x50, 0x50, 0x50)); defaultColors.append(QColor(0x00, 0x00, 0x00)); - bool ok; - if (m_controller->getOption("gb.pal[0]").toUInt(&ok) || ok) { - defaultColors[0] = QColor::fromRgb(m_controller->getOption("gb.pal[0]").toUInt()); - } - if (m_controller->getOption("gb.pal[1]").toUInt(&ok) || ok) { - defaultColors[1] = QColor::fromRgb(m_controller->getOption("gb.pal[1]").toUInt()); - } - if (m_controller->getOption("gb.pal[2]").toUInt(&ok) || ok) { - defaultColors[2] = QColor::fromRgb(m_controller->getOption("gb.pal[2]").toUInt()); - } - if (m_controller->getOption("gb.pal[3]").toUInt(&ok) || ok) { - defaultColors[3] = QColor::fromRgb(m_controller->getOption("gb.pal[3]").toUInt()); - } - m_colorPickers[0] = ColorPicker(m_ui.color0, defaultColors[0]); - m_colorPickers[1] = ColorPicker(m_ui.color1, defaultColors[1]); - m_colorPickers[2] = ColorPicker(m_ui.color2, defaultColors[2]); - m_colorPickers[3] = ColorPicker(m_ui.color3, defaultColors[3]); - for (int colorId = 0; colorId < 4; ++colorId) { + defaultColors.append(QColor(0xF8, 0xF8, 0xF8)); + defaultColors.append(QColor(0xA8, 0xA8, 0xA8)); + defaultColors.append(QColor(0x50, 0x50, 0x50)); + defaultColors.append(QColor(0x00, 0x00, 0x00)); + defaultColors.append(QColor(0xF8, 0xF8, 0xF8)); + defaultColors.append(QColor(0xA8, 0xA8, 0xA8)); + defaultColors.append(QColor(0x50, 0x50, 0x50)); + defaultColors.append(QColor(0x00, 0x00, 0x00)); + QList colors{ + m_ui.color0, + m_ui.color1, + m_ui.color2, + m_ui.color3, + m_ui.color4, + m_ui.color5, + m_ui.color6, + m_ui.color7, + 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) { m_gbColors[colorId] = color.rgb(); }); @@ -391,11 +405,13 @@ void SettingsView::updateConfig() { GBModel modelCGB = s_gbModelList[m_ui.cgbModel->currentIndex()]; m_controller->setOption("cgb.model", GBModelToName(modelCGB)); - if (m_gbColors[0] | m_gbColors[1] | m_gbColors[2] | m_gbColors[3]) { - m_controller->setOption("gb.pal[0]", m_gbColors[0]); - m_controller->setOption("gb.pal[1]", m_gbColors[1]); - m_controller->setOption("gb.pal[2]", m_gbColors[2]); - m_controller->setOption("gb.pal[3]", m_gbColors[3]); + for (int colorId = 0; colorId < 12; ++colorId) { + if (!(m_gbColors[colorId] & 0xFF000000)) { + continue; + } + QString color = QString("gb.pal[%0]").arg(colorId); + m_controller->setOption(color.toUtf8().constData(), m_gbColors[colorId] & ~0xFF000000); + } #endif diff --git a/src/platform/qt/SettingsView.h b/src/platform/qt/SettingsView.h index 0ae5d0b07..653dd6139 100644 --- a/src/platform/qt/SettingsView.h +++ b/src/platform/qt/SettingsView.h @@ -55,8 +55,8 @@ private: ShaderSelector* m_shader = nullptr; #ifdef M_CORE_GB - uint32_t m_gbColors[4]{}; - ColorPicker m_colorPickers[4]; + uint32_t m_gbColors[12]{}; + ColorPicker m_colorPickers[12]; static QList s_gbModelList; #endif diff --git a/src/platform/qt/SettingsView.ui b/src/platform/qt/SettingsView.ui index 8b470cc84..be801f5f3 100644 --- a/src/platform/qt/SettingsView.ui +++ b/src/platform/qt/SettingsView.ui @@ -1170,10 +1170,17 @@ + + + + Qt::Horizontal + + + - Default colors: + Default BG colors: @@ -1258,27 +1265,107 @@ + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Super Game Boy borders - + Qt::Horizontal - + Camera driver: - + @@ -1288,10 +1375,97 @@ - - - - Qt::Horizontal + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 30 + 30 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + Default sprite colors 1: + + + + + + + Default sprite colors 2: