diff options
author | Andreas Kling <kling@serenityos.org> | 2021-07-09 18:18:46 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-09 22:07:00 +0200 |
commit | 543945313985589f895a9c4d8bd7a3d97c352d16 (patch) | |
tree | 7cce7d9d8e34f0ae9d92c8093347905799d96065 /Userland/Libraries/LibGfx | |
parent | 69eb05e705d64085e8cda34a8b8fd6fc4190d728 (diff) | |
download | serenity-543945313985589f895a9c4d8bd7a3d97c352d16.zip |
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. :^)
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r-- | Userland/Libraries/LibGfx/Painter.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
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(); |