From 5bafb80255073e4c85a34708fe1e3d3e05749e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcolas=20F=2E=20R=2E=20A=2E=20Prado?= Date: Mon, 28 Feb 2022 22:28:55 -0500 Subject: [PATCH] SoundPlayer: Draw album cover with correct aspect ratio Instead of drawing the album cover scaled to cover the whole visualization area, draw it resized to fit the area without altering the aspect ratio. --- .../SoundPlayer/AlbumCoverVisualizationWidget.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/SoundPlayer/AlbumCoverVisualizationWidget.cpp b/Userland/Applications/SoundPlayer/AlbumCoverVisualizationWidget.cpp index c4bee0352c..2e69a68b00 100644 --- a/Userland/Applications/SoundPlayer/AlbumCoverVisualizationWidget.cpp +++ b/Userland/Applications/SoundPlayer/AlbumCoverVisualizationWidget.cpp @@ -10,6 +10,7 @@ #include #include #include +#include void AlbumCoverVisualizationWidget::paint_event(GUI::PaintEvent& event) { @@ -17,7 +18,16 @@ void AlbumCoverVisualizationWidget::paint_event(GUI::PaintEvent& event) GUI::Painter painter(*this); if (m_album_cover) { - painter.draw_scaled_bitmap(frame_inner_rect(), *m_album_cover, m_album_cover->rect(), 1.0f); + auto album_cover_rect = m_album_cover->rect(); + + auto height_ratio = frame_inner_rect().height() / (float)album_cover_rect.height(); + auto width_ratio = frame_inner_rect().width() / (float)album_cover_rect.width(); + auto scale = min(height_ratio, width_ratio); + + Gfx::IntRect fitted_rect = { 0, 0, (int)(album_cover_rect.width() * scale), (int)(album_cover_rect.height() * scale) }; + fitted_rect.center_within(frame_inner_rect()); + + painter.draw_scaled_bitmap(fitted_rect, *m_album_cover, m_album_cover->rect(), 1.0f); } else { if (!m_serenity_bg) m_serenity_bg = Gfx::Bitmap::try_load_from_file("/res/wallpapers/sunset-retro.png").release_value_but_fixme_should_propagate_errors();