From 8496f57fd49f1fd74d2c8662a91088374fb662ba Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 12 Nov 2010 22:51:54 +0000 Subject: Prevent marker labels overlapping. Fixes #3535. git-svn-id: svn://localhost/ardour2/branches/3.0@8015 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/marker.cc | 68 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) (limited to 'gtk2_ardour/marker.cc') diff --git a/gtk2_ardour/marker.cc b/gtk2_ardour/marker.cc index 466613b56f..8a73d5f385 100644 --- a/gtk2_ardour/marker.cc +++ b/gtk2_ardour/marker.cc @@ -56,6 +56,9 @@ Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, ArdourCanvas::Gro , _line_shown (false) , _canvas_height (0) , _color (rgba) + , _left_label_limit (DBL_MAX) + , _right_label_limit (DBL_MAX) + { double label_offset = 0; @@ -355,13 +358,40 @@ Marker::the_item() const void Marker::set_name (const string& new_name) { - int name_width = pixel_width (new_name, *name_font) + 2; + _name = new_name; + + setup_name_pixbuf (); +} + +/** @return true if our label is on the left of the mark, otherwise false */ +bool +Marker::label_on_left () const +{ + return (_type == SessionEnd || _type == RangeEnd || _type == LoopEnd || _type == PunchOut); +} + +void +Marker::setup_name_pixbuf () +{ + double limit = DBL_MAX; + + if (label_on_left ()) { + limit = _left_label_limit; + } else { + limit = _right_label_limit; + } - name_pixbuf->property_pixbuf() = pixbuf_from_string(new_name, name_font, name_width, name_height, Gdk::Color ("#000000")); + /* Work out how wide the name can be */ + int name_width = min ((double) pixel_width (_name, *name_font) + 2, limit); + if (name_width == 0) { + name_width = 1; + } - if (_type == SessionEnd || _type == RangeEnd || _type == LoopEnd || _type == PunchOut) { - name_pixbuf->property_x() = - (name_width); + if (label_on_left ()) { + name_pixbuf->property_x() = -name_width; } + + name_pixbuf->property_pixbuf() = pixbuf_from_string (_name, name_font, name_width, name_height, Gdk::Color ("#000000")); } void @@ -420,6 +450,36 @@ Marker::set_color_rgba (uint32_t c) } } +/** Set the number of pixels that are available for a label to the left of the centre of this marker */ +void +Marker::set_left_label_limit (double p) +{ + /* Account for the size of the marker */ + _left_label_limit = p - 13; + if (_left_label_limit < 0) { + _left_label_limit = 0; + } + + if (label_on_left ()) { + setup_name_pixbuf (); + } +} + +/** Set the number of pixels that are available for a label to the right of the centre of this marker */ +void +Marker::set_right_label_limit (double p) +{ + /* Account for the size of the marker */ + _right_label_limit = p - 13; + if (_right_label_limit < 0) { + _right_label_limit = 0; + } + + if (!label_on_left ()) { + setup_name_pixbuf (); + } +} + /***********************************************************************/ TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Group& parent, ArdourCanvas::Group& line_parent, guint32 rgba, const string& text, -- cgit v1.2.3