Update color stripable color-picker(s)
[ardour.git] / gtk2_ardour / stripable_colorpicker.cc
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #include "stripable_colorpicker.h"
20 #include "utils.h"
21
22 using namespace Gtk;
23 using namespace ARDOUR_UI_UTILS;
24
25 StripableColorDialog::StripableColorDialog ()
26 {
27         signal_response().connect (sigc::mem_fun (*this, &StripableColorDialog::finish_color_edit));
28 }
29
30 StripableColorDialog::~StripableColorDialog ()
31 {
32         reset ();
33 }
34
35 void
36 StripableColorDialog::reset ()
37 {
38         hide ();
39         _stripable.reset ();
40 }
41
42 void
43 StripableColorDialog::popup (boost::shared_ptr<ARDOUR::Stripable> s)
44 {
45         if (_stripable == s) {
46                 /* keep modified color */
47                 present ();
48                 return;
49         }
50
51         _stripable = s;
52
53         get_colorsel()->set_has_opacity_control (false);
54         get_colorsel()->set_has_palette (true);
55
56         Gdk::Color c = gdk_color_from_rgba (_stripable->presentation_info().color ());
57
58         get_colorsel()->set_previous_color (c);
59         get_colorsel()->set_current_color (c);
60
61         present ();
62 }
63
64 void
65 StripableColorDialog::finish_color_edit (int response)
66 {
67         if (_stripable && response == RESPONSE_OK) {
68                 _stripable->presentation_info().set_color (gdk_color_to_rgba (get_colorsel()->get_current_color()));
69         }
70         reset ();
71 }