summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Ledbetter <timledbetter@gmail.com>2023-02-25 06:46:18 +0000
committerAndreas Kling <kling@serenityos.org>2023-02-26 13:09:16 +0100
commit799d570afce18b0e84f7cf84b3d9edd2119480df (patch)
treeac0c1522c5f78ac4aadd23dce417aee06e374ceb
parent062c9efa8813e66461c5978b3bfc06de85ad5d76 (diff)
downloadserenity-799d570afce18b0e84f7cf84b3d9edd2119480df.zip
PixelPaint: Add "Apply Mask" action
This commit adds a "Apply Mask" action which merges the active layer mask with the layer bitmap. The option is only displayed if the active layer is masked.
-rw-r--r--Userland/Applications/PixelPaint/Layer.cpp8
-rw-r--r--Userland/Applications/PixelPaint/Layer.h2
-rw-r--r--Userland/Applications/PixelPaint/MainWidget.cpp9
-rw-r--r--Userland/Applications/PixelPaint/MainWidget.h1
4 files changed, 20 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/Layer.cpp b/Userland/Applications/PixelPaint/Layer.cpp
index 8869c2dd85..e861185b00 100644
--- a/Userland/Applications/PixelPaint/Layer.cpp
+++ b/Userland/Applications/PixelPaint/Layer.cpp
@@ -324,6 +324,14 @@ void Layer::delete_mask()
update_cached_bitmap();
}
+void Layer::apply_mask()
+{
+ m_content_bitmap->fill(Color::Transparent);
+ Gfx::Painter painter(m_content_bitmap);
+ painter.blit({}, m_cached_display_bitmap, m_cached_display_bitmap->rect());
+ delete_mask();
+}
+
Gfx::Bitmap& Layer::currently_edited_bitmap()
{
switch (edit_mode()) {
diff --git a/Userland/Applications/PixelPaint/Layer.h b/Userland/Applications/PixelPaint/Layer.h
index ef4156f4ea..8b1ec55f8e 100644
--- a/Userland/Applications/PixelPaint/Layer.h
+++ b/Userland/Applications/PixelPaint/Layer.h
@@ -47,6 +47,8 @@ public:
ErrorOr<void> create_mask();
void delete_mask();
+ void apply_mask();
+
Gfx::Bitmap& get_scratch_edited_bitmap();
Gfx::IntSize size() const { return content_bitmap().size(); }
diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp
index 705286cce2..9ed19ba725 100644
--- a/Userland/Applications/PixelPaint/MainWidget.cpp
+++ b/Userland/Applications/PixelPaint/MainWidget.cpp
@@ -774,6 +774,13 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
}));
m_layer_menu->add_action(*m_delete_mask_action);
+ m_apply_mask_action = GUI::Action::create(
+ "Apply Mask", create_layer_mask_callback("Apply Mask", [&](Layer* active_layer) {
+ VERIFY(active_layer->is_masked());
+ active_layer->apply_mask();
+ }));
+ m_layer_menu->add_action(*m_apply_mask_action);
+
m_layer_menu->add_separator();
m_layer_menu->add_action(GUI::Action::create(
@@ -1137,6 +1144,7 @@ void MainWidget::set_mask_actions_for_layer(Layer* layer)
if (!layer) {
m_add_mask_action->set_visible(true);
m_delete_mask_action->set_visible(false);
+ m_apply_mask_action->set_visible(false);
m_add_mask_action->set_enabled(false);
return;
}
@@ -1146,6 +1154,7 @@ void MainWidget::set_mask_actions_for_layer(Layer* layer)
auto masked = layer->is_masked();
m_add_mask_action->set_visible(!masked);
m_delete_mask_action->set_visible(masked);
+ m_apply_mask_action->set_visible(masked);
}
void MainWidget::open_image(FileSystemAccessClient::File file)
diff --git a/Userland/Applications/PixelPaint/MainWidget.h b/Userland/Applications/PixelPaint/MainWidget.h
index b419b4f0f1..a72593b4f7 100644
--- a/Userland/Applications/PixelPaint/MainWidget.h
+++ b/Userland/Applications/PixelPaint/MainWidget.h
@@ -113,6 +113,7 @@ private:
RefPtr<GUI::Action> m_add_mask_action;
RefPtr<GUI::Action> m_delete_mask_action;
+ RefPtr<GUI::Action> m_apply_mask_action;
Gfx::IntPoint m_last_image_editor_mouse_position;
};