mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
d28fb8926f
There are quite a few tools that might want to change certain values based on consistent keyboard shortcuts. This commit allows tools to hook up a "primary" and "secondary" slider with the base `Tool` class, which can then handle updating those sliders with the common shortcuts. Note that any derived classes that want to override the `on_keydown` function will manually need to call `Tool::on_keydown()`.
56 lines
1.2 KiB
C++
56 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "Tool.h"
|
|
#include "ImageEditor.h"
|
|
#include <LibGUI/Action.h>
|
|
|
|
namespace PixelPaint {
|
|
|
|
Tool::Tool()
|
|
{
|
|
}
|
|
|
|
Tool::~Tool()
|
|
{
|
|
}
|
|
|
|
void Tool::setup(ImageEditor& editor)
|
|
{
|
|
m_editor = editor;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
}
|