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 (boost::shared_ptr<ARDOUR::Stripable> s)
83 if (s && s->active_color_picker()) {
84 s->active_color_picker()->present ();
87 if (_stripable == s) {
88 /* keep modified color */
94 _stripable->set_active_color_picker (this);
95 _initial_color = _stripable->presentation_info().color ();
96 set_title (string_compose (_("Color Selection: %1"), s->name()));
98 get_colorsel()->set_has_opacity_control (false);
99 get_colorsel()->set_has_palette (true);
101 Gdk::Color c = gdk_color_from_rgba (_initial_color);
103 get_colorsel()->set_previous_color (c);
104 get_colorsel()->set_current_color (c);
105 _color_changed_connection = get_colorsel()->signal_color_changed().connect (sigc::mem_fun (*this, &StripableColorDialog::color_changed));
111 StripableColorDialog::finish_color_edit (int response)
113 if (_stripable && response == RESPONSE_OK) {
114 _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
116 _stripable->presentation_info().set_color (_initial_color);
122 StripableColorDialog::color_changed ()
125 _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));