summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-08-25 20:58:17 +0200
committerAndreas Kling <kling@serenityos.org>2022-08-26 01:04:52 +0200
commit49deb936be01cd96920dd0e8b34ab69743027b6e (patch)
tree1f4af0afb9417eb43b72d03492602aef109c4e1b /Userland/Applications
parentd571159aebbf1e7442622efb8346d5c0657c1e03 (diff)
downloadserenity-49deb936be01cd96920dd0e8b34ab69743027b6e.zip
PixelPaint: Make selection changes undoable
Using the Rectangle Select Tool will now generate undo/redo commands like any other tool. :^)
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/PixelPaint/Image.cpp4
-rw-r--r--Userland/Applications/PixelPaint/Selection.cpp5
-rw-r--r--Userland/Applications/PixelPaint/Selection.h1
-rw-r--r--Userland/Applications/PixelPaint/Tools/RectangleSelectTool.cpp2
4 files changed, 12 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp
index ce7e16f094..ed1d2dce5b 100644
--- a/Userland/Applications/PixelPaint/Image.cpp
+++ b/Userland/Applications/PixelPaint/Image.cpp
@@ -245,6 +245,7 @@ ErrorOr<NonnullRefPtr<Image>> Image::take_snapshot() const
auto layer_snapshot = TRY(Layer::try_create_snapshot(*snapshot, layer));
snapshot->add_layer(move(layer_snapshot));
}
+ snapshot->m_selection.set_mask(m_selection.mask());
return snapshot;
}
@@ -267,6 +268,9 @@ ErrorOr<void> Image::restore_snapshot(Image const& snapshot)
select_layer(&layer(0));
m_size = snapshot.size();
+
+ m_selection.set_mask(snapshot.m_selection.mask());
+
did_change_rect();
did_modify_layer_stack();
return {};
diff --git a/Userland/Applications/PixelPaint/Selection.cpp b/Userland/Applications/PixelPaint/Selection.cpp
index 41863c2c14..386ab9cbef 100644
--- a/Userland/Applications/PixelPaint/Selection.cpp
+++ b/Userland/Applications/PixelPaint/Selection.cpp
@@ -54,4 +54,9 @@ void Selection::remove_client(SelectionClient& client)
m_clients.remove(&client);
}
+void Selection::set_mask(Mask mask)
+{
+ m_mask = move(mask);
+}
+
}
diff --git a/Userland/Applications/PixelPaint/Selection.h b/Userland/Applications/PixelPaint/Selection.h
index c47f87690e..ce19399a77 100644
--- a/Userland/Applications/PixelPaint/Selection.h
+++ b/Userland/Applications/PixelPaint/Selection.h
@@ -49,6 +49,7 @@ public:
[[nodiscard]] u8 get_selection_alpha(Gfx::IntPoint const& point) const { return get_selection_alpha(point.x(), point.y()); }
Mask const& mask() const { return m_mask; }
+ void set_mask(Mask);
void begin_interactive_selection() { m_in_interactive_selection = true; }
void end_interactive_selection() { m_in_interactive_selection = false; }
diff --git a/Userland/Applications/PixelPaint/Tools/RectangleSelectTool.cpp b/Userland/Applications/PixelPaint/Tools/RectangleSelectTool.cpp
index 14a268c46b..ac215c62ad 100644
--- a/Userland/Applications/PixelPaint/Tools/RectangleSelectTool.cpp
+++ b/Userland/Applications/PixelPaint/Tools/RectangleSelectTool.cpp
@@ -99,6 +99,8 @@ void RectangleSelectTool::on_mouseup(Layer*, MouseEvent& event)
}
m_editor->image().selection().merge(mask, m_merge_mode);
+
+ m_editor->did_complete_action(tool_name());
}
void RectangleSelectTool::on_keydown(GUI::KeyEvent& key_event)