From 8318842c7e5a9ec72cdd7bcb10786749bf773793 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 13 May 2020 13:20:54 +0200 Subject: [PATCH] PaintBrush: Make the move tool handle arrow key events You can now nudge layers around with the arrow keys. :^) --- Applications/PaintBrush/MoveTool.cpp | 32 ++++++++++++++++++++++++++++ Applications/PaintBrush/MoveTool.h | 1 + 2 files changed, 33 insertions(+) diff --git a/Applications/PaintBrush/MoveTool.cpp b/Applications/PaintBrush/MoveTool.cpp index 372061a3667..99810243515 100644 --- a/Applications/PaintBrush/MoveTool.cpp +++ b/Applications/PaintBrush/MoveTool.cpp @@ -69,4 +69,36 @@ void MoveTool::on_mouseup(Layer&, GUI::MouseEvent& event, GUI::MouseEvent&) m_editor->window()->set_override_cursor(GUI::StandardCursor::None); } +void MoveTool::on_keydown(GUI::KeyEvent& event) +{ + if (event.modifiers() != 0) + return; + + auto* layer = m_editor->active_layer(); + if (!layer) + return; + + auto new_location = layer->location(); + + switch (event.key()) { + case Key_Up: + new_location.move_by(0, -1); + break; + case Key_Down: + new_location.move_by(0, 1); + break; + case Key_Left: + new_location.move_by(-1, 0); + break; + case Key_Right: + new_location.move_by(1, 0); + break; + default: + return; + } + + layer->set_location(new_location); + m_editor->layers_did_change(); +} + } diff --git a/Applications/PaintBrush/MoveTool.h b/Applications/PaintBrush/MoveTool.h index b4718dcb2bd..68cc76e90c6 100644 --- a/Applications/PaintBrush/MoveTool.h +++ b/Applications/PaintBrush/MoveTool.h @@ -38,6 +38,7 @@ public: virtual void on_mousedown(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; virtual void on_mousemove(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; virtual void on_mouseup(Layer&, GUI::MouseEvent& layer_event, GUI::MouseEvent& original_event) override; + virtual void on_keydown(GUI::KeyEvent&) override; private: virtual const char* class_name() const override { return "MoveTool"; }