mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:17:34 +00:00
PixelPaint: Add delete selection behavior
The delete key can now be used to erase the pixels on the active layer contained within the selection rectangle. Closes #11861
This commit is contained in:
parent
d3e7ec5a56
commit
d3dfb957a6
3 changed files with 17 additions and 0 deletions
|
@ -349,6 +349,11 @@ void ImageEditor::context_menu_event(GUI::ContextMenuEvent& event)
|
||||||
|
|
||||||
void ImageEditor::keydown_event(GUI::KeyEvent& event)
|
void ImageEditor::keydown_event(GUI::KeyEvent& event)
|
||||||
{
|
{
|
||||||
|
if (event.key() == Key_Delete && !selection().is_empty() && active_layer()) {
|
||||||
|
active_layer()->erase_selection(selection());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_active_tool)
|
if (m_active_tool)
|
||||||
m_active_tool->on_keydown(event);
|
m_active_tool->on_keydown(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <AK/Try.h>
|
#include <AK/Try.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
|
#include <LibGfx/Painter.h>
|
||||||
|
|
||||||
namespace PixelPaint {
|
namespace PixelPaint {
|
||||||
|
|
||||||
|
@ -129,4 +130,13 @@ RefPtr<Gfx::Bitmap> Layer::try_copy_bitmap(Selection const& selection) const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Layer::erase_selection(Selection const& selection)
|
||||||
|
{
|
||||||
|
Gfx::Painter painter { bitmap() };
|
||||||
|
auto const image_and_selection_intersection = m_image.rect().intersected(selection.bounding_rect());
|
||||||
|
auto const translated_to_layer_space = image_and_selection_intersection.translated(-location());
|
||||||
|
painter.clear_rect(translated_to_layer_space, Color::Transparent);
|
||||||
|
did_modify_bitmap(translated_to_layer_space);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,8 @@ public:
|
||||||
|
|
||||||
Image const& image() const { return m_image; }
|
Image const& image() const { return m_image; }
|
||||||
|
|
||||||
|
void erase_selection(Selection const&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Layer(Image&, NonnullRefPtr<Gfx::Bitmap>, String name);
|
Layer(Image&, NonnullRefPtr<Gfx::Bitmap>, String name);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue