mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
PixelPaint: Add Merge Active Layer Down
action
This allows you to merge the active layer with the one below it.
This commit is contained in:
parent
97cc34c034
commit
339f0d5bca
Notes:
sideshowbarker
2024-07-18 04:51:11 +09:00
Author: https://github.com/mustafaquraish Commit: https://github.com/SerenityOS/serenity/commit/339f0d5bcaf Pull-request: https://github.com/SerenityOS/serenity/pull/9745 Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 33 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -483,6 +484,23 @@ void Image::merge_visible_layers()
|
|||
}
|
||||
}
|
||||
|
||||
void Image::merge_active_layer_down(Layer& layer)
|
||||
{
|
||||
if (m_layers.size() < 2)
|
||||
return;
|
||||
int layer_index = this->index_of(layer);
|
||||
if (layer_index == 0) {
|
||||
dbgln("Cannot merge layer down: layer is already at the bottom");
|
||||
return; // FIXME: Notify user of error properly.
|
||||
}
|
||||
|
||||
auto& layer_below = m_layers.at(layer_index - 1);
|
||||
GUI::Painter painter(layer_below.bitmap());
|
||||
painter.draw_scaled_bitmap(rect(), layer.bitmap(), layer.rect(), (float)layer.opacity_percent() / 100.0f);
|
||||
remove_layer(layer);
|
||||
select_layer(&layer_below);
|
||||
}
|
||||
|
||||
void Image::select_layer(Layer* layer)
|
||||
{
|
||||
for (auto* client : m_clients)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -74,6 +75,7 @@ public:
|
|||
void select_layer(Layer*);
|
||||
void flatten_all_layers();
|
||||
void merge_visible_layers();
|
||||
void merge_active_layer_down(Layer& layer);
|
||||
|
||||
void add_client(ImageClient&);
|
||||
void remove_client(ImageClient&);
|
||||
|
|
|
@ -541,6 +541,19 @@ int main(int argc, char** argv)
|
|||
},
|
||||
window));
|
||||
|
||||
layer_menu.add_action(GUI::Action::create(
|
||||
"M&erge Active Layer Down", { Mod_Ctrl, Key_E }, [&](auto&) {
|
||||
auto* editor = current_image_editor();
|
||||
if (!editor)
|
||||
return;
|
||||
auto active_layer = editor->active_layer();
|
||||
if (!active_layer)
|
||||
return;
|
||||
editor->image().merge_active_layer_down(*active_layer);
|
||||
editor->did_complete_action();
|
||||
},
|
||||
window));
|
||||
|
||||
auto& filter_menu = window->add_menu("&Filter");
|
||||
auto& spatial_filters_menu = filter_menu.add_submenu("&Spatial");
|
||||
|
||||
|
|
Loading…
Reference in a new issue