mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:27:35 +00:00
PixelPaint: Show resize anchors when using the move tool
This commit adds a two color border around areas that the user must drag to resize, when using the move tool.
This commit is contained in:
parent
4c617d370e
commit
c82825379a
2 changed files with 27 additions and 6 deletions
|
@ -200,6 +200,28 @@ void MoveTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event)
|
|||
}
|
||||
painter.draw_rect_with_thickness(rect_in_editor, Color::Black, 3);
|
||||
painter.draw_rect_with_thickness(rect_in_editor, Color::White, 1);
|
||||
auto resize_anchors = resize_anchor_rects(rect_in_editor);
|
||||
for (auto const& resize_anchor_rect : resize_anchors) {
|
||||
painter.draw_rect_with_thickness(resize_anchor_rect, Color::Black, 3);
|
||||
painter.draw_rect_with_thickness(resize_anchor_rect, Color::White, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Gfx::IntRect MoveTool::resize_anchor_rect_from_position(Gfx::IntPoint position)
|
||||
{
|
||||
constexpr int resize_anchor_size = 20;
|
||||
auto resize_anchor_rect_top_left = position.translated(-resize_anchor_size / 2);
|
||||
return Gfx::IntRect(resize_anchor_rect_top_left, Gfx::IntSize(resize_anchor_size, resize_anchor_size));
|
||||
}
|
||||
|
||||
Array<Gfx::IntRect, 4> MoveTool::resize_anchor_rects(Gfx::IntRect layer_rect_in_frame_coordinates)
|
||||
{
|
||||
return Array {
|
||||
resize_anchor_rect_from_position(layer_rect_in_frame_coordinates.top_left()),
|
||||
resize_anchor_rect_from_position(layer_rect_in_frame_coordinates.top_right().translated(1, 0)),
|
||||
resize_anchor_rect_from_position(layer_rect_in_frame_coordinates.bottom_left().translated(0, 1)),
|
||||
resize_anchor_rect_from_position(layer_rect_in_frame_coordinates.bottom_right().translated(1))
|
||||
};
|
||||
}
|
||||
|
||||
ErrorOr<void> MoveTool::update_cached_preview_bitmap(Layer const* layer)
|
||||
|
@ -218,14 +240,11 @@ ErrorOr<void> MoveTool::update_cached_preview_bitmap(Layer const* layer)
|
|||
|
||||
Optional<ResizeAnchorLocation const> MoveTool::resize_anchor_location_from_cursor_position(Layer const* layer, MouseEvent& event)
|
||||
{
|
||||
auto cursor_within_resize_anchor_rect = [&](Gfx::IntPoint layer_position) {
|
||||
constexpr int sensitivity = 20;
|
||||
auto resize_anchor_rect_center = m_editor->content_to_frame_position(layer_position).to_rounded<int>();
|
||||
auto resize_anchor_rect_top_left = resize_anchor_rect_center.translated(-sensitivity / 2);
|
||||
auto resize_anchor_rect = Gfx::IntRect(resize_anchor_rect_top_left, Gfx::IntSize(sensitivity, sensitivity));
|
||||
auto cursor_within_resize_anchor_rect = [&](Gfx::IntPoint layer_position_in_frame_coordinates) {
|
||||
auto resize_anchor_rect = resize_anchor_rect_from_position(layer_position_in_frame_coordinates);
|
||||
return resize_anchor_rect.contains(event.raw_event().position());
|
||||
};
|
||||
auto layer_rect = layer->relative_rect();
|
||||
auto layer_rect = m_editor->content_to_frame_rect(layer->relative_rect()).to_rounded<int>();
|
||||
if (cursor_within_resize_anchor_rect(layer_rect.top_left()))
|
||||
return ResizeAnchorLocation::TopLeft;
|
||||
if (cursor_within_resize_anchor_rect(layer_rect.top_right().translated(1, 0)))
|
||||
|
|
|
@ -41,6 +41,8 @@ public:
|
|||
LayerSelectionMode layer_selection_mode() const { return m_layer_selection_mode; }
|
||||
|
||||
private:
|
||||
static Gfx::IntRect resize_anchor_rect_from_position(Gfx::IntPoint);
|
||||
static Array<Gfx::IntRect, 4> resize_anchor_rects(Gfx::IntRect layer_rect_in_frame_coordinates);
|
||||
virtual StringView tool_name() const override { return "Move Tool"sv; }
|
||||
ErrorOr<void> update_cached_preview_bitmap(Layer const* layer);
|
||||
Optional<ResizeAnchorLocation const> resize_anchor_location_from_cursor_position(Layer const*, MouseEvent&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue