mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
PixelPaint: Add new selection moving modes
If you press "spacebar" while moving a selection, it will now move the origin point of the selection; and if you press "control" it will move it relatively to the center.
This commit is contained in:
parent
e2215cc0e1
commit
90873781c1
2 changed files with 33 additions and 0 deletions
|
@ -37,6 +37,14 @@ void RectangleSelectTool::on_mousemove(Layer&, GUI::MouseEvent&, GUI::MouseEvent
|
||||||
if (!m_selecting)
|
if (!m_selecting)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (m_moving_mode != MovingMode::None) {
|
||||||
|
auto delta = m_selection_end - image_event.position();
|
||||||
|
if (m_moving_mode == MovingMode::MovingOrigin)
|
||||||
|
m_selection_start -= delta;
|
||||||
|
else if (m_moving_mode == MovingMode::AroundCenter)
|
||||||
|
m_selection_start += delta;
|
||||||
|
}
|
||||||
|
|
||||||
m_selection_end = image_event.position();
|
m_selection_end = image_event.position();
|
||||||
m_editor->update();
|
m_editor->update();
|
||||||
}
|
}
|
||||||
|
@ -55,6 +63,22 @@ void RectangleSelectTool::on_mouseup(Layer&, GUI::MouseEvent&, GUI::MouseEvent&
|
||||||
m_editor->selection().set(rect_in_image);
|
m_editor->selection().set(rect_in_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RectangleSelectTool::on_keydown(GUI::KeyEvent& key_event)
|
||||||
|
{
|
||||||
|
if (key_event.key() == KeyCode::Key_Space)
|
||||||
|
m_moving_mode = MovingMode::MovingOrigin;
|
||||||
|
else if (key_event.key() == KeyCode::Key_Control)
|
||||||
|
m_moving_mode = MovingMode::AroundCenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RectangleSelectTool::on_keyup(GUI::KeyEvent& key_event)
|
||||||
|
{
|
||||||
|
if (key_event.key() == KeyCode::Key_Space && m_moving_mode == MovingMode::MovingOrigin)
|
||||||
|
m_moving_mode = MovingMode::None;
|
||||||
|
else if (key_event.key() == KeyCode::Key_Control && m_moving_mode == MovingMode::AroundCenter)
|
||||||
|
m_moving_mode = MovingMode::None;
|
||||||
|
}
|
||||||
|
|
||||||
void RectangleSelectTool::on_second_paint(Layer const&, GUI::PaintEvent& event)
|
void RectangleSelectTool::on_second_paint(Layer const&, GUI::PaintEvent& event)
|
||||||
{
|
{
|
||||||
if (!m_selecting)
|
if (!m_selecting)
|
||||||
|
|
|
@ -18,10 +18,19 @@ public:
|
||||||
virtual void on_mousedown(Layer&, GUI::MouseEvent&, GUI::MouseEvent&) override;
|
virtual void on_mousedown(Layer&, GUI::MouseEvent&, GUI::MouseEvent&) override;
|
||||||
virtual void on_mousemove(Layer&, GUI::MouseEvent&, GUI::MouseEvent&) override;
|
virtual void on_mousemove(Layer&, GUI::MouseEvent&, GUI::MouseEvent&) override;
|
||||||
virtual void on_mouseup(Layer&, GUI::MouseEvent&, GUI::MouseEvent&) override;
|
virtual void on_mouseup(Layer&, GUI::MouseEvent&, GUI::MouseEvent&) override;
|
||||||
|
virtual void on_keydown(GUI::KeyEvent&) override;
|
||||||
|
virtual void on_keyup(GUI::KeyEvent&) override;
|
||||||
virtual void on_second_paint(Layer const&, GUI::PaintEvent&) override;
|
virtual void on_second_paint(Layer const&, GUI::PaintEvent&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum class MovingMode {
|
||||||
|
MovingOrigin,
|
||||||
|
AroundCenter,
|
||||||
|
None,
|
||||||
|
};
|
||||||
|
|
||||||
bool m_selecting { false };
|
bool m_selecting { false };
|
||||||
|
MovingMode m_moving_mode { MovingMode::None };
|
||||||
Gfx::IntPoint m_selection_start;
|
Gfx::IntPoint m_selection_start;
|
||||||
Gfx::IntPoint m_selection_end;
|
Gfx::IntPoint m_selection_end;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue