mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
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.
This commit is contained in:
parent
a373542f4c
commit
25ac38cac1
Notes:
sideshowbarker
2024-07-17 07:35:48 +09:00
Author: https://github.com/tslater2006 Commit: https://github.com/SerenityOS/serenity/commit/25ac38cac1 Pull-request: https://github.com/SerenityOS/serenity/pull/15076 Reviewed-by: https://github.com/linusg
1 changed files with 11 additions and 2 deletions
|
@ -135,10 +135,19 @@ RefPtr<Gfx::Bitmap> 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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue