Browse Source

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.
Cody Hein 2 years ago
parent
commit
ab8522aa17

+ 2 - 2
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())
     if (!color.alpha())
         return;
         return;
 
 
-    if (event.button() == GUI::MouseButton::Primary)
+    if (event.buttons() & GUI::MouseButton::Primary)
         set_primary_color(color);
         set_primary_color(color);
-    else if (event.button() == GUI::MouseButton::Secondary)
+    if (event.buttons() & GUI::MouseButton::Secondary)
         set_secondary_color(color);
         set_secondary_color(color);
 }
 }
 
 

+ 18 - 0
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);
     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()
 GUI::Widget* PickerTool::get_properties_widget()
 {
 {
     if (!m_properties_widget) {
     if (!m_properties_widget) {

+ 2 - 0
Userland/Applications/PixelPaint/Tools/PickerTool.h

@@ -18,6 +18,8 @@ public:
     virtual ~PickerTool() override = default;
     virtual ~PickerTool() override = default;
 
 
     virtual void on_mousedown(Layer*, MouseEvent&) override;
     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 GUI::Widget* get_properties_widget() override;
     virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override { return Gfx::StandardCursor::Eyedropper; }
     virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override { return Gfx::StandardCursor::Eyedropper; }