mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:07:35 +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:
parent
16f934474f
commit
f828bf6479
2 changed files with 13 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||||
* Copyright (c) 2022, the SerenityOS developers.
|
* Copyright (c) 2022, the SerenityOS developers.
|
||||||
|
* Copyright (c) 2023, networkException <networkexception@serenityos.social>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* 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) {
|
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 relative_offset = (float)pos / (float)inner_rect.primary_size_for_orientation(orientation());
|
||||||
float alpha = relative_offset * 255.0f;
|
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) {
|
if (orientation() == Gfx::Orientation::Horizontal) {
|
||||||
painter.fill_rect({ pos, inner_rect.top(), 1, inner_rect.height() }, color);
|
painter.fill_rect({ pos, inner_rect.top(), 1, inner_rect.height() }, color);
|
||||||
} else {
|
} else {
|
||||||
|
@ -149,6 +150,12 @@ int OpacitySlider::value_at(Gfx::IntPoint position) const
|
||||||
return min() + (int)(relative_offset * (float)range);
|
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)
|
void OpacitySlider::mousedown_event(MouseEvent& event)
|
||||||
{
|
{
|
||||||
if (event.button() == MouseButton::Primary) {
|
if (event.button() == MouseButton::Primary) {
|
||||||
|
|
|
@ -17,6 +17,9 @@ class OpacitySlider : public AbstractSlider {
|
||||||
public:
|
public:
|
||||||
virtual ~OpacitySlider() override = default;
|
virtual ~OpacitySlider() override = default;
|
||||||
|
|
||||||
|
void set_base_color(Gfx::Color);
|
||||||
|
Gfx::Color base_color() { return m_base_color; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit OpacitySlider(Gfx::Orientation);
|
explicit OpacitySlider(Gfx::Orientation);
|
||||||
|
|
||||||
|
@ -29,6 +32,8 @@ protected:
|
||||||
private:
|
private:
|
||||||
Gfx::IntRect frame_inner_rect() const;
|
Gfx::IntRect frame_inner_rect() const;
|
||||||
|
|
||||||
|
Gfx::Color m_base_color { 0, 0, 0 };
|
||||||
|
|
||||||
virtual Optional<UISize> calculated_min_size() const override;
|
virtual Optional<UISize> calculated_min_size() const override;
|
||||||
virtual Optional<UISize> calculated_preferred_size() const override;
|
virtual Optional<UISize> calculated_preferred_size() const override;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue