diff --git a/gtk2_ardour/ardour_color_dialog.cc b/gtk2_ardour/ardour_color_dialog.cc new file mode 100644 index 0000000000..c22ba35308 --- /dev/null +++ b/gtk2_ardour/ardour_color_dialog.cc @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2017-2018 Robin Gareus + * Copyright (C) 2026 Paul Davis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "pbd/compose.h" + +#include "ardour/stripable.h" + +#include "gtkmm2ext/colors.h" + +#include "ardour_color_dialog.h" +#include "ui_config.h" + +#include "pbd/i18n.h" + +using namespace Gtk; + +bool ArdourColorDialog::palette_initialized = false; +Gtk::ColorSelection::SlotChangePaletteHook ArdourColorDialog::gtk_palette_changed_hook; + +ArdourColorDialog::ArdourColorDialog () + : _initial_color (0) +{ + 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; +} + +void +ArdourColorDialog::popup (const std::string& name, uint32_t color, Gtk::Window* parent) +{ + set_title (string_compose (_("Color Selection: %1"), name)); + _initial_color = color; + + Gtk::ColorSelection* color_selection (get_color_selection()); + + Gdk::Color c = Gtkmm2ext::gdk_color_from_rgba (_initial_color); + + color_selection->set_previous_color (c); + color_selection->set_current_color (c); + + color_selection->signal_color_changed().connect (sigc::mem_fun (*this, &ArdourColorDialog::color_changed)); + + if (parent) { + set_transient_for (*parent); + } + + present (); +} + +/* ---------- */ + +ArdourColorButton::ArdourColorButton () +{ + _color_picker.get_color_selection()->signal_color_changed().connect (sigc::mem_fun(*this, &ArdourColorButton::color_selected)); + _color_picker.signal_response().connect (sigc::mem_fun (*this, &ArdourColorButton::finish)); +} + +void +ArdourColorButton::finish (int response) +{ + switch (response) { + case Gtk::RESPONSE_OK: + break; + default: + Gdk::Color c (Gtkmm2ext::gdk_color_from_rgba (_color_picker.initial_color())); + set_color (c); + g_signal_emit_by_name (GTK_WIDGET(gobj()), "color-set", 0); + break; + } + + _color_picker.hide (); +} + +void +ArdourColorButton::on_clicked () +{ + _color_picker.popup ("", Gtkmm2ext::gdk_color_to_rgba (get_color ()), dynamic_cast (get_toplevel())); + _color_picker.get_window ()->set_transient_for (get_window ()); +} + +void +ArdourColorButton::color_selected () +{ + Gdk::Color c (_color_picker.get_color_selection()->get_current_color()); + set_color (c); + g_signal_emit_by_name (GTK_WIDGET(gobj()), "color-set", 0); +} + diff --git a/gtk2_ardour/ardour_color_dialog.h b/gtk2_ardour/ardour_color_dialog.h new file mode 100644 index 0000000000..3b1909a8c8 --- /dev/null +++ b/gtk2_ardour/ardour_color_dialog.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2017 Robin Gareus + * Copyright (C) 2026 Paul Davis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include + +#include +#include + +#include "ardour/presentation_info.h" + +namespace ARDOUR { + class Stripable; +} + +class ArdourColorDialog : public Gtk::ColorSelectionDialog +{ + public: + ArdourColorDialog (); + + void popup (const std::string& name, uint32_t color, Gtk::Window* parent); + ARDOUR::PresentationInfo::color_t initial_color() const { return _initial_color; } + virtual void color_changed() {} + + protected: + ARDOUR::PresentationInfo::color_t _initial_color; + + 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 ArdourColorButton : public Gtk::ColorButton +{ +public: + ArdourColorButton (); + +protected: + void on_clicked(); + void color_selected (); + void finish (int response); + +private: + ArdourColorDialog _color_picker; +}; diff --git a/gtk2_ardour/route_group_dialog.h b/gtk2_ardour/route_group_dialog.h index a5c3259fe1..d1d309d1dc 100644 --- a/gtk2_ardour/route_group_dialog.h +++ b/gtk2_ardour/route_group_dialog.h @@ -26,7 +26,7 @@ #include #include "ardour_dialog.h" -#include "stripable_colorpicker.h" +#include "ardour_color_dialog.h" namespace ARDOUR { class RouteGroup; @@ -44,19 +44,19 @@ private: std::shared_ptr _group; std::string _initial_name; - Gtk::Entry _name; - Gtk::CheckButton _active; - Gtk::CheckButton _gain; - Gtk::CheckButton _relative; - Gtk::CheckButton _mute; - Gtk::CheckButton _solo; - Gtk::CheckButton _rec_enable; - Gtk::CheckButton _sursend_enable; - Gtk::CheckButton _select; - Gtk::CheckButton _edit; - Gtk::CheckButton _route_active; - Gtk::CheckButton _share_color; - Gtk::CheckButton _share_monitoring; + Gtk::Entry _name; + Gtk::CheckButton _active; + Gtk::CheckButton _gain; + Gtk::CheckButton _relative; + Gtk::CheckButton _mute; + Gtk::CheckButton _solo; + Gtk::CheckButton _rec_enable; + Gtk::CheckButton _sursend_enable; + Gtk::CheckButton _select; + Gtk::CheckButton _edit; + Gtk::CheckButton _route_active; + Gtk::CheckButton _share_color; + Gtk::CheckButton _share_monitoring; ArdourColorButton _color; void gain_toggled (); diff --git a/gtk2_ardour/stripable_colorpicker.cc b/gtk2_ardour/stripable_colorpicker.cc index c9f5dee058..4c1f2195a7 100644 --- a/gtk2_ardour/stripable_colorpicker.cc +++ b/gtk2_ardour/stripable_colorpicker.cc @@ -1,5 +1,6 @@ /* * Copyright (C) 2017-2018 Robin Gareus + * Copyright (C) 2026 Paul Davis * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,8 +17,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "pbd/compose.h" - #include "ardour/stripable.h" #include "gtkmm2ext/colors.h" @@ -27,109 +26,8 @@ #include "stripable_colorpicker.h" #include "ui_config.h" -#include "pbd/i18n.h" - using namespace Gtk; -bool ArdourColorDialog::palette_initialized = false; -Gtk::ColorSelection::SlotChangePaletteHook ArdourColorDialog::gtk_palette_changed_hook; - -ArdourColorDialog::ArdourColorDialog () - : _initial_color (0) -{ - 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; -} - -void -ArdourColorDialog::popup (const std::string& name, uint32_t color, Gtk::Window* parent) -{ - set_title (string_compose (_("Color Selection: %1"), name)); - _initial_color = color; - - Gtk::ColorSelection* color_selection (get_color_selection()); - - Gdk::Color c = Gtkmm2ext::gdk_color_from_rgba (_initial_color); - - color_selection->set_previous_color (c); - color_selection->set_current_color (c); - - color_selection->signal_color_changed().connect (sigc::mem_fun (*this, &ArdourColorDialog::color_changed)); - - if (parent) { - set_transient_for (*parent); - } - - present (); -} - -/* ---------- */ - -ArdourColorButton::ArdourColorButton () -{ - _color_picker.get_color_selection()->signal_color_changed().connect (sigc::mem_fun(*this, &ArdourColorButton::color_selected)); - _color_picker.signal_response().connect (sigc::mem_fun (*this, &ArdourColorButton::finish)); -} - -void -ArdourColorButton::finish (int response) -{ - switch (response) { - case Gtk::RESPONSE_OK: - break; - default: - Gdk::Color c (Gtkmm2ext::gdk_color_from_rgba (_color_picker.initial_color())); - set_color (c); - g_signal_emit_by_name (GTK_WIDGET(gobj()), "color-set", 0); - break; - } - - _color_picker.hide (); -} - -void -ArdourColorButton::on_clicked () -{ - _color_picker.popup ("", Gtkmm2ext::gdk_color_to_rgba (get_color ()), dynamic_cast (get_toplevel())); - _color_picker.get_window ()->set_transient_for (get_window ()); -} - -void -ArdourColorButton::color_selected () -{ - Gdk::Color c (_color_picker.get_color_selection()->get_current_color()); - set_color (c); - g_signal_emit_by_name (GTK_WIDGET(gobj()), "color-set", 0); -} - -/* ---------- */ - StripableColorDialog::StripableColorDialog (std::shared_ptr s) { assert (s); diff --git a/gtk2_ardour/stripable_colorpicker.h b/gtk2_ardour/stripable_colorpicker.h index 9d62c9f811..77c6b11826 100644 --- a/gtk2_ardour/stripable_colorpicker.h +++ b/gtk2_ardour/stripable_colorpicker.h @@ -23,32 +23,12 @@ #include #include -#include "ardour/presentation_info.h" +#include "ardour_color_dialog.h" namespace ARDOUR { class Stripable; } -class ArdourColorDialog : public Gtk::ColorSelectionDialog -{ - public: - ArdourColorDialog (); - - void popup (const std::string& name, uint32_t color, Gtk::Window* parent); - ARDOUR::PresentationInfo::color_t initial_color() const { return _initial_color; } - virtual void color_changed() {} - - protected: - ARDOUR::PresentationInfo::color_t _initial_color; - - 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: @@ -62,20 +42,6 @@ private: std::shared_ptr _stripable; - sigc::connection _color_changed_connection; PBD::ScopedConnectionList _connections; }; -class ArdourColorButton : public Gtk::ColorButton -{ -public: - ArdourColorButton (); - -protected: - void on_clicked(); - void color_selected (); - void finish (int response); - -private: - ArdourColorDialog _color_picker; -}; diff --git a/gtk2_ardour/trigger_ui.cc b/gtk2_ardour/trigger_ui.cc index 7b393c5f92..d07f7a0967 100644 --- a/gtk2_ardour/trigger_ui.cc +++ b/gtk2_ardour/trigger_ui.cc @@ -49,7 +49,7 @@ #include "keyboard.h" #include "public_editor.h" #include "region_view.h" -#include "stripable_colorpicker.h" +#include "ardour_color_dialog.h" #include "trigger_jump_dialog.h" #include "ui_config.h" diff --git a/gtk2_ardour/trigger_ui.h b/gtk2_ardour/trigger_ui.h index c19526c790..774139156e 100644 --- a/gtk2_ardour/trigger_ui.h +++ b/gtk2_ardour/trigger_ui.h @@ -28,8 +28,6 @@ #include "widgets/ardour_button.h" #include "widgets/frame.h" -#include "stripable_colorpicker.h" - namespace Gtk { class FileChooserDialog; @@ -37,6 +35,7 @@ namespace Gtk } class TriggerJumpDialog; +class ArdourColorDialog; class TriggerUI : virtual public sigc::trackable { diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index 1bcf456152..e9f38fa3fe 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -21,6 +21,7 @@ gtk2_ardour_sources = [ 'ambiguous_file_dialog.cc', 'analysis_window.cc', 'application_bar.cc', + 'ardour_color_dialog.cc', 'ardour_dialog.cc', 'ardour_http.cc', 'ardour_message.cc',