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 "port_matrix_column_labels.h"
23 #include "port_matrix.h"
25 PortMatrixColumnLabels::PortMatrixColumnLabels (PortMatrixBody* b, Location l)
26 : PortMatrixComponent (b), _location (l)
32 PortMatrixColumnLabels::compute_dimensions ()
34 GdkPixmap* pm = gdk_pixmap_new (NULL, 1, 1, 24);
35 gdk_drawable_set_colormap (pm, gdk_colormap_get_system());
36 cairo_t* cr = gdk_cairo_create (pm);
38 /* width of the longest bundle name */
39 _longest_bundle_name = 0;
40 /* width of the longest channel name */
41 _longest_channel_name = 0;
42 /* height of highest bit of text */
45 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->column_bundles().begin (); i != _body->column_bundles().end(); ++i) {
47 cairo_text_extents_t ext;
48 cairo_text_extents (cr, (*i)->name().c_str(), &ext);
49 if (ext.width > _longest_bundle_name) {
50 _longest_bundle_name = ext.width;
52 if (ext.height > _highest_text) {
53 _highest_text = ext.height;
56 for (uint32_t j = 0; j < (*i)->nchannels (); ++j) {
60 (*i)->channel_name (j).c_str(),
64 if (ext.width > _longest_channel_name) {
65 _longest_channel_name = ext.width;
67 if (ext.height > _highest_text) {
68 _highest_text = ext.height;
74 gdk_pixmap_unref (pm);
76 /* width and height of the whole thing */
79 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->column_bundles().begin (); i != _body->column_bundles().end(); ++i) {
80 _width += (*i)->nchannels() * column_width();
84 (_longest_bundle_name + _longest_channel_name + 4 * name_pad()) * sin (angle())
85 + _highest_text * cos (angle());
87 _width += _height / tan (angle ());
91 PortMatrixColumnLabels::basic_text_x_pos (int c) const
93 return column_width() / 2 +
94 _highest_text / (2 * sin (angle ()));
98 PortMatrixColumnLabels::render (cairo_t* cr)
102 set_source_rgb (cr, background_colour());
103 cairo_rectangle (cr, 0, 0, _width, _height);
106 /* BUNDLE PARALLELOGRAM-TYPE-THING AND NAME */
109 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->column_bundles().begin (); i != _body->column_bundles().end(); ++i) {
111 Gdk::Color colour = get_a_bundle_colour (i - _body->column_bundles().begin ());
112 set_source_rgb (cr, colour);
114 double const w = (*i)->nchannels() * column_width();
119 cairo_move_to (cr, x_, y_);
121 cairo_line_to (cr, x_, y_);
122 x_ += _height / tan (angle ());
124 cairo_line_to (cr, x_, y_);
126 cairo_line_to (cr, x_, y_);
127 cairo_line_to (cr, x, _height);
128 cairo_fill_preserve (cr);
129 set_source_rgb (cr, background_colour());
130 cairo_set_line_width (cr, label_border_width());
133 set_source_rgb (cr, text_colour());
136 if (_location == TOP) {
138 double const rl = 3 * name_pad() + _longest_channel_name;
141 x + basic_text_x_pos (0) + rl * cos (angle()),
142 _height - rl * sin (angle())
145 } else if (_location == BOTTOM) {
149 x + basic_text_x_pos (0),
150 _height - name_pad() * sin (angle())
155 cairo_rotate (cr, -angle());
156 cairo_show_text (cr, (*i)->name().c_str());
159 x += (*i)->nchannels () * column_width();
166 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = _body->column_bundles().begin(); i != _body->column_bundles().end(); ++i) {
168 for (uint32_t j = 0; j < (*i)->nchannels(); ++j) {
170 double const lc = _longest_channel_name + (2 * name_pad());
171 double const lb = _longest_bundle_name + (2 * name_pad());
172 double const w = column_width();
174 if (_location == BOTTOM) {
176 double x_ = x + _height / tan (angle()) + w;
177 double const ix = x_;
179 cairo_move_to (cr, x_, y_);
181 cairo_line_to (cr, x_, y_);
182 x_ -= lb * cos (angle());
183 y_ += lb * sin (angle());
184 cairo_line_to (cr, x_, y_);
185 x_ += w * pow (sin (angle()), 2);
186 y_ += w * sin (angle()) * cos (angle());
187 cairo_line_to (cr, x_, y_);
188 cairo_line_to (cr, ix, 0);
190 } else if (_location == TOP) {
194 cairo_move_to (cr, x_, y_);
196 cairo_line_to (cr, x_, y_);
197 x_ += lc * cos (angle());
198 y_ -= lc * sin (angle());
199 cairo_line_to (cr, x_, y_);
200 x_ -= column_width() * pow (sin (angle()), 2);
201 y_ -= column_width() * sin (angle()) * cos (angle());
202 cairo_line_to (cr, x_, y_);
203 cairo_line_to (cr, x, _height);
207 Gdk::Color colour = get_a_bundle_colour (i - _body->column_bundles().begin());
208 set_source_rgb (cr, colour);
209 cairo_fill_preserve (cr);
210 set_source_rgb (cr, background_colour());
211 cairo_set_line_width (cr, label_border_width());
214 set_source_rgb (cr, text_colour());
216 if (_location == TOP) {
217 cairo_move_to (cr, x + basic_text_x_pos(j), _height - name_pad() * sin (angle()));
218 } else if (_location == BOTTOM) {
219 double const rl = 3 * name_pad() + _longest_bundle_name;
220 cairo_move_to (cr, x + basic_text_x_pos(j) + rl * cos (angle ()), _height - rl * sin (angle()));
224 cairo_rotate (cr, -angle());
228 (*i)->channel_name(j).c_str()