From d59d26b89a875d226e8d7405d75c17c331fc6a0a Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 10 Jun 2014 12:38:31 -0400 Subject: change ::get_icon_path() and ::get_icon() to accept an "icon set" name to provide ability to use different sets of icons; use when creating MouseCursors --- gtk2_ardour/editor.cc | 1 + gtk2_ardour/mouse_cursors.cc | 131 +++++++++++++++++++++++++++++++++++-------- gtk2_ardour/mouse_cursors.h | 8 +++ gtk2_ardour/ui_config_vars.h | 1 + gtk2_ardour/utils.cc | 44 ++++++++++++--- gtk2_ardour/utils.h | 4 +- 6 files changed, 157 insertions(+), 32 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 13f851a8c7..68e3a2ee55 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -500,6 +500,7 @@ Editor::Editor () controls_layout.signal_scroll_event().connect (sigc::mem_fun(*this, &Editor::control_layout_scroll), false); _cursors = new MouseCursors; + _cursors->set_cursor_set (ARDOUR_UI::config()->get_icon_set()); ArdourCanvas::GtkCanvas* time_pad = manage (new ArdourCanvas::GtkCanvas ()); diff --git a/gtk2_ardour/mouse_cursors.cc b/gtk2_ardour/mouse_cursors.cc index 98e33d77d6..56a2eafac8 100644 --- a/gtk2_ardour/mouse_cursors.cc +++ b/gtk2_ardour/mouse_cursors.cc @@ -23,17 +23,102 @@ #include "editor_xpms" MouseCursors::MouseCursors () + : cross_hair (0) + , trimmer (0) + , right_side_trim (0) + , left_side_trim (0) + , right_side_trim_left_only (0) + , left_side_trim_right_only (0) + , fade_in (0) + , fade_out (0) + , selector (0) + , grabber (0) + , grabber_note (0) + , grabber_edit_point (0) + , zoom_in (0) + , zoom_out (0) + , time_fx (0) + , fader (0) + , speaker (0) + , midi_pencil (0) + , midi_select (0) + , midi_resize (0) + , midi_erase (0) + , up_down (0) + , wait (0) + , timebar (0) + , transparent (0) + , resize_left (0) + , resize_top_left (0) + , resize_top (0) + , resize_top_right (0) + , resize_right (0) + , resize_bottom_right (0) + , resize_bottom (0) + , resize_bottom_left (0) + , move (0) + , expand_left_right (0) + , expand_up_down (0) +{ +} + +void +MouseCursors::drop_all () +{ + delete cross_hair; cross_hair = 0; + delete trimmer; trimmer = 0; + delete right_side_trim; right_side_trim = 0; + delete left_side_trim; left_side_trim = 0; + delete right_side_trim_left_only; right_side_trim_left_only = 0; + delete left_side_trim_right_only; left_side_trim_right_only = 0; + delete fade_in; fade_in = 0; + delete fade_out; fade_out = 0; + delete selector; selector = 0; + delete grabber; grabber = 0; + delete grabber_note; grabber_note = 0; + delete grabber_edit_point; grabber_edit_point = 0; + delete zoom_in; zoom_in = 0; + delete zoom_out; zoom_out = 0; + delete time_fx; time_fx = 0; + delete fader; fader = 0; + delete speaker; speaker = 0; + delete midi_pencil; midi_pencil = 0; + delete midi_select; midi_select = 0; + delete midi_resize; midi_resize = 0; + delete midi_erase; midi_erase = 0; + delete up_down; up_down = 0; + delete wait; wait = 0; + delete timebar; timebar = 0; + delete transparent; transparent = 0; + delete resize_left; resize_left = 0; + delete resize_top_left; resize_top_left = 0; + delete resize_top; resize_top = 0; + delete resize_top_right; resize_top_right = 0; + delete resize_right; resize_right = 0; + delete resize_bottom_right; resize_bottom_right = 0; + delete resize_bottom; resize_bottom = 0; + delete resize_bottom_left; resize_bottom_left = 0; + delete move; move = 0; + delete expand_left_right; expand_left_right = 0; + delete expand_up_down; expand_up_down = 0; +} + +void +MouseCursors::set_cursor_set (const std::string& name) { using namespace Glib; using namespace Gdk; + + drop_all (); + _cursor_set = name; { - RefPtr p (::get_icon ("zoom_in_cursor")); + RefPtr p (::get_icon ("zoom_in_cursor", _cursor_set)); zoom_in = new Cursor (Display::get_default(), p, 10, 5); } { - RefPtr p (::get_icon ("zoom_out_cursor")); + RefPtr p (::get_icon ("zoom_out_cursor", _cursor_set)); zoom_out = new Cursor (Display::get_default(), p, 5, 5); } @@ -67,17 +152,17 @@ MouseCursors::MouseCursors () } { - RefPtr p (::get_icon ("grabber")); + RefPtr p (::get_icon ("grabber", _cursor_set)); grabber = new Cursor (Display::get_default(), p, 5, 0); } { - RefPtr p (::get_icon ("grabber_note")); + RefPtr p (::get_icon ("grabber_note", _cursor_set)); grabber_note = new Cursor (Display::get_default(), p, 5, 10); } { - RefPtr p (::get_icon ("grabber_edit_point")); + RefPtr p (::get_icon ("grabber_edit_point", _cursor_set)); grabber_edit_point = new Cursor (Display::get_default(), p, 5, 17); } @@ -85,92 +170,92 @@ MouseCursors::MouseCursors () trimmer = new Cursor (SB_H_DOUBLE_ARROW); { - RefPtr p (::get_icon ("trim_left_cursor")); + RefPtr p (::get_icon ("trim_left_cursor", _cursor_set)); left_side_trim = new Cursor (Display::get_default(), p, 5, 11); } { - RefPtr p (::get_icon ("trim_right_cursor")); + RefPtr p (::get_icon ("trim_right_cursor", _cursor_set)); right_side_trim = new Cursor (Display::get_default(), p, 23, 11); } { - RefPtr p (::get_icon ("trim_left_cursor_right_only")); + RefPtr p (::get_icon ("trim_left_cursor_right_only", _cursor_set)); left_side_trim_right_only = new Cursor (Display::get_default(), p, 5, 11); } { - RefPtr p (::get_icon ("trim_right_cursor_left_only")); + RefPtr p (::get_icon ("trim_right_cursor_left_only", _cursor_set)); right_side_trim_left_only = new Cursor (Display::get_default(), p, 23, 11); } { - RefPtr p (::get_icon ("fade_in_cursor")); + RefPtr p (::get_icon ("fade_in_cursor", _cursor_set)); fade_in = new Cursor (Display::get_default(), p, 0, 0); } { - RefPtr p (::get_icon ("fade_out_cursor")); + RefPtr p (::get_icon ("fade_out_cursor", _cursor_set)); fade_out = new Cursor (Display::get_default(), p, 29, 0); } { - RefPtr p (::get_icon ("resize_left_cursor")); + RefPtr p (::get_icon ("resize_left_cursor", _cursor_set)); resize_left = new Cursor (Display::get_default(), p, 3, 10); } { - RefPtr p (::get_icon ("resize_top_left_cursor")); + RefPtr p (::get_icon ("resize_top_left_cursor", _cursor_set)); resize_top_left = new Cursor (Display::get_default(), p, 3, 3); } { - RefPtr p (::get_icon ("resize_top_cursor")); + RefPtr p (::get_icon ("resize_top_cursor", _cursor_set)); resize_top = new Cursor (Display::get_default(), p, 10, 3); } { - RefPtr p (::get_icon ("resize_top_right_cursor")); + RefPtr p (::get_icon ("resize_top_right_cursor", _cursor_set)); resize_top_right = new Cursor (Display::get_default(), p, 18, 3); } { - RefPtr p (::get_icon ("resize_right_cursor")); + RefPtr p (::get_icon ("resize_right_cursor", _cursor_set)); resize_right = new Cursor (Display::get_default(), p, 24, 10); } { - RefPtr p (::get_icon ("resize_bottom_right_cursor")); + RefPtr p (::get_icon ("resize_bottom_right_cursor", _cursor_set)); resize_bottom_right = new Cursor (Display::get_default(), p, 18, 18); } { - RefPtr p (::get_icon ("resize_bottom_cursor")); + RefPtr p (::get_icon ("resize_bottom_cursor", _cursor_set)); resize_bottom = new Cursor (Display::get_default(), p, 10, 24); } { - RefPtr p (::get_icon ("resize_bottom_left_cursor")); + RefPtr p (::get_icon ("resize_bottom_left_cursor", _cursor_set)); resize_bottom_left = new Cursor (Display::get_default(), p, 3, 18); } { - RefPtr p (::get_icon ("move_cursor")); + RefPtr p (::get_icon ("move_cursor", _cursor_set)); move = new Cursor (Display::get_default(), p, 11, 11); } { - RefPtr p (::get_icon ("expand_left_right_cursor")); + RefPtr p (::get_icon ("expand_left_right_cursor", _cursor_set)); expand_left_right = new Cursor (Display::get_default(), p, 11, 4); } { - RefPtr p (::get_icon ("expand_up_down_cursor")); + RefPtr p (::get_icon ("expand_up_down_cursor", _cursor_set)); expand_up_down = new Cursor (Display::get_default(), p, 4, 11); } { - RefPtr p (::get_icon ("i_beam_cursor")); + RefPtr p (::get_icon ("i_beam_cursor", _cursor_set)); selector = new Cursor (Display::get_default(), p, 4, 11); } diff --git a/gtk2_ardour/mouse_cursors.h b/gtk2_ardour/mouse_cursors.h index bf93e1ad78..a6b54b62a5 100644 --- a/gtk2_ardour/mouse_cursors.h +++ b/gtk2_ardour/mouse_cursors.h @@ -30,6 +30,9 @@ class MouseCursors public: MouseCursors (); + void set_cursor_set (const std::string& name); + std::string cursor_set() const { return _cursor_set; } + Gdk::Cursor* cross_hair; Gdk::Cursor* trimmer; Gdk::Cursor* right_side_trim; @@ -66,6 +69,11 @@ public: Gdk::Cursor* move; Gdk::Cursor* expand_left_right; Gdk::Cursor* expand_up_down; + + private: + std::string _cursor_set; + void drop_all (); + }; #endif /* __gtk2_ardour_mouse_cursors__ */ diff --git a/gtk2_ardour/ui_config_vars.h b/gtk2_ardour/ui_config_vars.h index 18bda55457..16ffd26255 100644 --- a/gtk2_ardour/ui_config_vars.h +++ b/gtk2_ardour/ui_config_vars.h @@ -17,6 +17,7 @@ */ +UI_CONFIG_VARIABLE(std::string, icon_set, "icon-set", "default") UI_CONFIG_VARIABLE(std::string, ui_rc_file, "ui-rc-file", "ardour3_ui_dark.rc") UI_CONFIG_VARIABLE(bool, flat_buttons, "flat-buttons", false) UI_CONFIG_VARIABLE(float, waveform_gradient_depth, "waveform-gradient-depth", 0.6) diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index a04e37f9e5..3919a756cb 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -655,22 +655,52 @@ get_xpm (std::string name) } std::string -get_icon_path (const char* cname) +get_icon_path (const char* cname, string icon_set) { + std::string data_file_path; string name = cname; name += X_(".png"); Searchpath spath(ARDOUR::ardour_data_search_path()); + + if (!icon_set.empty() && icon_set != "default") { + string subdir = Glib::build_filename ("icons", icon_set); + spath.add_subdirectory_to_paths (subdir); + + find_file_in_search_path (spath, name, data_file_path); + } + + if (data_file_path.empty()) { + + if (!icon_set.empty() && icon_set != "default") { + warning << string_compose (_("icon \"%1\" not found for icon set \"%2\", fallback to default"), cname, icon_set) << endmsg; + } + + Searchpath def (ARDOUR::ardour_data_search_path()); + def.add_subdirectory_to_paths ("icons"); + + if (!find_file_in_search_path (def, name, data_file_path)) { + fatal << string_compose (_("cannot find icon image for %1 using %2"), name, spath.to_string()) << endmsg; + /*NOTREACHED*/ + } + } - spath.add_subdirectory_to_paths("icons"); - - std::string data_file_path; + return data_file_path; +} - if (!find_file_in_search_path (spath, name, data_file_path)) { - fatal << string_compose (_("cannot find icon image for %1 using %2"), name, spath.to_string()) << endmsg; +Glib::RefPtr +get_icon (const char* cname, string icon_set) +{ + Glib::RefPtr img; + try { + img = Gdk::Pixbuf::create_from_file (get_icon_path (cname, icon_set)); + } catch (const Gdk::PixbufError &e) { + cerr << "Caught PixbufError: " << e.what() << endl; + } catch (...) { + error << string_compose (_("Caught exception while loading icon named %1"), cname) << endmsg; } - return data_file_path; + return img; } Glib::RefPtr diff --git a/gtk2_ardour/utils.h b/gtk2_ardour/utils.h index bf5e5b85f5..a59f55eec1 100644 --- a/gtk2_ardour/utils.h +++ b/gtk2_ardour/utils.h @@ -76,8 +76,8 @@ bool key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey* ev); bool emulate_key_event (Gtk::Widget*, unsigned int); Glib::RefPtr get_xpm (std::string); -std::string get_icon_path (const char*); -Glib::RefPtr get_icon (const char*); +std::string get_icon_path (const char*, std::string icon_set = std::string()); +Glib::RefPtr get_icon (const char*, std::string icon_set = std::string()); static std::map > xpm_map; const char* const *get_xpm_data (std::string path); std::string longest (std::vector&); -- cgit v1.2.3