diff options
author | Sergiy Stupar <owner@sestolab.pp.ua> | 2022-09-11 19:56:17 +0300 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2022-10-06 12:29:16 +0100 |
commit | 8a37badc421d5e04157796a97ac348a7a12e8bb4 (patch) | |
tree | 2324fa82e39ffb3e5cf603485de4af0837d55dfa /Userland/Applications | |
parent | d77ced89433bcd5422563b74079420116ec95a1d (diff) | |
download | serenity-8a37badc421d5e04157796a97ac348a7a12e8bb4.zip |
PixelPaint: Add actions to crop layer to selection/content
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/PixelPaint/MainWidget.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index 6bb0af657c..5f9c93e0eb 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -815,6 +815,37 @@ void MainWidget::initialize_menubar(GUI::Window& window) editor->did_complete_action("Rotate Layer Clockwise"sv); })); + m_layer_menu->add_separator(); + m_layer_menu->add_action(GUI::Action::create( + "&Crop Layer to Selection", g_icon_bag.crop, [&](auto&) { + auto* editor = current_image_editor(); + VERIFY(editor); + // FIXME: disable this action if there is no selection + auto active_layer = editor->active_layer(); + if (!active_layer || editor->image().selection().is_empty()) + return; + auto intersection = editor->image().rect().intersected(editor->image().selection().bounding_rect()); + auto crop_rect = intersection.translated(-active_layer->location()); + active_layer->crop(crop_rect); + active_layer->set_location(intersection.location()); + editor->image().selection().clear(); + editor->did_complete_action("Crop Layer to Selection"sv); + })); + m_layer_menu->add_action(GUI::Action::create( + "&Crop Layer to Content", g_icon_bag.crop, [&](auto&) { + auto* editor = current_image_editor(); + VERIFY(editor); + auto active_layer = editor->active_layer(); + if (!active_layer) + return; + auto content_bounding_rect = active_layer->nonempty_content_bounding_rect(); + if (!content_bounding_rect.has_value()) + return; + active_layer->crop(content_bounding_rect.value()); + active_layer->set_location(content_bounding_rect->location()); + editor->did_complete_action("Crop Layer to Content"sv); + })); + m_filter_menu = window.add_menu("&Filter"); m_filter_menu->add_action(GUI::Action::create("Filter &Gallery", g_icon_bag.filter, [&](auto&) { |