diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-09-17 18:42:30 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-09-18 02:12:38 +0430 |
commit | 433725fef20e47ab5642acd6fc211e349e983730 (patch) | |
tree | 5d8c5c85c898db58d2f27ef271f05f61d8016f90 /Userland/Libraries/LibGfx/AntiAliasingPainter.cpp | |
parent | 02d949cfb61079594387d2ea7ac8c18f6e16c8b8 (diff) | |
download | serenity-433725fef20e47ab5642acd6fc211e349e983730.zip |
LibGfx: Implement cubic bezier curves by splitting them to subcurves
This makes them significantly more nicer-looking, and fixes a FIXME :^)
Diffstat (limited to 'Userland/Libraries/LibGfx/AntiAliasingPainter.cpp')
-rw-r--r-- | Userland/Libraries/LibGfx/AntiAliasingPainter.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp b/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp index 8d95a50c64..30dee5d413 100644 --- a/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp +++ b/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp @@ -132,6 +132,14 @@ void Gfx::AntiAliasingPainter::stroke_path(Path const& path, Color color, float cursor = segment.point(); break; } + case Segment::Type::CubicBezierCurveTo: { + auto& curve = static_cast<CubicBezierCurveSegment const&>(segment); + auto& through_0 = curve.through_0(); + auto& through_1 = curve.through_1(); + draw_cubic_bezier_curve(through_0, through_1, cursor, segment.point(), color, thickness); + cursor = segment.point(); + break; + } case Segment::Type::EllipticalArcTo: auto& arc = static_cast<EllipticalArcSegment const&>(segment); draw_elliptical_arc(cursor, segment.point(), arc.center(), arc.radii(), arc.x_axis_rotation(), arc.theta_1(), arc.theta_delta(), color, thickness); @@ -154,3 +162,10 @@ void Gfx::AntiAliasingPainter::draw_quadratic_bezier_curve(FloatPoint const& con draw_line(fp1, fp2, color, thickness, style); }); } + +void Gfx::AntiAliasingPainter::draw_cubic_bezier_curve(const FloatPoint& control_point_0, const FloatPoint& control_point_1, const FloatPoint& p1, const FloatPoint& p2, Color color, float thickness, Painter::LineStyle style) +{ + Gfx::Painter::for_each_line_segment_on_cubic_bezier_curve(control_point_0, control_point_1, p1, p2, [&](FloatPoint const& fp1, FloatPoint const& fp2) { + draw_line(fp1, fp2, color, thickness, style); + }); +} |