Keep port matrix group labels on screen where possible.
authorCarl Hetherington <carl@carlh.net>
Sat, 14 Nov 2009 11:50:01 +0000 (11:50 +0000)
committerCarl Hetherington <carl@carlh.net>
Sat, 14 Nov 2009 11:50:01 +0000 (11:50 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@6082 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/port_matrix_column_labels.cc
gtk2_ardour/port_matrix_column_labels.h
gtk2_ardour/port_matrix_labels.h
gtk2_ardour/port_matrix_row_labels.cc
gtk2_ardour/port_matrix_row_labels.h

index dfa14f1d89835fac21b068a9df3c52b3537765c1..5dcb710e7e83b0764f63a74b359f72abb322642c 100644 (file)
@@ -126,64 +126,9 @@ PortMatrixColumnLabels::render (cairo_t* cr)
        cairo_rectangle (cr, 0, 0, _width, _height);
        cairo_fill (cr);
 
-       /* PORT GROUP NAME */
-
-       double x = 0;
-       double y = 0;
-
-       if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
-               x = slanted_height() / tan (angle());
-               y = _highest_group_name + name_pad();
-       } else {
-               x = 0;
-               y = _height - name_pad();
-       }
-
-       int g = 0;
-       for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
-
-               /* compute width of this group */
-               uint32_t w = 0;
-               if (!(*i)->visible()) {
-                       w = grid_spacing ();
-               } else {
-                       if (_matrix->show_only_bundles()) {
-                               w = (*i)->bundles().size() * grid_spacing();
-                       } else {
-                               w = (*i)->total_channels() * grid_spacing();
-                       }
-               }
-
-               if (w == 0) {
-                       continue;
-               }
-
-               /* rectangle */
-               set_source_rgb (cr, get_a_group_colour (g));
-               double const rh = _highest_group_name + 2 * name_pad();
-               if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
-                       cairo_rectangle (cr, x, 0, w, rh);
-               } else {
-                       cairo_rectangle (cr, x, _height - rh, w, rh);
-               }
-               cairo_fill (cr);
-
-               string const upper = Glib::ustring ((*i)->name).uppercase ();
-               pair<string, double> const display = fit_to_pixels (cr, upper, w);
-
-               /* plot it */
-               set_source_rgb (cr, text_colour());
-               cairo_move_to (cr, x + (w - display.second) / 2, y);
-               cairo_show_text (cr, display.first.c_str());
-
-               x += w;
-               ++g;
-
-       }
-
         /* BUNDLE PARALLELOGRAM-TYPE-THING AND NAME */
 
-       x = 0;
+       double x = 0;
        int N = 0;
 
        for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
@@ -258,12 +203,14 @@ PortMatrixColumnLabels::parent_to_component_x (double x) const
 double
 PortMatrixColumnLabels::component_to_parent_y (double y) const
 {
+       /* Column labels don't scroll vertically, so y conversion does not depend on yoffset */
        return y + _parent_rectangle.get_y();
 }
 
 double
 PortMatrixColumnLabels::parent_to_component_y (double y) const
 {
+       /* Column labels don't scroll vertically, so y conversion does not depend on yoffset */
        return y - _parent_rectangle.get_y();
 }
 
@@ -543,3 +490,68 @@ PortMatrixColumnLabels::button_press (double x, double y, int b, uint32_t t)
        }
 }
 
+void
+PortMatrixColumnLabels::draw_extra (cairo_t* cr)
+{
+       PortMatrixLabels::draw_extra (cr);
+
+       /* PORT GROUP NAME */
+       
+       double x = 0;
+       double y = 0;
+
+       if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
+               x = component_to_parent_x (slanted_height() / tan (angle()));
+               y = component_to_parent_y ( _highest_group_name + name_pad());
+       } else {
+               x = component_to_parent_x (0);
+               y = component_to_parent_y (_height - name_pad());
+       }
+
+       int g = 0;
+       for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
+
+               /* compute width of this group */
+               uint32_t w = 0;
+               if (!(*i)->visible()) {
+                       w = grid_spacing ();
+               } else {
+                       if (_matrix->show_only_bundles()) {
+                               w = (*i)->bundles().size() * grid_spacing();
+                       } else {
+                               w = (*i)->total_channels() * grid_spacing();
+                       }
+               }
+
+               if (w == 0) {
+                       continue;
+               }
+
+               /* rectangle */
+               set_source_rgb (cr, get_a_group_colour (g));
+               double const rh = _highest_group_name + 2 * name_pad();
+               if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
+                       cairo_rectangle (cr, x, component_to_parent_y (0), w, rh);
+               } else {
+                       cairo_rectangle (cr, x, component_to_parent_y (_height - rh), w, rh);
+               }
+               cairo_fill (cr);
+
+               /* x area available to draw the label in (trying to keep it visible) */
+               double const lx = max (x, double (_parent_rectangle.get_x ()));
+               double const rx = min (x + w, double (_parent_rectangle.get_width()));
+
+               /* hence what abbreviation (or not) we need for the group name */
+               string const upper = Glib::ustring ((*i)->name).uppercase ();
+               pair<string, double> const display = fit_to_pixels (cr, upper, rx - lx);
+
+               /* plot it */
+               set_source_rgb (cr, text_colour());
+               cairo_move_to (cr, (lx + rx - display.second) / 2, y);
+               cairo_show_text (cr, display.first.c_str());
+
+               x += w;
+               ++g;
+
+       }
+}
index 3b1c5a128c40b745676cfc646bcb6ab507180fc3..5923bac4fc0f6b77f02efcf388900b6c36cfb386 100644 (file)
@@ -43,6 +43,7 @@ public:
        double component_to_parent_y (double y) const;
        double parent_to_component_y (double y) const;
        void mouseover_changed (PortMatrixNode const &);
+       void draw_extra (cairo_t *);
 
        uint32_t overhang () const {
                return _overhang;
index a977662e805dc1045d99d3756c68e1181b565c11..21dcf9de231cc5a7e7bb3cf0ad2129a886425cb6 100644 (file)
@@ -32,7 +32,7 @@ public:
        PortMatrixLabels (PortMatrix* m, PortMatrixBody* b) : PortMatrixComponent (m, b) {}
        virtual ~PortMatrixLabels () {}
 
-       void draw_extra (cairo_t *);
+       virtual void draw_extra (cairo_t *);
 
        void clear_channel_highlights ();
        void add_channel_highlight (ARDOUR::BundleChannel const &);
index e9dd59b695581546f849ee7bb9d10514b0bc300b..fdeaba77b61a66dd190229b242b3c23a3c6c14e6 100644 (file)
@@ -99,60 +99,9 @@ PortMatrixRowLabels::render (cairo_t* cr)
        cairo_rectangle (cr, 0, 0, _width, _height);
        cairo_fill (cr);
 
-       /* PORT GROUP NAMES */
-
-       double x = 0;
-       if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
-               x = 0;
-       } else {
-               x = _width - _highest_group_name - 2 * name_pad();
-       }
-
-       double y = 0;
-       int g = 0;
-       for (PortGroupList::List::const_iterator i = _matrix->rows()->begin(); i != _matrix->rows()->end(); ++i) {
-
-               /* compute height of this group */
-               double h = 0;
-               if (!(*i)->visible()) {
-                       h = grid_spacing ();
-               } else {
-                       if (_matrix->show_only_bundles()) {
-                               h = (*i)->bundles().size() * grid_spacing();
-                       } else {
-                               h = (*i)->total_channels () * grid_spacing();
-                       }
-               }
-
-               if (h == 0) {
-                       continue;
-               }
-
-               /* rectangle */
-               set_source_rgb (cr, get_a_group_colour (g));
-               double const rw = _highest_group_name + 2 * name_pad();
-               cairo_rectangle (cr, x, y, rw, h);
-               cairo_fill (cr);
-
-               /* hence what abbreviation (or not) we need for the group name */
-               string const upper = Glib::ustring ((*i)->name).uppercase ();
-               pair<string, double> display = fit_to_pixels (cr, upper, h);
-
-               /* plot it */
-               set_source_rgb (cr, text_colour());
-               cairo_move_to (cr, x + rw - name_pad(), y + (h + display.second) / 2);
-               cairo_save (cr);
-               cairo_rotate (cr, - M_PI / 2);
-               cairo_show_text (cr, display.first.c_str());
-               cairo_restore (cr);
-
-               y += h;
-               ++g;
-       }
-
        /* BUNDLE AND PORT NAMES */
 
-       y = 0;
+       double y = 0;
        int N = 0;
        int M = 0;
        for (PortGroupList::List::const_iterator i = _matrix->rows()->begin(); i != _matrix->rows()->end(); ++i) {
@@ -222,12 +171,14 @@ PortMatrixRowLabels::button_press (double x, double y, int b, uint32_t t)
 double
 PortMatrixRowLabels::component_to_parent_x (double x) const
 {
+       /* Row labels don't scroll horizontally, so x conversion does not depend on xoffset */
        return x + _parent_rectangle.get_x();
 }
 
 double
 PortMatrixRowLabels::parent_to_component_x (double x) const
 {
+       /* Row labels don't scroll horizontally, so x conversion does not depend on xoffset */
        return x - _parent_rectangle.get_x();
 }
 
@@ -369,3 +320,64 @@ PortMatrixRowLabels::mouseover_changed (PortMatrixNode const &)
                add_channel_highlight (_body->mouseover().row);
        }
 }
+
+void
+PortMatrixRowLabels::draw_extra (cairo_t* cr)
+{
+       PortMatrixLabels::draw_extra (cr);
+       
+       /* PORT GROUP NAMES */
+
+       double x = 0;
+       if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
+               x = component_to_parent_x (0);
+       } else {
+               x = component_to_parent_x (_width - _highest_group_name - 2 * name_pad());
+       }
+
+       double y = component_to_parent_y (0);
+       int g = 0;
+       for (PortGroupList::List::const_iterator i = _matrix->rows()->begin(); i != _matrix->rows()->end(); ++i) {
+
+               /* compute height of this group */
+               double h = 0;
+               if (!(*i)->visible()) {
+                       h = grid_spacing ();
+               } else {
+                       if (_matrix->show_only_bundles()) {
+                               h = (*i)->bundles().size() * grid_spacing();
+                       } else {
+                               h = (*i)->total_channels () * grid_spacing();
+                       }
+               }
+
+               if (h == 0) {
+                       continue;
+               }
+
+               /* rectangle */
+               set_source_rgb (cr, get_a_group_colour (g));
+               double const rw = _highest_group_name + 2 * name_pad();
+               cairo_rectangle (cr, x, y, rw, h);
+               cairo_fill (cr);
+
+               /* y area available to draw the label in (trying to keep it visible) */
+               double const ty = max (y, 0.0);
+               double const by = min (y + h, double (_body->alloc_scroll_height ()));
+
+               /* hence what abbreviation (or not) we need for the group name */
+               string const upper = Glib::ustring ((*i)->name).uppercase ();
+               pair<string, double> display = fit_to_pixels (cr, upper, by - ty);
+
+               /* plot it */
+               set_source_rgb (cr, text_colour());
+               cairo_move_to (cr, x + rw - name_pad(), (by + ty + display.second) / 2);
+               cairo_save (cr);
+               cairo_rotate (cr, - M_PI / 2);
+               cairo_show_text (cr, display.first.c_str());
+               cairo_restore (cr);
+
+               y += h;
+               ++g;
+       }
+}
index 508d45d943fbcf05c40c9d84f805fe6caf74ce71..13e274727645a6905638c4196af341bced8a6b12 100644 (file)
@@ -50,6 +50,7 @@ public:
        double component_to_parent_y (double y) const;
        double parent_to_component_y (double y) const;
        void mouseover_changed (PortMatrixNode const &);
+       void draw_extra (cairo_t *);
 
 private:
        void render_channel_name (cairo_t *, Gdk::Color, Gdk::Color, double, double, ARDOUR::BundleChannel const &);