From ab8522aa17be787b857c890d871b4bfc267e6bd0 Mon Sep 17 00:00:00 2001 From: Cody Hein Date: Tue, 13 Dec 2022 22:25:17 -0700 Subject: [PATCH] PixelPaint: ColorPicker updates user colors while dragging Now the user can hold primary and/or secondary mouse buttons and move the mouse around while previewing the color on the statusbar and fine tune their selection. The color will update live so the color selected when mouse is released is the final color used. --- .../Applications/PixelPaint/ImageEditor.cpp | 4 ++-- .../PixelPaint/Tools/PickerTool.cpp | 18 ++++++++++++++++++ .../Applications/PixelPaint/Tools/PickerTool.h | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp index bc206c3621..2599f752f4 100644 --- a/Userland/Applications/PixelPaint/ImageEditor.cpp +++ b/Userland/Applications/PixelPaint/ImageEditor.cpp @@ -350,9 +350,9 @@ void ImageEditor::set_editor_color_to_color_at_mouse_position(GUI::MouseEvent co if (!color.alpha()) return; - if (event.button() == GUI::MouseButton::Primary) + if (event.buttons() & GUI::MouseButton::Primary) set_primary_color(color); - else if (event.button() == GUI::MouseButton::Secondary) + if (event.buttons() & GUI::MouseButton::Secondary) set_secondary_color(color); } diff --git a/Userland/Applications/PixelPaint/Tools/PickerTool.cpp b/Userland/Applications/PixelPaint/Tools/PickerTool.cpp index fff91c5054..6c986efbf2 100644 --- a/Userland/Applications/PixelPaint/Tools/PickerTool.cpp +++ b/Userland/Applications/PixelPaint/Tools/PickerTool.cpp @@ -22,6 +22,24 @@ void PickerTool::on_mousedown(Layer* layer, MouseEvent& event) m_editor->set_editor_color_to_color_at_mouse_position(layer_event, m_sample_all_layers); } +void PickerTool::on_mouseup(Layer*, MouseEvent& event) +{ + auto layer_event = event.layer_event(); + if (layer_event.buttons() & GUI::MouseButton::Primary || layer_event.buttons() & GUI::MouseButton::Secondary) + return; + m_editor->set_appended_status_info(DeprecatedString::empty()); +} + +void PickerTool::on_mousemove(Layer* layer, MouseEvent& event) +{ + if (!layer) + return; + auto layer_event = event.layer_event(); + if (!(layer_event.buttons() & GUI::MouseButton::Primary || layer_event.buttons() & GUI::MouseButton::Secondary)) + return; + m_editor->set_editor_color_to_color_at_mouse_position(layer_event, m_sample_all_layers); +} + GUI::Widget* PickerTool::get_properties_widget() { if (!m_properties_widget) { diff --git a/Userland/Applications/PixelPaint/Tools/PickerTool.h b/Userland/Applications/PixelPaint/Tools/PickerTool.h index 2b83017d4f..f45a8a404e 100644 --- a/Userland/Applications/PixelPaint/Tools/PickerTool.h +++ b/Userland/Applications/PixelPaint/Tools/PickerTool.h @@ -18,6 +18,8 @@ public: virtual ~PickerTool() override = default; virtual void on_mousedown(Layer*, MouseEvent&) override; + virtual void on_mouseup(Layer*, MouseEvent&) override; + virtual void on_mousemove(Layer*, MouseEvent&) override; virtual GUI::Widget* get_properties_widget() override; virtual Variant> cursor() override { return Gfx::StandardCursor::Eyedropper; }