diff --git a/pcsx2-qt/GameList/GameListWidget.cpp b/pcsx2-qt/GameList/GameListWidget.cpp index 38809c541a..73fdef8a5c 100644 --- a/pcsx2-qt/GameList/GameListWidget.cpp +++ b/pcsx2-qt/GameList/GameListWidget.cpp @@ -22,7 +22,10 @@ #include #include #include +#include +#include #include +#include #include #include #include @@ -391,6 +394,9 @@ void GameListWidget::setCustomBackground() m_table_view->viewport()->setAutoFillBackground(true); m_list_view->viewport()->setAutoFillBackground(true); + m_ui.stack->setPalette(QPalette()); + m_background_text_color = QColor(); + m_ui.stack->update(); m_table_view->setAlternatingRowColors(true); return; @@ -447,6 +453,8 @@ void GameListWidget::processBackgroundFrames() return; QPixmap pm = m_background_movie->currentPixmap(); + updateBackgroundTextColor(pm); + const qreal dpr = devicePixelRatioF(); QtUtils::resizeAndScalePixmap(&pm, widget_width, widget_height, dpr, m_background_scaling, m_background_opacity); @@ -456,6 +464,28 @@ void GameListWidget::processBackgroundFrames() } } +void GameListWidget::updateBackgroundTextColor(const QPixmap& frame) +{ + if (frame.isNull()) + return; + + const QImage sampled = frame.scaled(32, 32, Qt::IgnoreAspectRatio, Qt::FastTransformation).toImage(); + const QColor average = sampled.scaled(1, 1, Qt::IgnoreAspectRatio, Qt::SmoothTransformation).pixelColor(0, 0); + const QColor base = qApp->palette().color(QPalette::Base); + const qreal coverage = average.alphaF() * std::clamp(m_background_opacity / 100.0f, 0.0f, 1.0f); + const qreal brightness = qGray(average.rgb()) * coverage + qGray(base.rgb()) * (1.0 - coverage); + const QColor text_color = (brightness > 127.5) ? Qt::black : Qt::white; + + if (m_background_text_color == text_color) + return; + m_background_text_color = text_color; + + QPalette palette; + palette.setColor(QPalette::Text, text_color); + palette.setColor(QPalette::WindowText, text_color); + m_ui.stack->setPalette(palette); +} + bool GameListWidget::isShowingGameList() const { return m_ui.stack->currentIndex() == 0; @@ -499,6 +529,7 @@ void GameListWidget::cancelRefresh() void GameListWidget::reloadThemeSpecificImages() { m_model->reloadThemeSpecificImages(); + processBackgroundFrames(); } void GameListWidget::onRefreshProgress(const QString& status, int current, int total) diff --git a/pcsx2-qt/GameList/GameListWidget.h b/pcsx2-qt/GameList/GameListWidget.h index 9110513524..1d2d2dcb6d 100644 --- a/pcsx2-qt/GameList/GameListWidget.h +++ b/pcsx2-qt/GameList/GameListWidget.h @@ -9,6 +9,7 @@ #include "pcsx2/GameList.h" +#include #include #include #include @@ -55,6 +56,7 @@ public: void setCustomBackground(); void updateCustomBackgroundState(const bool force_start = false); void processBackgroundFrames(); + void updateBackgroundTextColor(const QPixmap& frame); bool isShowingGameList() const; bool isShowingGameGrid() const; @@ -128,6 +130,7 @@ private: QMovie* m_background_movie = nullptr; QPixmap m_background_pixmap; + QColor m_background_text_color; QtUtils::ScalingMode m_background_scaling = QtUtils::ScalingMode::Fit; float m_background_opacity = 100.0f; };