2 Copyright (C) 2002-2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "ardour/bundle.h"
22 #include "ardour/types.h"
23 #include "port_matrix_column_labels.h"
24 #include "port_matrix.h"
25 #include "port_matrix_body.h"
30 PortMatrixColumnLabels::PortMatrixColumnLabels (PortMatrix* m, PortMatrixBody* b)
31 : PortMatrixLabels (m, b),
38 PortMatrixColumnLabels::compute_dimensions ()
40 GdkPixmap* pm = gdk_pixmap_new (NULL, 1, 1, 24);
41 gdk_drawable_set_colormap (pm, gdk_colormap_get_system());
42 cairo_t* cr = gdk_cairo_create (pm);
44 /* width of the longest bundle name */
45 _longest_bundle_name = 0;
46 /* width of the longest channel name */
47 _longest_channel_name = 0;
48 /* height of highest bit of text (apart from group names) */
50 /* width of the whole thing */
53 PortGroup::BundleList const c = _matrix->columns()->bundles();
54 for (PortGroup::BundleList::const_iterator i = c.begin (); i != c.end(); ++i) {
56 cairo_text_extents_t ext;
57 cairo_text_extents (cr, i->bundle->name().c_str(), &ext);
58 if (ext.width > _longest_bundle_name) {
59 _longest_bundle_name = ext.width;
61 if (ext.height > _highest_text) {
62 _highest_text = ext.height;
65 for (uint32_t j = 0; j < i->bundle->nchannels (); ++j) {
69 i->bundle->channel_name (j).c_str(),
73 if (ext.width > _longest_channel_name) {
74 _longest_channel_name = ext.width;
76 if (ext.height > _highest_text) {
77 _highest_text = ext.height;
81 if (_matrix->show_only_bundles()) {
82 _width += grid_spacing();
84 _width += i->bundle->nchannels() * grid_spacing();
88 _highest_group_name = 0;
89 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
90 if ((*i)->visible()) {
91 cairo_text_extents_t ext;
92 cairo_text_extents (cr, (*i)->name.c_str(), &ext);
93 if (ext.height > _highest_group_name) {
94 _highest_group_name = ext.height;
97 _width += grid_spacing ();
102 gdk_pixmap_unref (pm);
104 /* height of the whole thing */
106 int a = _longest_bundle_name + 4 * name_pad();
107 if (!_matrix->show_only_bundles()) {
108 a += _longest_channel_name;
111 double const parallelogram_height = a * sin (angle()) + _highest_text * cos (angle());
113 _height = parallelogram_height + _highest_group_name + 2 * name_pad();
115 _overhang = parallelogram_height / tan (angle ());
120 PortMatrixColumnLabels::basic_text_x_pos (int c) const
122 return grid_spacing() / 2 +
123 _highest_text / (2 * sin (angle ()));
127 PortMatrixColumnLabels::render (cairo_t* cr)
131 set_source_rgb (cr, background_colour());
132 cairo_rectangle (cr, 0, 0, _width, _height);
135 /* PORT GROUP NAME */
140 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
141 x = slanted_height() / tan (angle());
142 y = _highest_group_name + name_pad();
145 y = _height - name_pad();
149 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
151 /* compute width of this group */
153 if (!(*i)->visible()) {
156 if (_matrix->show_only_bundles()) {
157 w = (*i)->bundles().size() * grid_spacing();
159 w = (*i)->total_channels() * grid_spacing();
168 set_source_rgb (cr, get_a_group_colour (g));
169 double const rh = _highest_group_name + 2 * name_pad();
170 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
171 cairo_rectangle (cr, x, 0, w, rh);
173 cairo_rectangle (cr, x, _height - rh, w, rh);
177 string const upper = Glib::ustring ((*i)->name).uppercase ();
178 pair<string, double> const display = fit_to_pixels (cr, upper, w);
181 set_source_rgb (cr, text_colour());
182 cairo_move_to (cr, x + (w - display.second) / 2, y);
183 cairo_show_text (cr, display.first.c_str());
190 /* BUNDLE PARALLELOGRAM-TYPE-THING AND NAME */
195 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
197 if ((*i)->visible ()) {
199 PortGroup::BundleList const & bundles = (*i)->bundles ();
200 for (PortGroup::BundleList::const_iterator j = bundles.begin (); j != bundles.end(); ++j) {
202 Gdk::Color c = j->has_colour ? j->colour : get_a_bundle_colour (N);
203 render_bundle_name (cr, c, x, 0, j->bundle);
205 if (_matrix->show_only_bundles()) {
208 x += j->bundle->nchannels () * grid_spacing();
216 x += grid_spacing ();
224 if (!_matrix->show_only_bundles()) {
227 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
229 if ((*i)->visible ()) {
231 PortGroup::BundleList const & bundles = (*i)->bundles ();
232 for (PortGroup::BundleList::const_iterator j = bundles.begin (); j != bundles.end(); ++j) {
234 for (uint32_t k = 0; k < j->bundle->nchannels(); ++k) {
235 Gdk::Color c = j->has_colour ? j->colour : get_a_bundle_colour (N);
236 render_channel_name (cr, c, x, 0, ARDOUR::BundleChannel (j->bundle, k));
245 x += grid_spacing ();
253 PortMatrixColumnLabels::component_to_parent_x (double x) const
255 return x - _body->xoffset() + _parent_rectangle.get_x();
259 PortMatrixColumnLabels::parent_to_component_x (double x) const
261 return x + _body->xoffset() - _parent_rectangle.get_x();
265 PortMatrixColumnLabels::component_to_parent_y (double y) const
267 return y + _parent_rectangle.get_y();
271 PortMatrixColumnLabels::parent_to_component_y (double y) const
273 return y - _parent_rectangle.get_y();
277 PortMatrixColumnLabels::mouseover_changed (PortMatrixNode const &)
279 clear_channel_highlights ();
280 if (_body->mouseover().column.bundle) {
281 add_channel_highlight (_body->mouseover().column);
285 vector<pair<double, double> >
286 PortMatrixColumnLabels::port_name_shape (double xoff, double yoff) const
288 vector<pair<double, double> > shape;
290 double const lc = _longest_channel_name + name_pad();
291 double const w = grid_spacing();
293 if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
295 double x_ = xoff + slanted_height() / tan (angle()) + w;
297 shape.push_back (make_pair (x_, y_));
299 shape.push_back (make_pair (x_, y_));
300 x_ -= lc * cos (angle());
301 y_ += lc * sin (angle());
302 shape.push_back (make_pair (x_, y_));
303 x_ += w * pow (sin (angle()), 2);
304 y_ += w * sin (angle()) * cos (angle());
305 shape.push_back (make_pair (x_, y_));
310 double y_ = yoff + _height;
311 shape.push_back (make_pair (x_, y_));
313 shape.push_back (make_pair (x_, y_));
314 x_ += lc * cos (angle());
315 y_ -= lc * sin (angle());
316 shape.push_back (make_pair (x_, y_));
317 x_ -= grid_spacing() * pow (sin (angle()), 2);
318 y_ -= grid_spacing() * sin (angle()) * cos (angle());
319 shape.push_back (make_pair (x_, y_));
326 PortMatrixColumnLabels::render_bundle_name (
327 cairo_t* cr, Gdk::Color colour, double xoff, double yoff, boost::shared_ptr<ARDOUR::Bundle> b
330 set_source_rgb (cr, colour);
333 if (_matrix->show_only_bundles()) {
336 w = b->nchannels() * grid_spacing();
342 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
345 y += slanted_height();
349 cairo_move_to (cr, x_, y_);
351 cairo_line_to (cr, x_, y_);
352 x_ += slanted_height() / tan (angle ());
353 y_ -= slanted_height();
354 cairo_line_to (cr, x_, y_);
356 cairo_line_to (cr, x_, y_);
357 cairo_line_to (cr, xoff, y);
358 cairo_fill_preserve (cr);
359 set_source_rgb (cr, background_colour());
360 cairo_set_line_width (cr, label_border_width());
363 set_source_rgb (cr, text_colour());
365 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
368 if (_matrix->show_only_bundles()) {
371 rl = 3 * name_pad() + _longest_channel_name;
375 xoff + basic_text_x_pos (0) + rl * cos (angle()),
376 yoff + _height - rl * sin (angle())
383 xoff + basic_text_x_pos (0),
384 yoff + slanted_height() - name_pad() * sin (angle())
389 cairo_rotate (cr, -angle());
390 cairo_show_text (cr, b->name().c_str());
395 PortMatrixColumnLabels::render_channel_name (
396 cairo_t* cr, Gdk::Color colour, double xoff, double yoff, ARDOUR::BundleChannel const &bc
399 vector<pair<double, double> > const shape = port_name_shape (xoff, yoff);
401 cairo_move_to (cr, shape[0].first, shape[0].second);
402 for (uint32_t i = 1; i < 4; ++i) {
403 cairo_line_to (cr, shape[i].first, shape[i].second);
405 cairo_line_to (cr, shape[0].first, shape[0].second);
407 set_source_rgb (cr, colour);
408 cairo_fill_preserve (cr);
409 set_source_rgb (cr, background_colour());
410 cairo_set_line_width (cr, label_border_width());
413 set_source_rgb (cr, text_colour());
415 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
419 xoff + basic_text_x_pos(bc.channel),
420 yoff + _height - name_pad() * sin (angle())
425 double const rl = 3 * name_pad() + _longest_bundle_name;
428 xoff + basic_text_x_pos(bc.channel) + rl * cos (angle ()),
429 yoff + slanted_height() - rl * sin (angle())
434 cairo_rotate (cr, -angle());
438 bc.bundle->channel_name(bc.channel).c_str()
445 PortMatrixColumnLabels::channel_x (ARDOUR::BundleChannel const &bc) const
447 return channel_to_position (bc, _matrix->columns()) * grid_spacing ();
451 PortMatrixColumnLabels::channel_y (ARDOUR::BundleChannel const &bc) const
457 PortMatrixColumnLabels::queue_draw_for (ARDOUR::BundleChannel const & bc)
463 if (_matrix->show_only_bundles()) {
465 _body->queue_draw_area (
466 component_to_parent_x (channel_x (bc)),
467 component_to_parent_y (0),
468 grid_spacing() + _height * tan (angle()),
474 double const x = channel_x (bc);
475 double const lc = _longest_channel_name + name_pad();
476 double const h = lc * sin (angle ()) + grid_spacing() * sin (angle()) * cos (angle());
478 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
480 _body->queue_draw_area (
481 component_to_parent_x (x),
482 component_to_parent_y (_height - h),
483 grid_spacing() + lc * cos (angle()),
487 } else if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
489 double const x_ = x + slanted_height() / tan (angle()) - lc * cos (angle());
491 _body->queue_draw_area (
492 component_to_parent_x (x_),
493 component_to_parent_y (0),
494 grid_spacing() + lc * cos (angle()),
504 PortMatrixColumnLabels::button_press (double x, double y, int b, uint32_t t)
507 uint32_t const gh = _highest_group_name + 2 * name_pad();
509 bool group_name = false;
510 if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
511 if (y > (_height - gh)) {
515 cx = x - (_height - gh - y) * tan (angle ());
522 cx = x - (_height - y) * tan (angle ());
526 pair<boost::shared_ptr<PortGroup>, ARDOUR::BundleChannel> gc = position_to_group_and_channel (cx / grid_spacing(), _matrix->columns());
530 if (group_name && gc.first) {
531 gc.first->set_visible (!gc.first->visible ());
532 } else if (gc.second.bundle) {
533 _body->highlight_associated_channels (_matrix->column_index(), gc.second);
538 _matrix->popup_menu (
540 make_pair (boost::shared_ptr<PortGroup> (), ARDOUR::BundleChannel ()),