Qt: Better support for GB palettes
@@ -15,6 +15,7 @@ }
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 @@ if (m_parent) {
m_parent->removeEventFilter(this); } m_parent = other.m_parent; + m_defaultColor = other.m_defaultColor; m_parent->installEventFilter(this); return *this;@@ -45,8 +47,10 @@ QWidget* swatch = static_cast<QWidget*>(obj);
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);
@@ -5,9 +5,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #pragma once +#include <QColor> #include <QObject> -class QColor; class QWidget; namespace QGBA {@@ -29,6 +29,7 @@ bool eventFilter(QObject* obj, QEvent* event) override;
private: QWidget* m_parent = nullptr; + QColor m_defaultColor; }; }
@@ -70,9 +70,17 @@ m_colorPickers[0] = ColorPicker(m_ui.color0, QColor(0xF8, 0xF8, 0xF8));
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 @@ if (m_ui.tabWidget->currentWidget() == m_ui.tabGB) {
std::unique_ptr<GBOverride> 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 {
@@ -50,8 +50,8 @@ ConfigController* m_config;
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<enum GBModel> s_gbModelList; static QList<enum GBMemoryBankControllerType> s_mbcList;
@@ -344,7 +344,7 @@ </item>
<item row="2" column="0"> <widget class="QLabel" name="label_5"> <property name="text"> - <string>Colors</string> + <string>Background Colors</string> </property> </widget> </item>@@ -409,6 +409,180 @@ </widget>
</item> <item> <widget class="QFrame" name="color3"> + <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="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>
@@ -183,24 +183,38 @@ defaultColors.append(QColor(0xF8, 0xF8, 0xF8));
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<QWidget*> 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 @@
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
@@ -55,8 +55,8 @@ InputController* m_input;
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<enum GBModel> s_gbModelList; #endif
@@ -1170,10 +1170,17 @@ </property>
</item> </widget> </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"> <widget class="QLabel" name="label_28"> <property name="text"> - <string>Default colors:</string> + <string>Default BG colors:</string> </property> </widget> </item>@@ -1258,27 +1265,107 @@ </item>
</layout> </item> <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"> <property name="text"> <string>Super Game Boy borders</string> </property> </widget> </item> - <item row="6" column="0" colspan="2"> + <item row="8" column="0" colspan="2"> <widget class="Line" name="line_11"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> </widget> </item> - <item row="7" column="0"> + <item row="9" column="0"> <widget class="QLabel" name="label_27"> <property name="text"> <string>Camera driver:</string> </property> </widget> </item> - <item row="7" column="1"> + <item row="9" column="1"> <widget class="QComboBox" name="cameraDriver"> <property name="sizePolicy"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">@@ -1288,10 +1375,97 @@ </sizepolicy>
</property> </widget> </item> - <item row="3" column="0" colspan="2"> - <widget class="Line" name="line_12"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> + <item row="6" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_37"> + <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> + <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> </widget> </item>