diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index 67565b7a29..a9699e131c 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -349,6 +349,11 @@ void ImageEditor::context_menu_event(GUI::ContextMenuEvent& 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) m_active_tool->on_keydown(event); } diff --git a/Userland/Applications/PixelPaint/Layer.cpp b/Userland/Applications/PixelPaint/Layer.cpp index 3b1a1e1f8b..3b974f8593 100644 --- a/Userland/Applications/PixelPaint/Layer.cpp +++ b/Userland/Applications/PixelPaint/Layer.cpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace PixelPaint { @@ -129,4 +130,13 @@ RefPtr Layer::try_copy_bitmap(Selection const& selection) const 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); +} + } diff --git a/Userland/Applications/PixelPaint/Layer.h b/Userland/Applications/PixelPaint/Layer.h index 766575cf2b..966dad2b17 100644 --- a/Userland/Applications/PixelPaint/Layer.h +++ b/Userland/Applications/PixelPaint/Layer.h @@ -61,6 +61,8 @@ public: Image const& image() const { return m_image; } + void erase_selection(Selection const&); + private: Layer(Image&, NonnullRefPtr, String name);