PaintBrush: Clip layer contents outside the image rect when compositing

This commit is contained in:
Andreas Kling 2020-05-13 21:12:32 +02:00
parent 14aa7f2d44
commit 0f3e58ffe0
Notes: sideshowbarker 2024-07-19 06:40:06 +09:00

View file

@ -51,12 +51,16 @@ Image::Image(const Gfx::Size& size)
void Image::paint_into(GUI::Painter& painter, const Gfx::Rect& dest_rect, const Gfx::Rect& src_rect)
{
(void) src_rect;
Gfx::PainterStateSaver saver(painter);
painter.add_clip_rect(dest_rect);
for (auto& layer : m_layers) {
auto target = dest_rect.translated(layer.location());
target.set_size(layer.size());
#ifdef IMAGE_DEBUG
dbg() << "Composite layer " << layer.name() << " target: " << target << ", src_rect: " << src_rect;
dbg() << "Composite layer " << layer.name() << " target: " << target << ", layer.rect: " << layer.rect();
#endif
painter.draw_scaled_bitmap(target, layer.bitmap(), src_rect);
painter.draw_scaled_bitmap(target, layer.bitmap(), layer.rect());
}
}