Only recompute image if opacity or game changes

This commit is contained in:
Pablo Santana 2025-02-03 19:07:29 +01:00
parent 91ff7e743c
commit 88f3e06bd6
4 changed files with 26 additions and 10 deletions

View File

@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <fmt/format.h>
#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();

View File

@ -33,6 +33,8 @@ private:
std::shared_ptr<CompatibilityInfoClass> m_compat_info;
std::shared_ptr<QVector<GameInfo>> 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<GameInfoClass> game_info_get,

View File

@ -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();

View File

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