1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 00:37:35 +00:00

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. :^)
This commit is contained in:
Andreas Kling 2021-07-09 18:18:46 +02:00
parent 69eb05e705
commit 5439453139

View file

@ -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();