mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
for (auto* client : m_clients)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue