mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:48:12 +00:00
PixelPaint: Undo and redo actions
The most used feature of any image editor, undo. Each tool now notifies the ImageEditor that they completed an action, where it'll take a snapshot if its current state. For now, a snapshot is just a copy of the whole image and its layers. There's a hard limit on the amount of actions it stores.
This commit is contained in:
parent
5aeab9878e
commit
1c27568ab0
21 changed files with 256 additions and 2 deletions
|
@ -51,12 +51,42 @@ void ImageEditor::set_image(RefPtr<Image> image)
|
|||
m_image->remove_client(*this);
|
||||
|
||||
m_image = move(image);
|
||||
m_history.reset(*m_image);
|
||||
update();
|
||||
|
||||
if (m_image)
|
||||
m_image->add_client(*this);
|
||||
}
|
||||
|
||||
void ImageEditor::did_complete_action()
|
||||
{
|
||||
if (!m_image)
|
||||
return;
|
||||
m_history.on_action(*m_image);
|
||||
}
|
||||
|
||||
bool ImageEditor::undo()
|
||||
{
|
||||
if (!m_image)
|
||||
return false;
|
||||
if (m_history.undo(*m_image)) {
|
||||
layers_did_change();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImageEditor::redo()
|
||||
{
|
||||
if (!m_image)
|
||||
return false;
|
||||
if (m_history.redo(*m_image)) {
|
||||
layers_did_change();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ImageEditor::paint_event(GUI::PaintEvent& event)
|
||||
{
|
||||
GUI::Frame::paint_event(event);
|
||||
|
@ -371,4 +401,9 @@ void ImageEditor::image_did_change()
|
|||
update();
|
||||
}
|
||||
|
||||
void ImageEditor::image_select_layer(Layer* layer)
|
||||
{
|
||||
set_active_layer(layer);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue