Allow to customize color-picker-palette
authorRobin Gareus <robin@gareus.org>
Sat, 11 Mar 2017 01:23:34 +0000 (02:23 +0100)
committerRobin Gareus <robin@gareus.org>
Sat, 11 Mar 2017 01:23:34 +0000 (02:23 +0100)
gtk2_ardour/stripable_colorpicker.cc
gtk2_ardour/stripable_colorpicker.h
gtk2_ardour/ui_config_vars.h

index 6f89e615f34fc60b36a939e6f4663f73f35c772b..a7db947df8fa5471d19033f83d3d47648dc4a283 100644 (file)
 #include "pbd/i18n.h"
 
 #include "stripable_colorpicker.h"
+#include "ui_config.h"
 #include "utils.h"
 
 using namespace Gtk;
 using namespace ARDOUR_UI_UTILS;
 
+bool StripableColorDialog::palette_initialized = false;
+Gtk::ColorSelection::SlotChangePaletteHook StripableColorDialog::gtk_palette_changed_hook;
+
 StripableColorDialog::StripableColorDialog ()
 {
+       initialize_color_palette ();
        signal_response().connect (sigc::mem_fun (*this, &StripableColorDialog::finish_color_edit));
 }
 
@@ -35,6 +40,32 @@ StripableColorDialog::~StripableColorDialog ()
        reset ();
 }
 
+void
+StripableColorDialog::palette_changed_hook (const Glib::RefPtr<Gdk::Screen>& s, const Gdk::ArrayHandle_Color& c)
+{
+       std::string p = std::string (ColorSelection::palette_to_string (c));
+       UIConfiguration::instance ().set_stripable_color_palette (p);
+       gtk_palette_changed_hook (s, c);
+}
+
+void
+StripableColorDialog::initialize_color_palette ()
+{
+       // non-static member, because it needs a screen()
+       if (palette_initialized) {
+               return;
+       }
+       gtk_palette_changed_hook =
+               get_colorsel()->set_change_palette_hook (&StripableColorDialog::palette_changed_hook);
+
+       std::string cp = UIConfiguration::instance ().get_stripable_color_palette ();
+       if (!cp.empty()) {
+               Gdk::ArrayHandle_Color c = ColorSelection::palette_from_string (cp);
+               gtk_palette_changed_hook (get_screen (), c);
+       }
+       palette_initialized = true;
+}
+
 void
 StripableColorDialog::reset ()
 {
index 79b7ffcf622922378e7259b96b745736237da806..d05d67e974f6e37a56985db7682cf221730053db 100644 (file)
@@ -32,9 +32,15 @@ public:
        void popup (boost::shared_ptr<ARDOUR::Stripable> s);
 
 private:
+       void initialize_color_palette ();
        void finish_color_edit (int response);
 
        boost::shared_ptr<ARDOUR::Stripable> _stripable;
+
+
+       static bool palette_initialized;
+       static void palette_changed_hook (const Glib::RefPtr<Gdk::Screen>&, const Gdk::ArrayHandle_Color&);
+       static Gtk::ColorSelection::SlotChangePaletteHook gtk_palette_changed_hook;
 };
 
 #endif
index d72bea387459f56c90d314c4e553d6668ac9683c..fc868978f6657dd00f400022c722ea8bd80d4d5a 100644 (file)
@@ -92,3 +92,4 @@ UI_CONFIG_VARIABLE (bool, show_inline_display_by_default, "show-inline-display-b
 UI_CONFIG_VARIABLE (bool, prefer_inline_over_gui, "prefer-inline-over-gui", true)
 UI_CONFIG_VARIABLE (uint32_t, action_table_columns, "action-table-columns", 0)
 UI_CONFIG_VARIABLE (bool, use_wm_visibility, "use-wm-visibility", true)
+UI_CONFIG_VARIABLE (std::string, stripable_color_palette, "stripable-color-palette", "#7F7F7F:#FF0000:#800080:#0000FF:#ADD8E6:#008000:#FFFF00:#FFA500:#E6E6FA:#A52A2A:#8B6914:#1E90FF:#FFC0CB:#90EE90:#1A1A1A:#4D4D4D:#BFBFBF:#E5E5E5:#AAAAAA:#444444")  /* Gtk::ColorSelection::palette_to_string */