diff --git a/Userland/Libraries/LibGUI/OpacitySlider.cpp b/Userland/Libraries/LibGUI/OpacitySlider.cpp index ed12fdf512..89b1426a4e 100644 --- a/Userland/Libraries/LibGUI/OpacitySlider.cpp +++ b/Userland/Libraries/LibGUI/OpacitySlider.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2020, Andreas Kling * Copyright (c) 2022, the SerenityOS developers. + * Copyright (c) 2023, networkException * * SPDX-License-Identifier: BSD-2-Clause */ @@ -42,7 +43,7 @@ void OpacitySlider::paint_event(PaintEvent& event) 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 { 0, 0, 0, static_cast(AK::min(alpha, UINT8_MAX)) }; + 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 { @@ -149,6 +150,12 @@ int OpacitySlider::value_at(Gfx::IntPoint position) const return min() + (int)(relative_offset * (float)range); } +void OpacitySlider::set_base_color(Gfx::Color base_color) +{ + m_base_color = base_color; + update(); +} + void OpacitySlider::mousedown_event(MouseEvent& event) { if (event.button() == MouseButton::Primary) { diff --git a/Userland/Libraries/LibGUI/OpacitySlider.h b/Userland/Libraries/LibGUI/OpacitySlider.h index 8876d7be14..f00cd242a8 100644 --- a/Userland/Libraries/LibGUI/OpacitySlider.h +++ b/Userland/Libraries/LibGUI/OpacitySlider.h @@ -17,6 +17,9 @@ class OpacitySlider : public AbstractSlider { public: virtual ~OpacitySlider() override = default; + void set_base_color(Gfx::Color); + Gfx::Color base_color() { return m_base_color; } + protected: explicit OpacitySlider(Gfx::Orientation); @@ -29,6 +32,8 @@ protected: private: Gfx::IntRect frame_inner_rect() const; + Gfx::Color m_base_color { 0, 0, 0 }; + virtual Optional calculated_min_size() const override; virtual Optional calculated_preferred_size() const override;