From 543945313985589f895a9c4d8bd7a3d97c352d16 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 9 Jul 2021 18:18:46 +0200 Subject: [PATCH] LibGfx: Improve Painter::draw_line() alignment with (thickness > 1) Thicker lines are drawn by filling rectangles along the path. Previously these rectangles used the points as their top left corner. This patch changes it to use the points as the center of the rectangles which makes the PixelPaint line tool feel a lot more natural. :^) --- Userland/Libraries/LibGfx/Painter.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index d3bf8cb921..8552204678 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -1707,13 +1707,16 @@ void Painter::draw_physical_pixel(const IntPoint& physical_position, Color color fill_physical_rect(rect, color); } -void Painter::draw_line(const IntPoint& p1, const IntPoint& p2, Color color, int thickness, LineStyle style) +void Painter::draw_line(IntPoint const& a_p1, IntPoint const& a_p2, Color color, int thickness, LineStyle style) { if (color.alpha() == 0) return; auto clip_rect = this->clip_rect() * scale(); + auto const p1 = thickness > 1 ? a_p1.translated(-(thickness / 2), -(thickness / 2)) : a_p1; + auto const p2 = thickness > 1 ? a_p2.translated(-(thickness / 2), -(thickness / 2)) : a_p2; + auto point1 = to_physical(p1); auto point2 = to_physical(p2); thickness *= scale();