2 * Copyright (C) 2017-2018 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "pbd/compose.h"
21 #include "public_editor.h"
22 #include "stripable_colorpicker.h"
23 #include "ui_config.h"
29 using namespace ARDOUR_UI_UTILS;
31 bool StripableColorDialog::palette_initialized = false;
32 Gtk::ColorSelection::SlotChangePaletteHook StripableColorDialog::gtk_palette_changed_hook;
34 StripableColorDialog::StripableColorDialog ()
36 initialize_color_palette ();
37 signal_response().connect (sigc::mem_fun (*this, &StripableColorDialog::finish_color_edit));
40 /* hide eyedropper button -- which does not work on OSX:
41 * " the problem is worse than just `not getting the color' though.
42 * The action doesn't actually complete, and window focus is in a
43 * `weird state' until you click inside the color-picker dialog twice;
44 * then it all seems back to normal (but no color got picked)"
46 * the alternative is to patch gtk's source:
47 * gtk/gtkcolorsel.c gtk_color_selection_init() which packs
49 * top_hbox [ VBOX [ triangle || hbox [ sample-area || picker-button] ] || ... ]
51 ColorSelection* cs = get_colorsel(); // IS-A VBOX
53 Gtk::HBox* top_hbox = dynamic_cast<Gtk::HBox*> (cs->children()[0].get_widget());
54 if (!top_hbox) { return ; }
55 Gtk::VBox* vbox = dynamic_cast<Gtk::VBox*> (top_hbox->children()[0].get_widget());
56 if (!vbox) { return ; }
57 Gtk::HBox* hbox = dynamic_cast<Gtk::HBox*> (vbox->children()[1].get_widget());
58 if (!hbox) { return ; }
59 Gtk::Button* picker = dynamic_cast<Gtk::Button*> (hbox->children()[1].get_widget());
60 if (!picker) { return ; }
65 StripableColorDialog::~StripableColorDialog ()
71 StripableColorDialog::palette_changed_hook (const Glib::RefPtr<Gdk::Screen>& s, const Gdk::ArrayHandle_Color& c)
73 std::string p = std::string (ColorSelection::palette_to_string (c));
74 UIConfiguration::instance ().set_stripable_color_palette (p);
75 gtk_palette_changed_hook (s, c);
79 StripableColorDialog::initialize_color_palette ()
81 // non-static member, because it needs a screen()
82 if (palette_initialized) {
85 gtk_palette_changed_hook =
86 get_colorsel()->set_change_palette_hook (&StripableColorDialog::palette_changed_hook);
88 std::string cp = UIConfiguration::instance ().get_stripable_color_palette ();
90 Gdk::ArrayHandle_Color c = ColorSelection::palette_from_string (cp);
91 gtk_palette_changed_hook (get_screen (), c);
93 palette_initialized = true;
97 StripableColorDialog::reset ()
100 if (_stripable && _stripable->active_color_picker() == this) {
101 _stripable->set_active_color_picker (0);
104 _color_changed_connection.disconnect ();
108 StripableColorDialog::popup (const std::string& name, uint32_t color)
110 set_title (string_compose (_("Color Selection: %1"), name));
111 _initial_color = color;
113 get_colorsel()->set_has_opacity_control (false);
114 get_colorsel()->set_has_palette (true);
116 Gdk::Color c = gdk_color_from_rgba (_initial_color);
118 get_colorsel()->set_previous_color (c);
119 get_colorsel()->set_current_color (c);
120 _color_changed_connection.disconnect ();
121 _color_changed_connection = get_colorsel()->signal_color_changed().connect (sigc::mem_fun (*this, &StripableColorDialog::color_changed));
127 StripableColorDialog::popup (boost::shared_ptr<ARDOUR::Stripable> s)
129 if (s && s->active_color_picker()) {
130 s->active_color_picker()->present ();
133 if (_stripable == s) {
134 /* keep modified color */
140 _stripable->set_active_color_picker (this);
141 popup (s->name(), _stripable->presentation_info().color ());
145 StripableColorDialog::finish_color_edit (int response)
147 ARDOUR::RouteList rl = PublicEditor::instance().get_selection().tracks.routelist();
149 if (response == RESPONSE_OK) {
150 ColorChanged (gdk_color_to_rgba (get_colorsel()->get_current_color())); /* EMIT SIGNAL */
152 if (_stripable && response == RESPONSE_OK) {
153 for (ARDOUR::RouteList::iterator i = rl.begin(); i != rl.end(); ++i) {
154 (*i)->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
156 _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
157 } else if (_stripable) {
158 _stripable->presentation_info().set_color (_initial_color);
164 StripableColorDialog::color_changed ()
167 _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
172 ArdourColorButton::ArdourColorButton ()
174 _color_picker.ColorChanged.connect (sigc::mem_fun(*this, &ArdourColorButton::color_selected));
178 ArdourColorButton::on_clicked ()
180 _color_picker.popup ("", gdk_color_to_rgba (get_color ()));
181 _color_picker.get_window ()->set_transient_for (get_window ());
185 ArdourColorButton::color_selected (uint32_t color)
188 set_color_from_rgba (c, color);
190 g_signal_emit_by_name (GTK_WIDGET(gobj()), "color-set", 0);