diff options
author | Karol Kosek <krkk@serenityos.org> | 2023-02-13 17:24:06 +0100 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2023-02-16 10:50:58 +0000 |
commit | 83da3c5c3e5a7a0bc605e88883a659950bf4ce78 (patch) | |
tree | 5fd8c71de41f508fcd964c8c66a8219b92a08a40 | |
parent | 1ce2d7e6743d1fd200563e7c2e88258ef9d44131 (diff) | |
download | serenity-83da3c5c3e5a7a0bc605e88883a659950bf4ce78.zip |
PixelPaint: Add an option for making a Gradient with a secondary color
-rw-r--r-- | Userland/Applications/PixelPaint/Tools/GradientTool.cpp | 22 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/Tools/GradientTool.h | 2 |
2 files changed, 23 insertions, 1 deletions
diff --git a/Userland/Applications/PixelPaint/Tools/GradientTool.cpp b/Userland/Applications/PixelPaint/Tools/GradientTool.cpp index 721468017d..8ee6594bd2 100644 --- a/Userland/Applications/PixelPaint/Tools/GradientTool.cpp +++ b/Userland/Applications/PixelPaint/Tools/GradientTool.cpp @@ -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); diff --git a/Userland/Applications/PixelPaint/Tools/GradientTool.h b/Userland/Applications/PixelPaint/Tools/GradientTool.h index 6e1b47a683..f9b2e4e9be 100644 --- a/Userland/Applications/PixelPaint/Tools/GradientTool.h +++ b/Userland/Applications/PixelPaint/Tools/GradientTool.h @@ -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; |