mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:57:44 +00:00
PixelPaint: Add method to merge visible layers
This adds a function that merges all visible layers to one, ignoring the invisible.
This commit is contained in:
parent
0900e31fe0
commit
791a018c99
3 changed files with 39 additions and 0 deletions
|
@ -384,6 +384,34 @@ void Image::flatten_all_layers()
|
||||||
select_layer(&bottom_layer);
|
select_layer(&bottom_layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Image::merge_visible_layers()
|
||||||
|
{
|
||||||
|
if (m_layers.size() < 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
size_t index = 0;
|
||||||
|
|
||||||
|
while (index < m_layers.size()) {
|
||||||
|
if (m_layers.at(index).is_visible()) {
|
||||||
|
auto& bottom_layer = m_layers.at(index);
|
||||||
|
GUI::Painter painter(bottom_layer.bitmap());
|
||||||
|
paint_into(painter, { 0, 0, m_size.width(), m_size.height() });
|
||||||
|
select_layer(&bottom_layer);
|
||||||
|
index++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
while (index < m_layers.size()) {
|
||||||
|
if (m_layers.at(index).is_visible()) {
|
||||||
|
auto& layer = m_layers.at(index);
|
||||||
|
remove_layer(layer);
|
||||||
|
} else {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Image::select_layer(Layer* layer)
|
void Image::select_layer(Layer* layer)
|
||||||
{
|
{
|
||||||
for (auto* client : m_clients)
|
for (auto* client : m_clients)
|
||||||
|
|
|
@ -69,6 +69,7 @@ public:
|
||||||
void remove_layer(Layer&);
|
void remove_layer(Layer&);
|
||||||
void select_layer(Layer*);
|
void select_layer(Layer*);
|
||||||
void flatten_all_layers();
|
void flatten_all_layers();
|
||||||
|
void merge_visible_layers();
|
||||||
|
|
||||||
void add_client(ImageClient&);
|
void add_client(ImageClient&);
|
||||||
void remove_client(ImageClient&);
|
void remove_client(ImageClient&);
|
||||||
|
|
|
@ -419,6 +419,16 @@ int main(int argc, char** argv)
|
||||||
},
|
},
|
||||||
window));
|
window));
|
||||||
|
|
||||||
|
layer_menu.add_action(GUI::Action::create(
|
||||||
|
"&Merge Visible", { Mod_Ctrl, Key_M }, [&](auto&) {
|
||||||
|
auto* editor = current_image_editor();
|
||||||
|
if (!editor)
|
||||||
|
return;
|
||||||
|
editor->image().merge_visible_layers();
|
||||||
|
editor->did_complete_action();
|
||||||
|
},
|
||||||
|
window));
|
||||||
|
|
||||||
auto& filter_menu = menubar->add_menu("&Filter");
|
auto& filter_menu = menubar->add_menu("&Filter");
|
||||||
auto& spatial_filters_menu = filter_menu.add_submenu("&Spatial");
|
auto& spatial_filters_menu = filter_menu.add_submenu("&Spatial");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue