1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:07:46 +00:00

PixelPaint: Allow panning when right-clicking with MoveTool

The MoveTool now lets you pan if you're dragging with a right click.
Previously, right-clicking did not perform any actions at all, so this
isn't removing any old functionality.
This commit is contained in:
Mustafa Quraish 2021-09-11 23:26:09 -04:00 committed by Andreas Kling
parent abefe2391d
commit dd0cc58d6c
2 changed files with 26 additions and 0 deletions

View file

@ -25,6 +25,14 @@ MoveTool::~MoveTool()
void MoveTool::on_mousedown(Layer* layer, MouseEvent& event)
{
if (event.image_event().button() == GUI::MouseButton::Right && !m_is_panning) {
m_is_panning = true;
m_event_origin = event.raw_event().position();
m_saved_pan_origin = m_editor->pan_origin();
m_editor->set_override_cursor(Gfx::StandardCursor::Drag);
return;
}
if (!layer)
return;
@ -41,6 +49,15 @@ void MoveTool::on_mousedown(Layer* layer, MouseEvent& event)
void MoveTool::on_mousemove(Layer* layer, MouseEvent& event)
{
if (m_is_panning) {
auto& raw_event = event.raw_event();
auto delta = raw_event.position() - m_event_origin;
m_editor->set_pan_origin(m_saved_pan_origin.translated(
-delta.x(),
-delta.y()));
return;
}
if (!layer)
return;
@ -54,6 +71,12 @@ void MoveTool::on_mousemove(Layer* layer, MouseEvent& event)
void MoveTool::on_mouseup(Layer* layer, MouseEvent& event)
{
if (event.image_event().button() == GUI::MouseButton::Right && m_is_panning) {
m_is_panning = false;
m_editor->set_override_cursor(cursor());
return;
}
if (!layer)
return;