Update stripable color on the fly
authorRobin Gareus <robin@gareus.org>
Tue, 14 Mar 2017 16:03:14 +0000 (17:03 +0100)
committerRobin Gareus <robin@gareus.org>
Tue, 14 Mar 2017 16:03:38 +0000 (17:03 +0100)
gtk2_ardour/stripable_colorpicker.cc
gtk2_ardour/stripable_colorpicker.h

index 2e341f4d7e45ad68f4a3b094ba075d913a6a50ef..b9c4990cfe1a9450af1d15455679cebb869ed171 100644 (file)
@@ -74,6 +74,7 @@ StripableColorDialog::reset ()
                _stripable->set_active_color_picker (0);
        }
        _stripable.reset ();
+       _color_changed_connection.disconnect ();
 }
 
 void
@@ -91,15 +92,17 @@ StripableColorDialog::popup (boost::shared_ptr<ARDOUR::Stripable> s)
 
        _stripable = s;
        _stripable->set_active_color_picker (this);
+       _initial_color = _stripable->presentation_info().color ();
        set_title (string_compose (_("Color Selection: %1"), s->name()));
 
        get_colorsel()->set_has_opacity_control (false);
        get_colorsel()->set_has_palette (true);
 
-       Gdk::Color c = gdk_color_from_rgba (_stripable->presentation_info().color ());
+       Gdk::Color c = gdk_color_from_rgba (_initial_color);
 
        get_colorsel()->set_previous_color (c);
        get_colorsel()->set_current_color (c);
+       _color_changed_connection = get_colorsel()->signal_color_changed().connect (sigc::mem_fun (*this, &StripableColorDialog::color_changed));
 
        present ();
 }
@@ -109,6 +112,16 @@ StripableColorDialog::finish_color_edit (int response)
 {
        if (_stripable && response == RESPONSE_OK) {
                _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
+       } else {
+               _stripable->presentation_info().set_color (_initial_color);
        }
        reset ();
 }
+
+void
+StripableColorDialog::color_changed ()
+{
+       if (_stripable) {
+               _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
+       }
+}
index d05d67e974f6e37a56985db7682cf221730053db..952640da7079301b51d295a3f4760b3988a74028 100644 (file)
@@ -34,8 +34,12 @@ public:
 private:
        void initialize_color_palette ();
        void finish_color_edit (int response);
+       void color_changed ();
 
        boost::shared_ptr<ARDOUR::Stripable> _stripable;
+       ARDOUR::PresentationInfo::color_t _initial_color;
+
+       sigc::connection _color_changed_connection;
 
 
        static bool palette_initialized;