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 <boost/weak_ptr.hpp>
22 #include <cairo/cairo.h>
23 #include "ardour/bundle.h"
24 #include "port_matrix_row_labels.h"
25 #include "port_matrix.h"
26 #include "port_matrix_body.h"
32 PortMatrixRowLabels::PortMatrixRowLabels (PortMatrix* m, PortMatrixBody* b)
33 : PortMatrixLabels (m, b)
39 PortMatrixRowLabels::compute_dimensions ()
41 GdkPixmap* pm = gdk_pixmap_new (NULL, 1, 1, 24);
42 gdk_drawable_set_colormap (pm, gdk_colormap_get_system());
43 cairo_t* cr = gdk_cairo_create (pm);
45 _longest_port_name = 0;
46 _longest_bundle_name = 0;
49 PortGroup::BundleList const r = _matrix->rows()->bundles();
50 for (PortGroup::BundleList::const_iterator i = r.begin(); i != r.end(); ++i) {
51 for (uint32_t j = 0; j < i->bundle->nchannels(); ++j) {
52 cairo_text_extents_t ext;
53 cairo_text_extents (cr, i->bundle->channel_name(j).c_str(), &ext);
54 if (ext.width > _longest_port_name) {
55 _longest_port_name = ext.width;
59 cairo_text_extents_t ext;
60 cairo_text_extents (cr, i->bundle->name().c_str(), &ext);
61 if (ext.width > _longest_bundle_name) {
62 _longest_bundle_name = ext.width;
65 if (_matrix->show_only_bundles()) {
66 _height += grid_spacing ();
68 _height += i->bundle->nchannels() * grid_spacing();
72 _highest_group_name = 0;
73 for (PortGroupList::List::const_iterator i = _matrix->rows()->begin(); i != _matrix->rows()->end(); ++i) {
74 if ((*i)->visible()) {
75 cairo_text_extents_t ext;
76 cairo_text_extents (cr, (*i)->name.c_str(), &ext);
77 if (ext.height > _highest_group_name) {
78 _highest_group_name = ext.height;
81 /* add another grid_spacing for a tab for this hidden group */
82 _height += grid_spacing ();
87 gdk_pixmap_unref (pm);
89 _width = _highest_group_name +
90 _longest_bundle_name +
93 if (!_matrix->show_only_bundles()) {
94 _width += _longest_port_name;
95 _width += name_pad() * 2;
101 PortMatrixRowLabels::render (cairo_t* cr)
105 set_source_rgb (cr, background_colour());
106 cairo_rectangle (cr, 0, 0, _width, _height);
109 /* PORT GROUP NAMES */
112 if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
115 x = _width - _highest_group_name - 2 * name_pad();
120 for (PortGroupList::List::const_iterator i = _matrix->rows()->begin(); i != _matrix->rows()->end(); ++i) {
122 /* compute height of this group */
124 if (!(*i)->visible()) {
127 if (_matrix->show_only_bundles()) {
128 h = (*i)->bundles().size() * grid_spacing();
130 h = (*i)->total_channels () * grid_spacing();
139 set_source_rgb (cr, get_a_group_colour (g));
140 double const rw = _highest_group_name + 2 * name_pad();
141 cairo_rectangle (cr, x, y, rw, h);
144 /* hence what abbreviation (or not) we need for the group name */
145 string const upper = Glib::ustring ((*i)->name).uppercase ();
146 pair<string, double> display = fit_to_pixels (cr, upper, h);
149 set_source_rgb (cr, text_colour());
150 cairo_move_to (cr, x + rw - name_pad(), y + (h + display.second) / 2);
152 cairo_rotate (cr, - M_PI / 2);
153 cairo_show_text (cr, display.first.c_str());
160 /* BUNDLE AND PORT NAMES */
165 for (PortGroupList::List::const_iterator i = _matrix->rows()->begin(); i != _matrix->rows()->end(); ++i) {
167 if ((*i)->visible ()) {
169 PortGroup::BundleList const & bundles = (*i)->bundles ();
170 for (PortGroup::BundleList::const_iterator j = bundles.begin(); j != bundles.end(); ++j) {
171 render_bundle_name (cr, j->has_colour ? j->colour : get_a_bundle_colour (N), 0, y, j->bundle);
173 if (!_matrix->show_only_bundles()) {
174 for (uint32_t k = 0; k < j->bundle->nchannels(); ++k) {
175 Gdk::Color c = j->has_colour ? j->colour : get_a_bundle_colour (M);
176 render_channel_name (cr, c, 0, y, ARDOUR::BundleChannel (j->bundle, k));
189 y += grid_spacing ();
195 PortMatrixRowLabels::button_press (double x, double y, int b, uint32_t t)
197 uint32_t const gw = (_highest_group_name + 2 * name_pad());
199 pair<boost::shared_ptr<PortGroup>, ARDOUR::BundleChannel> w = position_to_group_and_channel (y / grid_spacing (), _matrix->rows());
202 (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM && x < gw) ||
203 (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT && x > (_width - gw))
206 w.second.bundle.reset ();
211 if (w.second.bundle) {
212 _body->highlight_associated_channels (_matrix->row_index(), w.second);
215 w.first->set_visible (!w.first->visible());
221 _matrix->popup_menu (
222 make_pair (boost::shared_ptr<PortGroup> (), ARDOUR::BundleChannel ()),
230 PortMatrixRowLabels::component_to_parent_x (double x) const
232 return x + _parent_rectangle.get_x();
236 PortMatrixRowLabels::parent_to_component_x (double x) const
238 return x - _parent_rectangle.get_x();
242 PortMatrixRowLabels::component_to_parent_y (double y) const
244 return y - _body->yoffset() + _parent_rectangle.get_y();
248 PortMatrixRowLabels::parent_to_component_y (double y) const
250 return y + _body->yoffset() - _parent_rectangle.get_y();
255 PortMatrixRowLabels::bundle_name_x () const
259 if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
260 x = _highest_group_name + 2 * name_pad();
262 if (_matrix->show_only_bundles()) {
265 x = _longest_port_name + name_pad() * 2;
273 PortMatrixRowLabels::port_name_x () const
275 if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
276 return _longest_bundle_name + _highest_group_name + name_pad() * 4;
285 PortMatrixRowLabels::render_bundle_name (
286 cairo_t* cr, Gdk::Color colour, double xoff, double yoff, boost::shared_ptr<ARDOUR::Bundle> b
289 double const x = bundle_name_x ();
291 int const n = _matrix->show_only_bundles() ? 1 : b->nchannels();
292 set_source_rgb (cr, colour);
293 cairo_rectangle (cr, xoff + x, yoff, _longest_bundle_name + name_pad() * 2, grid_spacing() * n);
294 cairo_fill_preserve (cr);
295 set_source_rgb (cr, background_colour());
296 cairo_set_line_width (cr, label_border_width ());
299 double const off = grid_spacing() / 2;
301 // if ((*i)->nchannels () > 0 && !_matrix->show_only_bundles()) {
302 // /* use the extent of our first channel name so that the bundle name is vertically aligned with it */
303 // cairo_text_extents_t ext;
304 // cairo_text_extents (cr, (*i)->channel_name(0).c_str(), &ext);
305 // off = (grid_spacing() - ext.height) / 2;
308 set_source_rgb (cr, text_colour());
309 cairo_move_to (cr, xoff + x + name_pad(), yoff + name_pad() + off);
310 cairo_show_text (cr, b->name().c_str());
314 PortMatrixRowLabels::render_channel_name (
315 cairo_t* cr, Gdk::Color colour, double xoff, double yoff, ARDOUR::BundleChannel const& bc
318 set_source_rgb (cr, colour);
319 cairo_rectangle (cr, port_name_x() + xoff, yoff, _longest_port_name + name_pad() * 2, grid_spacing());
320 cairo_fill_preserve (cr);
321 set_source_rgb (cr, background_colour());
322 cairo_set_line_width (cr, label_border_width ());
325 cairo_text_extents_t ext;
326 cairo_text_extents (cr, bc.bundle->channel_name(bc.channel).c_str(), &ext);
327 double const off = (grid_spacing() - ext.height) / 2;
329 set_source_rgb (cr, text_colour());
330 cairo_move_to (cr, port_name_x() + xoff + name_pad(), yoff + name_pad() + off);
331 cairo_show_text (cr, bc.bundle->channel_name(bc.channel).c_str());
335 PortMatrixRowLabels::channel_x (ARDOUR::BundleChannel const& bc) const
341 PortMatrixRowLabels::channel_y (ARDOUR::BundleChannel const& bc) const
343 return channel_to_position (bc, _matrix->rows()) * grid_spacing ();
347 PortMatrixRowLabels::queue_draw_for (ARDOUR::BundleChannel const & bc)
351 if (_matrix->show_only_bundles()) {
352 _body->queue_draw_area (
353 component_to_parent_x (bundle_name_x()),
354 component_to_parent_y (channel_y (bc)),
355 _longest_bundle_name + name_pad() * 2,
359 _body->queue_draw_area (
360 component_to_parent_x (port_name_x()),
361 component_to_parent_y (channel_y (bc)),
362 _longest_port_name + name_pad() * 2,
371 PortMatrixRowLabels::mouseover_changed (PortMatrixNode const &)
373 clear_channel_highlights ();
374 if (_body->mouseover().row.bundle) {
375 add_channel_highlight (_body->mouseover().row);