summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorMustafa Quraish <mustafaq9@gmail.com>2021-09-02 03:10:59 -0400
committerAndreas Kling <kling@serenityos.org>2021-09-03 01:49:32 +0200
commit339f0d5bcaf2c1197bdf8c376f30f106adefff4d (patch)
tree3a5ac54552e3a4ba0ab15d82861eec9150fd22c8 /Userland
parent97cc34c03441cef5cb601356c474debf2e85253f (diff)
downloadserenity-339f0d5bcaf2c1197bdf8c376f30f106adefff4d.zip
PixelPaint: Add `Merge Active Layer Down` action
This allows you to merge the active layer with the one below it.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/PixelPaint/Image.cpp18
-rw-r--r--Userland/Applications/PixelPaint/Image.h2
-rw-r--r--Userland/Applications/PixelPaint/main.cpp13
3 files changed, 33 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp
index 6f3676fa9a..271800c374 100644
--- a/Userland/Applications/PixelPaint/Image.cpp
+++ b/Userland/Applications/PixelPaint/Image.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -483,6 +484,23 @@ void Image::merge_visible_layers()
}
}
+void Image::merge_active_layer_down(Layer& layer)
+{
+ if (m_layers.size() < 2)
+ return;
+ int layer_index = this->index_of(layer);
+ if (layer_index == 0) {
+ dbgln("Cannot merge layer down: layer is already at the bottom");
+ return; // FIXME: Notify user of error properly.
+ }
+
+ auto& layer_below = m_layers.at(layer_index - 1);
+ GUI::Painter painter(layer_below.bitmap());
+ painter.draw_scaled_bitmap(rect(), layer.bitmap(), layer.rect(), (float)layer.opacity_percent() / 100.0f);
+ remove_layer(layer);
+ select_layer(&layer_below);
+}
+
void Image::select_layer(Layer* layer)
{
for (auto* client : m_clients)
diff --git a/Userland/Applications/PixelPaint/Image.h b/Userland/Applications/PixelPaint/Image.h
index f4c693d5e3..cefd0551e3 100644
--- a/Userland/Applications/PixelPaint/Image.h
+++ b/Userland/Applications/PixelPaint/Image.h
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -74,6 +75,7 @@ public:
void select_layer(Layer*);
void flatten_all_layers();
void merge_visible_layers();
+ void merge_active_layer_down(Layer& layer);
void add_client(ImageClient&);
void remove_client(ImageClient&);
diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp
index 246e7ddaa9..dc82695dfd 100644
--- a/Userland/Applications/PixelPaint/main.cpp
+++ b/Userland/Applications/PixelPaint/main.cpp
@@ -541,6 +541,19 @@ int main(int argc, char** argv)
},
window));
+ layer_menu.add_action(GUI::Action::create(
+ "M&erge Active Layer Down", { Mod_Ctrl, Key_E }, [&](auto&) {
+ auto* editor = current_image_editor();
+ if (!editor)
+ return;
+ auto active_layer = editor->active_layer();
+ if (!active_layer)
+ return;
+ editor->image().merge_active_layer_down(*active_layer);
+ editor->did_complete_action();
+ },
+ window));
+
auto& filter_menu = window->add_menu("&Filter");
auto& spatial_filters_menu = filter_menu.add_submenu("&Spatial");