diff options
author | Linus Groh <mail@linusgroh.de> | 2020-05-10 16:17:26 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-10 19:41:00 +0200 |
commit | 0669dbcf5d177e1cd59d801c41f3a9329b24c746 (patch) | |
tree | 4fee020170928f2eb2e8cf9b86b93e58d12cf357 /Libraries/LibGfx/Painter.cpp | |
parent | 3667677008cdbd55c1fcc2da747fbdcc1288b43f (diff) | |
download | serenity-0669dbcf5d177e1cd59d801c41f3a9329b24c746.zip |
LibGfx: Add support for dashed lines
Non-configurable for now.
Diffstat (limited to 'Libraries/LibGfx/Painter.cpp')
-rw-r--r-- | Libraries/LibGfx/Painter.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Libraries/LibGfx/Painter.cpp b/Libraries/LibGfx/Painter.cpp index 992e7a4cb8..f9a11853eb 100644 --- a/Libraries/LibGfx/Painter.cpp +++ b/Libraries/LibGfx/Painter.cpp @@ -992,6 +992,12 @@ void Painter::draw_line(const Point& p1, const Point& p2, Color color, int thick if (style == LineStyle::Dotted) { for (int y = min_y; y <= max_y; y += thickness * 2) draw_pixel({ x, y }, color, thickness); + } else if (style == LineStyle::Dashed) { + for (int y = min_y; y <= max_y; y += thickness * 6) { + draw_pixel({ x, y }, color, thickness); + draw_pixel({ x, min(y + thickness, max_y) }, color, thickness); + draw_pixel({ x, min(y + thickness * 2, max_y) }, color, thickness); + } } else { for (int y = min_y; y <= max_y; ++y) draw_pixel({ x, y }, color, thickness); @@ -1015,6 +1021,12 @@ void Painter::draw_line(const Point& p1, const Point& p2, Color color, int thick if (style == LineStyle::Dotted) { for (int x = min_x; x <= max_x; x += thickness * 2) draw_pixel({ x, y }, color, thickness); + } else if (style == LineStyle::Dashed) { + for (int x = min_x; x <= max_x; x += thickness * 6) { + draw_pixel({ x, y }, color, thickness); + draw_pixel({ min(x + thickness, max_x), y }, color, thickness); + draw_pixel({ min(x + thickness * 2, max_x), y }, color, thickness); + } } else { for (int x = min_x; x <= max_x; ++x) draw_pixel({ x, y }, color, thickness); @@ -1022,7 +1034,7 @@ void Painter::draw_line(const Point& p1, const Point& p2, Color color, int thick return; } - // FIXME: Implement dotted diagonal lines. + // FIXME: Implement dotted/dashed diagonal lines. ASSERT(style == LineStyle::Solid); const double adx = abs(point2.x() - point1.x()); |