diff options
author | Tobias Christiansen <tobi@tobyase.de> | 2021-08-05 16:34:03 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-08-07 02:52:47 +0430 |
commit | 61a1122c2d9f67beef6df2fc211244cad7ef08ab (patch) | |
tree | 6944e3719e8f952975e68be9ed8e7b47d92d1af5 /Userland/Libraries/LibGfx/Painter.cpp | |
parent | 4a57a4a0b36b5d3738bd6704c34dc69eef1d481b (diff) | |
download | serenity-61a1122c2d9f67beef6df2fc211244cad7ef08ab.zip |
LibGfx: Add alternate_color to draw_line
This alternate_color can be used when drawing dashed lines to have two
alternating Colors.
Diffstat (limited to 'Userland/Libraries/LibGfx/Painter.cpp')
-rw-r--r-- | Userland/Libraries/LibGfx/Painter.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 9a1815759b..30cf9e4fee 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -1631,7 +1631,7 @@ void Painter::draw_physical_pixel(const IntPoint& physical_position, Color color fill_physical_rect(rect, color); } -void Painter::draw_line(IntPoint const& a_p1, IntPoint const& a_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, Color alternate_color) { if (color.alpha() == 0) return; @@ -1645,6 +1645,8 @@ void Painter::draw_line(IntPoint const& a_p1, IntPoint const& a_p2, Color color, auto point2 = to_physical(p2); thickness *= scale(); + auto alternate_color_is_transparent = alternate_color == Color::Transparent; + // Special case: vertical line. if (point1.x() == point2.x()) { const int x = point1.x(); @@ -1666,6 +1668,11 @@ void Painter::draw_line(IntPoint const& a_p1, IntPoint const& a_p2, Color color, draw_physical_pixel({ x, y }, color, thickness); draw_physical_pixel({ x, min(y + thickness, max_y) }, color, thickness); draw_physical_pixel({ x, min(y + thickness * 2, max_y) }, color, thickness); + if (!alternate_color_is_transparent) { + draw_physical_pixel({ x, min(y + thickness * 3, max_y) }, alternate_color, thickness); + draw_physical_pixel({ x, min(y + thickness * 4, max_y) }, alternate_color, thickness); + draw_physical_pixel({ x, min(y + thickness * 5, max_y) }, alternate_color, thickness); + } } } else { for (int y = min_y; y <= max_y; y += thickness) @@ -1695,6 +1702,11 @@ void Painter::draw_line(IntPoint const& a_p1, IntPoint const& a_p2, Color color, draw_physical_pixel({ x, y }, color, thickness); draw_physical_pixel({ min(x + thickness, max_x), y }, color, thickness); draw_physical_pixel({ min(x + thickness * 2, max_x), y }, color, thickness); + if (!alternate_color_is_transparent) { + draw_physical_pixel({ min(x + thickness * 3, max_x), y }, alternate_color, thickness); + draw_physical_pixel({ min(x + thickness * 4, max_x), y }, alternate_color, thickness); + draw_physical_pixel({ min(x + thickness * 5, max_x), y }, alternate_color, thickness); + } } } else { for (int x = min_x; x <= max_x; x += thickness) |