Skip to content

Commit

Permalink
PaintBrush: Added 'Move active layer up/down' to the Menu
Browse files Browse the repository at this point in the history
This allowes the active layer to be moved up or down.
  • Loading branch information
phoffmeister authored and awesomekling committed May 14, 2020
1 parent 80a3606 commit 49727ff
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Applications/PaintBrush/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ void Image::move_layer_to_front(Layer& layer)
m_layers.append(layer);
}

void Image::move_layer_down(Layer& layer)
{
NonnullRefPtr<Layer> protector(layer);
auto index = index_of(layer);
if (!index)
return;
m_layers.remove(index);
m_layers.insert(index - 1, layer);
}

void Image::move_layer_up(Layer& layer)
{
NonnullRefPtr<Layer> protector(layer);
auto index = index_of(layer);
if (index == m_layers.size() - 1)
return;
m_layers.remove(index);
m_layers.insert(index + 1, layer);
}

void Image::remove_layer(Layer& layer)
{
NonnullRefPtr<Layer> protector(layer);
Expand Down
2 changes: 2 additions & 0 deletions Applications/PaintBrush/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class Image : public RefCounted<Image> {

void move_layer_to_front(Layer&);
void move_layer_to_back(Layer&);
void move_layer_up(Layer&);
void move_layer_down(Layer&);
void remove_layer(Layer&);

private:
Expand Down
17 changes: 17 additions & 0 deletions Applications/PaintBrush/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ int main(int argc, char** argv)
layer_table_view.selection().set(layer_table_view.model()->index(0));
}, window));
layer_menu.add_separator();
layer_menu.add_action(GUI::Action::create("Move active layer up", { Mod_Ctrl, Key_PageUp }, [&](auto&) {
auto active_layer = image_editor.active_layer();
if(!active_layer)
return;
image_editor.image()->move_layer_up(*active_layer);
layer_table_view.move_selection(1);
image_editor.layers_did_change();
}, window));
layer_menu.add_action(GUI::Action::create("Move active layer down", { Mod_Ctrl, Key_PageDown }, [&](auto&) {
auto active_layer = image_editor.active_layer();
if(!active_layer)
return;
image_editor.image()->move_layer_down(*active_layer);
layer_table_view.move_selection(-1);
image_editor.layers_did_change();
}, window));
layer_menu.add_separator();
layer_menu.add_action(GUI::Action::create("Remove active layer", { Mod_Ctrl , Key_D }, [&](auto&) {
auto active_layer = image_editor.active_layer();
if(!active_layer)
Expand Down

0 comments on commit 49727ff

Please sign in to comment.