PixelPaint: Add an option for making a Gradient with a secondary color

This commit is contained in:
Karol Kosek 2023-02-13 17:24:06 +01:00 committed by Sam Atkins
parent 1ce2d7e674
commit 83da3c5c3e
Notes: sideshowbarker 2024-07-17 00:37:23 +09:00
2 changed files with 23 additions and 1 deletions

View File

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

View File

@ -21,6 +21,7 @@ public:
virtual bool on_keydown(GUI::KeyEvent&) override;
virtual void on_keyup(GUI::KeyEvent&) override;
virtual void on_primary_color_change(Color) override;
virtual void on_secondary_color_change(Color) override;
virtual void on_tool_activation() override;
virtual GUI::Widget* get_properties_widget() override;
@ -45,6 +46,7 @@ private:
bool m_hover_over_start_handle = false;
bool m_hover_over_end_handle = false;
int m_opacity = 100;
bool m_use_secondary_color { false };
Gfx::FloatLine m_gradient_begin_line;
Gfx::FloatLine m_gradient_center_line;
Gfx::FloatLine m_gradient_end_line;