From 2743905845e0e3bc7bbb56f34bbc1be06d84ebaa Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 1 Jun 2019 15:52:23 -0700 Subject: [PATCH] Qt: Add backdrop editor --- src/platform/qt/ColorPicker.cpp | 8 +++ src/platform/qt/ColorPicker.h | 3 + src/platform/qt/FrameView.cpp | 30 +++++--- src/platform/qt/FrameView.h | 3 + src/platform/qt/FrameView.ui | 119 ++++++++++++++++---------------- 5 files changed, 93 insertions(+), 70 deletions(-) diff --git a/src/platform/qt/ColorPicker.cpp b/src/platform/qt/ColorPicker.cpp index 18782a5dc..818a25fd4 100644 --- a/src/platform/qt/ColorPicker.cpp +++ b/src/platform/qt/ColorPicker.cpp @@ -34,6 +34,14 @@ ColorPicker& ColorPicker::operator=(const ColorPicker& other) { return *this; } +void ColorPicker::setColor(const QColor& color) { + m_defaultColor = color; + + QPalette palette = m_parent->palette(); + palette.setColor(m_parent->backgroundRole(), color); + m_parent->setPalette(palette); +} + bool ColorPicker::eventFilter(QObject* obj, QEvent* event) { if (event->type() != QEvent::MouseButtonRelease) { return false; diff --git a/src/platform/qt/ColorPicker.h b/src/platform/qt/ColorPicker.h index 1e94933c8..bf50c5528 100644 --- a/src/platform/qt/ColorPicker.h +++ b/src/platform/qt/ColorPicker.h @@ -24,6 +24,9 @@ public: signals: void colorChanged(const QColor&); +public slots: + void setColor(const QColor&); + protected: bool eventFilter(QObject* obj, QEvent* event) override; diff --git a/src/platform/qt/FrameView.cpp b/src/platform/qt/FrameView.cpp index 2f1c68a08..2dea0f08b 100644 --- a/src/platform/qt/FrameView.cpp +++ b/src/platform/qt/FrameView.cpp @@ -41,7 +41,6 @@ FrameView::FrameView(std::shared_ptr controller, QWidget* parent invalidateQueue(); }); - m_ui.renderedView->installEventFilter(this); m_ui.compositedView->installEventFilter(this); connect(m_ui.queue, &QListWidget::itemChanged, this, [this](QListWidgetItem* item) { @@ -50,7 +49,7 @@ FrameView::FrameView(std::shared_ptr controller, QWidget* parent if (layer.enabled) { m_disabled.remove(layer.id); } else { - m_disabled.insert(layer.id); + m_disabled.insert(layer.id); } invalidateQueue(); }); @@ -64,12 +63,20 @@ FrameView::FrameView(std::shared_ptr controller, QWidget* parent }); connect(m_ui.magnification, static_cast(&QSpinBox::valueChanged), this, [this]() { invalidateQueue(); - - QPixmap rendered = m_rendered.scaledToHeight(m_rendered.height() * m_ui.magnification->value()); - m_ui.renderedView->setPixmap(rendered); }); connect(m_ui.exportButton, &QAbstractButton::pressed, this, &FrameView::exportFrame); + + m_backdropPicker = ColorPicker(m_ui.backdrop, QColor(0, 0, 0, 0)); + connect(&m_backdropPicker, &ColorPicker::colorChanged, this, [this](const QColor& color) { + m_overrideBackdrop = color; + }); m_controller->addFrameAction(std::bind(&FrameView::frameCallback, this, m_callbackLocker)); + + { + CoreController::Interrupter interrupter(m_controller); + refreshVl(); + } + m_controller->frameAdvance(); } FrameView::~FrameView() { @@ -237,7 +244,12 @@ void FrameView::injectGBA() { QPalette palette; gba->video.renderer->highlightColor = palette.color(QPalette::HighlightedText).rgb(); gba->video.renderer->highlightAmount = sin(m_glowFrame * M_PI / 30) * 64 + 64; + if (!m_overrideBackdrop.isValid()) { + QRgb backdrop = M_RGB5_TO_RGB8(gba->video.palette[0]) | 0xFF000000; + m_backdropPicker.setColor(backdrop); + } + m_vl->reset(m_vl); for (const Layer& layer : m_queue) { switch (layer.id.type) { case LayerId::SPRITE: @@ -256,10 +268,13 @@ void FrameView::injectGBA() { break; } } + if (m_overrideBackdrop.isValid()) { + mVideoLoggerInjectPalette(logger, 0, M_RGB8_TO_RGB5(m_overrideBackdrop.rgb())); + } if (m_ui.disableScanline->checkState() == Qt::Checked) { mVideoLoggerIgnoreAfterInjection(logger, (1 << DIRTY_PALETTE) | (1 << DIRTY_OAM) | (1 << DIRTY_REGISTER)); } else { - mVideoLoggerIgnoreAfterInjection(logger, 0); + mVideoLoggerIgnoreAfterInjection(logger, 0); } } #endif @@ -290,7 +305,6 @@ void FrameView::invalidateQueue(const QSize& dims) { bool blockSignals = m_ui.queue->blockSignals(true); QMutexLocker locker(&m_mutex); if (m_vl) { - m_vl->reset(m_vl); switch (m_controller->platform()) { #ifdef M_CORE_GBA case PLATFORM_GBA: @@ -342,8 +356,6 @@ void FrameView::updateRendered() { return; } m_rendered.convertFromImage(m_controller->getPixels()); - QPixmap rendered = m_rendered.scaledToHeight(m_rendered.height() * m_ui.magnification->value()); - m_ui.renderedView->setPixmap(rendered); } bool FrameView::eventFilter(QObject* obj, QEvent* event) { diff --git a/src/platform/qt/FrameView.h b/src/platform/qt/FrameView.h index 2a2b5f680..cce09a42c 100644 --- a/src/platform/qt/FrameView.h +++ b/src/platform/qt/FrameView.h @@ -16,6 +16,7 @@ #include #include "AssetView.h" +#include "ColorPicker.h" #include @@ -105,6 +106,8 @@ private: QPixmap m_composited; QPixmap m_rendered; mMapCacheEntry m_mapStatus[4][128 * 128] = {}; // TODO: Correct size + ColorPicker m_backdropPicker; + QColor m_overrideBackdrop; #ifdef M_CORE_GBA uint16_t m_gbaDispcnt; diff --git a/src/platform/qt/FrameView.ui b/src/platform/qt/FrameView.ui index c437b14f6..8cf75ec08 100644 --- a/src/platform/qt/FrameView.ui +++ b/src/platform/qt/FrameView.ui @@ -13,7 +13,7 @@ Inspect frame - + @@ -51,7 +51,63 @@ - + + + + + + + 0 + 0 + + + + + 32 + 32 + + + + true + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Backdrop color + + + + + + + + + Disable scanline effects + + + + + + + + + + false + + + Export + + + + true @@ -90,65 +146,6 @@ - - - - true - - - - - 0 - 0 - 567 - 467 - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - false - - - Export - - - - - - - Disable scanline effects - - -