mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +00:00
PixelPaint: Add method to flatten image layers
This adds Image::flatten_all_layers() that allows the user to flatten all the visible layers into one.
This commit is contained in:
parent
76a18e1172
commit
9be08e33ea
4 changed files with 30 additions and 0 deletions
|
@ -366,6 +366,24 @@ void Image::remove_layer(Layer& layer)
|
|||
did_modify_layer_stack();
|
||||
}
|
||||
|
||||
void Image::flatten_all_layers()
|
||||
{
|
||||
if (m_layers.size() < 2)
|
||||
return;
|
||||
|
||||
auto& bottom_layer = m_layers.at(0);
|
||||
|
||||
GUI::Painter painter(bottom_layer.bitmap());
|
||||
paint_into(painter, { 0, 0, m_size.width(), m_size.height() });
|
||||
|
||||
for (size_t index = m_layers.size() - 1; index > 0; index--) {
|
||||
auto& layer = m_layers.at(index);
|
||||
remove_layer(layer);
|
||||
}
|
||||
bottom_layer.set_name("Background");
|
||||
select_layer(&bottom_layer);
|
||||
}
|
||||
|
||||
void Image::select_layer(Layer* layer)
|
||||
{
|
||||
for (auto* client : m_clients)
|
||||
|
|
|
@ -68,6 +68,7 @@ public:
|
|||
void change_layer_index(size_t old_index, size_t new_index);
|
||||
void remove_layer(Layer&);
|
||||
void select_layer(Layer*);
|
||||
void flatten_all_layers();
|
||||
|
||||
void add_client(ImageClient&);
|
||||
void remove_client(ImageClient&);
|
||||
|
|
|
@ -217,6 +217,7 @@ void LayerListWidget::image_did_remove_layer(size_t layer_index)
|
|||
m_moving_gadget_index = {};
|
||||
}
|
||||
m_gadgets.remove(layer_index);
|
||||
m_selected_layer_index = 0;
|
||||
relayout_gadgets();
|
||||
}
|
||||
|
||||
|
|
|
@ -408,6 +408,16 @@ int main(int argc, char** argv)
|
|||
layer_list_widget.on_context_menu_request = [&](auto& event) {
|
||||
layer_menu.popup(event.screen_position());
|
||||
};
|
||||
layer_menu.add_separator();
|
||||
layer_menu.add_action(GUI::Action::create(
|
||||
"&Flatten Image", { Mod_Ctrl, Key_F }, [&](auto&) {
|
||||
auto* editor = current_image_editor();
|
||||
if (!editor)
|
||||
return;
|
||||
editor->image().flatten_all_layers();
|
||||
editor->did_complete_action();
|
||||
},
|
||||
window));
|
||||
|
||||
auto& filter_menu = menubar->add_menu("&Filter");
|
||||
auto& spatial_filters_menu = filter_menu.add_submenu("&Spatial");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue