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"
26 PortMatrixColumnLabels::PortMatrixColumnLabels (PortMatrixBody* b, Location l)
27 : PortMatrixComponent (b), _location (l)
33 PortMatrixColumnLabels::compute_dimensions ()
35 GdkPixmap* pm = gdk_pixmap_new (NULL, 1, 1, 24);
36 gdk_drawable_set_colormap (pm, gdk_colormap_get_system());
37 cairo_t* cr = gdk_cairo_create (pm);
39 /* width of the longest bundle name */
40 _longest_bundle_name = 0;
41 /* width of the longest channel name */
42 _longest_channel_name = 0;
43 /* height of highest bit of text (apart from group names) */
45 /* width of the whole thing */
48 ARDOUR::BundleList const c = _body->column_ports().bundles();
49 for (ARDOUR::BundleList::const_iterator i = c.begin (); i != c.end(); ++i) {
51 cairo_text_extents_t ext;
52 cairo_text_extents (cr, (*i)->name().c_str(), &ext);
53 if (ext.width > _longest_bundle_name) {
54 _longest_bundle_name = ext.width;
56 if (ext.height > _highest_text) {
57 _highest_text = ext.height;
60 for (uint32_t j = 0; j < (*i)->nchannels (); ++j) {
64 (*i)->channel_name (j).c_str(),
68 if (ext.width > _longest_channel_name) {
69 _longest_channel_name = ext.width;
71 if (ext.height > _highest_text) {
72 _highest_text = ext.height;
76 _width += (*i)->nchannels() * column_width();
79 _highest_group_name = 0;
80 for (PortGroupList::const_iterator i = _body->column_ports().begin(); i != _body->column_ports().end(); ++i) {
81 if ((*i)->visible()) {
82 cairo_text_extents_t ext;
83 cairo_text_extents (cr, (*i)->name.c_str(), &ext);
84 if (ext.height > _highest_group_name) {
85 _highest_group_name = ext.height;
91 gdk_pixmap_unref (pm);
93 /* height of the whole thing */
95 double const parallelogram_height =
96 (_longest_bundle_name + _longest_channel_name + 4 * name_pad()) * sin (angle())
97 + _highest_text * cos (angle());
99 _height = parallelogram_height + _highest_group_name + 2 * name_pad();
101 _width += parallelogram_height / tan (angle ());
105 PortMatrixColumnLabels::basic_text_x_pos (int c) const
107 return column_width() / 2 +
108 _highest_text / (2 * sin (angle ()));
112 PortMatrixColumnLabels::render (cairo_t* cr)
116 set_source_rgb (cr, background_colour());
117 cairo_rectangle (cr, 0, 0, _width, _height);
120 /* PORT GROUP NAME */
125 if (_location == TOP) {
126 x = slanted_height() / tan (angle());
127 y = _highest_group_name + name_pad();
130 y = _height - name_pad();
134 for (PortGroupList::const_iterator i = _body->column_ports().begin(); i != _body->column_ports().end(); ++i) {
136 if (!(*i)->visible() || ((*i)->bundles().empty() && (*i)->ports.empty()) ) {
140 /* compute width of this group */
142 for (ARDOUR::BundleList::const_iterator j = (*i)->bundles().begin(); j != (*i)->bundles().end(); ++j) {
143 w += (*j)->nchannels() * column_width();
145 w += (*i)->ports.size() * column_width();
148 set_source_rgb (cr, get_a_group_colour (g));
149 double const rh = _highest_group_name + 2 * name_pad();
150 if (_location == TOP) {
151 cairo_rectangle (cr, x, 0, w, rh);
152 } else if (_location == BOTTOM) {
153 cairo_rectangle (cr, x, _height - rh, w, rh);
157 std::pair<std::string, double> const display = display_port_name (cr, (*i)->name, w);
160 set_source_rgb (cr, text_colour());
161 cairo_move_to (cr, x + (w - display.second) / 2, y);
162 cairo_show_text (cr, display.first.c_str());
168 /* BUNDLE PARALLELOGRAM-TYPE-THING AND NAME */
171 ARDOUR::BundleList const c = _body->column_ports().bundles();
172 for (ARDOUR::BundleList::const_iterator i = c.begin (); i != c.end(); ++i) {
174 Gdk::Color colour = get_a_bundle_colour (i - c.begin ());
175 set_source_rgb (cr, colour);
177 double const w = (*i)->nchannels() * column_width();
181 if (_location == TOP) {
183 } else if (_location == BOTTOM) {
184 y = slanted_height();
188 cairo_move_to (cr, x_, y_);
190 cairo_line_to (cr, x_, y_);
191 x_ += slanted_height() / tan (angle ());
192 y_ -= slanted_height();
193 cairo_line_to (cr, x_, y_);
195 cairo_line_to (cr, x_, y_);
196 cairo_line_to (cr, x, y);
197 cairo_fill_preserve (cr);
198 set_source_rgb (cr, background_colour());
199 cairo_set_line_width (cr, label_border_width());
202 set_source_rgb (cr, text_colour());
204 if (_location == TOP) {
206 double const rl = 3 * name_pad() + _longest_channel_name;
209 x + basic_text_x_pos (0) + rl * cos (angle()),
210 _height - rl * sin (angle())
213 } else if (_location == BOTTOM) {
217 x + basic_text_x_pos (0),
218 slanted_height() - name_pad() * sin (angle())
223 cairo_rotate (cr, -angle());
224 cairo_show_text (cr, (*i)->name().c_str());
227 x += (*i)->nchannels () * column_width();
234 for (ARDOUR::BundleList::const_iterator i = c.begin (); i != c.end(); ++i) {
236 for (uint32_t j = 0; j < (*i)->nchannels(); ++j) {
238 render_port_name (cr, get_a_bundle_colour (i - c.begin()), x, 0, PortMatrixBundleChannel (*i, j));
245 PortMatrixColumnLabels::component_to_parent_x (double x) const
247 return x - _body->xoffset() + _parent_rectangle.get_x();
251 PortMatrixColumnLabels::parent_to_component_x (double x) const
253 return x + _body->xoffset() - _parent_rectangle.get_x();
257 PortMatrixColumnLabels::component_to_parent_y (double y) const
259 return y + _parent_rectangle.get_y();
263 PortMatrixColumnLabels::parent_to_component_y (double y) const
265 return y - _parent_rectangle.get_y();
269 PortMatrixColumnLabels::mouseover_changed (PortMatrixNode const& old)
271 queue_draw_for (old);
272 queue_draw_for (_body->mouseover());
276 PortMatrixColumnLabels::draw_extra (cairo_t* cr)
278 if (_body->mouseover().column.bundle) {
281 mouseover_port_colour (),
282 component_to_parent_x (channel_x (_body->mouseover().column)),
283 component_to_parent_y (0),
284 _body->mouseover().column
290 PortMatrixColumnLabels::render_port_name (cairo_t* cr, Gdk::Color colour, double xoff, double yoff, PortMatrixBundleChannel const &bc)
292 double const lc = _longest_channel_name + name_pad();
293 double const w = column_width();
295 if (_location == BOTTOM) {
297 double x_ = xoff + slanted_height() / tan (angle()) + w;
298 double const ix = x_;
300 cairo_move_to (cr, x_, y_);
302 cairo_line_to (cr, x_, y_);
303 x_ -= lc * cos (angle());
304 y_ += lc * sin (angle());
305 cairo_line_to (cr, x_, y_);
306 x_ += w * pow (sin (angle()), 2);
307 y_ += w * sin (angle()) * cos (angle());
308 cairo_line_to (cr, x_, y_);
309 cairo_line_to (cr, ix, yoff);
311 } else if (_location == TOP) {
314 double y_ = yoff + _height;
315 cairo_move_to (cr, x_, y_);
317 cairo_line_to (cr, x_, y_);
318 x_ += lc * cos (angle());
319 y_ -= lc * sin (angle());
320 cairo_line_to (cr, x_, y_);
321 x_ -= column_width() * pow (sin (angle()), 2);
322 y_ -= column_width() * sin (angle()) * cos (angle());
323 cairo_line_to (cr, x_, y_);
324 cairo_line_to (cr, xoff, yoff + _height);
328 set_source_rgb (cr, colour);
329 cairo_fill_preserve (cr);
330 set_source_rgb (cr, background_colour());
331 cairo_set_line_width (cr, label_border_width());
334 set_source_rgb (cr, text_colour());
336 if (_location == TOP) {
340 xoff + basic_text_x_pos(bc.channel),
341 yoff + _height - name_pad() * sin (angle())
344 } else if (_location == BOTTOM) {
346 double const rl = 3 * name_pad() + _longest_bundle_name;
349 xoff + basic_text_x_pos(bc.channel) + rl * cos (angle ()),
350 yoff + slanted_height() - rl * sin (angle())
355 cairo_rotate (cr, -angle());
359 bc.bundle->channel_name(bc.channel).c_str()
366 PortMatrixColumnLabels::channel_x (PortMatrixBundleChannel const &bc) const
368 return bc.nchannels (_body->column_ports().bundles()) * column_width();
372 PortMatrixColumnLabels::queue_draw_for (PortMatrixNode const& n)
374 if (n.column.bundle) {
376 double const x = channel_x (n.column);
377 double const lc = _longest_channel_name + name_pad();
378 double const h = lc * sin (angle ()) + column_width() * sin (angle()) * cos (angle());
379 if (_location == TOP) {
381 _body->queue_draw_area (
382 component_to_parent_x (x),
383 component_to_parent_y (_height - h),
384 column_width() + lc * cos (angle()),
388 } else if (_location == BOTTOM) {
390 double const x_ = x + slanted_height() / tan (angle()) - lc * cos (angle());
392 _body->queue_draw_area (
393 component_to_parent_x (x_),
394 component_to_parent_y (0),
395 column_width() + lc * cos (angle()),