From 4aeba817b96d981354623e269baae5ab4eaae73b Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 20 Jan 2026 08:39:27 -0700 Subject: [PATCH] introduce ArdourColorDialog, a Gtk::ColorSelectionDialog with a palette --- gtk2_ardour/stripable_colorpicker.cc | 70 +++++++++++++++------------- gtk2_ardour/stripable_colorpicker.h | 22 ++++++--- 2 files changed, 52 insertions(+), 40 deletions(-) diff --git a/gtk2_ardour/stripable_colorpicker.cc b/gtk2_ardour/stripable_colorpicker.cc index 31a53066db..45d125de14 100644 --- a/gtk2_ardour/stripable_colorpicker.cc +++ b/gtk2_ardour/stripable_colorpicker.cc @@ -31,20 +31,52 @@ using namespace Gtk; -bool StripableColorDialog::palette_initialized = false; -Gtk::ColorSelection::SlotChangePaletteHook StripableColorDialog::gtk_palette_changed_hook; +bool ArdourColorDialog::palette_initialized = false; +Gtk::ColorSelection::SlotChangePaletteHook ArdourColorDialog::gtk_palette_changed_hook; + +ArdourColorDialog::ArdourColorDialog () +{ + initialize_color_palette (); + get_color_selection()->set_has_opacity_control (false); + get_color_selection()->set_has_palette (true); +} + +void +ArdourColorDialog::palette_changed_hook (const Glib::RefPtr& 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 +ArdourColorDialog::initialize_color_palette () +{ + // non-static member, because it needs a screen() + if (palette_initialized) { + return; + } + gtk_palette_changed_hook = get_color_selection()->set_change_palette_hook (&ArdourColorDialog::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; +} + +/* ---------- */ StripableColorDialog::StripableColorDialog (std::shared_ptr s) { assert (s); - initialize_color_palette (); - signal_response().connect (sigc::mem_fun (*this, &StripableColorDialog::finish_color_edit)); - _stripable = s; _stripable->set_active_color_picker (this); _stripable->DropReferences.connect (_connections, invalidator (*this), [this]() { delete this; }, gui_context ()); + signal_response().connect (sigc::mem_fun (*this, &StripableColorDialog::finish_color_edit)); } StripableColorDialog::~StripableColorDialog () @@ -56,31 +88,6 @@ StripableColorDialog::~StripableColorDialog () _color_changed_connection.disconnect (); } -void -StripableColorDialog::palette_changed_hook (const Glib::RefPtr& 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_color_selection()->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::popup (Gtk::Window* parent) { @@ -122,9 +129,6 @@ StripableColorDialog::popup (const std::string& name, uint32_t color, Gtk::Windo Gtk::ColorSelection* color_selection (get_color_selection()); - color_selection->set_has_opacity_control (false); - color_selection->set_has_palette (true); - Gdk::Color c = Gtkmm2ext::gdk_color_from_rgba (_initial_color); color_selection->set_previous_color (c); diff --git a/gtk2_ardour/stripable_colorpicker.h b/gtk2_ardour/stripable_colorpicker.h index dbf68698d1..ca64b134e3 100644 --- a/gtk2_ardour/stripable_colorpicker.h +++ b/gtk2_ardour/stripable_colorpicker.h @@ -26,10 +26,23 @@ #include "ardour/presentation_info.h" namespace ARDOUR { -class Stripable; + class Stripable; } -class StripableColorDialog : public Gtk::ColorSelectionDialog +class ArdourColorDialog : public Gtk::ColorSelectionDialog +{ + public: + ArdourColorDialog (); + + private: + void initialize_color_palette (); + + static bool palette_initialized; + static void palette_changed_hook (const Glib::RefPtr&, const Gdk::ArrayHandle_Color&); + static Gtk::ColorSelection::SlotChangePaletteHook gtk_palette_changed_hook; +}; + +class StripableColorDialog : public ArdourColorDialog { public: StripableColorDialog (std::shared_ptr); @@ -38,7 +51,6 @@ public: sigc::signal ColorChanged; private: - void initialize_color_palette (); void finish_color_edit (int response); void color_changed (); void popup (const std::string& name, uint32_t color, Gtk::Window* parent); @@ -48,8 +60,4 @@ private: sigc::connection _color_changed_connection; PBD::ScopedConnectionList _connections; - - static bool palette_initialized; - static void palette_changed_hook (const Glib::RefPtr&, const Gdk::ArrayHandle_Color&); - static Gtk::ColorSelection::SlotChangePaletteHook gtk_palette_changed_hook; };