1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:38:11 +00:00

LibGfx: Add a draw_scaled_bitmap() variant that takes a FloatRect as src_rect

Consider

    draw_scaled_bitmap({0, 0, 10, 10}, source, {0, 0, 5, 5}).

Imagine wanting to split that up into two calls, like e.g. the
compositor when redrawing the background with damage rects. You really
want to be able to say

    draw_scaled_bitmap({0, 0, 5, 10}, source, {0, 0, 2.5, 5})

but up to now you couldn't. Now you can.

This makes painting very low-res images (such as tile.png) in mode
"stretch" work much better.
This commit is contained in:
Nico Weber 2021-01-22 15:13:47 -05:00 committed by Andreas Kling
parent 7278ff6605
commit 2ec6bbd7a1
4 changed files with 31 additions and 20 deletions

View file

@ -262,11 +262,12 @@ void Compositor::compose()
} else if (m_wallpaper_mode == WallpaperMode::Tile) {
painter.draw_tiled_bitmap(rect, *m_wallpaper);
} else if (m_wallpaper_mode == WallpaperMode::Stretch) {
float hscale = (float)m_wallpaper->size().width() / (float)ws.size().width();
float vscale = (float)m_wallpaper->size().height() / (float)ws.size().height();
float hscale = (float)m_wallpaper->width() / (float)ws.width();
float vscale = (float)m_wallpaper->height() / (float)ws.height();
// TODO: this may look ugly, we should scale to a backing bitmap and then blit
painter.draw_scaled_bitmap(rect, *m_wallpaper, { rect.x() * hscale, rect.y() * vscale, rect.width() * hscale, rect.height() * vscale });
auto src_rect = Gfx::FloatRect { rect.x() * hscale, rect.y() * vscale, rect.width() * hscale, rect.height() * vscale };
painter.draw_scaled_bitmap(rect, *m_wallpaper, src_rect);
} else {
ASSERT_NOT_REACHED();
}