2 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "pbd/compose.h"
22 #include "stripable_colorpicker.h"
23 #include "ui_config.h"
27 using namespace ARDOUR_UI_UTILS;
29 bool StripableColorDialog::palette_initialized = false;
30 Gtk::ColorSelection::SlotChangePaletteHook StripableColorDialog::gtk_palette_changed_hook;
32 StripableColorDialog::StripableColorDialog ()
34 initialize_color_palette ();
35 signal_response().connect (sigc::mem_fun (*this, &StripableColorDialog::finish_color_edit));
38 StripableColorDialog::~StripableColorDialog ()
44 StripableColorDialog::palette_changed_hook (const Glib::RefPtr<Gdk::Screen>& s, const Gdk::ArrayHandle_Color& c)
46 std::string p = std::string (ColorSelection::palette_to_string (c));
47 UIConfiguration::instance ().set_stripable_color_palette (p);
48 gtk_palette_changed_hook (s, c);
52 StripableColorDialog::initialize_color_palette ()
54 // non-static member, because it needs a screen()
55 if (palette_initialized) {
58 gtk_palette_changed_hook =
59 get_colorsel()->set_change_palette_hook (&StripableColorDialog::palette_changed_hook);
61 std::string cp = UIConfiguration::instance ().get_stripable_color_palette ();
63 Gdk::ArrayHandle_Color c = ColorSelection::palette_from_string (cp);
64 gtk_palette_changed_hook (get_screen (), c);
66 palette_initialized = true;
70 StripableColorDialog::reset ()
73 if (_stripable && _stripable->active_color_picker() == this) {
74 _stripable->set_active_color_picker (0);
77 _color_changed_connection.disconnect ();
81 StripableColorDialog::popup (const std::string& name, uint32_t color)
83 set_title (string_compose (_("Color Selection: %1"), name));
84 _initial_color = color;
86 get_colorsel()->set_has_opacity_control (false);
87 get_colorsel()->set_has_palette (true);
89 Gdk::Color c = gdk_color_from_rgba (_initial_color);
91 get_colorsel()->set_previous_color (c);
92 get_colorsel()->set_current_color (c);
93 _color_changed_connection.disconnect ();
94 _color_changed_connection = get_colorsel()->signal_color_changed().connect (sigc::mem_fun (*this, &StripableColorDialog::color_changed));
100 StripableColorDialog::popup (boost::shared_ptr<ARDOUR::Stripable> s)
102 if (s && s->active_color_picker()) {
103 s->active_color_picker()->present ();
106 if (_stripable == s) {
107 /* keep modified color */
113 _stripable->set_active_color_picker (this);
114 popup (s->name(), _stripable->presentation_info().color ());
118 StripableColorDialog::finish_color_edit (int response)
120 if (response == RESPONSE_OK) {
121 ColorChanged (gdk_color_to_rgba (get_colorsel()->get_current_color())); /* EMIT SIGNAL */
123 if (_stripable && response == RESPONSE_OK) {
124 _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
125 } else if (_stripable) {
126 _stripable->presentation_info().set_color (_initial_color);
132 StripableColorDialog::color_changed ()
135 _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
140 ArdourColorButton::ArdourColorButton ()
142 _color_picker.ColorChanged.connect (sigc::mem_fun(*this, &ArdourColorButton::color_selected));
146 ArdourColorButton::on_clicked ()
148 _color_picker.popup ("", gdk_color_to_rgba (get_color ()));
149 _color_picker.get_window ()->set_transient_for (get_window ());
153 ArdourColorButton::color_selected (uint32_t color)
156 set_color_from_rgba (c, color);
158 g_signal_emit_by_name (GTK_WIDGET(gobj()), "color-set", 0);