#include <gtkmm/paned.h>
#include <gtk/gtkpaned.h>
-#include <pbd/file_utils.h>
+#include "pbd/file_utils.h"
#include <gtkmm2ext/utils.h>
-#include <ardour/configuration.h>
-#include <ardour/configuration.h>
+#include "ardour/configuration.h"
+#include "ardour/configuration.h"
-#include <ardour/filesystem_paths.h>
+#include "ardour/filesystem_paths.h"
#include "ardour_ui.h"
#include "keyboard.h"
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.
+ * @param e Element to add.
+ * @param s true to make sensitive, false to make insensitive
+ */
+void
+add_item_with_sensitivity (Menu_Helpers::MenuList& m, Menu_Helpers::MenuElem e, bool s)
+{
+ m.push_back (e);
+ if (!s) {
+ m.back().set_sensitive (false);
+ }
+}
+
+
gint
-just_hide_it (GdkEventAny *ev, Gtk::Window *win)
+just_hide_it (GdkEventAny */*ev*/, Gtk::Window *win)
{
win->hide ();
- return TRUE;
+ return 0;
}
/* xpm2rgb copied from nixieclock, which bore the legend:
}
ArdourCanvas::Points*
-get_canvas_points (string who, uint32_t npoints)
+get_canvas_points (string /*who*/, uint32_t npoints)
{
// cerr << who << ": wants " << npoints << " canvas points" << endl;
#ifdef TRAP_EXCESSIVE_POINT_REQUESTS
return xpm_map[name];
}
-
-Glib::RefPtr<Gdk::Pixbuf>
-get_icon (const char* cname)
+Glib::ustring
+get_icon_path (const char* cname)
{
string name = cname;
name += X_(".png");
fatal << string_compose (_("cannot find icon image for %1"), name) << endmsg;
}
+ return data_file_path.to_string();
+}
+
+Glib::RefPtr<Gdk::Pixbuf>
+get_icon (const char* cname)
+{
Glib::RefPtr<Gdk::Pixbuf> img;
try {
- img = Gdk::Pixbuf::create_from_file (data_file_path.to_string());
+ img = Gdk::Pixbuf::create_from_file (get_icon_path (cname));
} catch (const Gdk::PixbufError &e) {
cerr << "Caught PixbufError: " << e.what() << endl;
} catch (...) {
return false;
}
+
+inline guint8
+convert_color_channel (guint8 src,
+ guint8 alpha)
+{
+ return alpha ? ((guint (src) << 8) - src) / alpha : 0;
+}
+
+void
+convert_bgra_to_rgba (guint8 const* src,
+ guint8* dst,
+ int width,
+ int height)
+{
+ guint8 const* src_pixel = src;
+ guint8* dst_pixel = dst;
+
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ {
+ dst_pixel[0] = convert_color_channel (src_pixel[2],
+ src_pixel[3]);
+ dst_pixel[1] = convert_color_channel (src_pixel[1],
+ src_pixel[3]);
+ dst_pixel[2] = convert_color_channel (src_pixel[0],
+ src_pixel[3]);
+ dst_pixel[3] = src_pixel[3];
+
+ dst_pixel += 4;
+ src_pixel += 4;
+ }
+}