diff options
author | MacDue <macdue@dueutil.tech> | 2022-06-11 17:35:29 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-06-11 17:46:46 +0100 |
commit | 0120c8580fd3a1eaa3ad2499f67fd000816b63cd (patch) | |
tree | efea89b5c0d85632093c5e8dec1a3156a4087eb7 /Userland/Libraries/LibGfx/AntiAliasingPainter.cpp | |
parent | 5bc5c0f31b4328adfe364b972858f973b80448aa (diff) | |
download | serenity-0120c8580fd3a1eaa3ad2499f67fd000816b63cd.zip |
LibGfx: Clip outside the corners when painting an AA rounded rectangle
Diffstat (limited to 'Userland/Libraries/LibGfx/AntiAliasingPainter.cpp')
-rw-r--r-- | Userland/Libraries/LibGfx/AntiAliasingPainter.cpp | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp b/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp index 2fd8f0aeaf..6ace4374dd 100644 --- a/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp +++ b/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp @@ -499,13 +499,39 @@ void Gfx::AntiAliasingPainter::fill_rect_with_rounded_corners(IntRect const& a_r m_underlying_painter.fill_rect(left_rect, color); m_underlying_painter.fill_rect(inner, color); - // FIXME: Don't draw a whole circle each time + enum class CornerClip { + TopLeft, + BottomLeft, + TopRight, + BottomRight + }; + + auto fill_corner = [&](auto const& point, int radius, CornerClip clip) { + PainterStateSaver save { m_underlying_painter }; + auto corner_clip = IntRect::from_two_points(point, [&] { + switch (clip) { + case CornerClip::TopLeft: + return point.translated(-radius, -radius); + case CornerClip::BottomLeft: + return point.translated(-radius, radius); + case CornerClip::TopRight: + return point.translated(radius, -radius); + case CornerClip::BottomRight: + return point.translated(radius, radius); + default: + VERIFY_NOT_REACHED(); + } + }()); + m_underlying_painter.add_clip_rect(corner_clip); + fill_circle(point, radius, color); + }; + if (top_left_radius) - fill_circle(top_left_corner, top_left_radius, color); + fill_corner(top_left_corner, top_left_radius, CornerClip::TopLeft); if (top_right_radius) - fill_circle(top_right_corner, top_right_radius, color); + fill_corner(top_right_corner, top_right_radius, CornerClip::TopRight); if (bottom_left_radius) - fill_circle(bottom_left_corner, bottom_left_radius, color); + fill_corner(bottom_left_corner, bottom_left_radius, CornerClip::BottomLeft); if (bottom_right_radius) - fill_circle(bottom_right_corner, bottom_right_radius, color); + fill_corner(bottom_right_corner, bottom_right_radius, CornerClip::BottomRight); } |