diff --git a/gtk2_ardour/editor_group_tabs.cc b/gtk2_ardour/editor_group_tabs.cc index ba94b16dd4..352eec88cc 100644 --- a/gtk2_ardour/editor_group_tabs.cc +++ b/gtk2_ardour/editor_group_tabs.cc @@ -17,6 +17,8 @@ */ +#include "gtkmm2ext/utils.h" + #include "ardour/route_group.h" #include "editor_group_tabs.h" #include "editor.h" @@ -96,7 +98,7 @@ EditorGroupTabs::draw_tab (cairo_t* cr, Tab const & tab) const cairo_fill (cr); if (tab.group) { - pair const f = fit_to_pixels (cr, tab.group->name(), tab.to - tab.from - arc_radius * 2); + pair const f = Gtkmm2ext::fit_to_pixels (cr, tab.group->name(), tab.to - tab.from - arc_radius * 2); cairo_text_extents_t ext; cairo_text_extents (cr, tab.group->name().c_str(), &ext); diff --git a/gtk2_ardour/mixer_group_tabs.cc b/gtk2_ardour/mixer_group_tabs.cc index 2d33b54af3..6482abebc2 100644 --- a/gtk2_ardour/mixer_group_tabs.cc +++ b/gtk2_ardour/mixer_group_tabs.cc @@ -19,6 +19,8 @@ #include +#include "gtkmm2ext/utils.h" + #include "ardour/route_group.h" #include "ardour/session.h" #include "mixer_group_tabs.h" @@ -104,7 +106,7 @@ MixerGroupTabs::draw_tab (cairo_t* cr, Tab const & tab) const cairo_fill (cr); if (tab.group) { - pair const f = fit_to_pixels (cr, tab.group->name(), tab.to - tab.from - arc_radius * 2); + pair const f = Gtkmm2ext::fit_to_pixels (cr, tab.group->name(), tab.to - tab.from - arc_radius * 2); cairo_text_extents_t ext; cairo_text_extents (cr, tab.group->name().c_str(), &ext); diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index f2e774740d..23cceba72e 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -63,99 +63,6 @@ using Gtkmm2ext::Keyboard; sigc::signal DPIReset; -int -pixel_width (const string& str, Pango::FontDescription& font) -{ - Label foo; - Glib::RefPtr layout = foo.create_pango_layout (""); - - layout->set_font_description (font); - layout->set_text (str); - - int width, height; - Gtkmm2ext::get_ink_pixel_size (layout, width, height); - return width; -} - -string -fit_to_pixels (const string& str, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses) -{ - Label foo; - Glib::RefPtr layout = foo.create_pango_layout (""); - string::size_type shorter_by = 0; - string txt; - - layout->set_font_description (font); - - actual_width = 0; - - string ustr = str; - string::iterator last = ustr.end(); - --last; /* now points at final entry */ - - txt = ustr; - - while (!ustr.empty()) { - - layout->set_text (txt); - - int width, height; - Gtkmm2ext::get_ink_pixel_size (layout, width, height); - - if (width < pixel_width) { - actual_width = width; - break; - } - - ustr.erase (last--); - shorter_by++; - - if (with_ellipses && shorter_by > 3) { - txt = ustr; - txt += "..."; - } else { - txt = ustr; - } - } - - return txt; -} - -/** Try to fit a string into a given horizontal space by ellipsizing it. - * @param cr Cairo context in which the text will be plotted. - * @param name Text. - * @param avail Available horizontal space. - * @return (Text, possibly ellipsized) and (horizontal size of text) - */ - -std::pair -fit_to_pixels (cairo_t* cr, std::string name, double avail) -{ - /* XXX hopefully there exists a more efficient way of doing this */ - - bool abbreviated = false; - uint32_t width = 0; - - while (1) { - cairo_text_extents_t ext; - cairo_text_extents (cr, name.c_str(), &ext); - - if (ext.width < avail || name.length() <= 4) { - width = ext.width; - break; - } - - if (abbreviated) { - name = name.substr (0, name.length() - 4) + "..."; - } else { - name = name.substr (0, name.length() - 3) + "..."; - abbreviated = true; - } - } - - return std::make_pair (name, width); -} - /** Add an element to a menu, settings its sensitivity. * @param m Menu to add to. diff --git a/gtk2_ardour/utils.h b/gtk2_ardour/utils.h index d511b0e718..cc6c988b18 100644 --- a/gtk2_ardour/utils.h +++ b/gtk2_ardour/utils.h @@ -44,14 +44,7 @@ namespace Gtk { extern sigc::signal DPIReset; -std::string fit_to_pixels (const std::string&, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses = false); - -std::pair fit_to_pixels (cairo_t *, std::string, double); - -int pixel_width (const std::string& str, Pango::FontDescription& font); - gint just_hide_it (GdkEventAny*, Gtk::Window*); -void allow_keyboard_focus (bool); void add_item_with_sensitivity (Gtk::Menu_Helpers::MenuList &, Gtk::Menu_Helpers::MenuElem, bool); unsigned char* xpm2rgb (const char** xpm, uint32_t& w, uint32_t& h);