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() || (*i)->bundles().empty()) {
156 if (_matrix->show_only_bundles()) {
157 w = (*i)->bundles().size() * grid_spacing();
159 w = (*i)->total_channels() * grid_spacing();
164 set_source_rgb (cr, get_a_group_colour (g));
165 double const rh = _highest_group_name + 2 * name_pad();
166 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
167 cairo_rectangle (cr, x, 0, w, rh);
169 cairo_rectangle (cr, x, _height - rh, w, rh);
173 string const upper = Glib::ustring ((*i)->name).uppercase ();
174 pair<string, double> const display = fit_to_pixels (cr, upper, w);
177 set_source_rgb (cr, text_colour());
178 cairo_move_to (cr, x + (w - display.second) / 2, y);
179 cairo_show_text (cr, display.first.c_str());
186 /* BUNDLE PARALLELOGRAM-TYPE-THING AND NAME */
191 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
193 if ((*i)->visible ()) {
195 PortGroup::BundleList const & bundles = (*i)->bundles ();
196 for (PortGroup::BundleList::const_iterator j = bundles.begin (); j != bundles.end(); ++j) {
198 Gdk::Color c = j->has_colour ? j->colour : get_a_bundle_colour (N);
199 render_bundle_name (cr, c, x, 0, j->bundle);
201 if (_matrix->show_only_bundles()) {
204 x += j->bundle->nchannels () * grid_spacing();
212 x += grid_spacing ();
220 if (!_matrix->show_only_bundles()) {
223 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
225 if ((*i)->visible ()) {
227 PortGroup::BundleList const & bundles = (*i)->bundles ();
228 for (PortGroup::BundleList::const_iterator j = bundles.begin (); j != bundles.end(); ++j) {
230 for (uint32_t k = 0; k < j->bundle->nchannels(); ++k) {
231 Gdk::Color c = j->has_colour ? j->colour : get_a_bundle_colour (N);
232 render_channel_name (cr, c, x, 0, ARDOUR::BundleChannel (j->bundle, k));
241 x += grid_spacing ();
249 PortMatrixColumnLabels::component_to_parent_x (double x) const
251 return x - _body->xoffset() + _parent_rectangle.get_x();
255 PortMatrixColumnLabels::parent_to_component_x (double x) const
257 return x + _body->xoffset() - _parent_rectangle.get_x();
261 PortMatrixColumnLabels::component_to_parent_y (double y) const
263 return y + _parent_rectangle.get_y();
267 PortMatrixColumnLabels::parent_to_component_y (double y) const
269 return y - _parent_rectangle.get_y();
273 PortMatrixColumnLabels::mouseover_changed (PortMatrixNode const &)
275 clear_channel_highlights ();
276 if (_body->mouseover().column.bundle) {
277 add_channel_highlight (_body->mouseover().column);
281 vector<pair<double, double> >
282 PortMatrixColumnLabels::port_name_shape (double xoff, double yoff) const
284 vector<pair<double, double> > shape;
286 double const lc = _longest_channel_name + name_pad();
287 double const w = grid_spacing();
289 if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
291 double x_ = xoff + slanted_height() / tan (angle()) + w;
293 shape.push_back (make_pair (x_, y_));
295 shape.push_back (make_pair (x_, y_));
296 x_ -= lc * cos (angle());
297 y_ += lc * sin (angle());
298 shape.push_back (make_pair (x_, y_));
299 x_ += w * pow (sin (angle()), 2);
300 y_ += w * sin (angle()) * cos (angle());
301 shape.push_back (make_pair (x_, y_));
306 double y_ = yoff + _height;
307 shape.push_back (make_pair (x_, y_));
309 shape.push_back (make_pair (x_, y_));
310 x_ += lc * cos (angle());
311 y_ -= lc * sin (angle());
312 shape.push_back (make_pair (x_, y_));
313 x_ -= grid_spacing() * pow (sin (angle()), 2);
314 y_ -= grid_spacing() * sin (angle()) * cos (angle());
315 shape.push_back (make_pair (x_, y_));
322 PortMatrixColumnLabels::render_bundle_name (
323 cairo_t* cr, Gdk::Color colour, double xoff, double yoff, boost::shared_ptr<ARDOUR::Bundle> b
326 set_source_rgb (cr, colour);
329 if (_matrix->show_only_bundles()) {
332 w = b->nchannels() * grid_spacing();
338 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
341 y += slanted_height();
345 cairo_move_to (cr, x_, y_);
347 cairo_line_to (cr, x_, y_);
348 x_ += slanted_height() / tan (angle ());
349 y_ -= slanted_height();
350 cairo_line_to (cr, x_, y_);
352 cairo_line_to (cr, x_, y_);
353 cairo_line_to (cr, xoff, y);
354 cairo_fill_preserve (cr);
355 set_source_rgb (cr, background_colour());
356 cairo_set_line_width (cr, label_border_width());
359 set_source_rgb (cr, text_colour());
361 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
364 if (_matrix->show_only_bundles()) {
367 rl = 3 * name_pad() + _longest_channel_name;
371 xoff + basic_text_x_pos (0) + rl * cos (angle()),
372 yoff + _height - rl * sin (angle())
379 xoff + basic_text_x_pos (0),
380 yoff + slanted_height() - name_pad() * sin (angle())
385 cairo_rotate (cr, -angle());
386 cairo_show_text (cr, b->name().c_str());
391 PortMatrixColumnLabels::render_channel_name (
392 cairo_t* cr, Gdk::Color colour, double xoff, double yoff, ARDOUR::BundleChannel const &bc
395 vector<pair<double, double> > const shape = port_name_shape (xoff, yoff);
397 cairo_move_to (cr, shape[0].first, shape[0].second);
398 for (uint32_t i = 1; i < 4; ++i) {
399 cairo_line_to (cr, shape[i].first, shape[i].second);
401 cairo_line_to (cr, shape[0].first, shape[0].second);
403 set_source_rgb (cr, colour);
404 cairo_fill_preserve (cr);
405 set_source_rgb (cr, background_colour());
406 cairo_set_line_width (cr, label_border_width());
409 set_source_rgb (cr, text_colour());
411 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
415 xoff + basic_text_x_pos(bc.channel),
416 yoff + _height - name_pad() * sin (angle())
421 double const rl = 3 * name_pad() + _longest_bundle_name;
424 xoff + basic_text_x_pos(bc.channel) + rl * cos (angle ()),
425 yoff + slanted_height() - rl * sin (angle())
430 cairo_rotate (cr, -angle());
434 bc.bundle->channel_name(bc.channel).c_str()
441 PortMatrixColumnLabels::channel_x (ARDOUR::BundleChannel const &bc) const
443 return channel_to_position (bc, _matrix->columns()) * grid_spacing ();
447 PortMatrixColumnLabels::channel_y (ARDOUR::BundleChannel const &bc) const
453 PortMatrixColumnLabels::queue_draw_for (ARDOUR::BundleChannel const & bc)
459 if (_matrix->show_only_bundles()) {
461 _body->queue_draw_area (
462 component_to_parent_x (channel_x (bc)),
463 component_to_parent_y (0),
464 grid_spacing() + _height * tan (angle()),
470 double const x = channel_x (bc);
471 double const lc = _longest_channel_name + name_pad();
472 double const h = lc * sin (angle ()) + grid_spacing() * sin (angle()) * cos (angle());
474 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
476 _body->queue_draw_area (
477 component_to_parent_x (x),
478 component_to_parent_y (_height - h),
479 grid_spacing() + lc * cos (angle()),
483 } else if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
485 double const x_ = x + slanted_height() / tan (angle()) - lc * cos (angle());
487 _body->queue_draw_area (
488 component_to_parent_x (x_),
489 component_to_parent_y (0),
490 grid_spacing() + lc * cos (angle()),
500 PortMatrixColumnLabels::button_press (double x, double y, int b, uint32_t t)
503 uint32_t const gh = _highest_group_name + 2 * name_pad();
505 bool group_name = false;
506 if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
507 if (y > (_height - gh)) {
511 cx = x - (_height - gh - y) * tan (angle ());
518 cx = x - (_height - y) * tan (angle ());
522 pair<boost::shared_ptr<PortGroup>, ARDOUR::BundleChannel> gc = position_to_group_and_channel (cx / grid_spacing(), _matrix->columns());
526 if (group_name && gc.first) {
527 gc.first->set_visible (!gc.first->visible ());
528 } else if (gc.second.bundle) {
529 _body->highlight_associated_channels (_matrix->column_index(), gc.second);
534 _matrix->popup_menu (
536 make_pair (boost::shared_ptr<PortGroup> (), ARDOUR::BundleChannel ()),