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 */
52 _highest_group_name = 0;
54 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
55 PortGroup::BundleList const c = _matrix->columns()->bundles();
56 for (PortGroup::BundleList::const_iterator j = c.begin (); j != c.end(); ++j) {
58 cairo_text_extents_t ext;
59 cairo_text_extents (cr, j->bundle->name().c_str(), &ext);
60 if (ext.width > _longest_bundle_name) {
61 _longest_bundle_name = ext.width;
64 if (ext.height > _highest_text) {
65 _highest_text = ext.height;
68 for (uint32_t k = 0; k < j->bundle->nchannels (); ++k) {
72 j->bundle->channel_name (k).c_str(),
76 if (ext.width > _longest_channel_name) {
77 _longest_channel_name = ext.width;
80 if (ext.height > _highest_text) {
81 _highest_text = ext.height;
86 _width += group_size (*i) * grid_spacing ();
88 cairo_text_extents_t ext;
89 cairo_text_extents (cr, (*i)->name.c_str(), &ext);
90 if (ext.height > _highest_group_name) {
91 _highest_group_name = ext.height;
96 gdk_pixmap_unref (pm);
98 /* height of the whole thing */
100 int a = _longest_bundle_name + 4 * name_pad();
101 if (!_matrix->show_only_bundles()) {
102 a += _longest_channel_name;
105 double const parallelogram_height = a * sin (angle()) + _highest_text * cos (angle());
107 _height = parallelogram_height + _highest_group_name + 2 * name_pad();
109 _overhang = parallelogram_height / tan (angle ());
114 PortMatrixColumnLabels::basic_text_x_pos (int) const
116 return grid_spacing() / 2 +
117 _highest_text / (2 * sin (angle ()));
121 PortMatrixColumnLabels::render (cairo_t* cr)
125 set_source_rgb (cr, background_colour());
126 cairo_rectangle (cr, 0, 0, _width, _height);
129 /* PORT GROUP NAME */
134 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
135 x = slanted_height() / tan (angle());
136 y = _highest_group_name + name_pad();
139 y = _height - name_pad();
143 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
145 /* compute width of this group */
147 if (!(*i)->visible()) {
150 if (_matrix->show_only_bundles()) {
151 w = (*i)->bundles().size() * grid_spacing();
153 w = (*i)->total_channels() * grid_spacing();
162 set_source_rgb (cr, get_a_group_colour (g));
163 double const rh = _highest_group_name + 2 * name_pad();
164 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
165 cairo_rectangle (cr, x, 0, w, rh);
167 cairo_rectangle (cr, x, _height - rh, w, rh);
171 string const upper = Glib::ustring ((*i)->name).uppercase ();
172 pair<string, double> const display = fit_to_pixels (cr, upper, w);
175 set_source_rgb (cr, text_colour());
176 cairo_move_to (cr, x + (w - display.second) / 2, y);
177 cairo_show_text (cr, display.first.c_str());
184 /* BUNDLE PARALLELOGRAM-TYPE-THING AND NAME */
189 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
191 if ((*i)->visible ()) {
193 PortGroup::BundleList const & bundles = (*i)->bundles ();
194 for (PortGroup::BundleList::const_iterator j = bundles.begin (); j != bundles.end(); ++j) {
196 Gdk::Color c = j->has_colour ? j->colour : get_a_bundle_colour (N);
197 render_bundle_name (cr, background_colour (), c, x, 0, j->bundle);
199 if (_matrix->show_only_bundles()) {
202 x += j->bundle->nchannels () * grid_spacing();
210 x += grid_spacing ();
218 if (!_matrix->show_only_bundles()) {
221 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
223 if ((*i)->visible ()) {
225 PortGroup::BundleList const & bundles = (*i)->bundles ();
226 for (PortGroup::BundleList::const_iterator j = bundles.begin (); j != bundles.end(); ++j) {
228 for (uint32_t k = 0; k < j->bundle->nchannels(); ++k) {
229 Gdk::Color c = j->has_colour ? j->colour : get_a_bundle_colour (N);
230 render_channel_name (cr, background_colour (), c, x, 0, ARDOUR::BundleChannel (j->bundle, k));
239 x += grid_spacing ();
247 PortMatrixColumnLabels::component_to_parent_x (double x) const
249 return x - _body->xoffset() + _parent_rectangle.get_x();
253 PortMatrixColumnLabels::parent_to_component_x (double x) const
255 return x + _body->xoffset() - _parent_rectangle.get_x();
259 PortMatrixColumnLabels::component_to_parent_y (double y) const
261 return y + _parent_rectangle.get_y();
265 PortMatrixColumnLabels::parent_to_component_y (double y) const
267 return y - _parent_rectangle.get_y();
271 PortMatrixColumnLabels::mouseover_changed (PortMatrixNode const &)
273 clear_channel_highlights ();
274 if (_body->mouseover().column.bundle && _body->mouseover().row.bundle) {
275 add_channel_highlight (_body->mouseover().column);
279 vector<pair<double, double> >
280 PortMatrixColumnLabels::port_name_shape (double xoff, double yoff) const
282 vector<pair<double, double> > shape;
284 double const lc = _longest_channel_name + name_pad();
285 double const w = grid_spacing();
287 if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
289 double x_ = xoff + slanted_height() / tan (angle()) + w;
291 shape.push_back (make_pair (x_, y_));
293 shape.push_back (make_pair (x_, y_));
294 x_ -= lc * cos (angle());
295 y_ += lc * sin (angle());
296 shape.push_back (make_pair (x_, y_));
297 x_ += w * pow (sin (angle()), 2);
298 y_ += w * sin (angle()) * cos (angle());
299 shape.push_back (make_pair (x_, y_));
304 double y_ = yoff + _height;
305 shape.push_back (make_pair (x_, y_));
307 shape.push_back (make_pair (x_, y_));
308 x_ += lc * cos (angle());
309 y_ -= lc * sin (angle());
310 shape.push_back (make_pair (x_, y_));
311 x_ -= grid_spacing() * pow (sin (angle()), 2);
312 y_ -= grid_spacing() * sin (angle()) * cos (angle());
313 shape.push_back (make_pair (x_, y_));
320 PortMatrixColumnLabels::render_bundle_name (
321 cairo_t* cr, Gdk::Color fg_colour, Gdk::Color bg_colour, double xoff, double yoff, boost::shared_ptr<ARDOUR::Bundle> b
324 set_source_rgb (cr, bg_colour);
327 if (_matrix->show_only_bundles()) {
330 w = b->nchannels() * grid_spacing();
336 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
339 y += slanted_height();
343 cairo_move_to (cr, x_, y_);
345 cairo_line_to (cr, x_, y_);
346 x_ += slanted_height() / tan (angle ());
347 y_ -= slanted_height();
348 cairo_line_to (cr, x_, y_);
350 cairo_line_to (cr, x_, y_);
351 cairo_line_to (cr, xoff, y);
352 cairo_fill_preserve (cr);
353 set_source_rgb (cr, fg_colour);
354 cairo_set_line_width (cr, label_border_width());
357 set_source_rgb (cr, text_colour());
359 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
362 if (_matrix->show_only_bundles()) {
365 rl = 3 * name_pad() + _longest_channel_name;
369 xoff + basic_text_x_pos (0) + rl * cos (angle()),
370 yoff + _height - rl * sin (angle())
377 xoff + basic_text_x_pos (0),
378 yoff + slanted_height() - name_pad() * sin (angle())
383 cairo_rotate (cr, -angle());
384 cairo_show_text (cr, b->name().c_str());
389 PortMatrixColumnLabels::render_channel_name (
390 cairo_t* cr, Gdk::Color fg_colour, Gdk::Color bg_colour, double xoff, double yoff, ARDOUR::BundleChannel const &bc
393 vector<pair<double, double> > const shape = port_name_shape (xoff, yoff);
395 cairo_move_to (cr, shape[0].first, shape[0].second);
396 for (uint32_t i = 1; i < 4; ++i) {
397 cairo_line_to (cr, shape[i].first, shape[i].second);
399 cairo_line_to (cr, shape[0].first, shape[0].second);
401 set_source_rgb (cr, bg_colour);
402 cairo_fill_preserve (cr);
403 set_source_rgb (cr, fg_colour);
404 cairo_set_line_width (cr, label_border_width());
407 set_source_rgb (cr, text_colour());
409 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
413 xoff + basic_text_x_pos(bc.channel),
414 yoff + _height - name_pad() * sin (angle())
419 double const rl = 3 * name_pad() + _longest_bundle_name;
422 xoff + basic_text_x_pos(bc.channel) + rl * cos (angle ()),
423 yoff + slanted_height() - rl * sin (angle())
428 cairo_rotate (cr, -angle());
432 bc.bundle->channel_name(bc.channel).c_str()
439 PortMatrixColumnLabels::channel_x (ARDOUR::BundleChannel const &bc) const
441 return channel_to_position (bc, _matrix->columns()) * grid_spacing ();
445 PortMatrixColumnLabels::channel_y (ARDOUR::BundleChannel const &) const
451 PortMatrixColumnLabels::queue_draw_for (ARDOUR::BundleChannel const & bc)
457 if (_matrix->show_only_bundles()) {
459 _body->queue_draw_area (
460 component_to_parent_x (channel_x (bc)) - 1,
461 component_to_parent_y (0) - 1,
462 grid_spacing() + _height * tan (angle()) + 2,
468 double const x = channel_x (bc);
469 double const lc = _longest_channel_name + name_pad();
470 double const h = lc * sin (angle ()) + grid_spacing() * sin (angle()) * cos (angle());
472 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
474 _body->queue_draw_area (
475 component_to_parent_x (x) - 1,
476 component_to_parent_y (_height - h) - 1,
477 grid_spacing() + lc * cos (angle()) + 2,
481 } else if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
483 double const x_ = x + slanted_height() / tan (angle()) - lc * cos (angle());
485 _body->queue_draw_area (
486 component_to_parent_x (x_) - 1,
487 component_to_parent_y (0) - 1,
488 grid_spacing() + lc * cos (angle()) + 2,
498 PortMatrixColumnLabels::button_press (double x, double y, int b, uint32_t t)
501 uint32_t const gh = _highest_group_name + 2 * name_pad();
503 bool group_name = false;
504 if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
505 if (y > (_height - gh)) {
509 cx = x - (_height - gh - y) * tan (angle ());
516 cx = x - (_height - y) * tan (angle ());
520 pair<boost::shared_ptr<PortGroup>, ARDOUR::BundleChannel> gc = position_to_group_and_channel (cx / grid_spacing(), _matrix->columns());
524 if (group_name && gc.first) {
525 gc.first->set_visible (!gc.first->visible ());
526 } else if (gc.second.bundle) {
527 _body->highlight_associated_channels (_matrix->column_index(), gc.second);
532 _matrix->popup_menu (
534 make_pair (boost::shared_ptr<PortGroup> (), ARDOUR::BundleChannel ()),