From c4ef1db33d30b603ad51b3583f983a6e92b4e916 Mon Sep 17 00:00:00 2001 From: MacDue Date: Fri, 5 May 2023 22:55:13 +0100 Subject: [PATCH] LibGUI: Use linear gradient to paint opacity sliders No need to implement gradients again :^) --- Userland/Libraries/LibGUI/OpacitySlider.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibGUI/OpacitySlider.cpp b/Userland/Libraries/LibGUI/OpacitySlider.cpp index a554017ffd..5e027fa226 100644 --- a/Userland/Libraries/LibGUI/OpacitySlider.cpp +++ b/Userland/Libraries/LibGUI/OpacitySlider.cpp @@ -41,16 +41,8 @@ void OpacitySlider::paint_event(PaintEvent& event) Gfx::StylePainter::paint_transparency_grid(painter, inner_rect, palette()); // Alpha gradient - for (int pos = inner_rect.first_edge_for_orientation(orientation()); pos <= inner_rect.last_edge_for_orientation(orientation()); ++pos) { - float relative_offset = (float)pos / (float)inner_rect.primary_size_for_orientation(orientation()); - float alpha = relative_offset * 255.0f; - Color color = m_base_color.with_alpha(static_cast(AK::min(alpha, UINT8_MAX))); - if (orientation() == Gfx::Orientation::Horizontal) { - painter.fill_rect({ pos, inner_rect.top(), 1, inner_rect.height() }, color); - } else { - painter.fill_rect({ inner_rect.left(), pos, inner_rect.right(), 1 }, color); - } - } + painter.fill_rect_with_linear_gradient(inner_rect, Array { Gfx::ColorStop { Color::Transparent, 0 }, Gfx::ColorStop { m_base_color, 1 } }, + orientation() == Orientation::Horizontal ? 90.0f : 180.0f); constexpr int notch_size = 3; if (orientation() == Gfx::Orientation::Horizontal) {