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

PixelPaint: Make "Crop Image to Selection" work with disjoint layers

The "Crop Image to Selection" action will now crop all layers within
the current selection.

Any layers outside of the current selection are deleted.

If there are no layers within the current selection, a new layer the
same size as the selection is created, which has the same name as the
current active layer.
This commit is contained in:
Tim Ledbetter 2023-02-24 06:12:34 +00:00 committed by Jelle Raaijmakers
parent 89ba00304c
commit c98ec85fb5
2 changed files with 31 additions and 12 deletions

View file

@ -673,6 +673,10 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
if (editor->image().selection().is_empty())
return;
auto crop_rect = editor->image().rect().intersected(editor->image().selection().bounding_rect());
// FIXME: It is only possible to hit this condition, as transforming the image (crop, rotate etc.), does not update the selection.
// We should ensure that image transformations also transform the selection, so that its relative size and position are maintained.
if (crop_rect.is_empty())
return;
auto image_crop_or_error = editor->image().crop(crop_rect);
if (image_crop_or_error.is_error()) {
GUI::MessageBox::show_error(&window, MUST(String::formatted("Failed to crop image: {}", image_crop_or_error.release_error())));