Sort palette colors by name only
[ardour.git] / gtk2_ardour / color_theme_manager.cc
index 1e381f1854d2508b18cb7ed83c4a51fb65bf3e15..6e434515352b08c8a2bbc65e0f972b8ba9d9f15d 100644 (file)
@@ -1,32 +1,31 @@
 /*
-    Copyright (C) 2000-2016 Paul Davis
-
-    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.
-
-    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.
-
-    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., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
+ * Copyright (C) 2016-2017 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2016-2019 Paul Davis <paul@linuxaudiosystems.com>
+ *
* 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.
+ *
+ * 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.
+ *
+ * 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.
+ */
 
 #include <cmath>
 #include <errno.h>
 
+#include <gtkmm/stock.h>
+
 #include "fix_carbon.h"
 
 #include "pbd/gstdio_compat.h"
 
-#include "gtkmm2ext/cell_renderer_color_selector.h"
-#include "gtkmm2ext/utils.h"
-
 #include "pbd/compose.h"
 #include "pbd/file_utils.h"
 #include "pbd/replace_all.h"
 #include "ardour/filesystem_paths.h"
 #include "ardour/profile.h"
 
+#include "gtkmm2ext/cell_renderer_color_selector.h"
+#include "gtkmm2ext/utils.h"
+
 #include "canvas/container.h"
 #include "canvas/rectangle.h"
 #include "canvas/scroll_group.h"
-#include "canvas/wave_view.h"
 
-#include "ardour_button.h"
+#include "waveview/wave_view.h"
+
 #include "ardour_dialog.h"
 #include "color_theme_manager.h"
 #include "rgb_macros.h"
@@ -52,6 +54,7 @@ using namespace std;
 using namespace Gtk;
 using namespace PBD;
 using namespace ARDOUR;
+using namespace Gtkmm2ext;
 using namespace ARDOUR_UI_UTILS;
 
 ColorThemeManager::ColorThemeManager ()
@@ -61,14 +64,10 @@ ColorThemeManager::ColorThemeManager ()
        , palette_window (0)
        , color_theme_label (_("Color Theme"))
 {
-       Label* l = manage (new Label (string_compose ("<b>%1</b>", _("Colors"))));
-       l->set_alignment (0, 0.5);
-       l->set_use_markup (true);
-       _box->pack_start (*l, false, false);
-
        std::map<string,string> color_themes;
 
        get_color_themes (color_themes);
+       int n = 0;
 
        if (color_themes.size() > 1) {
                theme_list = TreeStore::create (color_theme_columns);
@@ -102,14 +101,14 @@ ColorThemeManager::ColorThemeManager ()
                }
 
                Gtk::HBox* hbox = Gtk::manage (new Gtk::HBox());
-               Gtk::Alignment* align = Gtk::manage (new Gtk::Alignment);
-               align->set (0, 0.5);
+               Gtk::Alignment* align = Gtk::manage (new Gtk::Alignment (0, 0.5, 0, 1.0));
                align->add (color_theme_dropdown);
                hbox->set_spacing (6);
                hbox->pack_start (color_theme_label, false, false);
                hbox->pack_start (*align, true, true);
-               _box->pack_start (*hbox, PACK_SHRINK);
                hbox->show_all ();
+               table.attach (*hbox, 0, 3, n, n + 1);
+               ++n;
        }
 
        reset_button.signal_clicked().connect (sigc::mem_fun (*this, &ColorThemeManager::reset_canvas_colors));
@@ -149,8 +148,12 @@ ColorThemeManager::ColorThemeManager ()
 
        notebook.set_size_request (400, 400);
 
-       _box->pack_start (notebook, true, true, 12);
-       _box->pack_start (reset_button, false, false, 12);
+       table.attach (notebook, 0, 3, n, n + 1);
+       ++n;
+
+       Alignment* a = manage (new Alignment (0, 0.5, 0, 1.0));
+       a->add (reset_button);
+       table.attach (*a, 0, 1, n, n + 1);
 
        color_dialog.get_colorsel()->set_has_opacity_control (true);
        color_dialog.get_colorsel()->set_has_palette (true);
@@ -164,15 +167,13 @@ ColorThemeManager::ColorThemeManager ()
        setup_modifiers ();
 
        UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ColorThemeManager::colors_changed));
-
-       _box->show_all ();
 }
 
 
 ColorThemeManager::~ColorThemeManager ()
 {
-       if (palette_group) { 
-               palette_group->clear (true);  
+       if (palette_group) {
+               palette_group->clear (true);
                delete palette_group;
        }
 }
@@ -276,21 +277,13 @@ ColorThemeManager::palette_canvas_allocated (Gtk::Allocation& alloc, ArdourCanva
 
 struct NamedColor {
        string name;
-       ArdourCanvas::HSV    color;
-       NamedColor (string s, ArdourCanvas::HSV c) : name (s), color (c) {}
+       Gtkmm2ext::HSV    color;
+       NamedColor (string s, Gtkmm2ext::HSV c) : name (s), color (c) {}
 };
 
-struct SortByHue {
+struct SortNamedColor {
        bool operator() (NamedColor const & a, NamedColor const & b) {
-               using namespace ArdourCanvas;
-               const HSV black (0, 0, 0);
-               if (a.color.is_gray() || b.color.is_gray()) {
-                       return black.distance (a.color) < black.distance (b.color);
-               } else {
-                       return a.color.h < b.color.h;
-                       // const HSV red (rgba_to_color (1.0, 0.0, 0.0, 1.0));
-                       // return red.distance (a.color) < red.distance (b.color);
-               }
+               return a.name < b.name;
        }
 };
 
@@ -307,7 +300,7 @@ ColorThemeManager::build_palette_canvas (ArdourCanvas::Canvas& canvas, ArdourCan
        for (UIConfiguration::Colors::const_iterator x = colors.begin(); x != colors.end(); ++x) {
                nc.push_back (NamedColor (x->first, HSV (x->second)));
        }
-       SortByHue sorter;
+       SortNamedColor sorter;
        sort (nc.begin(), nc.end(), sorter);
 
        const uint32_t color_limit = nc.size();
@@ -381,7 +374,7 @@ ColorThemeManager::edit_palette_color (std::string name)
        using namespace ArdourCanvas;
        double r,g, b, a;
        UIConfiguration* uic (&UIConfiguration::instance());
-       ArdourCanvas::Color c = uic->color (name);
+       Gtkmm2ext::Color c = uic->color (name);
        Gdk::Color gdkcolor;
 
        color_to_rgba (c, r, g, b, a);
@@ -606,6 +599,19 @@ ColorThemeManager::set_state_from_config ()
 
 }
 
+void
+ColorThemeManager::add_to_page (OptionEditorPage* p)
+{
+       int const n = p->table.property_n_rows();
+       int m = n + 1;
+       if (!_note.empty ()) {
+               ++m;
+       }
+       p->table.resize (m, 3);
+       p->table.attach (box, 1, 3, n, n + 1, FILL | EXPAND, SHRINK, 0, 0);
+       maybe_add_note (p, n + 1);
+}
+
 Gtk::Widget&
 ColorThemeManager::tip_widget()
 {