2017-03-10 17:51:39 -05:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2017-2018 Robin Gareus <robin@gareus.org>
|
2017-03-10 17:51:39 -05:00
|
|
|
*
|
2019-08-02 17:26:43 -04:00
|
|
|
* 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.
|
2017-03-10 17:51:39 -05:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2019-08-02 17:26:43 -04:00
|
|
|
* 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.
|
2017-03-10 17:51:39 -05:00
|
|
|
*/
|
|
|
|
|
2017-03-10 18:52:17 -05:00
|
|
|
#include "pbd/compose.h"
|
|
|
|
|
2022-08-10 23:11:52 -04:00
|
|
|
#include "gtkmm2ext/colors.h"
|
|
|
|
|
2018-04-03 16:38:54 -04:00
|
|
|
#include "public_editor.h"
|
2017-03-10 17:51:39 -05:00
|
|
|
#include "stripable_colorpicker.h"
|
2017-03-10 20:23:34 -05:00
|
|
|
#include "ui_config.h"
|
2017-03-10 17:51:39 -05:00
|
|
|
|
2018-09-21 13:05:57 -04:00
|
|
|
#include "pbd/i18n.h"
|
|
|
|
|
2017-03-10 17:51:39 -05:00
|
|
|
using namespace Gtk;
|
|
|
|
|
2017-03-10 20:23:34 -05:00
|
|
|
bool StripableColorDialog::palette_initialized = false;
|
|
|
|
Gtk::ColorSelection::SlotChangePaletteHook StripableColorDialog::gtk_palette_changed_hook;
|
|
|
|
|
2017-03-10 17:51:39 -05:00
|
|
|
StripableColorDialog::StripableColorDialog ()
|
|
|
|
{
|
2017-03-10 20:23:34 -05:00
|
|
|
initialize_color_palette ();
|
2017-03-10 17:51:39 -05:00
|
|
|
signal_response().connect (sigc::mem_fun (*this, &StripableColorDialog::finish_color_edit));
|
2017-03-30 20:21:38 -04:00
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
/* hide eyedropper button -- which does not work on OSX:
|
|
|
|
* " the problem is worse than just `not getting the color' though.
|
|
|
|
* The action doesn't actually complete, and window focus is in a
|
|
|
|
* `weird state' until you click inside the color-picker dialog twice;
|
|
|
|
* then it all seems back to normal (but no color got picked)"
|
|
|
|
*
|
|
|
|
* the alternative is to patch gtk's source:
|
|
|
|
* gtk/gtkcolorsel.c gtk_color_selection_init() which packs
|
|
|
|
*
|
|
|
|
* top_hbox [ VBOX [ triangle || hbox [ sample-area || picker-button] ] || ... ]
|
|
|
|
*/
|
2022-01-26 18:06:19 -05:00
|
|
|
ColorSelection* cs = get_color_selection(); // IS-A VBOX
|
2017-03-30 20:21:38 -04:00
|
|
|
if (!cs) { return ; }
|
|
|
|
Gtk::HBox* top_hbox = dynamic_cast<Gtk::HBox*> (cs->children()[0].get_widget());
|
|
|
|
if (!top_hbox) { return ; }
|
|
|
|
Gtk::VBox* vbox = dynamic_cast<Gtk::VBox*> (top_hbox->children()[0].get_widget());
|
|
|
|
if (!vbox) { return ; }
|
|
|
|
Gtk::HBox* hbox = dynamic_cast<Gtk::HBox*> (vbox->children()[1].get_widget());
|
|
|
|
if (!hbox) { return ; }
|
|
|
|
Gtk::Button* picker = dynamic_cast<Gtk::Button*> (hbox->children()[1].get_widget());
|
|
|
|
if (!picker) { return ; }
|
|
|
|
picker->hide ();
|
|
|
|
#endif
|
2017-03-10 17:51:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
StripableColorDialog::~StripableColorDialog ()
|
|
|
|
{
|
|
|
|
reset ();
|
|
|
|
}
|
|
|
|
|
2017-03-10 20:23:34 -05:00
|
|
|
void
|
|
|
|
StripableColorDialog::palette_changed_hook (const Glib::RefPtr<Gdk::Screen>& 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
|
|
|
|
StripableColorDialog::initialize_color_palette ()
|
|
|
|
{
|
|
|
|
// non-static member, because it needs a screen()
|
|
|
|
if (palette_initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gtk_palette_changed_hook =
|
2022-01-26 18:06:19 -05:00
|
|
|
get_color_selection()->set_change_palette_hook (&StripableColorDialog::palette_changed_hook);
|
2017-03-10 20:23:34 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-03-10 17:51:39 -05:00
|
|
|
void
|
|
|
|
StripableColorDialog::reset ()
|
|
|
|
{
|
|
|
|
hide ();
|
2017-03-12 11:54:38 -04:00
|
|
|
if (_stripable && _stripable->active_color_picker() == this) {
|
|
|
|
_stripable->set_active_color_picker (0);
|
|
|
|
}
|
2017-03-10 17:51:39 -05:00
|
|
|
_stripable.reset ();
|
2017-03-14 12:03:14 -04:00
|
|
|
_color_changed_connection.disconnect ();
|
2017-03-10 17:51:39 -05:00
|
|
|
}
|
|
|
|
|
2017-03-30 09:20:48 -04:00
|
|
|
void
|
|
|
|
StripableColorDialog::popup (const std::string& name, uint32_t color)
|
|
|
|
{
|
|
|
|
set_title (string_compose (_("Color Selection: %1"), name));
|
|
|
|
_initial_color = color;
|
|
|
|
|
2022-01-26 18:06:19 -05:00
|
|
|
get_color_selection()->set_has_opacity_control (false);
|
|
|
|
get_color_selection()->set_has_palette (true);
|
2017-03-30 09:20:48 -04:00
|
|
|
|
2022-08-10 23:11:52 -04:00
|
|
|
Gdk::Color c = Gtkmm2ext::gdk_color_from_rgba (_initial_color);
|
2017-03-30 09:20:48 -04:00
|
|
|
|
2022-01-26 18:06:19 -05:00
|
|
|
get_color_selection()->set_previous_color (c);
|
|
|
|
get_color_selection()->set_current_color (c);
|
2017-03-30 09:20:48 -04:00
|
|
|
_color_changed_connection.disconnect ();
|
2022-01-26 18:06:19 -05:00
|
|
|
_color_changed_connection = get_color_selection()->signal_color_changed().connect (sigc::mem_fun (*this, &StripableColorDialog::color_changed));
|
2017-03-30 09:20:48 -04:00
|
|
|
|
|
|
|
present ();
|
|
|
|
}
|
|
|
|
|
2017-03-10 17:51:39 -05:00
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
StripableColorDialog::popup (std::shared_ptr<ARDOUR::Stripable> s)
|
2017-03-10 17:51:39 -05:00
|
|
|
{
|
2017-03-12 11:54:38 -04:00
|
|
|
if (s && s->active_color_picker()) {
|
|
|
|
s->active_color_picker()->present ();
|
|
|
|
return;
|
|
|
|
}
|
2017-03-10 17:51:39 -05:00
|
|
|
if (_stripable == s) {
|
|
|
|
/* keep modified color */
|
|
|
|
present ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_stripable = s;
|
2017-03-12 11:54:38 -04:00
|
|
|
_stripable->set_active_color_picker (this);
|
2017-03-30 09:20:48 -04:00
|
|
|
popup (s->name(), _stripable->presentation_info().color ());
|
2017-03-10 17:51:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StripableColorDialog::finish_color_edit (int response)
|
|
|
|
{
|
2018-04-03 16:38:54 -04:00
|
|
|
ARDOUR::RouteList rl = PublicEditor::instance().get_selection().tracks.routelist();
|
|
|
|
|
2017-03-30 09:20:48 -04:00
|
|
|
if (response == RESPONSE_OK) {
|
2022-08-10 23:11:52 -04:00
|
|
|
ColorChanged (Gtkmm2ext::gdk_color_to_rgba (get_color_selection()->get_current_color())); /* EMIT SIGNAL */
|
2017-03-30 09:20:48 -04:00
|
|
|
}
|
2017-03-10 17:51:39 -05:00
|
|
|
if (_stripable && response == RESPONSE_OK) {
|
2018-04-03 16:38:54 -04:00
|
|
|
for (ARDOUR::RouteList::iterator i = rl.begin(); i != rl.end(); ++i) {
|
2022-08-10 23:11:52 -04:00
|
|
|
(*i)->presentation_info().set_color (Gtkmm2ext::gdk_color_to_rgba (get_color_selection()->get_current_color()));
|
2018-04-03 16:38:54 -04:00
|
|
|
}
|
2022-08-10 23:11:52 -04:00
|
|
|
_stripable->presentation_info().set_color (Gtkmm2ext::gdk_color_to_rgba (get_color_selection()->get_current_color()));
|
2017-03-30 09:20:48 -04:00
|
|
|
} else if (_stripable) {
|
2017-03-14 12:03:14 -04:00
|
|
|
_stripable->presentation_info().set_color (_initial_color);
|
2017-03-10 17:51:39 -05:00
|
|
|
}
|
|
|
|
reset ();
|
|
|
|
}
|
2017-03-14 12:03:14 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
StripableColorDialog::color_changed ()
|
|
|
|
{
|
|
|
|
if (_stripable) {
|
2022-08-10 23:11:52 -04:00
|
|
|
_stripable->presentation_info().set_color (Gtkmm2ext::gdk_color_to_rgba (get_color_selection()->get_current_color()));
|
2017-03-14 12:03:14 -04:00
|
|
|
}
|
|
|
|
}
|
2017-03-30 09:20:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
ArdourColorButton::ArdourColorButton ()
|
|
|
|
{
|
|
|
|
_color_picker.ColorChanged.connect (sigc::mem_fun(*this, &ArdourColorButton::color_selected));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ArdourColorButton::on_clicked ()
|
|
|
|
{
|
2022-08-10 23:11:52 -04:00
|
|
|
_color_picker.popup ("", Gtkmm2ext::gdk_color_to_rgba (get_color ()));
|
2017-03-30 09:20:48 -04:00
|
|
|
_color_picker.get_window ()->set_transient_for (get_window ());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ArdourColorButton::color_selected (uint32_t color)
|
|
|
|
{
|
|
|
|
Gdk::Color c;
|
2022-08-10 23:11:52 -04:00
|
|
|
Gtkmm2ext::set_color_from_rgba (c, color);
|
2017-03-30 09:20:48 -04:00
|
|
|
set_color (c);
|
|
|
|
g_signal_emit_by_name (GTK_WIDGET(gobj()), "color-set", 0);
|
|
|
|
}
|