From 25ac38cac151bd9a1e1d95363414c1aba3f9d5bf Mon Sep 17 00:00:00 2001 From: Timothy Slater Date: Tue, 30 Aug 2022 05:54:04 -0500 Subject: [PATCH] PixelPaint: Make erase_selection work for non-rectangular selections Layer::erase_selection used to erase the entire bounding box of the selection. With the add/subtract merge modes for the selection tool it is possible to create selections which are not rectangular. This leads to deleting pixels that were not selected. This change adjusts the erase behavior to walk the selection rect and check if a pixel is selected or not before deleting. --- Userland/Applications/PixelPaint/Layer.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Userland/Applications/PixelPaint/Layer.cpp b/Userland/Applications/PixelPaint/Layer.cpp index ef9d500585..90b8609a44 100644 --- a/Userland/Applications/PixelPaint/Layer.cpp +++ b/Userland/Applications/PixelPaint/Layer.cpp @@ -135,10 +135,19 @@ RefPtr Layer::try_copy_bitmap(Selection const& selection) const void Layer::erase_selection(Selection const& selection) { - Gfx::Painter painter { content_bitmap() }; auto const image_and_selection_intersection = m_image.rect().intersected(selection.bounding_rect()); auto const translated_to_layer_space = image_and_selection_intersection.translated(-location()); - painter.clear_rect(translated_to_layer_space, Color::Transparent); + + for (int y = translated_to_layer_space.top(); y < translated_to_layer_space.top() + translated_to_layer_space.height(); ++y) { + for (int x = translated_to_layer_space.left(); x < translated_to_layer_space.left() + translated_to_layer_space.width(); ++x) { + + // Selection is still in pre-translated coordinates, account for this by adding the layer's relative location + if (selection.is_selected(x + location().x(), y + location().y())) { + content_bitmap().set_pixel(x, y, Color::Transparent); + } + } + } + did_modify_bitmap(translated_to_layer_space); }