Add ColorButton drop-in replacement with palette support
authorRobin Gareus <robin@gareus.org>
Thu, 30 Mar 2017 13:20:48 +0000 (15:20 +0200)
committerRobin Gareus <robin@gareus.org>
Thu, 30 Mar 2017 13:20:48 +0000 (15:20 +0200)
gtk2_ardour/stripable_colorpicker.cc
gtk2_ardour/stripable_colorpicker.h

index b9c4990cfe1a9450af1d15455679cebb869ed171..3defed81201e12cd3399785ee384ab8d337a31cd 100644 (file)
@@ -77,6 +77,25 @@ StripableColorDialog::reset ()
        _color_changed_connection.disconnect ();
 }
 
+void
+StripableColorDialog::popup (const std::string& name, uint32_t color)
+{
+       set_title (string_compose (_("Color Selection: %1"), name));
+       _initial_color = color;
+
+       get_colorsel()->set_has_opacity_control (false);
+       get_colorsel()->set_has_palette (true);
+
+       Gdk::Color c = gdk_color_from_rgba (_initial_color);
+
+       get_colorsel()->set_previous_color (c);
+       get_colorsel()->set_current_color (c);
+       _color_changed_connection.disconnect ();
+       _color_changed_connection = get_colorsel()->signal_color_changed().connect (sigc::mem_fun (*this, &StripableColorDialog::color_changed));
+
+       present ();
+}
+
 void
 StripableColorDialog::popup (boost::shared_ptr<ARDOUR::Stripable> s)
 {
@@ -92,27 +111,18 @@ 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 (_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 ();
+       popup (s->name(), _stripable->presentation_info().color ());
 }
 
 void
 StripableColorDialog::finish_color_edit (int response)
 {
+       if (response == RESPONSE_OK) {
+               ColorChanged (gdk_color_to_rgba (get_colorsel()->get_current_color())); /* EMIT SIGNAL */
+       }
        if (_stripable && response == RESPONSE_OK) {
                _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
-       } else {
+       } else if (_stripable) {
                _stripable->presentation_info().set_color (_initial_color);
        }
        reset ();
@@ -125,3 +135,25 @@ StripableColorDialog::color_changed ()
                _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
        }
 }
+
+
+ArdourColorButton::ArdourColorButton ()
+{
+       _color_picker.ColorChanged.connect (sigc::mem_fun(*this, &ArdourColorButton::color_selected));
+}
+
+void
+ArdourColorButton::on_clicked ()
+{
+       _color_picker.popup ("", gdk_color_to_rgba (get_color ()));
+       _color_picker.get_window ()->set_transient_for (get_window ());
+}
+
+void
+ArdourColorButton::color_selected (uint32_t color)
+{
+       Gdk::Color c;
+       set_color_from_rgba (c, color);
+       set_color (c);
+       g_signal_emit_by_name (GTK_WIDGET(gobj()), "color-set", 0);
+}
index 952640da7079301b51d295a3f4760b3988a74028..4af5bbd7e1dcabe5e51c24e84ad75e5306f97fa1 100644 (file)
@@ -20,7 +20,9 @@
 #define __gtkardour_stripable_colorpicker_h__
 
 #include <boost/shared_ptr.hpp>
+#include <gtkmm/colorbutton.h>
 #include <gtkmm/colorselection.h>
+
 #include "ardour/stripable.h"
 
 class StripableColorDialog : public Gtk::ColorSelectionDialog
@@ -30,6 +32,8 @@ public:
        ~StripableColorDialog ();
        void reset ();
        void popup (boost::shared_ptr<ARDOUR::Stripable> s);
+       void popup (const std::string&, uint32_t);
+       sigc::signal<void, uint32_t> ColorChanged;
 
 private:
        void initialize_color_palette ();
@@ -47,4 +51,17 @@ private:
        static Gtk::ColorSelection::SlotChangePaletteHook gtk_palette_changed_hook;
 };
 
+class ArdourColorButton : public Gtk::ColorButton
+{
+public:
+       ArdourColorButton ();
+
+protected:
+       void on_clicked();
+       void color_selected (uint32_t color);
+
+private:
+       StripableColorDialog _color_picker;
+};
+
 #endif