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)
37 PortMatrixColumnLabels::compute_dimensions ()
39 GdkPixmap* pm = gdk_pixmap_new (NULL, 1, 1, 24);
40 gdk_drawable_set_colormap (pm, gdk_colormap_get_system());
41 cairo_t* cr = gdk_cairo_create (pm);
43 /* width of the longest bundle name */
44 _longest_bundle_name = 0;
45 /* width of the longest channel name */
46 _longest_channel_name = 0;
47 /* height of highest bit of text (apart from group names) */
49 /* width of the whole thing */
52 PortGroup::BundleList const c = _matrix->columns()->bundles();
53 for (PortGroup::BundleList::const_iterator i = c.begin (); i != c.end(); ++i) {
55 cairo_text_extents_t ext;
56 cairo_text_extents (cr, i->bundle->name().c_str(), &ext);
57 if (ext.width > _longest_bundle_name) {
58 _longest_bundle_name = ext.width;
60 if (ext.height > _highest_text) {
61 _highest_text = ext.height;
64 for (uint32_t j = 0; j < i->bundle->nchannels (); ++j) {
68 i->bundle->channel_name (j).c_str(),
72 if (ext.width > _longest_channel_name) {
73 _longest_channel_name = ext.width;
75 if (ext.height > _highest_text) {
76 _highest_text = ext.height;
80 if (_matrix->show_only_bundles()) {
81 _width += column_width();
83 _width += i->bundle->nchannels() * column_width();
87 _highest_group_name = 0;
88 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
89 if ((*i)->visible()) {
90 cairo_text_extents_t ext;
91 cairo_text_extents (cr, (*i)->name.c_str(), &ext);
92 if (ext.height > _highest_group_name) {
93 _highest_group_name = ext.height;
99 gdk_pixmap_unref (pm);
101 /* height of the whole thing */
103 int a = _longest_bundle_name + 4 * name_pad();
104 if (!_matrix->show_only_bundles()) {
105 a += _longest_channel_name;
108 double const parallelogram_height = a * sin (angle()) + _highest_text * cos (angle());
110 _height = parallelogram_height + _highest_group_name + 2 * name_pad();
112 _width += parallelogram_height / tan (angle ());
116 PortMatrixColumnLabels::basic_text_x_pos (int c) const
118 return column_width() / 2 +
119 _highest_text / (2 * sin (angle ()));
123 PortMatrixColumnLabels::render (cairo_t* cr)
127 set_source_rgb (cr, background_colour());
128 cairo_rectangle (cr, 0, 0, _width, _height);
131 /* PORT GROUP NAME */
136 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
137 x = slanted_height() / tan (angle());
138 y = _highest_group_name + name_pad();
141 y = _height - name_pad();
145 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
147 if (!(*i)->visible() || (*i)->bundles().empty()) {
151 /* compute width of this group */
153 if (_matrix->show_only_bundles()) {
154 w = (*i)->bundles().size() * column_width();
156 w = (*i)->total_channels() * column_width();
160 set_source_rgb (cr, get_a_group_colour (g));
161 double const rh = _highest_group_name + 2 * name_pad();
162 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
163 cairo_rectangle (cr, x, 0, w, rh);
165 cairo_rectangle (cr, x, _height - rh, w, rh);
169 string const upper = Glib::ustring ((*i)->name).uppercase ();
170 pair<string, double> const display = fit_to_pixels (cr, upper, w);
173 set_source_rgb (cr, text_colour());
174 cairo_move_to (cr, x + (w - display.second) / 2, y);
175 cairo_show_text (cr, display.first.c_str());
181 /* BUNDLE PARALLELOGRAM-TYPE-THING AND NAME */
185 PortGroup::BundleList const bundles = _matrix->columns()->bundles();
186 for (PortGroup::BundleList::const_iterator i = bundles.begin (); i != bundles.end(); ++i) {
188 Gdk::Color c = i->has_colour ? i->colour : get_a_bundle_colour (N);
189 render_bundle_name (cr, c, x, 0, i->bundle);
191 if (_matrix->show_only_bundles()) {
194 x += i->bundle->nchannels () * column_width();
203 if (!_matrix->show_only_bundles()) {
206 for (PortGroup::BundleList::const_iterator i = bundles.begin (); i != bundles.end(); ++i) {
208 for (uint32_t j = 0; j < i->bundle->nchannels(); ++j) {
209 Gdk::Color c = i->has_colour ? i->colour : get_a_bundle_colour (N);
210 render_channel_name (cr, c, x, 0, ARDOUR::BundleChannel (i->bundle, j));
220 PortMatrixColumnLabels::component_to_parent_x (double x) const
222 return x - _body->xoffset() + _parent_rectangle.get_x();
226 PortMatrixColumnLabels::parent_to_component_x (double x) const
228 return x + _body->xoffset() - _parent_rectangle.get_x();
232 PortMatrixColumnLabels::component_to_parent_y (double y) const
234 return y + _parent_rectangle.get_y();
238 PortMatrixColumnLabels::parent_to_component_y (double y) const
240 return y - _parent_rectangle.get_y();
244 PortMatrixColumnLabels::mouseover_changed (PortMatrixNode const &)
246 clear_channel_highlights ();
247 if (_body->mouseover().column.bundle) {
248 add_channel_highlight (_body->mouseover().column);
252 vector<pair<double, double> >
253 PortMatrixColumnLabels::port_name_shape (double xoff, double yoff) const
255 vector<pair<double, double> > shape;
257 double const lc = _longest_channel_name + name_pad();
258 double const w = column_width();
260 if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
262 double x_ = xoff + slanted_height() / tan (angle()) + w;
264 shape.push_back (make_pair (x_, y_));
266 shape.push_back (make_pair (x_, y_));
267 x_ -= lc * cos (angle());
268 y_ += lc * sin (angle());
269 shape.push_back (make_pair (x_, y_));
270 x_ += w * pow (sin (angle()), 2);
271 y_ += w * sin (angle()) * cos (angle());
272 shape.push_back (make_pair (x_, y_));
277 double y_ = yoff + _height;
278 shape.push_back (make_pair (x_, y_));
280 shape.push_back (make_pair (x_, y_));
281 x_ += lc * cos (angle());
282 y_ -= lc * sin (angle());
283 shape.push_back (make_pair (x_, y_));
284 x_ -= column_width() * pow (sin (angle()), 2);
285 y_ -= column_width() * sin (angle()) * cos (angle());
286 shape.push_back (make_pair (x_, y_));
293 PortMatrixColumnLabels::render_bundle_name (
294 cairo_t* cr, Gdk::Color colour, double xoff, double yoff, boost::shared_ptr<ARDOUR::Bundle> b
297 set_source_rgb (cr, colour);
300 if (_matrix->show_only_bundles()) {
303 w = b->nchannels() * column_width();
309 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
312 y += slanted_height();
316 cairo_move_to (cr, x_, y_);
318 cairo_line_to (cr, x_, y_);
319 x_ += slanted_height() / tan (angle ());
320 y_ -= slanted_height();
321 cairo_line_to (cr, x_, y_);
323 cairo_line_to (cr, x_, y_);
324 cairo_line_to (cr, xoff, y);
325 cairo_fill_preserve (cr);
326 set_source_rgb (cr, background_colour());
327 cairo_set_line_width (cr, label_border_width());
330 set_source_rgb (cr, text_colour());
332 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
335 if (_matrix->show_only_bundles()) {
338 rl = 3 * name_pad() + _longest_channel_name;
342 xoff + basic_text_x_pos (0) + rl * cos (angle()),
343 yoff + _height - rl * sin (angle())
350 xoff + basic_text_x_pos (0),
351 yoff + slanted_height() - name_pad() * sin (angle())
356 cairo_rotate (cr, -angle());
357 cairo_show_text (cr, b->name().c_str());
362 PortMatrixColumnLabels::render_channel_name (
363 cairo_t* cr, Gdk::Color colour, double xoff, double yoff, ARDOUR::BundleChannel const &bc
366 vector<pair<double, double> > const shape = port_name_shape (xoff, yoff);
368 cairo_move_to (cr, shape[0].first, shape[0].second);
369 for (uint32_t i = 1; i < 4; ++i) {
370 cairo_line_to (cr, shape[i].first, shape[i].second);
372 cairo_line_to (cr, shape[0].first, shape[0].second);
374 set_source_rgb (cr, colour);
375 cairo_fill_preserve (cr);
376 set_source_rgb (cr, background_colour());
377 cairo_set_line_width (cr, label_border_width());
380 set_source_rgb (cr, text_colour());
382 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
386 xoff + basic_text_x_pos(bc.channel),
387 yoff + _height - name_pad() * sin (angle())
392 double const rl = 3 * name_pad() + _longest_bundle_name;
395 xoff + basic_text_x_pos(bc.channel) + rl * cos (angle ()),
396 yoff + slanted_height() - rl * sin (angle())
401 cairo_rotate (cr, -angle());
405 bc.bundle->channel_name(bc.channel).c_str()
412 PortMatrixColumnLabels::channel_x (ARDOUR::BundleChannel const &bc) const
416 PortGroup::BundleList::const_iterator i = _matrix->columns()->bundles().begin();
417 while (i != _matrix->columns()->bundles().end() && i->bundle != bc.bundle) {
418 if (_matrix->show_only_bundles()) {
421 n += i->bundle->nchannels ();
426 if (!_matrix->show_only_bundles()) {
430 return n * column_width();
434 PortMatrixColumnLabels::channel_y (ARDOUR::BundleChannel const &bc) const
440 PortMatrixColumnLabels::queue_draw_for (ARDOUR::BundleChannel const & bc)
446 if (_matrix->show_only_bundles()) {
448 _body->queue_draw_area (
449 component_to_parent_x (channel_x (bc)),
450 component_to_parent_y (0),
451 column_width() + _height * tan (angle()),
457 double const x = channel_x (bc);
458 double const lc = _longest_channel_name + name_pad();
459 double const h = lc * sin (angle ()) + column_width() * sin (angle()) * cos (angle());
461 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
463 _body->queue_draw_area (
464 component_to_parent_x (x),
465 component_to_parent_y (_height - h),
466 column_width() + lc * cos (angle()),
470 } else if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
472 double const x_ = x + slanted_height() / tan (angle()) - lc * cos (angle());
474 _body->queue_draw_area (
475 component_to_parent_x (x_),
476 component_to_parent_y (0),
477 column_width() + lc * cos (angle()),
487 PortMatrixColumnLabels::button_press (double x, double y, int b, uint32_t t)
489 uint32_t N = _matrix->columns()->total_visible_channels ();
493 vector<pair<double, double> > const shape = port_name_shape (i * column_width(), 0);
497 uint32_t k = (j + 1) % 4;
499 double const P = (y - shape[j].second) * (shape[k].first - shape[j].first) -
500 (x - shape[j].first) * (shape[k].second - shape[j].second);
518 _body->highlight_associated_channels (_matrix->column_index(), i);
521 _matrix->popup_channel_context_menu (_matrix->column_index(), i, t);