summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2022-06-13 23:31:17 +0100
committerLinus Groh <mail@linusgroh.de>2022-06-14 00:25:12 +0100
commitc1798620d9f6259a25e7b6a649fdf8c44a546122 (patch)
tree28b9e624b853def725107032a9d2749fe364d3dd /Userland/Libraries/LibGfx
parent0805911a93588f839aa04c0bca7058e409204939 (diff)
downloadserenity-c1798620d9f6259a25e7b6a649fdf8c44a546122.zip
LibGfx: Support AlphaSubtract blend mode for AA rounded rectangle
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r--Userland/Libraries/LibGfx/AntiAliasingPainter.cpp32
-rw-r--r--Userland/Libraries/LibGfx/AntiAliasingPainter.h2
2 files changed, 23 insertions, 11 deletions
diff --git a/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp b/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp
index fe0e47bc8f..62a1d835ef 100644
--- a/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp
+++ b/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp
@@ -445,10 +445,14 @@ void Gfx::AntiAliasingPainter::fill_rect_with_rounded_corners(IntRect const& a_r
{ bottom_left_radius, bottom_left_radius });
}
-void Gfx::AntiAliasingPainter::fill_rect_with_rounded_corners(IntRect const& a_rect, Color color, CornerRadius top_left, CornerRadius top_right, CornerRadius bottom_right, CornerRadius bottom_left)
+void Gfx::AntiAliasingPainter::fill_rect_with_rounded_corners(IntRect const& a_rect, Color color, CornerRadius top_left, CornerRadius top_right, CornerRadius bottom_right, CornerRadius bottom_left, BlendMode blend_mode)
{
- if (!top_left && !top_right && !bottom_right && !bottom_left)
- return m_underlying_painter.fill_rect(a_rect, color);
+ if (!top_left && !top_right && !bottom_right && !bottom_left) {
+ if (blend_mode == BlendMode::Normal)
+ return m_underlying_painter.fill_rect(a_rect, color);
+ else if (blend_mode == BlendMode::AlphaSubtract)
+ return m_underlying_painter.clear_rect(a_rect, Color());
+ }
if (color.alpha() == 0)
return;
@@ -472,7 +476,7 @@ void Gfx::AntiAliasingPainter::fill_rect_with_rounded_corners(IntRect const& a_r
// All corners are centered at the same point, so this can be painted as a single ellipse.
if (top_left_corner == top_right_corner && top_right_corner == bottom_left_corner && bottom_left_corner == bottom_right_corner)
- return fill_ellipse(a_rect, color);
+ return fill_ellipse(a_rect, color, blend_mode);
IntRect top_rect {
a_rect.x() + top_left.horizontal_radius,
@@ -506,16 +510,24 @@ void Gfx::AntiAliasingPainter::fill_rect_with_rounded_corners(IntRect const& a_r
a_rect.height() - top_rect.height() - bottom_rect.height()
};
- m_underlying_painter.fill_rect(top_rect, color);
- m_underlying_painter.fill_rect(right_rect, color);
- m_underlying_painter.fill_rect(bottom_rect, color);
- m_underlying_painter.fill_rect(left_rect, color);
- m_underlying_painter.fill_rect(inner, color);
+ if (blend_mode == BlendMode::Normal) {
+ m_underlying_painter.fill_rect(top_rect, color);
+ m_underlying_painter.fill_rect(right_rect, color);
+ m_underlying_painter.fill_rect(bottom_rect, color);
+ m_underlying_painter.fill_rect(left_rect, color);
+ m_underlying_painter.fill_rect(inner, color);
+ } else if (blend_mode == BlendMode::AlphaSubtract) {
+ m_underlying_painter.clear_rect(top_rect, Gfx::Color());
+ m_underlying_painter.clear_rect(right_rect, Gfx::Color());
+ m_underlying_painter.clear_rect(bottom_rect, Gfx::Color());
+ m_underlying_painter.clear_rect(left_rect, Gfx::Color());
+ m_underlying_painter.clear_rect(inner, Gfx::Color());
+ }
auto fill_corner = [&](auto const& ellipse_center, auto const& corner_point, CornerRadius const& corner) {
PainterStateSaver save { m_underlying_painter };
m_underlying_painter.add_clip_rect(IntRect::from_two_points(ellipse_center, corner_point));
- fill_ellipse(IntRect::centered_at(ellipse_center, { corner.horizontal_radius * 2, corner.vertical_radius * 2 }), color);
+ fill_ellipse(IntRect::centered_at(ellipse_center, { corner.horizontal_radius * 2, corner.vertical_radius * 2 }), color, blend_mode);
};
auto bounding_rect = a_rect.inflated(0, 1, 1, 0);
diff --git a/Userland/Libraries/LibGfx/AntiAliasingPainter.h b/Userland/Libraries/LibGfx/AntiAliasingPainter.h
index 65abb088e6..6726a09ab2 100644
--- a/Userland/Libraries/LibGfx/AntiAliasingPainter.h
+++ b/Userland/Libraries/LibGfx/AntiAliasingPainter.h
@@ -51,7 +51,7 @@ public:
}
};
- void fill_rect_with_rounded_corners(IntRect const&, Color, CornerRadius top_left, CornerRadius top_right, CornerRadius bottom_right, CornerRadius bottom_left);
+ void fill_rect_with_rounded_corners(IntRect const&, Color, CornerRadius top_left, CornerRadius top_right, CornerRadius bottom_right, CornerRadius bottom_left, BlendMode blend_mode = BlendMode::Normal);
private:
struct Range {