summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Applications/PixelPaint/Tools/MoveTool.cpp44
-rw-r--r--Userland/Applications/PixelPaint/Tools/MoveTool.h5
2 files changed, 34 insertions, 15 deletions
diff --git a/Userland/Applications/PixelPaint/Tools/MoveTool.cpp b/Userland/Applications/PixelPaint/Tools/MoveTool.cpp
index 0816afccb5..16f8aa9e06 100644
--- a/Userland/Applications/PixelPaint/Tools/MoveTool.cpp
+++ b/Userland/Applications/PixelPaint/Tools/MoveTool.cpp
@@ -21,6 +21,9 @@
namespace PixelPaint {
+constexpr int resize_anchor_min_size = 5;
+constexpr int resize_anchor_max_size = 20;
+
void MoveTool::on_mousedown(Layer* layer, MouseEvent& event)
{
if (event.image_event().button() == GUI::MouseButton::Secondary) {
@@ -200,27 +203,39 @@ 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);
+ auto size = resize_anchor_size(rect_in_editor);
+ if (size < resize_anchor_min_size)
+ return;
+
+ auto resize_anchors = resize_anchor_rects(rect_in_editor, size);
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)
+Gfx::IntRect MoveTool::resize_anchor_rect_from_position(Gfx::IntPoint position, int size)
+{
+ auto resize_anchor_rect_top_left = position.translated(-size / 2);
+ return Gfx::IntRect(resize_anchor_rect_top_left, Gfx::IntSize(size, size));
+}
+
+int MoveTool::resize_anchor_size(Gfx::IntRect layer_rect_in_frame_coordinates)
{
- 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));
+ auto shortest_side = min(layer_rect_in_frame_coordinates.width(), layer_rect_in_frame_coordinates.height());
+ if (shortest_side <= 1)
+ return 1;
+ int x = ceilf(shortest_side / 3.0f);
+ return min(resize_anchor_max_size, x);
}
-Array<Gfx::IntRect, 4> MoveTool::resize_anchor_rects(Gfx::IntRect layer_rect_in_frame_coordinates)
+Array<Gfx::IntRect, 4> MoveTool::resize_anchor_rects(Gfx::IntRect layer_rect_in_frame_coordinates, int resize_anchor_size)
{
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))
+ resize_anchor_rect_from_position(layer_rect_in_frame_coordinates.top_left(), resize_anchor_size),
+ resize_anchor_rect_from_position(layer_rect_in_frame_coordinates.top_right().translated(1, 0), resize_anchor_size),
+ resize_anchor_rect_from_position(layer_rect_in_frame_coordinates.bottom_left().translated(0, 1), resize_anchor_size),
+ resize_anchor_rect_from_position(layer_rect_in_frame_coordinates.bottom_right().translated(1), resize_anchor_size)
};
}
@@ -240,11 +255,14 @@ 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_in_frame_coordinates) {
- auto resize_anchor_rect = resize_anchor_rect_from_position(layer_position_in_frame_coordinates);
+ auto layer_rect = m_editor->content_to_frame_rect(layer->relative_rect()).to_rounded<int>();
+ auto size = max(resize_anchor_min_size, resize_anchor_size(layer_rect));
+
+ auto cursor_within_resize_anchor_rect = [&event, size](Gfx::IntPoint layer_position_in_frame_coordinates) {
+ auto resize_anchor_rect = resize_anchor_rect_from_position(layer_position_in_frame_coordinates, size);
return resize_anchor_rect.contains(event.raw_event().position());
};
- 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)))
diff --git a/Userland/Applications/PixelPaint/Tools/MoveTool.h b/Userland/Applications/PixelPaint/Tools/MoveTool.h
index 71640a84e4..4a02025022 100644
--- a/Userland/Applications/PixelPaint/Tools/MoveTool.h
+++ b/Userland/Applications/PixelPaint/Tools/MoveTool.h
@@ -41,8 +41,9 @@ 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);
+ static int resize_anchor_size(Gfx::IntRect layer_rect_in_frame_coordinates);
+ static Gfx::IntRect resize_anchor_rect_from_position(Gfx::IntPoint, int resize_anchor_size);
+ static Array<Gfx::IntRect, 4> resize_anchor_rects(Gfx::IntRect layer_rect_in_frame_coordinates, int resize_anchor_size);
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&);