diff --git a/shadPS4/gui/game_list_frame.cpp b/shadPS4/gui/game_list_frame.cpp index b1aa17bf..177f5224 100644 --- a/shadPS4/gui/game_list_frame.cpp +++ b/shadPS4/gui/game_list_frame.cpp @@ -2,6 +2,7 @@ #include "gui_settings.h" #include "custom_table_widget_item.h" #include "../emulator/fileFormat/PSF.h" +#include game_list_frame::game_list_frame(std::shared_ptr gui_settings, QWidget* parent) : QWidget(parent) @@ -323,7 +324,7 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after) const int scroll_position = m_game_list->verticalScrollBar()->value(); PopulateGameList(); SortGameList(); - //RepaintIcons(); + RepaintIcons(); if (scroll_after) { @@ -336,7 +337,7 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after) } else { - //RepaintIcons(); + RepaintIcons(); } @@ -367,6 +368,7 @@ void game_list_frame::PopulateGameList() int row = 0; int index = -1; + RepaintIcons();//hackish for (const auto& game : m_game_data) { index++; @@ -374,6 +376,7 @@ void game_list_frame::PopulateGameList() // Icon custom_table_widget_item* icon_item = new custom_table_widget_item; + icon_item->setData(Qt::DecorationRole, game->pxmap); icon_item->setData(Qt::UserRole, index, true); icon_item->setData(gui::custom_roles::game_role, QVariant::fromValue(game)); @@ -441,4 +444,72 @@ std::string game_list_frame::CurrentSelectionPath() m_old_layout_is_list = m_is_list_layout; return selection; +} + +void game_list_frame::RepaintIcons(const bool& from_settings) +{ + for (auto& game : m_game_data) + { + game->icon.load(QString::fromStdString(game->info.icon_path)); + game->pxmap = PaintedPixmap(game->icon); + } + +} + +QPixmap game_list_frame::PaintedPixmap(const QPixmap& icon) const +{ + const qreal device_pixel_ratio = devicePixelRatioF(); + QSize canvas_size(320, 176); + QSize icon_size(icon.size()); + QPoint target_pos; + + if (!icon.isNull()) + { + // Let's upscale the original icon to at least fit into the outer rect of the size of PS3's ICON0.PNG + if (icon_size.width() < 320 || icon_size.height() < 176) + { + icon_size.scale(320, 176, Qt::KeepAspectRatio); + } + + canvas_size = icon_size; + + // Calculate the centered size and position of the icon on our canvas. + if (icon_size.width() != 320 || icon_size.height() != 176) + { + constexpr double target_ratio = 320.0 / 176.0; // aspect ratio 20:11 + + if ((icon_size.width() / static_cast(icon_size.height())) > target_ratio) + { + canvas_size.setHeight(std::ceil(icon_size.width() / target_ratio)); + } + else + { + canvas_size.setWidth(std::ceil(icon_size.height() * target_ratio)); + } + + target_pos.setX(std::max(0, (canvas_size.width() - icon_size.width()) / 2.0)); + target_pos.setY(std::max(0, (canvas_size.height() - icon_size.height()) / 2.0)); + } + } + + // Create a canvas large enough to fit our entire scaled icon + QPixmap canvas(canvas_size * device_pixel_ratio); + canvas.setDevicePixelRatio(device_pixel_ratio); + canvas.fill(m_icon_color); + + // Create a painter for our canvas + QPainter painter(&canvas); + painter.setRenderHint(QPainter::SmoothPixmapTransform); + + // Draw the icon onto our canvas + if (!icon.isNull()) + { + painter.drawPixmap(target_pos.x(), target_pos.y(), icon_size.width(), icon_size.height(), icon); + } + + // Finish the painting + painter.end(); + + // Scale and return our final image + return canvas.scaled(m_icon_size * device_pixel_ratio, Qt::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation); } \ No newline at end of file diff --git a/shadPS4/gui/game_list_frame.h b/shadPS4/gui/game_list_frame.h index 95e561ff..29ad1ee6 100644 --- a/shadPS4/gui/game_list_frame.h +++ b/shadPS4/gui/game_list_frame.h @@ -30,9 +30,14 @@ public : /** Refresh the gamelist with/without loading game data from files. Public so that main frame can refresh after vfs or install */ void Refresh(const bool from_drive = false, const bool scroll_after = true); + /** Repaint Gamelist Icons with new background color */ + void RepaintIcons(const bool& from_settings = false); + + private Q_SLOTS: void OnHeaderColumnClicked(int col); private: + QPixmap PaintedPixmap(const QPixmap& icon) const; void SortGameList() const; std::string CurrentSelectionPath(); void PopulateGameList(); diff --git a/shadPS4/shadps4.ini b/shadPS4/shadps4.ini index 325a6916..2160d85d 100644 --- a/shadPS4/shadps4.ini +++ b/shadPS4/shadps4.ini @@ -6,9 +6,9 @@ visibility_column_serial=true visibility_column_firmware=true visibility_column_version=true visibility_column_category=true -sortCol=4 -sortAsc=false -state="@ByteArray(\0\0\0\xff\0\0\0\0\0\0\0\x1\0\0\0\x1\0\0\0\x4\x1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x3\xfe\0\0\0\a\0\x1\0\x1\0\0\0\0\0\0\0\0\0\0\0\0\x96\xff\xff\xff\xff\0\0\0\x1\0\0\0\0\0\0\0\a\0\0\0'\0\0\0\x1\0\0\0\x2\0\0\0\xbc\0\0\0\x1\0\0\0\0\0\0\0\x42\0\0\0\x1\0\0\0\0\0\0\0=\0\0\0\x1\0\0\0\0\0\0\0\x96\0\0\0\x1\0\0\0\0\0\0\0\x96\0\0\0\x1\0\0\0\0\0\0\x1p\0\0\0\x1\0\0\0\0\0\0\x3\xe8\x1\0\0\0\x42\0\0\0\0)" +sortCol=1 +sortAsc=true +state="@ByteArray(\0\0\0\xff\0\0\0\0\0\0\0\x1\0\0\0\0\0\0\0\x1\x1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x2\xe1\0\0\0\a\0\x1\0\x1\0\0\0\0\0\0\0\0\0\0\0\0\x96\xff\xff\xff\xff\0\0\0\x1\0\0\0\0\0\0\0\a\0\0\0.\0\0\0\x1\0\0\0\x2\0\0\0\xc6\0\0\0\x1\0\0\0\0\0\0\0\x42\0\0\0\x1\0\0\0\0\0\0\0=\0\0\0\x1\0\0\0\0\0\0\0\x96\0\0\0\x1\0\0\0\0\0\0\0\x96\0\0\0\x1\0\0\0\0\0\0\0\x42\0\0\0\x1\0\0\0\0\0\0\x3\xe8\x1\0\0\0\x42\0\0\0\0)" iconColor=@Variant(\0\0\0\x43\x1\xff\xff\xf0\xf0\xf0\xf0\xf0\xf0\0\0) marginFactor=0.09 textFactor=2