summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2011-12-07 13:08:00 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2011-12-07 13:08:00 +0000
commitbb737997aea86f08ec16e6444f3666ff6a524be2 (patch)
tree6264b4a2b3357707f447878ef84c7911b8f107fa
parent2f837b66f75ad95ff5b6032ca8600bed6ba79fe5 (diff)
move 2 other non-ardour-specific utility functions into gtkmm2ext
git-svn-id: svn://localhost/ardour2/branches/3.0@10932 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r--gtk2_ardour/editor_group_tabs.cc4
-rw-r--r--gtk2_ardour/mixer_group_tabs.cc4
-rw-r--r--gtk2_ardour/utils.cc93
-rw-r--r--gtk2_ardour/utils.h7
4 files changed, 6 insertions, 102 deletions
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<string, double> const f = fit_to_pixels (cr, tab.group->name(), tab.to - tab.from - arc_radius * 2);
+ pair<string, double> 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 <boost/foreach.hpp>
+#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<string, double> const f = fit_to_pixels (cr, tab.group->name(), tab.to - tab.from - arc_radius * 2);
+ pair<string, double> 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<void> DPIReset;
-int
-pixel_width (const string& str, Pango::FontDescription& font)
-{
- Label foo;
- Glib::RefPtr<Pango::Layout> 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<Pango::Layout> 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<std::string, double>
-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<void> DPIReset;
-std::string fit_to_pixels (const std::string&, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses = false);
-
-std::pair<std::string, double> 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);