diff options
author | Nico Weber <thakis@chromium.org> | 2021-01-22 15:13:47 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-22 22:13:53 +0100 |
commit | 2ec6bbd7a15088c2e56e1450132b05777093e89c (patch) | |
tree | f2f4f0c45e27535ca1d5e1392d276f6618a4a364 /Userland/Services | |
parent | 7278ff66051f9b71403c28521c3f07c11d4e8ff5 (diff) | |
download | serenity-2ec6bbd7a15088c2e56e1450132b05777093e89c.zip |
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.
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/WindowServer/Compositor.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Userland/Services/WindowServer/Compositor.cpp b/Userland/Services/WindowServer/Compositor.cpp index e93d4fddbf..1be79338bb 100644 --- a/Userland/Services/WindowServer/Compositor.cpp +++ b/Userland/Services/WindowServer/Compositor.cpp @@ -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(); } |