2 Copyright (C) 2000-2007 Paul Davis
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
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "fix_carbon.h"
27 #include <gtkmm/stock.h>
28 #include <gtkmm/settings.h>
30 #include "gtkmm2ext/gtk_ui.h"
31 #include "gtkmm2ext/cell_renderer_color_selector.h"
32 #include "gtkmm2ext/utils.h"
34 #include "pbd/file_utils.h"
35 #include "pbd/compose.h"
37 #include "ardour/filesystem_paths.h"
39 #include "canvas/container.h"
40 #include "canvas/rectangle.h"
41 #include "canvas/scroll_group.h"
42 #include "canvas/wave_view.h"
44 #include "ardour_button.h"
45 #include "ardour_dialog.h"
46 #include "theme_manager.h"
47 #include "rgb_macros.h"
48 #include "ardour_ui.h"
49 #include "global_signals.h"
57 using namespace ARDOUR;
58 using namespace ARDOUR_UI_UTILS;
60 namespace ARDOUR_UI_UTILS {
61 sigc::signal<void> ColorsChanged;
64 ThemeManager::ThemeManager()
65 : ArdourWindow (_("Theme Manager"))
66 , dark_button (_("Dark Theme"))
67 , light_button (_("Light Theme"))
68 , reset_button (_("Restore Defaults"))
69 , flat_buttons (_("Draw \"flat\" buttons"))
70 , blink_rec_button (_("Blink Rec-Arm buttons"))
71 , region_color_button (_("Color regions using their track's color"))
72 , show_clipping_button (_("Show waveform clipping"))
73 , waveform_gradient_depth (0, 1.0, 0.05)
74 , waveform_gradient_depth_label (_("Waveforms color gradient depth"))
75 , timeline_item_gradient_depth (0, 1.0, 0.05)
76 , timeline_item_gradient_depth_label (_("Timeline item gradient depth"))
77 , all_dialogs (_("All floating windows are dialogs"))
78 , icon_set_label (_("Icon Set"))
79 , palette_viewport (*palette_scroller.get_hadjustment(), *palette_scroller.get_vadjustment())
83 set_title (_("Theme Manager"));
85 /* Now the alias list */
87 alias_list = TreeStore::create (alias_columns);
88 alias_display.set_model (alias_list);
89 alias_display.append_column (_("Object"), alias_columns.name);
91 Gtkmm2ext::CellRendererColorSelector* color_renderer = manage (new Gtkmm2ext::CellRendererColorSelector);
92 TreeViewColumn* color_column = manage (new TreeViewColumn (_("Color"), *color_renderer));
93 color_column->add_attribute (color_renderer->property_color(), alias_columns.color);
94 alias_display.append_column (*color_column);
96 alias_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
97 alias_display.get_column (0)->set_expand (true);
98 alias_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
99 alias_display.get_column (1)->set_expand (false);
100 alias_display.set_reorderable (false);
101 alias_display.get_selection()->set_mode (SELECTION_NONE);
102 alias_display.set_headers_visible (true);
104 alias_display.signal_button_press_event().connect (sigc::mem_fun (*this, &ThemeManager::alias_button_press_event), false);
106 alias_scroller.add (alias_display);
108 /* various buttons */
110 RadioButton::Group group = dark_button.get_group();
111 light_button.set_group(group);
112 theme_selection_hbox.set_homogeneous(false);
113 theme_selection_hbox.pack_start (dark_button);
114 theme_selection_hbox.pack_start (light_button);
116 Gtk::VBox* vbox = Gtk::manage (new Gtk::VBox ());
117 vbox->set_homogeneous (false);
118 vbox->pack_start (theme_selection_hbox, PACK_SHRINK);
119 vbox->pack_start (reset_button, PACK_SHRINK);
121 vbox->pack_start (all_dialogs, PACK_SHRINK);
123 vbox->pack_start (flat_buttons, PACK_SHRINK);
124 vbox->pack_start (blink_rec_button, PACK_SHRINK);
125 vbox->pack_start (region_color_button, PACK_SHRINK);
126 vbox->pack_start (show_clipping_button, PACK_SHRINK);
130 vector<string> icon_sets = ::get_icon_sets ();
132 if (icon_sets.size() > 1) {
133 Gtkmm2ext::set_popdown_strings (icon_set_dropdown, icon_sets);
134 icon_set_dropdown.set_active_text (ARDOUR_UI::config()->get_icon_set());
136 hbox = Gtk::manage (new Gtk::HBox());
137 hbox->set_spacing (6);
138 hbox->pack_start (icon_set_label, false, false);
139 hbox->pack_start (icon_set_dropdown, true, true);
140 vbox->pack_start (*hbox, PACK_SHRINK);
144 hbox = Gtk::manage (new Gtk::HBox());
145 hbox->set_spacing (6);
146 hbox->pack_start (waveform_gradient_depth, true, true);
147 hbox->pack_start (waveform_gradient_depth_label, false, false);
148 vbox->pack_start (*hbox, PACK_SHRINK);
150 hbox = Gtk::manage (new Gtk::HBox());
151 hbox->set_spacing (6);
152 hbox->pack_start (timeline_item_gradient_depth, true, true);
153 hbox->pack_start (timeline_item_gradient_depth_label, false, false);
154 vbox->pack_start (*hbox, PACK_SHRINK);
156 palette_group = initialize_palette_canvas (*palette_viewport.canvas());
157 palette_viewport.signal_size_allocate().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::palette_canvas_allocated), palette_group, palette_viewport.canvas(),
158 sigc::mem_fun (*this, &ThemeManager::palette_event)));
159 palette_scroller.add (palette_viewport);
161 notebook.append_page (alias_scroller, _("Items"));
162 notebook.append_page (palette_scroller, _("Palette"));
164 vbox->pack_start (notebook);
170 waveform_gradient_depth.set_update_policy (Gtk::UPDATE_DELAYED);
171 timeline_item_gradient_depth.set_update_policy (Gtk::UPDATE_DELAYED);
173 color_dialog.get_colorsel()->set_has_opacity_control (true);
174 color_dialog.get_colorsel()->set_has_palette (true);
176 flat_buttons.set_active (ARDOUR_UI::config()->get_flat_buttons());
177 blink_rec_button.set_active (ARDOUR_UI::config()->get_blink_rec_arm());
178 region_color_button.set_active (ARDOUR_UI::config()->get_color_regions_using_track_color());
179 show_clipping_button.set_active (ARDOUR_UI::config()->get_show_waveform_clipping());
181 color_dialog.get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_ACCEPT));
182 color_dialog.get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_CANCEL));
183 dark_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_dark_theme_button_toggled));
184 light_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_light_theme_button_toggled));
185 reset_button.signal_clicked().connect (sigc::mem_fun (*this, &ThemeManager::reset_canvas_colors));
186 flat_buttons.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_flat_buttons_toggled));
187 blink_rec_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_blink_rec_arm_toggled));
188 region_color_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_region_color_toggled));
189 show_clipping_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_show_clip_toggled));
190 waveform_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_waveform_gradient_depth_change));
191 timeline_item_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_timeline_item_gradient_depth_change));
192 all_dialogs.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_all_dialogs_toggled));
193 icon_set_dropdown.signal_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_icon_set_changed));
195 Gtkmm2ext::UI::instance()->set_tip (all_dialogs,
196 string_compose (_("Mark all floating windows to be type \"Dialog\" rather than using \"Utility\" for some.\n"
197 "This may help with some window managers. This requires a restart of %1 to take effect"),
200 set_size_request (-1, 400);
201 /* no need to call setup_palette() here, it will be done when its size is allocated */
204 /* Trigger setting up the color scheme and loading the GTK RC file */
206 ARDOUR_UI::config()->load_rc_file (false);
208 ARDOUR_UI_UTILS::ColorsChanged.connect (sigc::mem_fun (*this, &ThemeManager::colors_changed));
211 ThemeManager::~ThemeManager()
216 ThemeManager::colors_changed ()
223 ThemeManager::save (string /*path*/)
229 ThemeManager::on_flat_buttons_toggled ()
231 ARDOUR_UI::config()->set_flat_buttons (flat_buttons.get_active());
232 ArdourButton::set_flat_buttons (flat_buttons.get_active());
234 gtk_rc_reset_styles (gtk_settings_get_default());
238 ThemeManager::on_blink_rec_arm_toggled ()
240 ARDOUR_UI::config()->set_blink_rec_arm (blink_rec_button.get_active());
241 ARDOUR::Config->ParameterChanged("blink-rec-arm");
245 ThemeManager::on_region_color_toggled ()
247 ARDOUR_UI::config()->set_color_regions_using_track_color (region_color_button.get_active());
251 ThemeManager::on_show_clip_toggled ()
253 ARDOUR_UI::config()->set_show_waveform_clipping (show_clipping_button.get_active());
257 ThemeManager::on_all_dialogs_toggled ()
259 ARDOUR_UI::config()->set_all_floating_windows_are_dialogs (all_dialogs.get_active());
263 ThemeManager::on_waveform_gradient_depth_change ()
265 double v = waveform_gradient_depth.get_value();
267 ARDOUR_UI::config()->set_waveform_gradient_depth (v);
268 ArdourCanvas::WaveView::set_global_gradient_depth (v);
272 ThemeManager::on_timeline_item_gradient_depth_change ()
274 double v = timeline_item_gradient_depth.get_value();
276 ARDOUR_UI::config()->set_timeline_item_gradient_depth (v);
280 ThemeManager::on_icon_set_changed ()
282 string new_set = icon_set_dropdown.get_active_text();
283 ARDOUR_UI::config()->set_icon_set (new_set);
287 ThemeManager::on_dark_theme_button_toggled()
289 if (!dark_button.get_active()) return;
291 UIConfiguration* uic (ARDOUR_UI::config());
293 uic->set_color_file("dark");
297 ThemeManager::on_light_theme_button_toggled()
299 if (!light_button.get_active()) return;
301 UIConfiguration* uic (ARDOUR_UI::config());
303 uic->set_color_file("light");
307 ThemeManager::reset_canvas_colors()
309 ARDOUR_UI::config()->load_defaults();
310 ARDOUR_UI::config()->save_state ();
313 ArdourCanvas::Container*
314 ThemeManager::initialize_palette_canvas (ArdourCanvas::Canvas& canvas)
316 using namespace ArdourCanvas;
318 /* hide background */
319 canvas.set_background_color (rgba_to_color (0.0, 0.0, 1.0, 0.0));
321 /* bi-directional scroll group */
323 ScrollGroup* scroll_group = new ScrollGroup (canvas.root(), ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally));
324 canvas.add_scroller (*scroll_group);
326 /* new container to hold everything */
328 return new ArdourCanvas::Container (scroll_group);
332 ThemeManager::palette_canvas_allocated (Gtk::Allocation& alloc, ArdourCanvas::Container* group, ArdourCanvas::Canvas* canvas, sigc::slot<bool,GdkEvent*,std::string> event_handler)
334 build_palette_canvas (*canvas, *group, event_handler);
339 ArdourCanvas::HSV color;
340 NamedColor (string s, ArdourCanvas::HSV c) : name (s), color (c) {}
344 bool operator() (NamedColor const & a, NamedColor const & b) {
345 using namespace ArdourCanvas;
346 const HSV black (0, 0, 0);
347 if (a.color.is_gray() || b.color.is_gray()) {
348 return black.distance (a.color) < black.distance (b.color);
350 return a.color.h < b.color.h;
351 // const HSV red (rgba_to_color (1.0, 0.0, 0.0, 1.0));
352 // return red.distance (a.color) < red.distance (b.color);
359 ThemeManager::build_palette_canvas (ArdourCanvas::Canvas& canvas, ArdourCanvas::Container& group, sigc::slot<bool,GdkEvent*,std::string> event_handler)
361 using namespace ArdourCanvas;
363 /* we want the colors sorted by hue, with their name */
365 UIConfiguration::Colors& colors (ARDOUR_UI::instance()->config()->colors);
366 vector<NamedColor> nc;
367 for (UIConfiguration::Colors::const_iterator x = colors.begin(); x != colors.end(); ++x) {
368 nc.push_back (NamedColor (x->first, HSV (x->second)));
371 sort (nc.begin(), nc.end(), sorter);
373 const uint32_t color_limit = nc.size();
374 const double box_size = 20.0;
375 const double width = canvas.width();
376 const double height = canvas.height();
378 uint32_t color_num = 0;
380 /* clear existing rects and delete them */
384 for (uint32_t y = 0; y < height - box_size && color_num < color_limit; y += box_size) {
385 for (uint32_t x = 0; x < width - box_size && color_num < color_limit; x += box_size) {
386 ArdourCanvas::Rectangle* r = new ArdourCanvas::Rectangle (&group, ArdourCanvas::Rect (x, y, x + box_size, y + box_size));
388 string name = nc[color_num++].name;
390 UIConfiguration::Colors::iterator c = colors.find (name);
392 if (c != colors.end()) {
393 Color color = c->second;
394 r->set_fill_color (color);
395 r->set_outline_color (rgba_to_color (0.0, 0.0, 0.0, 1.0));
396 r->set_tooltip (name);
397 r->Event.connect (sigc::bind (event_handler, name));
404 ThemeManager::palette_size_request (Gtk::Requisition* req)
406 uint32_t ncolors = ARDOUR_UI::instance()->config()->colors.size();
407 const int box_size = 20;
409 double c = sqrt ((double)ncolors);
410 req->width = (int) floor (c * box_size);
411 req->height = (int) floor (c * box_size);
413 /* add overflow row if necessary */
415 if (fmod (ncolors, c) != 0.0) {
416 req->height += box_size;
421 ThemeManager::setup_palette ()
423 build_palette_canvas (*palette_viewport.canvas(), *palette_group, sigc::mem_fun (*this, &ThemeManager::palette_event));
427 ThemeManager::palette_event (GdkEvent* ev, string name)
430 case GDK_BUTTON_RELEASE:
431 edit_palette_color (name);
440 ThemeManager::edit_palette_color (std::string name)
442 using namespace ArdourCanvas;
444 UIConfiguration* uic (ARDOUR_UI::instance()->config());
445 ArdourCanvas::Color c = uic->color (name);
448 color_to_rgba (c, r, g, b, a);
450 gdkcolor.set_rgb_p (r, g, b);
451 color_dialog.get_colorsel()->set_previous_color (gdkcolor);
452 color_dialog.get_colorsel()->set_current_color (gdkcolor);
453 color_dialog.get_colorsel()->set_previous_alpha ((guint16) (a * 65535));
454 color_dialog.get_colorsel()->set_current_alpha ((guint16) (a * 65535));
456 color_dialog_connection.disconnect ();
457 color_dialog_connection = color_dialog.signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::palette_color_response), name));
458 color_dialog.present();
462 ThemeManager::palette_color_response (int result, std::string name)
464 using namespace ArdourCanvas;
466 color_dialog_connection.disconnect ();
468 UIConfiguration* uic (ARDOUR_UI::instance()->config());
473 case RESPONSE_ACCEPT:
475 gdkcolor = color_dialog.get_colorsel()->get_current_color();
476 a = color_dialog.get_colorsel()->get_current_alpha() / 65535.0;
477 r = gdkcolor.get_red_p();
478 g = gdkcolor.get_green_p();
479 b = gdkcolor.get_blue_p();
481 uic->set_color (name, rgba_to_color (r, g, b, a));
488 color_dialog.hide ();
492 ThemeManager::alias_palette_event (GdkEvent* ev, string new_alias, string target_name)
495 case GDK_BUTTON_RELEASE:
496 ARDOUR_UI::instance()->config()->set_alias (target_name, new_alias);
506 ThemeManager::alias_palette_response (int response, std::string target_name, std::string old_alias)
509 case GTK_RESPONSE_OK:
510 case GTK_RESPONSE_ACCEPT:
511 /* rebuild alias list with new color: inefficient but simple */
515 case GTK_RESPONSE_REJECT:
517 ARDOUR_UI::instance()->config()->set_alias (target_name, old_alias);
525 palette_window->hide ();
529 ThemeManager::choose_color_from_palette (string const & name)
531 UIConfiguration* uic (ARDOUR_UI::config());
532 UIConfiguration::ColorAliases::iterator i = uic->color_aliases.find (name);
534 if (i == uic->color_aliases.end()) {
538 delete palette_window;
540 palette_window = new ArdourDialog (_("Color Palette"));
541 palette_window->add_button (Stock::CANCEL, RESPONSE_REJECT); /* using CANCEL causes confusion if dialog is closed via CloseAllDialogs */
542 palette_window->add_button (Stock::OK, RESPONSE_OK);
544 ArdourCanvas::GtkCanvas* canvas = new ArdourCanvas::GtkCanvas ();
545 ArdourCanvas::Container* group = initialize_palette_canvas (*canvas);
547 canvas->signal_size_request().connect (sigc::mem_fun (*this, &ThemeManager::palette_size_request));
548 canvas->signal_size_allocate().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::palette_canvas_allocated), group, canvas,
549 sigc::bind (sigc::mem_fun (*this, &ThemeManager::alias_palette_event), name)));
551 palette_window->get_vbox()->pack_start (*canvas);
552 palette_window->show_all ();
554 palette_response_connection = palette_window->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::alias_palette_response), name, i->second));
556 palette_window->set_position (WIN_POS_MOUSE);
557 palette_window->present ();
561 ThemeManager::setup_aliases ()
563 using namespace ArdourCanvas;
565 UIConfiguration* uic (ARDOUR_UI::instance()->config());
566 UIConfiguration::ColorAliases& aliases (uic->color_aliases);
568 alias_list->clear ();
570 for (UIConfiguration::ColorAliases::iterator i = aliases.begin(); i != aliases.end(); ++i) {
571 TreeModel::Children rows = alias_list->children();
573 string::size_type colon;
575 if ((colon = i->first.find (':')) != string::npos) {
577 /* this is supposed to be a child node, so find the
581 string parent = i->first.substr (0, colon);
582 TreeModel::iterator ri;
584 for (ri = rows.begin(); ri != rows.end(); ++ri) {
585 string s = (*ri)[alias_columns.name];
591 if (ri == rows.end()) {
592 /* not found, add the parent as new top level row */
593 row = *(alias_list->append());
594 row[alias_columns.name] = parent;
595 row[alias_columns.alias] = "";
597 /* now add the child as a child of this one */
599 row = *(alias_list->insert (row->children().end()));
600 row[alias_columns.name] = i->first.substr (colon+1);
602 row = *(alias_list->insert ((*ri)->children().end()));
603 row[alias_columns.name] = i->first.substr (colon+1);
608 row = *(alias_list->append());
609 row[alias_columns.name] = i->first;
612 row[alias_columns.alias] = i->second;
616 Color c (uic->color (i->second));
617 color_to_rgba (c, r, g, b, a);
618 col.set_rgb_p (r, g, b);
620 row[alias_columns.color] = col;
625 ThemeManager::alias_button_press_event (GdkEventButton* ev)
628 TreeModel::Path path;
629 TreeViewColumn* column;
633 if (!alias_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
637 guint32 colnum = GPOINTER_TO_UINT (column->get_data (X_("colnum")));
641 /* allow normal processing to occur */
645 if ((iter = alias_list->get_iter (path))) {
646 string target_color_name = (*iter)[alias_columns.name];
647 choose_color_from_palette (target_color_name);