mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 21:08:12 +00:00
LibGfx: Add Painter::draw_triangle_wave()
This patch adds support for drawing triangular waves. For now those can only be horizontal, but as they are intended for underlining text, it's an okay way to handle this.
This commit is contained in:
parent
7b51102495
commit
0277118cb4
2 changed files with 21 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
|||
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||
* Copyright (c) 2021, Mustafa Quraish <mustafa@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -1821,6 +1822,25 @@ void Painter::draw_line(IntPoint const& a_p1, IntPoint const& a_p2, Color color,
|
|||
}
|
||||
}
|
||||
|
||||
void Painter::draw_triangle_wave(IntPoint const& a_p1, IntPoint const& a_p2, Color color, int amplitude, int thickness)
|
||||
{
|
||||
// FIXME: Support more than horizontal waves
|
||||
VERIFY(a_p1.y() == a_p2.y());
|
||||
|
||||
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);
|
||||
|
||||
auto y = point1.y();
|
||||
|
||||
for (int x = 0; x <= point2.x() - point1.x(); ++x) {
|
||||
auto y_offset = abs(x % (2 * amplitude) - amplitude) - amplitude;
|
||||
draw_physical_pixel({ point1.x() + x, y + y_offset }, color, thickness);
|
||||
}
|
||||
}
|
||||
|
||||
static bool can_approximate_bezier_curve(FloatPoint const& p1, FloatPoint const& p2, FloatPoint const& control)
|
||||
{
|
||||
constexpr static int tolerance = 15;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue