using namespace PBD;
using Gtkmm2ext::Keyboard;
-sigc::signal<void> DPIReset;
+namespace ARDOUR_UI_UTILS {
+ sigc::signal<void> DPIReset;
+}
#ifdef PLATFORM_WINDOWS
#define random() rand()
* @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)
+ARDOUR_UI_UTILS::add_item_with_sensitivity (Menu_Helpers::MenuList& m, Menu_Helpers::MenuElem e, bool s)
{
m.push_back (e);
if (!s) {
gint
-just_hide_it (GdkEventAny */*ev*/, Gtk::Window *win)
+ARDOUR_UI_UTILS::just_hide_it (GdkEventAny */*ev*/, Gtk::Window *win)
{
win->hide ();
return 0;
*/
unsigned char*
-xpm2rgb (const char** xpm, uint32_t& w, uint32_t& h)
+ARDOUR_UI_UTILS::xpm2rgb (const char** xpm, uint32_t& w, uint32_t& h)
{
static long vals[256], val;
uint32_t t, x, y, colors, cpp;
}
unsigned char*
-xpm2rgba (const char** xpm, uint32_t& w, uint32_t& h)
+ARDOUR_UI_UTILS::xpm2rgba (const char** xpm, uint32_t& w, uint32_t& h)
{
static long vals[256], val;
uint32_t t, x, y, colors, cpp;
* that we might add here later.
*/
Pango::FontDescription
-sanitized_font (std::string const& name)
+ARDOUR_UI_UTILS::sanitized_font (std::string const& name)
{
Pango::FontDescription fd (name);
}
Pango::FontDescription
-get_font_for_style (string widgetname)
+ARDOUR_UI_UTILS::get_font_for_style (string widgetname)
{
Gtk::Window window (WINDOW_TOPLEVEL);
Gtk::Label foobar;
}
uint32_t
-rgba_from_style (string style, uint32_t r, uint32_t g, uint32_t b, uint32_t a, string attr, int state, bool rgba)
+ARDOUR_UI_UTILS::rgba_from_style (string style, uint32_t r, uint32_t g, uint32_t b, uint32_t a, string attr, int state, bool rgba)
{
/* In GTK+2, styles aren't set up correctly if the widget is not
attached to a toplevel window that has a screen pointer.
}
bool
-rgba_p_from_style (string style, float *r, float *g, float *b, string attr, int state)
+ARDOUR_UI_UTILS::rgba_p_from_style (string style, float *r, float *g, float *b, string attr, int state)
{
static Gtk::Window* window = 0;
assert (r && g && b);
}
void
-set_color_from_rgb (Gdk::Color& c, uint32_t rgb)
+ARDOUR_UI_UTILS::set_color_from_rgb (Gdk::Color& c, uint32_t rgb)
{
/* Gdk::Color color ranges are 16 bit, so scale from 8 bit by
multiplying by 256.
}
void
-set_color_from_rgba (Gdk::Color& c, uint32_t rgba)
+ARDOUR_UI_UTILS::set_color_from_rgba (Gdk::Color& c, uint32_t rgba)
{
/* Gdk::Color color ranges are 16 bit, so scale from 8 bit by
multiplying by 256.
}
uint32_t
-gdk_color_to_rgba (Gdk::Color const& c)
+ARDOUR_UI_UTILS::gdk_color_to_rgba (Gdk::Color const& c)
{
/* since alpha value is not available from a Gdk::Color, it is
hardcoded as 0xff (aka 255 or 1.0)
return RGBA_TO_UINT (r,g,b,a);
}
-uint32_t
-contrasting_text_color (uint32_t c)
-{
- double r, g, b, a;
- ArdourCanvas::color_to_rgba (c, r, g, b, a);
-
- const double black_r = 0.0;
- const double black_g = 0.0;
- const double black_b = 0.0;
-
- const double white_r = 1.0;
- const double white_g = 1.0;
- const double white_b = 1.0;
-
- /* Use W3C contrast guideline calculation */
-
- double white_contrast = (max (r, white_r) - min (r, white_r)) +
- (max (g, white_g) - min (g, white_g)) +
- (max (b, white_b) - min (b, white_b));
-
- double black_contrast = (max (r, black_r) - min (r, black_r)) +
- (max (g, black_g) - min (g, black_g)) +
- (max (b, black_b) - min (b, black_b));
-
- if (white_contrast > black_contrast) {
- /* use white */
- return ArdourCanvas::rgba_to_color (1.0, 1.0, 1.0, 1.0);
- } else {
- /* use black */
- return ArdourCanvas::rgba_to_color (0.0, 0.0, 0.0, 1.0);
- }
-}
bool
-relay_key_press (GdkEventKey* ev, Gtk::Window* win)
+ARDOUR_UI_UTILS::relay_key_press (GdkEventKey* ev, Gtk::Window* win)
{
PublicEditor& ed (PublicEditor::instance());
}
bool
-forward_key_press (GdkEventKey* ev)
+ARDOUR_UI_UTILS::forward_key_press (GdkEventKey* ev)
{
- return PublicEditor::instance().on_key_press_event(ev);
+ return PublicEditor::instance().on_key_press_event(ev);
}
bool
-emulate_key_event (Gtk::Widget* w, unsigned int keyval)
+ARDOUR_UI_UTILS::emulate_key_event (Gtk::Widget* w, unsigned int keyval)
{
GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET(w->gobj()));
GdkKeymap *keymap = gdk_keymap_get_for_display (display);
}
bool
-key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey* ev)
+ARDOUR_UI_UTILS::key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey* ev)
{
GtkWindow* win = window.gobj();
GtkWidget* focus = gtk_window_get_focus (win);
/* no special handling or there are modifiers in effect: accelerate first */
DEBUG_TRACE (DEBUG::Accelerators, "\tactivate, then propagate\n");
- DEBUG_TRACE (DEBUG::Accelerators, string_compose ("\tevent send-event:%1 time:%2 length:%3 string:%4 hardware_keycode:%5 group:%6\n",
- ev->send_event, ev->time, ev->length, ev->string, ev->hardware_keycode, ev->group));
+ DEBUG_TRACE (DEBUG::Accelerators, string_compose ("\tevent send-event:%1 time:%2 length:%3 name %7 string:%4 hardware_keycode:%5 group:%6\n",
+ ev->send_event, ev->time, ev->length, ev->string, ev->hardware_keycode, ev->group, gdk_keyval_name (ev->keyval)));
if (allow_activating) {
DEBUG_TRACE (DEBUG::Accelerators, "\tsending to window\n");
}
Glib::RefPtr<Gdk::Pixbuf>
-get_xpm (std::string name)
+ARDOUR_UI_UTILS::get_xpm (std::string name)
{
if (!xpm_map[name]) {
std::string data_file_path;
- if(!find_file_in_search_path (spath, name, data_file_path)) {
+ if(!find_file (spath, name, data_file_path)) {
fatal << string_compose (_("cannot find XPM file for %1"), name) << endmsg;
}
}
vector<string>
-get_icon_sets ()
+ARDOUR_UI_UTILS::get_icon_sets ()
{
Searchpath spath(ARDOUR::ardour_data_search_path());
spath.add_subdirectory_to_paths ("icons");
vector<string> entries;
- get_files_in_directory (*s, entries);
+ get_paths (entries, *s, false, false);
for (vector<string>::iterator e = entries.begin(); e != entries.end(); ++e) {
-
- string d = *e;
-
- /* ignore dotfiles, . and .. */
-
- if (d.empty() || d[0] == '.') {
- continue;
- }
-
- Glib::ustring path = Glib::build_filename (*s, *e);
-
- if (Glib::file_test (path, Glib::FILE_TEST_IS_DIR)) {
- r.push_back (Glib::filename_to_utf8 (*e));
+ if (Glib::file_test (*e, Glib::FILE_TEST_IS_DIR)) {
+ r.push_back (Glib::filename_to_utf8 (Glib::path_get_basename(*e)));
}
}
}
}
std::string
-get_icon_path (const char* cname, string icon_set)
+ARDOUR_UI_UTILS::get_icon_path (const char* cname, string icon_set)
{
std::string data_file_path;
string name = cname;
spath.add_subdirectory_to_paths ("icons");
spath.add_subdirectory_to_paths (icon_set);
- find_file_in_search_path (spath, name, data_file_path);
+ find_file (spath, name, data_file_path);
}
if (data_file_path.empty()) {
Searchpath def (ARDOUR::ardour_data_search_path());
def.add_subdirectory_to_paths ("icons");
- if (!find_file_in_search_path (def, name, data_file_path)) {
+ if (!find_file (def, name, data_file_path)) {
fatal << string_compose (_("cannot find icon image for %1 using %2"), name, spath.to_string()) << endmsg;
/*NOTREACHED*/
}
}
Glib::RefPtr<Gdk::Pixbuf>
-get_icon (const char* cname, string icon_set)
+ARDOUR_UI_UTILS::get_icon (const char* cname, string icon_set)
{
Glib::RefPtr<Gdk::Pixbuf> img;
try {
return img;
}
+namespace ARDOUR_UI_UTILS {
Glib::RefPtr<Gdk::Pixbuf>
get_icon (const char* cname)
{
return img;
}
+}
string
-longest (vector<string>& strings)
+ARDOUR_UI_UTILS::longest (vector<string>& strings)
{
if (strings.empty()) {
return string ("");
}
bool
-key_is_legal_for_numeric_entry (guint keyval)
+ARDOUR_UI_UTILS::key_is_legal_for_numeric_entry (guint keyval)
{
/* we assume that this does not change over the life of the process
*/
return false;
}
+
void
-set_pango_fontsize ()
+ARDOUR_UI_UTILS::set_pango_fontsize ()
{
long val = ARDOUR::Config->get_font_scale();
}
void
-reset_dpi ()
+ARDOUR_UI_UTILS::reset_dpi ()
{
long val = ARDOUR::Config->get_font_scale();
set_pango_fontsize ();
}
void
-resize_window_to_proportion_of_monitor (Gtk::Window* window, int max_width, int max_height)
+ARDOUR_UI_UTILS::resize_window_to_proportion_of_monitor (Gtk::Window* window, int max_width, int max_height)
{
Glib::RefPtr<Gdk::Screen> screen = window->get_screen ();
Gdk::Rectangle monitor_rect;
/** Replace _ with __ in a string; for use with menu item text to make underscores displayed correctly */
string
-escape_underscores (string const & s)
+ARDOUR_UI_UTILS::escape_underscores (string const & s)
{
string o;
string::size_type const N = s.length ();
/** Replace < and > with < and > respectively to make < > display correctly in markup strings */
string
-escape_angled_brackets (string const & s)
+ARDOUR_UI_UTILS::escape_angled_brackets (string const & s)
{
string o = s;
boost::replace_all (o, "<", "<");
}
Gdk::Color
-unique_random_color (list<Gdk::Color>& used_colors)
+ARDOUR_UI_UTILS::unique_random_color (list<Gdk::Color>& used_colors)
{
Gdk::Color newcolor;
}
string
-rate_as_string (float r)
+ARDOUR_UI_UTILS::rate_as_string (float r)
{
char buf[32];
if (fmod (r, 1000.0f)) {
}
return buf;
}
+
+
+string
+ARDOUR_UI_UTILS::track_number_to_string (
+ int64_t tracknumber,
+ std::string sep,
+ std::string postfix
+ )
+{
+ string rv;
+ if (tracknumber > 0) {
+ rv = "<span weight=\"bold\" font_family=\"ArdourMono, Mono\">";
+ rv += PBD::to_string (tracknumber, std::dec);
+ rv += "</span>";
+ rv += sep;
+ }
+ else if (tracknumber < 0) {
+ rv = "<span weight=\"bold\" font_family=\"ArdourMono, Mono\">";
+ rv += PBD::to_string (-tracknumber, std::dec);
+ rv += "</span>";
+ rv += sep;
+ }
+ rv += Glib::Markup::escape_text(postfix);
+ return rv;
+}