diff --git a/src/qt_gui/game_grid_frame.cpp b/src/qt_gui/game_grid_frame.cpp index 17dd77ef9..7e4ade2f6 100644 --- a/src/qt_gui/game_grid_frame.cpp +++ b/src/qt_gui/game_grid_frame.cpp @@ -1,8 +1,6 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include - #include "common/path_util.h" #include "game_grid_frame.h" #include "qt_gui/compatibility_info.h" @@ -165,6 +163,8 @@ void GameGridFrame::SetGridBackgroundImage(int row, int column) { // If background images are hidden, clear the background image if (!Config::getShowBackgroundImage()) { backgroundImage = QImage(); + m_last_opacity = -1; // Reset opacity tracking when disabled + m_current_game_path.clear(); // Reset current game path RefreshGridBackgroundImage(); return; } @@ -172,10 +172,15 @@ void GameGridFrame::SetGridBackgroundImage(int row, int column) { const auto& game = (*m_games_shared)[itemID]; const int opacity = Config::getBackgroundImageOpacity(); - QImage original_image(QString::fromStdString(game.pic_path.string())); - if (!original_image.isNull()) { - backgroundImage = m_game_list_utils.ChangeImageOpacity( - original_image, original_image.rect(), opacity / 100.0f); + // Recompute if opacity changed or we switched to a different game + if (opacity != m_last_opacity || game.pic_path != m_current_game_path) { + QImage original_image(QString::fromStdString(game.pic_path.string())); + if (!original_image.isNull()) { + backgroundImage = m_game_list_utils.ChangeImageOpacity( + original_image, original_image.rect(), opacity / 100.0f); + m_last_opacity = opacity; + m_current_game_path = game.pic_path; + } } RefreshGridBackgroundImage(); diff --git a/src/qt_gui/game_grid_frame.h b/src/qt_gui/game_grid_frame.h index 4825d6daf..370b71dcb 100644 --- a/src/qt_gui/game_grid_frame.h +++ b/src/qt_gui/game_grid_frame.h @@ -33,6 +33,8 @@ private: std::shared_ptr m_compat_info; std::shared_ptr> m_games_shared; bool validCellSelected = false; + int m_last_opacity = -1; // Track last opacity to avoid unnecessary recomputation + std::filesystem::path m_current_game_path; // Track current game path to detect changes public: explicit GameGridFrame(std::shared_ptr game_info_get, diff --git a/src/qt_gui/game_list_frame.cpp b/src/qt_gui/game_list_frame.cpp index 9d4f8943a..0327a5e10 100644 --- a/src/qt_gui/game_list_frame.cpp +++ b/src/qt_gui/game_list_frame.cpp @@ -171,6 +171,8 @@ void GameListFrame::SetListBackgroundImage(QTableWidgetItem* item) { // If background images are hidden, clear the background image if (!Config::getShowBackgroundImage()) { backgroundImage = QImage(); + m_last_opacity = -1; // Reset opacity tracking when disabled + m_current_game_path.clear(); // Reset current game path RefreshListBackgroundImage(); return; } @@ -178,10 +180,15 @@ void GameListFrame::SetListBackgroundImage(QTableWidgetItem* item) { const auto& game = m_game_info->m_games[item->row()]; const int opacity = Config::getBackgroundImageOpacity(); - QImage original_image(QString::fromStdString(game.pic_path.string())); - if (!original_image.isNull()) { - backgroundImage = m_game_list_utils.ChangeImageOpacity( - original_image, original_image.rect(), opacity / 100.0f); + // Recompute if opacity changed or we switched to a different game + if (opacity != m_last_opacity || game.pic_path != m_current_game_path) { + QImage original_image(QString::fromStdString(game.pic_path.string())); + if (!original_image.isNull()) { + backgroundImage = m_game_list_utils.ChangeImageOpacity( + original_image, original_image.rect(), opacity / 100.0f); + m_last_opacity = opacity; + m_current_game_path = game.pic_path; + } } RefreshListBackgroundImage(); diff --git a/src/qt_gui/game_list_frame.h b/src/qt_gui/game_list_frame.h index 96d27ef05..b2e5f1e2f 100644 --- a/src/qt_gui/game_list_frame.h +++ b/src/qt_gui/game_list_frame.h @@ -45,6 +45,8 @@ private: GameInfoClass* game_inf_get = nullptr; bool ListSortedAsc = true; QTableWidgetItem* m_current_item = nullptr; + int m_last_opacity = -1; // Track last opacity to avoid unnecessary recomputation + std::filesystem::path m_current_game_path; // Track current game path to detect changes public: void PopulateGameList(bool isInitialPopulation = true);