mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:37:44 +00:00
PixelPaint: Add an option for making a Gradient with a secondary color
This commit is contained in:
parent
1ce2d7e674
commit
83da3c5c3e
2 changed files with 23 additions and 1 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/CheckBox.h>
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/OpacitySlider.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
|
@ -169,6 +170,12 @@ void GradientTool::on_primary_color_change(Color)
|
|||
m_editor->update();
|
||||
}
|
||||
|
||||
void GradientTool::on_secondary_color_change(Color)
|
||||
{
|
||||
if (m_gradient_end.has_value())
|
||||
m_editor->update();
|
||||
}
|
||||
|
||||
void GradientTool::on_tool_activation()
|
||||
{
|
||||
reset();
|
||||
|
@ -199,6 +206,12 @@ GUI::Widget* GradientTool::get_properties_widget()
|
|||
|
||||
set_primary_slider(&opacity_slider);
|
||||
|
||||
auto& use_secondary_color_checkbox = m_properties_widget->add<GUI::CheckBox>(String::from_utf8("Use secondary color"sv).release_value_but_fixme_should_propagate_errors());
|
||||
use_secondary_color_checkbox.on_checked = [this](bool checked) {
|
||||
m_use_secondary_color = checked;
|
||||
m_editor->update();
|
||||
};
|
||||
|
||||
auto& button_container = m_properties_widget->add<GUI::Widget>();
|
||||
button_container.set_fixed_height(22);
|
||||
auto& button_container_layout = button_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
|
@ -285,7 +298,14 @@ void GradientTool::draw_gradient(GUI::Painter& painter, bool with_guidelines, co
|
|||
auto gradient_half_width_percentage_offset = (m_gradient_half_length * scale) / overall_gradient_length_in_rect;
|
||||
auto start_color = m_editor->color_for(GUI::MouseButton::Primary);
|
||||
start_color.set_alpha(start_color.alpha() * m_opacity / 100);
|
||||
auto end_color = start_color.with_alpha(0);
|
||||
|
||||
auto end_color = [&] {
|
||||
if (m_use_secondary_color) {
|
||||
auto color = m_editor->color_for(GUI::MouseButton::Secondary);
|
||||
return color.with_alpha(color.alpha() * m_opacity / 100);
|
||||
}
|
||||
return start_color.with_alpha(0);
|
||||
}();
|
||||
|
||||
{
|
||||
Gfx::PainterStateSaver saver(painter);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue