diff options
-rw-r--r-- | Userland/Applications/PixelPaint/Tool.cpp | 25 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/Tool.h | 10 |
2 files changed, 34 insertions, 1 deletions
diff --git a/Userland/Applications/PixelPaint/Tool.cpp b/Userland/Applications/PixelPaint/Tool.cpp index 82b3b37424..0d747807b0 100644 --- a/Userland/Applications/PixelPaint/Tool.cpp +++ b/Userland/Applications/PixelPaint/Tool.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -28,4 +29,28 @@ void Tool::set_action(GUI::Action* action) m_action = action; } +void Tool::on_keydown(GUI::KeyEvent& event) +{ + switch (event.key()) { + case KeyCode::Key_LeftBracket: + if (m_primary_slider) + m_primary_slider->set_value(m_primary_slider->value() - 1); + break; + case KeyCode::Key_RightBracket: + if (m_primary_slider) + m_primary_slider->set_value(m_primary_slider->value() + 1); + break; + case KeyCode::Key_LeftBrace: + if (m_secondary_slider) + m_secondary_slider->set_value(m_secondary_slider->value() - 1); + break; + case KeyCode::Key_RightBrace: + if (m_secondary_slider) + m_secondary_slider->set_value(m_secondary_slider->value() + 1); + break; + default: + break; + } +} + } diff --git a/Userland/Applications/PixelPaint/Tool.h b/Userland/Applications/PixelPaint/Tool.h index 6466d051ae..be2d783166 100644 --- a/Userland/Applications/PixelPaint/Tool.h +++ b/Userland/Applications/PixelPaint/Tool.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -8,6 +9,7 @@ #include <LibGUI/Event.h> #include <LibGUI/Forward.h> +#include <LibGUI/ValueSlider.h> #include <LibGfx/StandardCursor.h> namespace PixelPaint { @@ -54,7 +56,7 @@ public: virtual void on_context_menu(Layer*, GUI::ContextMenuEvent&) { } virtual void on_tool_button_contextmenu(GUI::ContextMenuEvent&) { } virtual void on_second_paint(Layer const*, GUI::PaintEvent&) { } - virtual void on_keydown(GUI::KeyEvent&) { } + virtual void on_keydown(GUI::KeyEvent&); virtual void on_keyup(GUI::KeyEvent&) { } virtual void on_tool_activation() { } virtual GUI::Widget* get_properties_widget() { return nullptr; } @@ -73,6 +75,12 @@ protected: Tool(); WeakPtr<ImageEditor> m_editor; RefPtr<GUI::Action> m_action; + + void set_primary_slider(GUI::ValueSlider* primary) { m_primary_slider = primary; } + void set_secondary_slider(GUI::ValueSlider* secondary) { m_secondary_slider = secondary; } + + GUI::ValueSlider* m_primary_slider { nullptr }; + GUI::ValueSlider* m_secondary_slider { nullptr }; }; } |