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"
27 PortMatrixColumnLabels::PortMatrixColumnLabels (PortMatrix* m, PortMatrixBody* b)
28 : PortMatrixLabels (m, b)
34 PortMatrixColumnLabels::compute_dimensions ()
36 GdkPixmap* pm = gdk_pixmap_new (NULL, 1, 1, 24);
37 gdk_drawable_set_colormap (pm, gdk_colormap_get_system());
38 cairo_t* cr = gdk_cairo_create (pm);
40 /* width of the longest bundle name */
41 _longest_bundle_name = 0;
42 /* width of the longest channel name */
43 _longest_channel_name = 0;
44 /* height of highest bit of text (apart from group names) */
46 /* width of the whole thing */
49 ARDOUR::BundleList const c = _matrix->columns()->bundles();
50 for (ARDOUR::BundleList::const_iterator i = c.begin (); i != c.end(); ++i) {
52 cairo_text_extents_t ext;
53 cairo_text_extents (cr, (*i)->name().c_str(), &ext);
54 if (ext.width > _longest_bundle_name) {
55 _longest_bundle_name = ext.width;
57 if (ext.height > _highest_text) {
58 _highest_text = ext.height;
61 for (uint32_t j = 0; j < (*i)->nchannels (); ++j) {
65 (*i)->channel_name (j).c_str(),
69 if (ext.width > _longest_channel_name) {
70 _longest_channel_name = ext.width;
72 if (ext.height > _highest_text) {
73 _highest_text = ext.height;
77 _width += (*i)->nchannels() * column_width();
80 _highest_group_name = 0;
81 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
82 if ((*i)->visible()) {
83 cairo_text_extents_t ext;
84 cairo_text_extents (cr, (*i)->name.c_str(), &ext);
85 if (ext.height > _highest_group_name) {
86 _highest_group_name = ext.height;
92 gdk_pixmap_unref (pm);
94 /* height of the whole thing */
96 double const parallelogram_height =
97 (_longest_bundle_name + _longest_channel_name + 4 * name_pad()) * sin (angle())
98 + _highest_text * cos (angle());
100 _height = parallelogram_height + _highest_group_name + 2 * name_pad();
102 _width += parallelogram_height / tan (angle ());
106 PortMatrixColumnLabels::basic_text_x_pos (int c) const
108 return column_width() / 2 +
109 _highest_text / (2 * sin (angle ()));
113 PortMatrixColumnLabels::render (cairo_t* cr)
117 set_source_rgb (cr, background_colour());
118 cairo_rectangle (cr, 0, 0, _width, _height);
121 /* PORT GROUP NAME */
126 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
127 x = slanted_height() / tan (angle());
128 y = _highest_group_name + name_pad();
131 y = _height - name_pad();
135 for (PortGroupList::List::const_iterator i = _matrix->columns()->begin(); i != _matrix->columns()->end(); ++i) {
137 if (!(*i)->visible() || (*i)->bundles().empty()) {
141 /* compute width of this group */
142 uint32_t w = (*i)->total_channels() * column_width();
145 set_source_rgb (cr, get_a_group_colour (g));
146 double const rh = _highest_group_name + 2 * name_pad();
147 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
148 cairo_rectangle (cr, x, 0, w, rh);
150 cairo_rectangle (cr, x, _height - rh, w, rh);
154 std::pair<std::string, double> const display = display_port_name (cr, (*i)->name, w);
157 set_source_rgb (cr, text_colour());
158 cairo_move_to (cr, x + (w - display.second) / 2, y);
159 cairo_show_text (cr, display.first.c_str());
165 /* BUNDLE PARALLELOGRAM-TYPE-THING AND NAME */
168 ARDOUR::BundleList const c = _matrix->columns()->bundles();
169 for (ARDOUR::BundleList::const_iterator i = c.begin (); i != c.end(); ++i) {
171 Gdk::Color colour = get_a_bundle_colour (i - c.begin ());
172 set_source_rgb (cr, colour);
174 double const w = (*i)->nchannels() * column_width();
178 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
181 y = slanted_height();
185 cairo_move_to (cr, x_, y_);
187 cairo_line_to (cr, x_, y_);
188 x_ += slanted_height() / tan (angle ());
189 y_ -= slanted_height();
190 cairo_line_to (cr, x_, y_);
192 cairo_line_to (cr, x_, y_);
193 cairo_line_to (cr, x, y);
194 cairo_fill_preserve (cr);
195 set_source_rgb (cr, background_colour());
196 cairo_set_line_width (cr, label_border_width());
199 set_source_rgb (cr, text_colour());
201 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
203 double const rl = 3 * name_pad() + _longest_channel_name;
206 x + basic_text_x_pos (0) + rl * cos (angle()),
207 _height - rl * sin (angle())
214 x + basic_text_x_pos (0),
215 slanted_height() - name_pad() * sin (angle())
220 cairo_rotate (cr, -angle());
221 cairo_show_text (cr, (*i)->name().c_str());
224 x += (*i)->nchannels () * column_width();
231 for (ARDOUR::BundleList::const_iterator i = c.begin (); i != c.end(); ++i) {
233 for (uint32_t j = 0; j < (*i)->nchannels(); ++j) {
235 render_channel_name (cr, get_a_bundle_colour (i - c.begin()), x, 0, ARDOUR::BundleChannel (*i, j));
242 PortMatrixColumnLabels::component_to_parent_x (double x) const
244 return x - _body->xoffset() + _parent_rectangle.get_x();
248 PortMatrixColumnLabels::parent_to_component_x (double x) const
250 return x + _body->xoffset() - _parent_rectangle.get_x();
254 PortMatrixColumnLabels::component_to_parent_y (double y) const
256 return y + _parent_rectangle.get_y();
260 PortMatrixColumnLabels::parent_to_component_y (double y) const
262 return y - _parent_rectangle.get_y();
266 PortMatrixColumnLabels::mouseover_changed (PortMatrixNode const &)
268 clear_channel_highlights ();
269 if (_body->mouseover().column.bundle) {
270 add_channel_highlight (_body->mouseover().column);
274 std::vector<std::pair<double, double> >
275 PortMatrixColumnLabels::port_name_shape (double xoff, double yoff) const
277 std::vector<std::pair<double, double> > shape;
279 double const lc = _longest_channel_name + name_pad();
280 double const w = column_width();
282 if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
284 double x_ = xoff + slanted_height() / tan (angle()) + w;
286 shape.push_back (std::make_pair (x_, y_));
288 shape.push_back (std::make_pair (x_, y_));
289 x_ -= lc * cos (angle());
290 y_ += lc * sin (angle());
291 shape.push_back (std::make_pair (x_, y_));
292 x_ += w * pow (sin (angle()), 2);
293 y_ += w * sin (angle()) * cos (angle());
294 shape.push_back (std::make_pair (x_, y_));
299 double y_ = yoff + _height;
300 shape.push_back (std::make_pair (x_, y_));
302 shape.push_back (std::make_pair (x_, y_));
303 x_ += lc * cos (angle());
304 y_ -= lc * sin (angle());
305 shape.push_back (std::make_pair (x_, y_));
306 x_ -= column_width() * pow (sin (angle()), 2);
307 y_ -= column_width() * sin (angle()) * cos (angle());
308 shape.push_back (std::make_pair (x_, y_));
315 PortMatrixColumnLabels::render_channel_name (cairo_t* cr, Gdk::Color colour, double xoff, double yoff, ARDOUR::BundleChannel const &bc)
317 std::vector<std::pair<double, double> > const shape = port_name_shape (xoff, yoff);
319 cairo_move_to (cr, shape[0].first, shape[0].second);
320 for (uint32_t i = 1; i < 4; ++i) {
321 cairo_line_to (cr, shape[i].first, shape[i].second);
323 cairo_line_to (cr, shape[0].first, shape[0].second);
325 set_source_rgb (cr, colour);
326 cairo_fill_preserve (cr);
327 set_source_rgb (cr, background_colour());
328 cairo_set_line_width (cr, label_border_width());
331 set_source_rgb (cr, text_colour());
333 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
337 xoff + basic_text_x_pos(bc.channel),
338 yoff + _height - name_pad() * sin (angle())
343 double const rl = 3 * name_pad() + _longest_bundle_name;
346 xoff + basic_text_x_pos(bc.channel) + rl * cos (angle ()),
347 yoff + slanted_height() - rl * sin (angle())
352 cairo_rotate (cr, -angle());
356 bc.bundle->channel_name(bc.channel).c_str()
363 PortMatrixColumnLabels::channel_x (ARDOUR::BundleChannel const &bc) const
367 ARDOUR::BundleList::const_iterator i = _matrix->columns()->bundles().begin();
368 while (i != _matrix->columns()->bundles().end() && *i != bc.bundle) {
369 n += (*i)->nchannels ();
374 return n * column_width();
378 PortMatrixColumnLabels::channel_y (ARDOUR::BundleChannel const &bc) const
384 PortMatrixColumnLabels::queue_draw_for (ARDOUR::BundleChannel const & bc)
388 double const x = channel_x (bc);
389 double const lc = _longest_channel_name + name_pad();
390 double const h = lc * sin (angle ()) + column_width() * sin (angle()) * cos (angle());
391 if (_matrix->arrangement() == PortMatrix::TOP_TO_RIGHT) {
393 _body->queue_draw_area (
394 component_to_parent_x (x),
395 component_to_parent_y (_height - h),
396 column_width() + lc * cos (angle()),
400 } else if (_matrix->arrangement() == PortMatrix::LEFT_TO_BOTTOM) {
402 double const x_ = x + slanted_height() / tan (angle()) - lc * cos (angle());
404 _body->queue_draw_area (
405 component_to_parent_x (x_),
406 component_to_parent_y (0),
407 column_width() + lc * cos (angle()),
417 PortMatrixColumnLabels::button_press (double x, double y, int b, uint32_t t)
419 uint32_t N = _matrix->columns()->total_visible_channels ();
423 std::vector<std::pair<double, double> > const shape = port_name_shape (i * column_width(), 0);
427 uint32_t k = (j + 1) % 4;
429 double const P = (y - shape[j].second) * (shape[k].first - shape[j].first) -
430 (x - shape[j].first) * (shape[k].second - shape[j].second);
448 _body->highlight_associated_channels (_matrix->column_index(), i);
451 _matrix->popup_channel_context_menu (_matrix->column_index(), i, t);