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(),
77 if (ext.width > _longest_channel_name) {
78 _longest_channel_name = ext.width;
80 if (ext.height > _highest_text) {
81 _highest_text = ext.height;
85 _width += group_size (*i) * grid_spacing ();
87 cairo_text_extents_t ext;
88 cairo_text_extents (cr, (*i)->name.c_str(), &ext);
89 if (ext.height > _highest_group_name) {
90 _highest_group_name = ext.height;
95 gdk_pixmap_unref (pm);
97 /* height of the whole thing */
99 int a = _longest_bundle_name + 4 * name_pad();
100 if (!_matrix->show_only_bundles()) {
101 a += _longest_channel_name;
104 double const parallelogram_height = a * sin (angle()) + _highest_text * cos (angle());
106 _height = parallelogram_height + _highest_group_name + 2 * name_pad();
108 _overhang = parallelogram_height / tan (angle ());
113 PortMatrixColumnLabels::basic_text_x_pos (int c) const
115 return grid_spacing() / 2 +
116 _highest_text / (2 * sin (angle ()));
120 PortMatrixColumnLabels::render (cairo_t* cr)
124 set_source_rgb (cr, background_colour());
125 cairo_rectangle (cr, 0, 0, _width, _height);
128 /* PORT GROUP NAME */
133 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
134 x = slanted_height() / tan (angle());
135 y = _highest_group_name + name_pad();
138 y = _height - name_pad();
142 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
144 /* compute width of this group */
146 if (!(*i)->visible()) {
149 if (_matrix->show_only_bundles()) {
150 w = (*i)->bundles().size() * grid_spacing();
152 w = (*i)->total_channels() * grid_spacing();
161 set_source_rgb (cr, get_a_group_colour (g));
162 double const rh = _highest_group_name + 2 * name_pad();
163 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
164 cairo_rectangle (cr, x, 0, w, rh);
166 cairo_rectangle (cr, x, _height - rh, w, rh);
170 string const upper = Glib::ustring ((*i)->name).uppercase ();
171 pair<string, double> const display = fit_to_pixels (cr, upper, w);
174 set_source_rgb (cr, text_colour());
175 cairo_move_to (cr, x + (w - display.second) / 2, y);
176 cairo_show_text (cr, display.first.c_str());
183 /* BUNDLE PARALLELOGRAM-TYPE-THING AND NAME */
188 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
190 if ((*i)->visible ()) {
192 PortGroup::BundleList const & bundles = (*i)->bundles ();
193 for (PortGroup::BundleList::const_iterator j = bundles.begin (); j != bundles.end(); ++j) {
195 Gdk::Color c = j->has_colour ? j->colour : get_a_bundle_colour (N);
196 render_bundle_name (cr, background_colour (), c, x, 0, j->bundle);
198 if (_matrix->show_only_bundles()) {
201 x += j->bundle->nchannels () * grid_spacing();
209 x += grid_spacing ();
217 if (!_matrix->show_only_bundles()) {
220 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
222 if ((*i)->visible ()) {
224 PortGroup::BundleList const & bundles = (*i)->bundles ();
225 for (PortGroup::BundleList::const_iterator j = bundles.begin (); j != bundles.end(); ++j) {
227 for (uint32_t k = 0; k < j->bundle->nchannels(); ++k) {
228 Gdk::Color c = j->has_colour ? j->colour : get_a_bundle_colour (N);
229 render_channel_name (cr, background_colour (), c, x, 0, ARDOUR::BundleChannel (j->bundle, k));
238 x += grid_spacing ();
246 PortMatrixColumnLabels::component_to_parent_x (double x) const
248 return x - _body->xoffset() + _parent_rectangle.get_x();
252 PortMatrixColumnLabels::parent_to_component_x (double x) const
254 return x + _body->xoffset() - _parent_rectangle.get_x();
258 PortMatrixColumnLabels::component_to_parent_y (double y) const
260 return y + _parent_rectangle.get_y();
264 PortMatrixColumnLabels::parent_to_component_y (double y) const
266 return y - _parent_rectangle.get_y();
270 PortMatrixColumnLabels::mouseover_changed (PortMatrixNode const &)
272 clear_channel_highlights ();
273 if (_body->mouseover().column.bundle && _body->mouseover().row.bundle) {
274 add_channel_highlight (_body->mouseover().column);
278 vector<pair<double, double> >
279 PortMatrixColumnLabels::port_name_shape (double xoff, double yoff) const
281 vector<pair<double, double> > shape;
283 double const lc = _longest_channel_name + name_pad();
284 double const w = grid_spacing();
286 if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
288 double x_ = xoff + slanted_height() / tan (angle()) + w;
290 shape.push_back (make_pair (x_, y_));
292 shape.push_back (make_pair (x_, y_));
293 x_ -= lc * cos (angle());
294 y_ += lc * sin (angle());
295 shape.push_back (make_pair (x_, y_));
296 x_ += w * pow (sin (angle()), 2);
297 y_ += w * sin (angle()) * cos (angle());
298 shape.push_back (make_pair (x_, y_));
303 double y_ = yoff + _height;
304 shape.push_back (make_pair (x_, y_));
306 shape.push_back (make_pair (x_, y_));
307 x_ += lc * cos (angle());
308 y_ -= lc * sin (angle());
309 shape.push_back (make_pair (x_, y_));
310 x_ -= grid_spacing() * pow (sin (angle()), 2);
311 y_ -= grid_spacing() * sin (angle()) * cos (angle());
312 shape.push_back (make_pair (x_, y_));
319 PortMatrixColumnLabels::render_bundle_name (
320 cairo_t* cr, Gdk::Color fg_colour, Gdk::Color bg_colour, double xoff, double yoff, boost::shared_ptr<ARDOUR::Bundle> b
323 set_source_rgb (cr, bg_colour);
326 if (_matrix->show_only_bundles()) {
329 w = b->nchannels() * grid_spacing();
335 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
338 y += slanted_height();
342 cairo_move_to (cr, x_, y_);
344 cairo_line_to (cr, x_, y_);
345 x_ += slanted_height() / tan (angle ());
346 y_ -= slanted_height();
347 cairo_line_to (cr, x_, y_);
349 cairo_line_to (cr, x_, y_);
350 cairo_line_to (cr, xoff, y);
351 cairo_fill_preserve (cr);
352 set_source_rgb (cr, fg_colour);
353 cairo_set_line_width (cr, label_border_width());
356 set_source_rgb (cr, text_colour());
358 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
361 if (_matrix->show_only_bundles()) {
364 rl = 3 * name_pad() + _longest_channel_name;
368 xoff + basic_text_x_pos (0) + rl * cos (angle()),
369 yoff + _height - rl * sin (angle())
376 xoff + basic_text_x_pos (0),
377 yoff + slanted_height() - name_pad() * sin (angle())
382 cairo_rotate (cr, -angle());
383 cairo_show_text (cr, b->name().c_str());
388 PortMatrixColumnLabels::render_channel_name (
389 cairo_t* cr, Gdk::Color fg_colour, Gdk::Color bg_colour, double xoff, double yoff, ARDOUR::BundleChannel const &bc
392 vector<pair<double, double> > const shape = port_name_shape (xoff, yoff);
394 cairo_move_to (cr, shape[0].first, shape[0].second);
395 for (uint32_t i = 1; i < 4; ++i) {
396 cairo_line_to (cr, shape[i].first, shape[i].second);
398 cairo_line_to (cr, shape[0].first, shape[0].second);
400 set_source_rgb (cr, bg_colour);
401 cairo_fill_preserve (cr);
402 set_source_rgb (cr, fg_colour);
403 cairo_set_line_width (cr, label_border_width());
406 set_source_rgb (cr, text_colour());
408 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
412 xoff + basic_text_x_pos(bc.channel),
413 yoff + _height - name_pad() * sin (angle())
418 double const rl = 3 * name_pad() + _longest_bundle_name;
421 xoff + basic_text_x_pos(bc.channel) + rl * cos (angle ()),
422 yoff + slanted_height() - rl * sin (angle())
427 cairo_rotate (cr, -angle());
431 bc.bundle->channel_name(bc.channel).c_str()
438 PortMatrixColumnLabels::channel_x (ARDOUR::BundleChannel const &bc) const
440 return channel_to_position (bc, _matrix->columns()) * grid_spacing ();
444 PortMatrixColumnLabels::channel_y (ARDOUR::BundleChannel const &bc) const
450 PortMatrixColumnLabels::queue_draw_for (ARDOUR::BundleChannel const & bc)
456 if (_matrix->show_only_bundles()) {
458 _body->queue_draw_area (
459 component_to_parent_x (channel_x (bc)) - 1,
460 component_to_parent_y (0) - 1,
461 grid_spacing() + _height * tan (angle()) + 2,
467 double const x = channel_x (bc);
468 double const lc = _longest_channel_name + name_pad();
469 double const h = lc * sin (angle ()) + grid_spacing() * sin (angle()) * cos (angle());
471 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
473 _body->queue_draw_area (
474 component_to_parent_x (x) - 1,
475 component_to_parent_y (_height - h) - 1,
476 grid_spacing() + lc * cos (angle()) + 2,
480 } else if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
482 double const x_ = x + slanted_height() / tan (angle()) - lc * cos (angle());
484 _body->queue_draw_area (
485 component_to_parent_x (x_) - 1,
486 component_to_parent_y (0) - 1,
487 grid_spacing() + lc * cos (angle()) + 2,
497 PortMatrixColumnLabels::button_press (double x, double y, int b, uint32_t t)
500 uint32_t const gh = _highest_group_name + 2 * name_pad();
502 bool group_name = false;
503 if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
504 if (y > (_height - gh)) {
508 cx = x - (_height - gh - y) * tan (angle ());
515 cx = x - (_height - y) * tan (angle ());
519 pair<boost::shared_ptr<PortGroup>, ARDOUR::BundleChannel> gc = position_to_group_and_channel (cx / grid_spacing(), _matrix->columns());
523 if (group_name && gc.first) {
524 gc.first->set_visible (!gc.first->visible ());
525 } else if (gc.second.bundle) {
526 _body->highlight_associated_channels (_matrix->column_index(), gc.second);
531 _matrix->popup_menu (
533 make_pair (boost::shared_ptr<PortGroup> (), ARDOUR::BundleChannel ()),