Qt: Set default Game Boy colors

This commit is contained in:
Vicki Pfau 2017-07-28 14:32:17 -07:00
parent 0c0fab5402
commit f15aacd0b6
9 changed files with 146 additions and 57 deletions

View File

@ -2,6 +2,7 @@
Features: Features:
- ELF support - ELF support
- Game Boy Camera support - Game Boy Camera support
- Qt: Set default Game Boy colors
Bugfixes: Bugfixes:
- GB Audio: Make audio unsigned with bias (fixes mgba.io/i/749) - GB Audio: Make audio unsigned with bias (fixes mgba.io/i/749)
- Python: Fix importing .gb or .gba before .core - Python: Fix importing .gb or .gba before .core

View File

@ -66,6 +66,7 @@ set(SOURCE_FILES
CheatsModel.cpp CheatsModel.cpp
CheatsView.cpp CheatsView.cpp
ConfigController.cpp ConfigController.cpp
ColorPicker.cpp
CoreManager.cpp CoreManager.cpp
CoreController.cpp CoreController.cpp
Display.cpp Display.cpp

View File

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

View File

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

View File

@ -5,7 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "OverrideView.h" #include "OverrideView.h"
#include <QColorDialog>
#include <QPushButton> #include <QPushButton>
#include "ConfigController.h" #include "ConfigController.h"
@ -76,20 +75,16 @@ OverrideView::OverrideView(ConfigController* config, QWidget* parent)
connect(m_ui.gbModel, &QComboBox::currentTextChanged, this, &OverrideView::updateOverrides); connect(m_ui.gbModel, &QComboBox::currentTextChanged, this, &OverrideView::updateOverrides);
connect(m_ui.mbc, &QComboBox::currentTextChanged, this, &OverrideView::updateOverrides); connect(m_ui.mbc, &QComboBox::currentTextChanged, this, &OverrideView::updateOverrides);
QPalette palette = m_ui.color0->palette(); m_colorPickers[0] = ColorPicker(m_ui.color0, QColor(0xF8, 0xF8, 0xF8));
palette.setColor(backgroundRole(), QColor(0xF8, 0xF8, 0xF8)); m_colorPickers[1] = ColorPicker(m_ui.color1, QColor(0xA8, 0xA8, 0xA8));
m_ui.color0->setPalette(palette); m_colorPickers[2] = ColorPicker(m_ui.color2, QColor(0x50, 0x50, 0x50));
palette.setColor(backgroundRole(), QColor(0xA8, 0xA8, 0xA8)); m_colorPickers[3] = ColorPicker(m_ui.color3, QColor(0x00, 0x00, 0x00));
m_ui.color1->setPalette(palette); for (int colorId = 0; colorId < 4; ++colorId) {
palette.setColor(backgroundRole(), QColor(0x50, 0x50, 0x50)); connect(&m_colorPickers[colorId], &ColorPicker::colorChanged, this, [this, colorId](const QColor& color) {
m_ui.color2->setPalette(palette); m_gbColors[colorId] = color.rgb();
palette.setColor(backgroundRole(), QColor(0x00, 0x00, 0x00)); updateOverrides();
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);
connect(m_ui.tabWidget, &QTabWidget::currentChanged, this, &OverrideView::updateOverrides); connect(m_ui.tabWidget, &QTabWidget::currentChanged, this, &OverrideView::updateOverrides);
#ifndef M_CORE_GBA #ifndef M_CORE_GBA
@ -115,42 +110,6 @@ void OverrideView::setController(std::shared_ptr<CoreController> controller) {
} }
} }
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() { void OverrideView::saveOverride() {
if (!m_config || !m_controller) { if (!m_config || !m_controller) {
return; return;

View File

@ -14,6 +14,7 @@
#include <mgba/gb/interface.h> #include <mgba/gb/interface.h>
#endif #endif
#include "ColorPicker.h"
#include "Override.h" #include "Override.h"
#include "ui_OverrideView.h" #include "ui_OverrideView.h"
@ -42,9 +43,6 @@ private slots:
void gameStarted(); void gameStarted();
void gameStopped(); void gameStopped();
protected:
bool eventFilter(QObject* obj, QEvent* event) override;
private: private:
Ui::OverrideView m_ui; Ui::OverrideView m_ui;
@ -54,6 +52,7 @@ private:
#ifdef M_CORE_GB #ifdef M_CORE_GB
uint32_t m_gbColors[4]{}; uint32_t m_gbColors[4]{};
ColorPicker m_colorPickers[4];
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

@ -159,6 +159,34 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC
connect(m_ui.gbcBiosBrowse, &QPushButton::clicked, [this]() { connect(m_ui.gbcBiosBrowse, &QPushButton::clicked, [this]() {
selectBios(m_ui.gbcBios); 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 #else
m_ui.gbBiosBrowse->hide(); m_ui.gbBiosBrowse->hide();
m_ui.gbcBiosBrowse->hide(); m_ui.gbcBiosBrowse->hide();
@ -331,6 +359,13 @@ void SettingsView::updateConfig() {
emit languageChanged(); 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_controller->write();
emit pathsChanged(); emit pathsChanged();

View File

@ -8,6 +8,8 @@
#include <QDialog> #include <QDialog>
#include "ColorPicker.h"
#include <mgba/core/core.h> #include <mgba/core/core.h>
#include "ui_SettingsView.h" #include "ui_SettingsView.h"
@ -48,6 +50,8 @@ private:
ConfigController* m_controller; ConfigController* m_controller;
InputController* m_input; InputController* m_input;
ShaderSelector* m_shader = nullptr; 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 QAbstractButton*);
void saveSetting(const char* key, const QComboBox*); void saveSetting(const char* key, const QComboBox*);

View File

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