Keep port matrix group labels on screen where possible.

git-svn-id: svn://localhost/ardour2/branches/3.0@6082 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2009-11-14 11:50:01 +00:00
parent 67601c6c50
commit 9dbecd0fa1
5 changed files with 135 additions and 109 deletions

View 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;
}
}

View 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;

View 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 &);

View 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;
}
}

View 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 &);