Skip to content

Commit

Permalink
Qt: Use device pixel ratio when scaling gameicons
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jul 14, 2024
1 parent 594962d commit 5d4f6e4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/duckstation-qt/gamelistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,17 @@ QIcon GameListModel::getIconForGame(const QString& path)

void GameListModel::fixIconPixmapSize(QPixmap& pm)
{
const int width = pm.width();
const int height = pm.height();
const qreal dpr = pm.devicePixelRatio();
const int width = static_cast<int>(static_cast<float>(pm.width()) * dpr);
const int height = static_cast<int>(static_cast<float>(pm.height()) * dpr);
const int max_dim = std::max(width, height);
if (max_dim == 16)
return;

const float scale = static_cast<float>(max_dim) / 16.0f;
const float wanted_dpr = qApp->devicePixelRatio();
pm.setDevicePixelRatio(wanted_dpr);

const float scale = static_cast<float>(max_dim) / 16.0f / wanted_dpr;
const int new_width = static_cast<int>(static_cast<float>(width) / scale);
const int new_height = static_cast<int>(static_cast<float>(height) / scale);
pm = pm.scaled(new_width, new_height);
Expand Down

0 comments on commit 5d4f6e4

Please sign in to comment.