1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:47:35 +00:00

LibGUI: Use linear gradient to paint opacity sliders

No need to implement gradients again :^)
This commit is contained in:
MacDue 2023-05-05 22:55:13 +01:00 committed by Andreas Kling
parent 5f93f62f1c
commit c4ef1db33d

View file

@ -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) {