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"
33 #include "pbd/file_utils.h"
34 #include "pbd/compose.h"
36 #include "ardour/filesystem_paths.h"
38 #include "canvas/wave_view.h"
40 #include "ardour_button.h"
41 #include "theme_manager.h"
42 #include "rgb_macros.h"
43 #include "ardour_ui.h"
44 #include "global_signals.h"
51 using namespace ARDOUR;
53 sigc::signal<void> ColorsChanged;
54 sigc::signal<void,uint32_t> ColorChanged;
56 ThemeManager::ThemeManager()
57 : ArdourWindow (_("Theme Manager"))
58 , dark_button (_("Dark Theme"))
59 , light_button (_("Light Theme"))
60 , reset_button (_("Restore Defaults"))
61 , flat_buttons (_("Draw \"flat\" buttons"))
62 , region_color_button (_("Color regions using their track's color"))
63 , show_clipping_button (_("Show waveform clipping"))
64 , waveform_gradient_depth (0, 1.0, 0.05)
65 , waveform_gradient_depth_label (_("Waveforms color gradient depth"))
66 , timeline_item_gradient_depth (0, 1.0, 0.05)
67 , timeline_item_gradient_depth_label (_("Timeline item gradient depth"))
68 , all_dialogs (_("All floating windows are dialogs"))
70 set_title (_("Theme Manager"));
72 color_list = TreeStore::create (columns);
73 color_display.set_model (color_list);
74 color_display.append_column (_("Object"), columns.name);
76 Gtkmm2ext::CellRendererColorSelector* color_renderer = manage (new Gtkmm2ext::CellRendererColorSelector);
77 TreeViewColumn* color_column = manage (new TreeViewColumn (_("Color"), *color_renderer));
78 color_column->add_attribute (color_renderer->property_color(), columns.gdkcolor);
80 color_display.append_column (*color_column);
82 color_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
83 color_display.get_column (0)->set_expand (true);
84 color_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
85 color_display.get_column (1)->set_expand (false);
86 color_display.set_reorderable (false);
87 color_display.get_selection()->set_mode (SELECTION_NONE);
88 color_display.set_headers_visible (true);
90 scroller.add (color_display);
91 scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
93 RadioButton::Group group = dark_button.get_group();
94 light_button.set_group(group);
95 theme_selection_hbox.set_homogeneous(false);
96 theme_selection_hbox.pack_start (dark_button);
97 theme_selection_hbox.pack_start (light_button);
99 Gtk::VBox* vbox = Gtk::manage (new Gtk::VBox ());
100 vbox->set_homogeneous (false);
101 vbox->pack_start (theme_selection_hbox, PACK_SHRINK);
102 vbox->pack_start (reset_button, PACK_SHRINK);
104 vbox->pack_start (all_dialogs, PACK_SHRINK);
106 vbox->pack_start (flat_buttons, PACK_SHRINK);
107 vbox->pack_start (region_color_button, PACK_SHRINK);
108 vbox->pack_start (show_clipping_button, PACK_SHRINK);
110 Gtk::HBox* hbox = Gtk::manage (new Gtk::HBox());
111 hbox->set_spacing (6);
112 hbox->pack_start (waveform_gradient_depth, true, true);
113 hbox->pack_start (waveform_gradient_depth_label, false, false);
114 vbox->pack_start (*hbox, PACK_SHRINK);
116 hbox = Gtk::manage (new Gtk::HBox());
117 hbox->set_spacing (6);
118 hbox->pack_start (timeline_item_gradient_depth, true, true);
119 hbox->pack_start (timeline_item_gradient_depth_label, false, false);
121 vbox->pack_start (*hbox, PACK_SHRINK);
122 vbox->pack_start (scroller);
128 waveform_gradient_depth.set_update_policy (Gtk::UPDATE_DELAYED);
129 timeline_item_gradient_depth.set_update_policy (Gtk::UPDATE_DELAYED);
131 color_display.signal_button_press_event().connect (sigc::mem_fun (*this, &ThemeManager::button_press_event), false);
133 color_dialog.get_colorsel()->set_has_opacity_control (true);
134 color_dialog.get_colorsel()->set_has_palette (true);
136 flat_buttons.set_active (ARDOUR_UI::config()->get_flat_buttons());
137 region_color_button.set_active (ARDOUR_UI::config()->get_color_regions_using_track_color());
138 show_clipping_button.set_active (ARDOUR_UI::config()->get_show_waveform_clipping());
140 color_dialog.get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_ACCEPT));
141 color_dialog.get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_CANCEL));
142 dark_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_dark_theme_button_toggled));
143 light_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_light_theme_button_toggled));
144 reset_button.signal_clicked().connect (sigc::mem_fun (*this, &ThemeManager::reset_canvas_colors));
145 flat_buttons.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_flat_buttons_toggled));
146 region_color_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_region_color_toggled));
147 show_clipping_button.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_show_clip_toggled));
148 waveform_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_waveform_gradient_depth_change));
149 timeline_item_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_timeline_item_gradient_depth_change));
150 all_dialogs.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_all_dialogs_toggled));
152 Gtkmm2ext::UI::instance()->set_tip (all_dialogs,
153 string_compose (_("Mark all floating windows to be type \"Dialog\" rather than using \"Utility\" for some.\n"
154 "This may help with some window managers. This requires a restart of %1 to take effect"),
157 set_size_request (-1, 400);
161 ThemeManager::~ThemeManager()
166 ThemeManager::save (string /*path*/)
172 ThemeManager::button_press_event (GdkEventButton* ev)
175 TreeModel::Path path;
176 TreeViewColumn* column;
180 UIConfigVariable<uint32_t> *ccvar;
182 if (!color_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
186 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
188 /* allow normal processing to occur */
192 if ((iter = color_list->get_iter (path))) {
194 UIConfigVariable<uint32_t>* var = (*iter)[columns.pVar];
196 /* parent row, do nothing */
201 uint32_t rgba = (*iter)[columns.rgba];
204 UINT_TO_RGBA (rgba, &r, &g, &b, &a);
205 color.set_rgb_p (r / 255.0, g / 255.0, b / 255.0);
206 color_dialog.get_colorsel()->set_previous_color (color);
207 color_dialog.get_colorsel()->set_current_color (color);
208 color_dialog.get_colorsel()->set_previous_alpha (a * 256);
209 color_dialog.get_colorsel()->set_current_alpha (a * 256);
211 ResponseType result = (ResponseType) color_dialog.run();
214 case RESPONSE_CANCEL:
216 case RESPONSE_ACCEPT:
217 color = color_dialog.get_colorsel()->get_current_color();
218 a = color_dialog.get_colorsel()->get_current_alpha();
219 r = (int) floor (color.get_red_p() * 255.0);
220 g = (int) floor (color.get_green_p() * 255.0);
221 b = (int) floor (color.get_blue_p() * 255.0);
223 rgba = RGBA_TO_UINT(r,g,b,a>>8);
224 (*iter)[columns.rgba] = rgba;
225 (*iter)[columns.gdkcolor] = color;
227 ccvar = (*iter)[columns.pVar];
230 ARDOUR_UI::config()->set_dirty ();
231 /* but save it immediately */
232 ARDOUR_UI::config()->save_state ();
234 ColorsChanged(); //EMIT SIGNAL
242 color_dialog.hide ();
254 load_rc_file (const string& filename, bool themechange)
256 std::string rc_file_path;
258 if (!find_file_in_search_path (ardour_config_search_path(), filename, rc_file_path)) {
259 warning << string_compose (_("Unable to find UI style file %1 in search path %2. %3 will look strange"),
260 filename, ardour_config_search_path().to_string(), PROGRAM_NAME)
265 info << "Loading ui configuration file " << rc_file_path << endmsg;
267 Gtkmm2ext::UI::instance()->load_rcfile (rc_file_path, themechange);
270 /* hmm, this is a problem. the profile doesn't
271 exist when the theme manager is constructed
272 and toggles buttons during "normal" GTK setup.
274 a better solution will be to make all Profile
275 methods static or something.
280 #define HACK_PROFILE_IS_SAE() (getenv("ARDOUR_SAE")!=0)
283 ThemeManager::on_flat_buttons_toggled ()
285 ARDOUR_UI::config()->set_flat_buttons (flat_buttons.get_active());
286 ARDOUR_UI::config()->set_dirty ();
287 ArdourButton::set_flat_buttons (flat_buttons.get_active());
289 gtk_rc_reset_styles (gtk_settings_get_default());
293 ThemeManager::on_region_color_toggled ()
295 ARDOUR_UI::config()->set_color_regions_using_track_color (region_color_button.get_active());
296 ARDOUR_UI::config()->set_dirty ();
300 ThemeManager::on_show_clip_toggled ()
302 ARDOUR_UI::config()->set_show_waveform_clipping (show_clipping_button.get_active());
303 ARDOUR_UI::config()->set_dirty ();
307 ThemeManager::on_all_dialogs_toggled ()
309 ARDOUR_UI::config()->set_all_floating_windows_are_dialogs (all_dialogs.get_active());
310 ARDOUR_UI::config()->set_dirty ();
314 ThemeManager::on_waveform_gradient_depth_change ()
316 double v = waveform_gradient_depth.get_value();
318 ARDOUR_UI::config()->set_waveform_gradient_depth (v);
319 ARDOUR_UI::config()->set_dirty ();
320 ArdourCanvas::WaveView::set_global_gradient_depth (v);
324 ThemeManager::on_timeline_item_gradient_depth_change ()
326 double v = timeline_item_gradient_depth.get_value();
328 ARDOUR_UI::config()->set_timeline_item_gradient_depth (v);
329 ARDOUR_UI::config()->set_dirty ();
333 ThemeManager::on_dark_theme_button_toggled()
335 if (!dark_button.get_active()) return;
337 if (HACK_PROFILE_IS_SAE()){
338 ARDOUR_UI::config()->set_ui_rc_file("ardour3_ui_dark_sae.rc");
340 ARDOUR_UI::config()->set_ui_rc_file("ardour3_ui_dark.rc");
342 ARDOUR_UI::config()->set_dirty ();
344 load_rc_file (ARDOUR_UI::config()->get_ui_rc_file(), true);
348 ThemeManager::on_light_theme_button_toggled()
350 if (!light_button.get_active()) return;
352 if (HACK_PROFILE_IS_SAE()){
353 ARDOUR_UI::config()->set_ui_rc_file("ardour3_ui_light_sae.rc");
355 ARDOUR_UI::config()->set_ui_rc_file("ardour3_ui_light.rc");
358 load_rc_file (ARDOUR_UI::config()->get_ui_rc_file(), true);
362 ThemeManager::setup_theme ()
368 for (std::map<std::string,UIConfigVariable<uint32_t> *>::iterator i = ARDOUR_UI::config()->canvas_colors.begin(); i != ARDOUR_UI::config()->canvas_colors.end(); i++) {
371 UIConfigVariable<uint32_t>* var = i->second;
373 TreeModel::Children rows = color_list->children();
375 string::size_type colon;
377 if ((colon = var->name().find (':')) != string::npos) {
379 /* this is supposed to be a child node, so find the
383 string parent = var->name().substr (0, colon);
384 TreeModel::iterator ri;
386 for (ri = rows.begin(); ri != rows.end(); ++ri) {
387 string s = (*ri)[columns.name];
393 if (ri == rows.end()) {
394 /* not found, add the parent as new top level row */
395 row = *(color_list->append());
396 row[columns.name] = parent;
397 row[columns.pVar] = 0;
399 /* now add the child as a child of this one */
401 row = *(color_list->insert (row->children().end()));
402 row[columns.name] = var->name().substr (colon+1);
404 row = *(color_list->insert ((*ri)->children().end()));
405 row[columns.name] = var->name().substr (colon+1);
410 row = *(color_list->append());
411 row[columns.name] = var->name();
415 uint32_t rgba = var->get();
416 UINT_TO_RGBA (rgba, &r, &g, &b, &a);
417 //cerr << (*i)->name() << " == " << hex << rgba << ": " << hex << r << " " << hex << g << " " << hex << b << endl;
418 col.set_rgb_p (r / 255.0, g / 255.0, b / 255.0);
420 row[columns.pVar] = var;
421 row[columns.rgba] = rgba;
422 row[columns.gdkcolor] = col;
425 ColorsChanged.emit();
427 bool env_defined = false;
428 string rcfile = Glib::getenv("ARDOUR3_UI_RC", env_defined);
431 rcfile = ARDOUR_UI::config()->get_ui_rc_file();
434 if (rcfile == "ardour3_ui_dark.rc" || rcfile == "ardour3_ui_dark_sae.rc") {
435 dark_button.set_active();
436 } else if (rcfile == "ardour3_ui_light.rc" || rcfile == "ardour3_ui_light_sae.rc") {
437 light_button.set_active();
440 flat_buttons.set_active (ARDOUR_UI::config()->get_flat_buttons());
441 waveform_gradient_depth.set_value (ARDOUR_UI::config()->get_waveform_gradient_depth());
442 timeline_item_gradient_depth.set_value (ARDOUR_UI::config()->get_timeline_item_gradient_depth());
443 all_dialogs.set_active (ARDOUR_UI::config()->get_all_floating_windows_are_dialogs());
445 load_rc_file(rcfile, false);
449 ThemeManager::reset_canvas_colors()
451 ARDOUR_UI::config()->load_defaults();
454 ARDOUR_UI::config()->set_dirty ();
455 /* but save it immediately */
456 ARDOUR_UI::config()->save_state ();