X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Ftheme_manager.cc;h=884a970e284aaef3b078fbf9f745d9aebf7e061d;hb=bdfddec6fc45b9570d1f3fc03182f4166187c52c;hp=4ed26171a14237eed412e1d0147c3204ce3a8437;hpb=12a4ddc9522a2c154be7c84de5b12c475bee0eda;p=ardour.git diff --git a/gtk2_ardour/theme_manager.cc b/gtk2_ardour/theme_manager.cc index 4ed26171a1..884a970e28 100644 --- a/gtk2_ardour/theme_manager.cc +++ b/gtk2_ardour/theme_manager.cc @@ -18,12 +18,12 @@ */ #include -#include -#include #include #include "fix_carbon.h" +#include "pbd/gstdio_compat.h" + #include #include @@ -42,10 +42,10 @@ #include "canvas/wave_view.h" #include "ardour_button.h" +#include "ardour_dialog.h" #include "theme_manager.h" #include "rgb_macros.h" -#include "ardour_ui.h" -#include "global_signals.h" +#include "ui_config.h" #include "utils.h" #include "i18n.h" @@ -56,14 +56,8 @@ using namespace PBD; using namespace ARDOUR; using namespace ARDOUR_UI_UTILS; -namespace ARDOUR_UI_UTILS { - sigc::signal ColorsChanged; - sigc::signal ColorChanged; -} - ThemeManager::ThemeManager() - : ArdourWindow (_("Theme Manager")) - , dark_button (_("Dark Theme")) + : dark_button (_("Dark Theme")) , light_button (_("Light Theme")) , reset_button (_("Restore Defaults")) , flat_buttons (_("Draw \"flat\" buttons")) @@ -75,56 +69,28 @@ ThemeManager::ThemeManager() , timeline_item_gradient_depth (0, 1.0, 0.05) , timeline_item_gradient_depth_label (_("Timeline item gradient depth")) , all_dialogs (_("All floating windows are dialogs")) + , transients_follow_front (_("Transient windows follow front window.")) , icon_set_label (_("Icon Set")) - , base_color_viewport (*base_color_scroller.get_hadjustment(), *base_color_scroller.get_vadjustment()) - , base_color_group (0) + , palette_viewport (*palette_scroller.get_hadjustment(), *palette_scroller.get_vadjustment()) + , palette_group (0) , palette_window (0) { - set_title (_("Theme Manager")); - - /* Basic color list */ - - color_list = TreeStore::create (columns); - color_display.set_model (color_list); - color_display.append_column (_("Object"), columns.name); - - Gtkmm2ext::CellRendererColorSelector* color_renderer = manage (new Gtkmm2ext::CellRendererColorSelector); - TreeViewColumn* color_column = manage (new TreeViewColumn (_("Color"), *color_renderer)); - color_column->add_attribute (color_renderer->property_color(), columns.gdkcolor); - - color_display.append_column (*color_column); - - color_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0)); - color_display.get_column (0)->set_expand (true); - color_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1)); - color_display.get_column (1)->set_expand (false); - color_display.set_reorderable (false); - color_display.get_selection()->set_mode (SELECTION_NONE); - color_display.set_headers_visible (true); - - color_display.signal_button_press_event().connect (sigc::mem_fun (*this, &ThemeManager::button_press_event), false); - - scroller.add (color_display); - scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC); - /* Now the alias list */ - + alias_list = TreeStore::create (alias_columns); alias_display.set_model (alias_list); - alias_display.append_column (_("Object"), columns.name); + alias_display.append_column (_("Object"), alias_columns.name); - color_renderer = manage (new Gtkmm2ext::CellRendererColorSelector); - color_column = manage (new TreeViewColumn (_("Color"), *color_renderer)); + Gtkmm2ext::CellRendererColorSelector* color_renderer = manage (new Gtkmm2ext::CellRendererColorSelector); + TreeViewColumn* color_column = manage (new TreeViewColumn (_("Color"), *color_renderer)); color_column->add_attribute (color_renderer->property_color(), alias_columns.color); - alias_display.append_column (*color_column); - + alias_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0)); alias_display.get_column (0)->set_expand (true); alias_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1)); alias_display.get_column (1)->set_expand (false); alias_display.set_reorderable (false); - alias_display.get_selection()->set_mode (SELECTION_NONE); alias_display.set_headers_visible (true); alias_display.signal_button_press_event().connect (sigc::mem_fun (*this, &ThemeManager::alias_button_press_event), false); @@ -132,24 +98,26 @@ ThemeManager::ThemeManager() alias_scroller.add (alias_display); /* various buttons */ - + RadioButton::Group group = dark_button.get_group(); light_button.set_group(group); theme_selection_hbox.set_homogeneous(false); theme_selection_hbox.pack_start (dark_button); theme_selection_hbox.pack_start (light_button); - Gtk::VBox* vbox = Gtk::manage (new Gtk::VBox ()); - vbox->set_homogeneous (false); - vbox->pack_start (theme_selection_hbox, PACK_SHRINK); - vbox->pack_start (reset_button, PACK_SHRINK); + set_homogeneous (false); +#if 0 // disable light/dark theme choice. until the 'light theme gets some attention. + pack_start (theme_selection_hbox, PACK_SHRINK); +#endif + pack_start (reset_button, PACK_SHRINK); #ifndef __APPLE__ - vbox->pack_start (all_dialogs, PACK_SHRINK); + pack_start (all_dialogs, PACK_SHRINK); + pack_start (transients_follow_front, PACK_SHRINK); #endif - vbox->pack_start (flat_buttons, PACK_SHRINK); - vbox->pack_start (blink_rec_button, PACK_SHRINK); - vbox->pack_start (region_color_button, PACK_SHRINK); - vbox->pack_start (show_clipping_button, PACK_SHRINK); + pack_start (flat_buttons, PACK_SHRINK); + pack_start (blink_rec_button, PACK_SHRINK); + pack_start (region_color_button, PACK_SHRINK); + pack_start (show_clipping_button, PACK_SHRINK); Gtk::HBox* hbox; @@ -157,51 +125,50 @@ ThemeManager::ThemeManager() if (icon_sets.size() > 1) { Gtkmm2ext::set_popdown_strings (icon_set_dropdown, icon_sets); - icon_set_dropdown.set_active_text (ARDOUR_UI::config()->get_icon_set()); + icon_set_dropdown.set_active_text (UIConfiguration::instance().get_icon_set()); hbox = Gtk::manage (new Gtk::HBox()); hbox->set_spacing (6); hbox->pack_start (icon_set_label, false, false); hbox->pack_start (icon_set_dropdown, true, true); - vbox->pack_start (*hbox, PACK_SHRINK); + pack_start (*hbox, PACK_SHRINK); } - + hbox = Gtk::manage (new Gtk::HBox()); hbox->set_spacing (6); hbox->pack_start (waveform_gradient_depth, true, true); hbox->pack_start (waveform_gradient_depth_label, false, false); - vbox->pack_start (*hbox, PACK_SHRINK); + pack_start (*hbox, PACK_SHRINK); hbox = Gtk::manage (new Gtk::HBox()); hbox->set_spacing (6); hbox->pack_start (timeline_item_gradient_depth, true, true); hbox->pack_start (timeline_item_gradient_depth_label, false, false); - vbox->pack_start (*hbox, PACK_SHRINK); + pack_start (*hbox, PACK_SHRINK); + + palette_group = initialize_palette_canvas (*palette_viewport.canvas()); + palette_viewport.signal_size_allocate().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::palette_canvas_allocated), palette_group, palette_viewport.canvas(), + sigc::mem_fun (*this, &ThemeManager::palette_event))); + palette_scroller.add (palette_viewport); + + modifier_scroller.add (modifier_vbox); - base_color_viewport.signal_size_allocate().connect (sigc::mem_fun (*this, &ThemeManager::base_color_viewport_allocated)); - base_color_scroller.add (base_color_viewport); - - notebook.append_page (scroller, _("Palette")); - notebook.append_page (base_color_scroller, _("Base Colors")); notebook.append_page (alias_scroller, _("Items")); - - vbox->pack_start (notebook); + notebook.append_page (palette_scroller, _("Palette")); + notebook.append_page (modifier_scroller, _("Transparency")); - vbox->show_all (); + pack_start (notebook); - add (*vbox); + show_all (); waveform_gradient_depth.set_update_policy (Gtk::UPDATE_DELAYED); timeline_item_gradient_depth.set_update_policy (Gtk::UPDATE_DELAYED); - + color_dialog.get_colorsel()->set_has_opacity_control (true); color_dialog.get_colorsel()->set_has_palette (true); - - flat_buttons.set_active (ARDOUR_UI::config()->get_flat_buttons()); - blink_rec_button.set_active (ARDOUR_UI::config()->get_blink_rec_arm()); - region_color_button.set_active (ARDOUR_UI::config()->get_color_regions_using_track_color()); - show_clipping_button.set_active (ARDOUR_UI::config()->get_show_waveform_clipping()); + + set_ui_to_state(); color_dialog.get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_ACCEPT)); color_dialog.get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_CANCEL)); @@ -215,139 +182,91 @@ ThemeManager::ThemeManager() waveform_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_waveform_gradient_depth_change)); timeline_item_gradient_depth.signal_value_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_timeline_item_gradient_depth_change)); all_dialogs.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_all_dialogs_toggled)); + transients_follow_front.signal_toggled().connect (sigc::mem_fun (*this, &ThemeManager::on_transients_follow_front_toggled)); icon_set_dropdown.signal_changed().connect (sigc::mem_fun (*this, &ThemeManager::on_icon_set_changed)); - Gtkmm2ext::UI::instance()->set_tip (all_dialogs, + Gtkmm2ext::UI::instance()->set_tip (all_dialogs, string_compose (_("Mark all floating windows to be type \"Dialog\" rather than using \"Utility\" for some.\n" "This may help with some window managers. This requires a restart of %1 to take effect"), PROGRAM_NAME)); + Gtkmm2ext::UI::instance()->set_tip (transients_follow_front, + string_compose (_("Make transient windows follow the front window when toggling between the editor and mixer.\n" + "This requires a restart of %1 to take effect"), PROGRAM_NAME)); set_size_request (-1, 400); - setup_theme (); + /* no need to call setup_palette() here, it will be done when its size is allocated */ setup_aliases (); + setup_modifiers (); + + UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &ThemeManager::colors_changed)); } ThemeManager::~ThemeManager() { } -int -ThemeManager::save (string /*path*/) +void +ThemeManager::setup_modifiers () { - return 0; -} + UIConfiguration* uic (&UIConfiguration::instance()); + UIConfiguration::Modifiers& modifiers (uic->modifiers); + Gtk::HBox* mod_hbox; + Gtk::Label* mod_label; + Gtk::HScale* mod_scale; -bool -ThemeManager::button_press_event (GdkEventButton* ev) -{ - TreeIter iter; - TreeModel::Path path; - TreeViewColumn* column; - int cellx; - int celly; + Gtkmm2ext::container_clear (modifier_vbox); - if (!color_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) { - return false; - } + for (UIConfiguration::Modifiers::const_iterator m = modifiers.begin(); m != modifiers.end(); ++m) { + mod_hbox = manage (new HBox); - switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) { - case 0: - /* allow normal processing to occur */ - return false; + mod_scale = manage (new HScale (0.0, 1.0, 0.01)); + mod_scale->set_draw_value (false); + mod_scale->set_value (m->second.a()); + mod_scale->set_update_policy (Gtk::UPDATE_DISCONTINUOUS); + mod_scale->signal_value_changed().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::modifier_edited), mod_scale, m->first)); - case 1: /* color */ - if ((iter = color_list->get_iter (path))) { + mod_label = manage (new Label (m->first)); + mod_label->set_alignment (1.0, 0.5); + mod_label->set_size_request (150, -1); /* 150 pixels should be enough for anyone */ - ColorVariable* var = (*iter)[columns.pVar]; - if (!var) { - /* parent row, do nothing */ - return false; - } - - int r,g, b, a; - uint32_t rgba = (*iter)[columns.rgba]; - Gdk::Color color; - - UINT_TO_RGBA (rgba, &r, &g, &b, &a); - color.set_rgb_p (r / 255.0, g / 255.0, b / 255.0); - color_dialog.get_colorsel()->set_previous_color (color); - color_dialog.get_colorsel()->set_current_color (color); - color_dialog.get_colorsel()->set_previous_alpha ((guint16) (a * 256)); - color_dialog.get_colorsel()->set_current_alpha ((guint16) (a * 256)); - - color_dialog_connection.disconnect (); - color_dialog_connection = color_dialog.signal_response().connect (sigc::mem_fun (*this, &ThemeManager::foobar_response)); - color_dialog.present (); - } + mod_hbox->pack_start (*mod_label, false, true, 12); + mod_hbox->pack_start (*mod_scale, true, true); + + modifier_vbox.pack_start (*mod_hbox, false, false); } - return true; + modifier_vbox.show_all (); + } void -ThemeManager::foobar_response (int result) +ThemeManager::modifier_edited (Gtk::Range* range, string name) { - // ColorVariable *ccvar; - int r,g, b, a; - uint32_t rgba; - Gdk::Color color; + using namespace ArdourCanvas; - color_dialog_connection.disconnect (); - - switch (result) { - case RESPONSE_CANCEL: - break; - case RESPONSE_ACCEPT: - color = color_dialog.get_colorsel()->get_current_color(); - a = color_dialog.get_colorsel()->get_current_alpha(); - r = (int) floor (color.get_red_p() * 255.0); - g = (int) floor (color.get_green_p() * 255.0); - b = (int) floor (color.get_blue_p() * 255.0); - - rgba = RGBA_TO_UINT(r,g,b,a>>8); - // (*iter)[columns.rgba] = rgba; - // (*iter)[columns.gdkcolor] = color; - - // ccvar = (*iter)[columns.pVar]; - // ccvar->set(rgba); - /* mark dirty ... */ - ARDOUR_UI::config()->set_dirty (); - /* but save it immediately */ - ARDOUR_UI::config()->save_state (); - - ColorsChanged(); //EMIT SIGNAL - break; - - default: - break; - - } - - color_dialog.hide (); + double alpha = range->get_value(); + SVAModifier svam (SVAModifier::Assign, -1.0, -1.0, alpha); + UIConfiguration::instance().set_modifier (name, svam); } void -load_rc_file (const string& filename, bool themechange) +ThemeManager::colors_changed () { - std::string rc_file_path; - - if (!find_file (ardour_config_search_path(), filename, rc_file_path)) { - warning << string_compose (_("Unable to find UI style file %1 in search path %2. %3 will look strange"), - filename, ardour_config_search_path().to_string(), PROGRAM_NAME) - << endmsg; - return; - } - - info << "Loading ui configuration file " << rc_file_path << endmsg; + setup_palette (); + setup_aliases (); + setup_modifiers (); +} - Gtkmm2ext::UI::instance()->load_rcfile (rc_file_path, themechange); +int +ThemeManager::save (string /*path*/) +{ + return 0; } void ThemeManager::on_flat_buttons_toggled () { - ARDOUR_UI::config()->set_flat_buttons (flat_buttons.get_active()); - ARDOUR_UI::config()->set_dirty (); + UIConfiguration::instance().set_flat_buttons (flat_buttons.get_active()); ArdourButton::set_flat_buttons (flat_buttons.get_active()); /* force a redraw */ gtk_rc_reset_styles (gtk_settings_get_default()); @@ -356,30 +275,34 @@ ThemeManager::on_flat_buttons_toggled () void ThemeManager::on_blink_rec_arm_toggled () { - ARDOUR_UI::config()->set_blink_rec_arm (blink_rec_button.get_active()); - ARDOUR_UI::config()->set_dirty (); - ARDOUR::Config->ParameterChanged("blink-rec-arm"); + UIConfiguration::instance().set_blink_rec_arm (blink_rec_button.get_active()); + UIConfiguration::instance().ParameterChanged("blink-rec-arm"); } void ThemeManager::on_region_color_toggled () { - ARDOUR_UI::config()->set_color_regions_using_track_color (region_color_button.get_active()); - ARDOUR_UI::config()->set_dirty (); + UIConfiguration::instance().set_color_regions_using_track_color (region_color_button.get_active()); } void ThemeManager::on_show_clip_toggled () { - ARDOUR_UI::config()->set_show_waveform_clipping (show_clipping_button.get_active()); - ARDOUR_UI::config()->set_dirty (); + UIConfiguration::instance().set_show_waveform_clipping (show_clipping_button.get_active()); + // "show-waveform-clipping" was a session config key + ArdourCanvas::WaveView::set_global_show_waveform_clipping (UIConfiguration::instance().get_show_waveform_clipping()); } void ThemeManager::on_all_dialogs_toggled () { - ARDOUR_UI::config()->set_all_floating_windows_are_dialogs (all_dialogs.get_active()); - ARDOUR_UI::config()->set_dirty (); + UIConfiguration::instance().set_all_floating_windows_are_dialogs (all_dialogs.get_active()); +} + +void +ThemeManager::on_transients_follow_front_toggled () +{ + UIConfiguration::instance().set_transients_follow_front (transients_follow_front.get_active()); } void @@ -387,8 +310,7 @@ ThemeManager::on_waveform_gradient_depth_change () { double v = waveform_gradient_depth.get_value(); - ARDOUR_UI::config()->set_waveform_gradient_depth (v); - ARDOUR_UI::config()->set_dirty (); + UIConfiguration::instance().set_waveform_gradient_depth (v); ArdourCanvas::WaveView::set_global_gradient_depth (v); } @@ -397,15 +319,14 @@ ThemeManager::on_timeline_item_gradient_depth_change () { double v = timeline_item_gradient_depth.get_value(); - ARDOUR_UI::config()->set_timeline_item_gradient_depth (v); - ARDOUR_UI::config()->set_dirty (); + UIConfiguration::instance().set_timeline_item_gradient_depth (v); } void ThemeManager::on_icon_set_changed () { string new_set = icon_set_dropdown.get_active_text(); - ARDOUR_UI::config()->set_icon_set (new_set); + UIConfiguration::instance().set_icon_set (new_set); } void @@ -413,10 +334,9 @@ ThemeManager::on_dark_theme_button_toggled() { if (!dark_button.get_active()) return; - ARDOUR_UI::config()->set_ui_rc_file("ui_dark.rc"); - ARDOUR_UI::config()->set_dirty (); + UIConfiguration* uic (&UIConfiguration::instance()); - load_rc_file (ARDOUR_UI::config()->get_ui_rc_file(), true); + uic->set_color_file("dark"); } void @@ -424,107 +344,81 @@ ThemeManager::on_light_theme_button_toggled() { if (!light_button.get_active()) return; - ARDOUR_UI::config()->set_ui_rc_file("ui_light.rc"); - load_rc_file (ARDOUR_UI::config()->get_ui_rc_file(), true); + UIConfiguration* uic (&UIConfiguration::instance()); + + uic->set_color_file("light"); } void -ThemeManager::setup_theme () +ThemeManager::set_ui_to_state() { - int r, g, b, a; - - color_list->clear(); - - for (std::map *>::iterator i = ARDOUR_UI::config()->configurable_colors.begin(); i != ARDOUR_UI::config()->configurable_colors.end(); i++) { - - - ColorVariable* var = i->second; - - TreeModel::Children rows = color_list->children(); - TreeModel::Row row; - string::size_type colon; - - if ((colon = var->name().find (':')) != string::npos) { + /* there is no way these values can change individually + * by themselves (w/o user-interaction) + * hence a common combined update function suffices + */ + + if (UIConfiguration::instance().get_color_file() == "light") { + light_button.set_active(true); + } else { + dark_button.set_active(true); + } - /* this is supposed to be a child node, so find the - * parent - */ + /* there is no need to block signal handlers, here, + * all elements check if the value has changed and ignore NOOPs + */ + all_dialogs.set_active (UIConfiguration::instance().get_all_floating_windows_are_dialogs()); + transients_follow_front.set_active (UIConfiguration::instance().get_transients_follow_front()); + flat_buttons.set_active (UIConfiguration::instance().get_flat_buttons()); + blink_rec_button.set_active (UIConfiguration::instance().get_blink_rec_arm()); + region_color_button.set_active (UIConfiguration::instance().get_color_regions_using_track_color()); + show_clipping_button.set_active (UIConfiguration::instance().get_show_waveform_clipping()); + waveform_gradient_depth.set_value(UIConfiguration::instance().get_waveform_gradient_depth()); + timeline_item_gradient_depth.set_value(UIConfiguration::instance().get_timeline_item_gradient_depth()); +} - string parent = var->name().substr (0, colon); - TreeModel::iterator ri; +void +ThemeManager::reset_canvas_colors() +{ + string cfile; + string basename; - for (ri = rows.begin(); ri != rows.end(); ++ri) { - string s = (*ri)[columns.name]; - if (s == parent) { - break; - } - } + basename = "my-"; + basename += UIConfiguration::instance().get_color_file(); + basename += ".colors"; - if (ri == rows.end()) { - /* not found, add the parent as new top level row */ - row = *(color_list->append()); - row[columns.name] = parent; - row[columns.pVar] = 0; - - /* now add the child as a child of this one */ + if (find_file (ardour_config_search_path(), basename, cfile)) { + string backup = cfile + string (X_(".old")); + g_rename (cfile.c_str(), backup.c_str()); + /* don't really care if it fails */ + } - row = *(color_list->insert (row->children().end())); - row[columns.name] = var->name().substr (colon+1); - } else { - row = *(color_list->insert ((*ri)->children().end())); - row[columns.name] = var->name().substr (colon+1); - } + UIConfiguration::instance().load_defaults(); + UIConfiguration::instance().save_state (); + set_ui_to_state(); +} - } else { - /* add as a child */ - row = *(color_list->append()); - row[columns.name] = var->name(); - } +ArdourCanvas::Container* +ThemeManager::initialize_palette_canvas (ArdourCanvas::Canvas& canvas) +{ + using namespace ArdourCanvas; - Gdk::Color col; - uint32_t rgba = var->get(); - UINT_TO_RGBA (rgba, &r, &g, &b, &a); - //cerr << (*i)->name() << " == " << hex << rgba << ": " << hex << r << " " << hex << g << " " << hex << b << endl; - col.set_rgb_p (r / 255.0, g / 255.0, b / 255.0); - - row[columns.pVar] = var; - row[columns.rgba] = rgba; - row[columns.gdkcolor] = col; - } + /* hide background */ + canvas.set_background_color (rgba_to_color (0.0, 0.0, 1.0, 0.0)); - ColorsChanged.emit(); + /* bi-directional scroll group */ - bool env_defined = false; - string rcfile = Glib::getenv("ARDOUR3_UI_RC", env_defined); + ScrollGroup* scroll_group = new ScrollGroup (canvas.root(), ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally)); + canvas.add_scroller (*scroll_group); - if(!env_defined) { - rcfile = ARDOUR_UI::config()->get_ui_rc_file(); - } + /* new container to hold everything */ - if (rcfile == "ui_dark.rc") { - dark_button.set_active(); - } else if (rcfile == "ui_light.rc") { - light_button.set_active(); - } - - flat_buttons.set_active (ARDOUR_UI::config()->get_flat_buttons()); - blink_rec_button.set_active (ARDOUR_UI::config()->get_blink_rec_arm()); - waveform_gradient_depth.set_value (ARDOUR_UI::config()->get_waveform_gradient_depth()); - timeline_item_gradient_depth.set_value (ARDOUR_UI::config()->get_timeline_item_gradient_depth()); - all_dialogs.set_active (ARDOUR_UI::config()->get_all_floating_windows_are_dialogs()); - - load_rc_file(rcfile, false); + return new ArdourCanvas::Container (scroll_group); } void -ThemeManager::reset_canvas_colors() +ThemeManager::palette_canvas_allocated (Gtk::Allocation& alloc, ArdourCanvas::Container* group, ArdourCanvas::Canvas* canvas, sigc::slot event_handler) { - ARDOUR_UI::config()->load_defaults(); - setup_theme (); - /* mark dirty ... */ - ARDOUR_UI::config()->set_dirty (); - /* but save it immediately */ - ARDOUR_UI::config()->save_state (); + build_palette_canvas (*canvas, *group, event_handler); } struct NamedColor { @@ -547,95 +441,94 @@ struct SortByHue { } }; -ArdourCanvas::Container* -ThemeManager::initialize_canvas (ArdourCanvas::Canvas& canvas) -{ - using namespace ArdourCanvas; - - /* hide background */ - canvas.set_background_color (rgba_to_color (0.0, 0.0, 1.0, 0.0)); - - ScrollGroup* base_color_scroll_group = new ScrollGroup (canvas.root(), ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally)); - canvas.add_scroller (*base_color_scroll_group); - return new ArdourCanvas::Container (base_color_scroll_group); -} void -ThemeManager::build_base_color_canvas (ArdourCanvas::Container& group, bool (ThemeManager::*event_handler)(GdkEvent*,std::string), double width, double height) +ThemeManager::build_palette_canvas (ArdourCanvas::Canvas& canvas, ArdourCanvas::Container& group, sigc::slot event_handler) { using namespace ArdourCanvas; /* we want the colors sorted by hue, with their name */ - UIConfiguration::RelativeColors& relatives (ARDOUR_UI::instance()->config()->relative_colors); + UIConfiguration::Colors& colors (UIConfiguration::instance().colors); vector nc; - for (UIConfiguration::RelativeColors::const_iterator x = relatives.begin(); x != relatives.end(); ++x) { - nc.push_back (NamedColor (x->first, x->second.get())); + for (UIConfiguration::Colors::const_iterator x = colors.begin(); x != colors.end(); ++x) { + nc.push_back (NamedColor (x->first, HSV (x->second))); } SortByHue sorter; sort (nc.begin(), nc.end(), sorter); - + const uint32_t color_limit = nc.size(); const double box_size = 20.0; + const double width = canvas.width(); + const double height = canvas.height(); uint32_t color_num = 0; /* clear existing rects and delete them */ - + group.clear (true); - + for (uint32_t y = 0; y < height - box_size && color_num < color_limit; y += box_size) { for (uint32_t x = 0; x < width - box_size && color_num < color_limit; x += box_size) { - ArdourCanvas::Rectangle* r = new Rectangle (&group, ArdourCanvas::Rect (x, y, x + box_size, y + box_size)); + ArdourCanvas::Rectangle* r = new ArdourCanvas::Rectangle (&group, ArdourCanvas::Rect (x, y, x + box_size, y + box_size)); string name = nc[color_num++].name; - UIConfiguration::RelativeColors::iterator c = relatives.find (name); + UIConfiguration::Colors::iterator c = colors.find (name); - if (c != relatives.end()) { - Color color = c->second.get().color (); + if (c != colors.end()) { + Color color = c->second; r->set_fill_color (color); r->set_outline_color (rgba_to_color (0.0, 0.0, 0.0, 1.0)); r->set_tooltip (name); - r->Event.connect (sigc::bind (sigc::mem_fun (*this, event_handler), name)); + r->Event.connect (sigc::bind (event_handler, name)); } } } } - + void -ThemeManager::base_color_viewport_allocated (Gtk::Allocation&) +ThemeManager::palette_size_request (Gtk::Requisition* req) { - if (!base_color_group) { - base_color_group = initialize_canvas (*base_color_viewport.canvas()); + uint32_t ncolors = UIConfiguration::instance().colors.size(); + const int box_size = 20; + + double c = sqrt ((double)ncolors); + req->width = (int) floor (c * box_size); + req->height = (int) floor (c * box_size); + + /* add overflow row if necessary */ + + if (fmod (ncolors, c) != 0.0) { + req->height += box_size; } +} - build_base_color_canvas (*base_color_group, &ThemeManager::base_color_event, - base_color_viewport.canvas()->width(), - base_color_viewport.canvas()->height()); - +void +ThemeManager::setup_palette () +{ + build_palette_canvas (*palette_viewport.canvas(), *palette_group, sigc::mem_fun (*this, &ThemeManager::palette_event)); } bool -ThemeManager::base_color_event (GdkEvent*ev, string name) +ThemeManager::palette_event (GdkEvent* ev, string name) { switch (ev->type) { case GDK_BUTTON_RELEASE: - edit_named_color (name); - break; + edit_palette_color (name); + return true; default: break; } - return true; } void -ThemeManager::edit_named_color (std::string name) +ThemeManager::edit_palette_color (std::string name) { using namespace ArdourCanvas; double r,g, b, a; - UIConfiguration* uic (ARDOUR_UI::instance()->config()); + UIConfiguration* uic (&UIConfiguration::instance()); ArdourCanvas::Color c = uic->color (name); Gdk::Color gdkcolor; @@ -647,113 +540,105 @@ ThemeManager::edit_named_color (std::string name) color_dialog.get_colorsel()->set_previous_alpha ((guint16) (a * 65535)); color_dialog.get_colorsel()->set_current_alpha ((guint16) (a * 65535)); - base_color_edit_name = name; - color_dialog_connection.disconnect (); - color_dialog_connection = color_dialog.signal_response().connect (sigc::mem_fun (*this, &ThemeManager::base_color_dialog_done)); + color_dialog_connection = color_dialog.signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::palette_color_response), name)); color_dialog.present(); } void -ThemeManager::base_color_dialog_done (int result) +ThemeManager::palette_color_response (int result, std::string name) { using namespace ArdourCanvas; - cerr << "Done, using [" << base_color_edit_name << "] res = " << result << endl; - - if (base_color_edit_name.empty()) { - color_dialog.hide (); - return; - } + color_dialog_connection.disconnect (); - UIConfiguration* uic (ARDOUR_UI::instance()->config()); - UIConfiguration::RelativeHSV rhsv ("", HSV()); + UIConfiguration* uic (&UIConfiguration::instance()); Gdk::Color gdkcolor; double r,g, b, a; switch (result) { case RESPONSE_ACCEPT: case RESPONSE_OK: - cerr << "Accepting\n"; gdkcolor = color_dialog.get_colorsel()->get_current_color(); a = color_dialog.get_colorsel()->get_current_alpha() / 65535.0; r = gdkcolor.get_red_p(); g = gdkcolor.get_green_p(); b = gdkcolor.get_blue_p(); - rhsv = uic->color_as_relative_hsv (rgba_to_color (r, g, b, a)); - uic->reset_relative (base_color_edit_name, rhsv); - - /* rebuild */ - - build_base_color_canvas (*base_color_group, &ThemeManager::base_color_event, - base_color_viewport.canvas()->width(), - base_color_viewport.canvas()->height()); - - ColorsChanged(); //EMIT SIGNAL + uic->set_color (name, rgba_to_color (r, g, b, a)); break; - + default: break; } color_dialog.hide (); - base_color_edit_name = ""; -} - -void -ThemeManager::palette_canvas_allocated (Gtk::Allocation& alloc, ArdourCanvas::Container* group, bool (ThemeManager::*event_handler)(GdkEvent*,std::string)) -{ - build_base_color_canvas (*group, event_handler, alloc.get_width(), alloc.get_height()); } bool -ThemeManager::palette_chosen (GdkEvent* ev, string name) +ThemeManager::alias_palette_event (GdkEvent* ev, string new_alias, string target_name) { switch (ev->type) { case GDK_BUTTON_RELEASE: + UIConfiguration::instance().set_alias (target_name, new_alias); + return true; break; default: - return false; break; } + return false; +} - UIConfiguration* uic (ARDOUR_UI::instance()->config()); - uic->set_alias (palette_edit_name, name); +void +ThemeManager::alias_palette_response (int response, std::string target_name, std::string old_alias) +{ + switch (response) { + case GTK_RESPONSE_OK: + case GTK_RESPONSE_ACCEPT: + /* rebuild alias list with new color: inefficient but simple */ + setup_aliases (); + break; - (void) palette_done ((GdkEventAny*) 0); + case GTK_RESPONSE_REJECT: + /* revert choice */ + UIConfiguration::instance().set_alias (target_name, old_alias); + break; - /* rebuild alias list with new color: inefficient but simple */ - - setup_aliases (); - - return true; -} + default: + /* do nothing */ + break; + } -bool -ThemeManager::palette_done (GdkEventAny*) -{ - palette_edit_name = ""; palette_window->hide (); - return true; } void ThemeManager::choose_color_from_palette (string const & name) { - if (!palette_window) { - palette_window = new Gtk::Window (WINDOW_TOPLEVEL); - ArdourCanvas::GtkCanvas* canvas = new ArdourCanvas::GtkCanvas (); - ArdourCanvas::Container* group = initialize_canvas (*canvas); - - canvas->signal_size_allocate().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::palette_canvas_allocated), group, &ThemeManager::palette_chosen)); - palette_window->signal_delete_event().connect (sigc::mem_fun (*this, &ThemeManager::palette_done)); - - palette_window->add (*canvas); - canvas->show (); + UIConfiguration* uic (&UIConfiguration::instance()); + UIConfiguration::ColorAliases::iterator i = uic->color_aliases.find (name); + + if (i == uic->color_aliases.end()) { + return; } - palette_edit_name = name; + delete palette_window; + + palette_window = new ArdourDialog (_("Color Palette")); + palette_window->add_button (Stock::CANCEL, RESPONSE_REJECT); /* using CANCEL causes confusion if dialog is closed via CloseAllDialogs */ + palette_window->add_button (Stock::OK, RESPONSE_OK); + + ArdourCanvas::GtkCanvas* canvas = new ArdourCanvas::GtkCanvas (); + ArdourCanvas::Container* group = initialize_palette_canvas (*canvas); + + canvas->signal_size_request().connect (sigc::mem_fun (*this, &ThemeManager::palette_size_request)); + canvas->signal_size_allocate().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::palette_canvas_allocated), group, canvas, + sigc::bind (sigc::mem_fun (*this, &ThemeManager::alias_palette_event), name))); + + palette_window->get_vbox()->pack_start (*canvas); + palette_window->show_all (); + + palette_response_connection = palette_window->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ThemeManager::alias_palette_response), name, i->second)); palette_window->set_position (WIN_POS_MOUSE); palette_window->present (); @@ -763,29 +648,65 @@ void ThemeManager::setup_aliases () { using namespace ArdourCanvas; - - UIConfiguration* uic (ARDOUR_UI::instance()->config()); + + UIConfiguration* uic (&UIConfiguration::instance()); UIConfiguration::ColorAliases& aliases (uic->color_aliases); alias_list->clear (); for (UIConfiguration::ColorAliases::iterator i = aliases.begin(); i != aliases.end(); ++i) { + TreeModel::Children rows = alias_list->children(); TreeModel::Row row; + string::size_type colon; - row = *(alias_list->append()); - row[alias_columns.name] = i->first; - row[alias_columns.alias] = i->second; + if ((colon = i->first.find (':')) != string::npos) { + + /* this is supposed to be a child node, so find the + * parent + */ + + string parent = i->first.substr (0, colon); + TreeModel::iterator ri; + + for (ri = rows.begin(); ri != rows.end(); ++ri) { + string s = (*ri)[alias_columns.name]; + if (s == parent) { + break; + } + } + + if (ri == rows.end()) { + /* not found, add the parent as new top level row */ + row = *(alias_list->append()); + row[alias_columns.name] = parent; + row[alias_columns.alias] = ""; - Color c = uic->color (i->second); + /* now add the child as a child of this one */ + + row = *(alias_list->insert (row->children().end())); + row[alias_columns.name] = i->first.substr (colon+1); + } else { + row = *(alias_list->insert ((*ri)->children().end())); + row[alias_columns.name] = i->first.substr (colon+1); + } + + } else { + /* add as a child */ + row = *(alias_list->append()); + row[alias_columns.name] = i->first; + row[alias_columns.key] = i->first; + } - /* Gdk colors don't support alpha */ + row[alias_columns.key] = i->first; + row[alias_columns.alias] = i->second; + Gdk::Color col; double r, g, b, a; + Color c (uic->color (i->second)); color_to_rgba (c, r, g, b, a); - Gdk::Color gcolor; - gcolor.set_rgb_p (r, g, b); + col.set_rgb_p (r, g, b); - row[alias_columns.color] = gcolor; + row[alias_columns.color] = col; } } @@ -803,7 +724,7 @@ ThemeManager::alias_button_press_event (GdkEventButton* ev) } guint32 colnum = GPOINTER_TO_UINT (column->get_data (X_("colnum"))); - + switch (colnum) { case 0: /* allow normal processing to occur */ @@ -811,7 +732,10 @@ ThemeManager::alias_button_press_event (GdkEventButton* ev) case 1: /* color */ if ((iter = alias_list->get_iter (path))) { - choose_color_from_palette ((*iter)[alias_columns.name]); + string target_color_alias = (*iter)[alias_columns.key]; + if (!target_color_alias.empty()) { + choose_color_from_palette (target_color_alias); + } } break; }