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)
: 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);

View File

@ -5,9 +5,9 @@
* 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 @@ protected:
private:
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[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<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 {

View File

@ -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<enum GBModel> s_gbModelList;
static QList<enum GBMemoryBankControllerType> s_mbcList;

View File

@ -344,7 +344,7 @@
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Colors</string>
<string>Background Colors</string>
</property>
</widget>
</item>
@ -428,6 +428,180 @@
</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>
<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>
</widget>
</widget>

View File

@ -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<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 @@ 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

View File

@ -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<enum GBModel> s_gbModelList;
#endif

View File

@ -1170,10 +1170,17 @@
</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 @@
</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 @@
</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>