Browse Source

LibGUI: Use linear gradient to paint opacity sliders

No need to implement gradients again :^)
MacDue 2 years ago
parent
commit
c4ef1db33d
1 changed files with 2 additions and 10 deletions
  1. 2 10
      Userland/Libraries/LibGUI/OpacitySlider.cpp

+ 2 - 10
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<u8>(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) {