diff options
author | MacDue <macdue@dueutil.tech> | 2022-07-04 21:04:10 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-07-04 23:09:06 +0200 |
commit | b7fd844c9da8c5047e26a9baf6a0f37f8ed58884 (patch) | |
tree | e5ddfbd47fa65a60890bb22f57eeaeaf322f31a7 /Userland/Libraries | |
parent | f283e0ddc5696e8ba87a2d73cad896dfaadb2368 (diff) | |
download | serenity-b7fd844c9da8c5047e26a9baf6a0f37f8ed58884.zip |
LibWeb: Add ScopedCornerRadiusClip
This a simple RAII helper for the BorderRadiusCornerClipper it
samples under the corners on construction, then blits them back
on exiting the scope. This encapsulates a fairly common pattern.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/Painting/BorderRadiusCornerClipper.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/BorderRadiusCornerClipper.h b/Userland/Libraries/LibWeb/Painting/BorderRadiusCornerClipper.h index c60cf747de..602395f246 100644 --- a/Userland/Libraries/LibWeb/Painting/BorderRadiusCornerClipper.h +++ b/Userland/Libraries/LibWeb/Painting/BorderRadiusCornerClipper.h @@ -60,4 +60,32 @@ private: } }; +struct ScopedCornerRadiusClip { + ScopedCornerRadiusClip(Gfx::Painter& painter, Gfx::IntRect const& border_rect, BorderRadiiData const& border_radii, CornerClip corner_clip = CornerClip::Outside, BorderRadiusCornerClipper::UseCachedBitmap use_cached_bitmap = BorderRadiusCornerClipper::UseCachedBitmap::Yes) + : m_painter(painter) + { + if (border_radii.has_any_radius()) { + auto clipper = BorderRadiusCornerClipper::create(border_rect, border_radii, corner_clip, use_cached_bitmap); + if (!clipper.is_error()) { + m_corner_clipper = clipper.release_value(); + m_corner_clipper->sample_under_corners(m_painter); + } + } + } + + ~ScopedCornerRadiusClip() + { + if (m_corner_clipper.has_value()) { + m_corner_clipper->blit_corner_clipping(m_painter); + } + } + + AK_MAKE_NONMOVABLE(ScopedCornerRadiusClip); + AK_MAKE_NONCOPYABLE(ScopedCornerRadiusClip); + +private: + Gfx::Painter& m_painter; + Optional<BorderRadiusCornerClipper> m_corner_clipper; +}; + } |