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.
This commit is contained in:
parent
f283e0ddc5
commit
b7fd844c9d
Notes:
sideshowbarker
2024-07-17 09:43:01 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/b7fd844c9d Pull-request: https://github.com/SerenityOS/serenity/pull/14482
1 changed files with 28 additions and 0 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue