mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
PaintBrush: Make the move tool handle arrow key events
You can now nudge layers around with the arrow keys. :^)
This commit is contained in:
parent
06405e83d7
commit
8318842c7e
Notes:
sideshowbarker
2024-07-19 06:40:53 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/8318842c7e5
2 changed files with 33 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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"; }
|
||||
|
|
Loading…
Reference in a new issue