all repos — mgba @ f15aacd0b6aaf33c17eae8e0ec0558bc124b3bc4

mGBA Game Boy Advance Emulator

Qt: Set default Game Boy colors
Vicki Pfau vi@endrift.com
Fri, 28 Jul 2017 14:32:17 -0700
commit

f15aacd0b6aaf33c17eae8e0ec0558bc124b3bc4

parent

0c0fab5402726e988a1335539008a03012dea844

M CHANGESCHANGES

@@ -2,6 +2,7 @@ 0.7.0: (Future)

Features: - ELF support - Game Boy Camera support + - Qt: Set default Game Boy colors Bugfixes: - GB Audio: Make audio unsigned with bias (fixes mgba.io/i/749) - Python: Fix importing .gb or .gba before .core
M src/platform/qt/CMakeLists.txtsrc/platform/qt/CMakeLists.txt

@@ -66,6 +66,7 @@ AudioProcessor.cpp

CheatsModel.cpp CheatsView.cpp ConfigController.cpp + ColorPicker.cpp CoreManager.cpp CoreController.cpp Display.cpp
A src/platform/qt/ColorPicker.cpp

@@ -0,0 +1,56 @@

+/* Copyright (c) 2013-2017 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ +#include "ColorPicker.h" + +#include <QColorDialog> +#include <QEvent> + +using namespace QGBA; + +ColorPicker::ColorPicker() { +} + +ColorPicker::ColorPicker(QWidget* parent, const QColor& defaultColor) + : m_parent(parent) +{ + QPalette palette = parent->palette(); + palette.setColor(parent->backgroundRole(), defaultColor); + parent->setPalette(palette); + parent->installEventFilter(this); +} + +ColorPicker& ColorPicker::operator=(const ColorPicker& other) { + if (m_parent) { + m_parent->removeEventFilter(this); + } + m_parent = other.m_parent; + m_parent->installEventFilter(this); + + return *this; +} + +bool ColorPicker::eventFilter(QObject* obj, QEvent* event) { + if (event->type() != QEvent::MouseButtonRelease) { + return false; + } + int colorId; + if (obj != m_parent) { + return false; + } + + QWidget* swatch = static_cast<QWidget*>(obj); + + QColorDialog* colorPicker = new QColorDialog; + colorPicker->setAttribute(Qt::WA_DeleteOnClose); + colorPicker->open(); + connect(colorPicker, &QColorDialog::colorSelected, [this, swatch](const QColor& color) { + QPalette palette = swatch->palette(); + palette.setColor(swatch->backgroundRole(), color); + swatch->setPalette(palette); + emit colorChanged(color); + }); + return true; +}
A src/platform/qt/ColorPicker.h

@@ -0,0 +1,37 @@

+/* Copyright (c) 2013-2015 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ +#ifndef QGBA_COLOR_PICKER +#define QGBA_COLOR_PICKER + +#include <QObject> + +class QColor; +class QWidget; + +namespace QGBA { + +class ColorPicker : public QObject { +Q_OBJECT + +public: + ColorPicker(); + ColorPicker(QWidget* parent, const QColor& defaultColor); + + ColorPicker& operator=(const ColorPicker&); + +signals: + void colorChanged(const QColor&); + +protected: + bool eventFilter(QObject* obj, QEvent* event) override; + +private: + QWidget* m_parent = nullptr; +}; + +} + +#endif
M src/platform/qt/OverrideView.cppsrc/platform/qt/OverrideView.cpp

@@ -5,7 +5,6 @@ * 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/. */ #include "OverrideView.h" -#include <QColorDialog> #include <QPushButton> #include "ConfigController.h"

@@ -76,20 +75,16 @@

connect(m_ui.gbModel, &QComboBox::currentTextChanged, this, &OverrideView::updateOverrides); connect(m_ui.mbc, &QComboBox::currentTextChanged, this, &OverrideView::updateOverrides); - QPalette palette = m_ui.color0->palette(); - palette.setColor(backgroundRole(), QColor(0xF8, 0xF8, 0xF8)); - m_ui.color0->setPalette(palette); - palette.setColor(backgroundRole(), QColor(0xA8, 0xA8, 0xA8)); - m_ui.color1->setPalette(palette); - palette.setColor(backgroundRole(), QColor(0x50, 0x50, 0x50)); - m_ui.color2->setPalette(palette); - palette.setColor(backgroundRole(), QColor(0x00, 0x00, 0x00)); - m_ui.color3->setPalette(palette); - - m_ui.color0->installEventFilter(this); - m_ui.color1->installEventFilter(this); - m_ui.color2->installEventFilter(this); - m_ui.color3->installEventFilter(this); + 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) { + connect(&m_colorPickers[colorId], &ColorPicker::colorChanged, this, [this, colorId](const QColor& color) { + m_gbColors[colorId] = color.rgb(); + updateOverrides(); + }); + } connect(m_ui.tabWidget, &QTabWidget::currentChanged, this, &OverrideView::updateOverrides); #ifndef M_CORE_GBA

@@ -113,42 +108,6 @@ m_controller->setOverride(std::move(m_override));

} else { m_controller->clearOverride(); } -} - -bool OverrideView::eventFilter(QObject* obj, QEvent* event) { -#ifdef M_CORE_GB - if (event->type() != QEvent::MouseButtonRelease) { - return false; - } - int colorId; - if (obj == m_ui.color0) { - colorId = 0; - } else if (obj == m_ui.color1) { - colorId = 1; - } else if (obj == m_ui.color2) { - colorId = 2; - } else if (obj == m_ui.color3) { - colorId = 3; - } else { - return false; - } - - QWidget* swatch = static_cast<QWidget*>(obj); - - QColorDialog* colorPicker = new QColorDialog; - colorPicker->setAttribute(Qt::WA_DeleteOnClose); - colorPicker->open(); - connect(colorPicker, &QColorDialog::colorSelected, [this, swatch, colorId](const QColor& color) { - QPalette palette = swatch->palette(); - palette.setColor(backgroundRole(), color); - swatch->setPalette(palette); - m_gbColors[colorId] = color.rgb(); - updateOverrides(); - }); - return true; -#else - return false; -#endif } void OverrideView::saveOverride() {
M src/platform/qt/OverrideView.hsrc/platform/qt/OverrideView.h

@@ -14,6 +14,7 @@ #ifdef M_CORE_GB

#include <mgba/gb/interface.h> #endif +#include "ColorPicker.h" #include "Override.h" #include "ui_OverrideView.h"

@@ -42,9 +43,6 @@ void updateOverrides();

void gameStarted(); void gameStopped(); -protected: - bool eventFilter(QObject* obj, QEvent* event) override; - private: Ui::OverrideView m_ui;

@@ -54,6 +52,7 @@ ConfigController* m_config;

#ifdef M_CORE_GB uint32_t m_gbColors[4]{}; + ColorPicker m_colorPickers[4]; static QList<enum GBModel> s_gbModelList; static QList<enum GBMemoryBankControllerType> s_mbcList;
M src/platform/qt/SettingsView.cppsrc/platform/qt/SettingsView.cpp

@@ -159,6 +159,34 @@ });

connect(m_ui.gbcBiosBrowse, &QPushButton::clicked, [this]() { selectBios(m_ui.gbcBios); }); + + QList<QColor> defaultColors; + 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) { + connect(&m_colorPickers[colorId], &ColorPicker::colorChanged, this, [this, colorId](const QColor& color) { + m_gbColors[colorId] = color.rgb(); + }); + } #else m_ui.gbBiosBrowse->hide(); m_ui.gbcBiosBrowse->hide();

@@ -329,6 +357,13 @@ QLocale language = m_ui.languages->itemData(m_ui.languages->currentIndex()).toLocale();

if (language != m_controller->getQtOption("language").toLocale() && !(language.bcp47Name() == QLocale::system().bcp47Name() && m_controller->getQtOption("language").isNull())) { m_controller->setQtOption("language", language.bcp47Name()); emit languageChanged(); + } + + 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]); } m_controller->write();
M src/platform/qt/SettingsView.hsrc/platform/qt/SettingsView.h

@@ -8,6 +8,8 @@ #define QGBA_SETTINGS_VIEW

#include <QDialog> +#include "ColorPicker.h" + #include <mgba/core/core.h> #include "ui_SettingsView.h"

@@ -48,6 +50,8 @@

ConfigController* m_controller; InputController* m_input; ShaderSelector* m_shader = nullptr; + uint32_t m_gbColors[4]{}; + ColorPicker m_colorPickers[4]; void saveSetting(const char* key, const QAbstractButton*); void saveSetting(const char* key, const QComboBox*);
M src/platform/qt/SettingsView.uisrc/platform/qt/SettingsView.ui

@@ -1056,9 +1056,6 @@ </widget>

</item> <item row="1" column="0"> <widget class="QLabel" name="label_28"> - <property name="enabled"> - <bool>false</bool> - </property> <property name="text"> <string>Default colors</string> </property>