diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index b61152a4ae..c4ada542a7 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -369,6 +369,23 @@ void Image::merge_visible_layers() } } +void Image::merge_active_layer_up(Layer& layer) +{ + if (m_layers.size() < 2) + return; + size_t layer_index = this->index_of(layer); + if ((layer_index + 1) == m_layers.size()) { + dbgln("Cannot merge layer up: layer is already at the top"); + return; // FIXME: Notify user of error properly. + } + + auto& layer_above = m_layers.at(layer_index + 1); + GUI::Painter painter(layer_above.bitmap()); + painter.draw_scaled_bitmap(rect(), layer.bitmap(), layer.rect(), (float)layer.opacity_percent() / 100.0f); + remove_layer(layer); + select_layer(&layer_above); +} + void Image::merge_active_layer_down(Layer& layer) { if (m_layers.size() < 2) diff --git a/Userland/Applications/PixelPaint/Image.h b/Userland/Applications/PixelPaint/Image.h index ac71c9141a..c425e18ffe 100644 --- a/Userland/Applications/PixelPaint/Image.h +++ b/Userland/Applications/PixelPaint/Image.h @@ -81,6 +81,7 @@ public: void select_layer(Layer*); void flatten_all_layers(); void merge_visible_layers(); + void merge_active_layer_up(Layer& layer); void merge_active_layer_down(Layer& layer); void add_client(ImageClient&); diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index 8cc78bf481..877c262856 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -591,6 +591,17 @@ void MainWidget::initialize_menubar(GUI::Window& window) editor->did_complete_action(); })); + m_layer_menu->add_action(GUI::Action::create( + "Merge &Active Layer Up", [&](auto&) { + auto* editor = current_image_editor(); + VERIFY(editor); + auto active_layer = editor->active_layer(); + if (!active_layer) + return; + editor->image().merge_active_layer_up(*active_layer); + editor->did_complete_action(); + })); + m_layer_menu->add_action(GUI::Action::create( "M&erge Active Layer Down", { Mod_Ctrl, Key_E }, [&](auto&) { auto* editor = current_image_editor();