1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:57:43 +00:00

LibGUI: Add base color to OpacitySlider

This patch adds a base color to OpacitySlider which will be used to
render the alpha gradient.
This commit is contained in:
networkException 2023-01-01 02:16:46 +01:00 committed by Sam Atkins
parent 16f934474f
commit f828bf6479
2 changed files with 13 additions and 1 deletions

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* Copyright (c) 2023, networkException <networkexception@serenityos.social>
*
* 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<u8>(AK::min(alpha, UINT8_MAX)) };
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 {
@ -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) {