mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:47:34 +00:00
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.
This commit is contained in:
parent
062c9efa88
commit
799d570afc
4 changed files with 20 additions and 0 deletions
|
@ -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()) {
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue