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;
48 _highest_group_name
= 0;
50 for (PortGroupList::List::const_iterator i
= _matrix
->rows()->begin(); i
!= _matrix
->rows()->end(); ++i
) {
52 PortGroup::BundleList
const r
= (*i
)->bundles ();
53 for (PortGroup::BundleList::const_iterator j
= r
.begin(); j
!= r
.end(); ++j
) {
55 for (uint32_t k
= 0; k
< j
->bundle
->nchannels(); ++k
) {
56 cairo_text_extents_t ext
;
57 cairo_text_extents (cr
, j
->bundle
->channel_name(k
).c_str(), &ext
);
58 if (ext
.width
> _longest_port_name
) {
59 _longest_port_name
= ext
.width
;
63 cairo_text_extents_t ext
;
64 cairo_text_extents (cr
, j
->bundle
->name().c_str(), &ext
);
65 if (ext
.width
> _longest_bundle_name
) {
66 _longest_bundle_name
= ext
.width
;
70 _height
+= group_size (*i
) * grid_spacing ();
72 cairo_text_extents_t ext
;
73 cairo_text_extents (cr
, (*i
)->name
.c_str(), &ext
);
74 if (ext
.height
> _highest_group_name
) {
75 _highest_group_name
= ext
.height
;
80 gdk_pixmap_unref (pm
);
82 _width
= _highest_group_name
+
83 _longest_bundle_name
+
86 if (!_matrix
->show_only_bundles()) {
87 _width
+= _longest_port_name
;
88 _width
+= name_pad() * 2;
94 PortMatrixRowLabels::render (cairo_t
* cr
)
98 set_source_rgb (cr
, background_colour());
99 cairo_rectangle (cr
, 0, 0, _width
, _height
);
102 /* PORT GROUP NAMES */
105 if (_matrix
->arrangement() == PortMatrix::LEFT_TO_BOTTOM
) {
108 x
= _width
- _highest_group_name
- 2 * name_pad();
113 for (PortGroupList::List::const_iterator i
= _matrix
->rows()->begin(); i
!= _matrix
->rows()->end(); ++i
) {
115 /* compute height of this group */
117 if (!(*i
)->visible()) {
120 if (_matrix
->show_only_bundles()) {
121 h
= (*i
)->bundles().size() * grid_spacing();
123 h
= (*i
)->total_channels () * grid_spacing();
132 set_source_rgb (cr
, get_a_group_colour (g
));
133 double const rw
= _highest_group_name
+ 2 * name_pad();
134 cairo_rectangle (cr
, x
, y
, rw
, h
);
137 /* hence what abbreviation (or not) we need for the group name */
138 string
const upper
= Glib::ustring ((*i
)->name
).uppercase ();
139 pair
<string
, double> display
= fit_to_pixels (cr
, upper
, h
);
142 set_source_rgb (cr
, text_colour());
143 cairo_move_to (cr
, x
+ rw
- name_pad(), y
+ (h
+ display
.second
) / 2);
145 cairo_rotate (cr
, - M_PI
/ 2);
146 cairo_show_text (cr
, display
.first
.c_str());
153 /* BUNDLE AND PORT NAMES */
158 for (PortGroupList::List::const_iterator i
= _matrix
->rows()->begin(); i
!= _matrix
->rows()->end(); ++i
) {
160 if ((*i
)->visible ()) {
162 PortGroup::BundleList
const & bundles
= (*i
)->bundles ();
163 for (PortGroup::BundleList::const_iterator j
= bundles
.begin(); j
!= bundles
.end(); ++j
) {
164 render_bundle_name (cr
, background_colour (), j
->has_colour
? j
->colour
: get_a_bundle_colour (N
), 0, y
, j
->bundle
);
166 if (!_matrix
->show_only_bundles()) {
167 for (uint32_t k
= 0; k
< j
->bundle
->nchannels(); ++k
) {
168 Gdk::Color c
= j
->has_colour
? j
->colour
: get_a_bundle_colour (M
);
169 render_channel_name (cr
, background_colour (), c
, 0, y
, ARDOUR::BundleChannel (j
->bundle
, k
));
182 y
+= grid_spacing ();
188 PortMatrixRowLabels::button_press (double x
, double y
, int b
, uint32_t t
)
190 uint32_t const gw
= (_highest_group_name
+ 2 * name_pad());
192 pair
<boost::shared_ptr
<PortGroup
>, ARDOUR::BundleChannel
> w
= position_to_group_and_channel (y
/ grid_spacing (), _matrix
->rows());
195 (_matrix
->arrangement() == PortMatrix::LEFT_TO_BOTTOM
&& x
< gw
) ||
196 (_matrix
->arrangement() == PortMatrix::TOP_TO_RIGHT
&& x
> (_width
- gw
))
199 w
.second
.bundle
.reset ();
204 if (w
.second
.bundle
) {
205 _body
->highlight_associated_channels (_matrix
->row_index(), w
.second
);
208 w
.first
->set_visible (!w
.first
->visible());
214 _matrix
->popup_menu (
215 make_pair (boost::shared_ptr
<PortGroup
> (), ARDOUR::BundleChannel ()),
223 PortMatrixRowLabels::component_to_parent_x (double x
) const
225 return x
+ _parent_rectangle
.get_x();
229 PortMatrixRowLabels::parent_to_component_x (double x
) const
231 return x
- _parent_rectangle
.get_x();
235 PortMatrixRowLabels::component_to_parent_y (double y
) const
237 return y
- _body
->yoffset() + _parent_rectangle
.get_y();
241 PortMatrixRowLabels::parent_to_component_y (double y
) const
243 return y
+ _body
->yoffset() - _parent_rectangle
.get_y();
248 PortMatrixRowLabels::bundle_name_x () const
252 if (_matrix
->arrangement() == PortMatrix::LEFT_TO_BOTTOM
) {
253 x
= _highest_group_name
+ 2 * name_pad();
255 if (_matrix
->show_only_bundles()) {
258 x
= _longest_port_name
+ name_pad() * 2;
266 PortMatrixRowLabels::port_name_x () const
268 if (_matrix
->arrangement() == PortMatrix::LEFT_TO_BOTTOM
) {
269 return _longest_bundle_name
+ _highest_group_name
+ name_pad() * 4;
278 PortMatrixRowLabels::render_bundle_name (
279 cairo_t
* cr
, Gdk::Color fg_colour
, Gdk::Color bg_colour
, double xoff
, double yoff
, boost::shared_ptr
<ARDOUR::Bundle
> b
282 double const x
= bundle_name_x ();
284 int const n
= _matrix
->show_only_bundles() ? 1 : b
->nchannels();
285 set_source_rgb (cr
, bg_colour
);
286 cairo_rectangle (cr
, xoff
+ x
, yoff
, _longest_bundle_name
+ name_pad() * 2, grid_spacing() * n
);
287 cairo_fill_preserve (cr
);
288 set_source_rgb (cr
, fg_colour
);
289 cairo_set_line_width (cr
, label_border_width ());
292 double const off
= grid_spacing() / 2;
294 // if ((*i)->nchannels () > 0 && !_matrix->show_only_bundles()) {
295 // /* use the extent of our first channel name so that the bundle name is vertically aligned with it */
296 // cairo_text_extents_t ext;
297 // cairo_text_extents (cr, (*i)->channel_name(0).c_str(), &ext);
298 // off = (grid_spacing() - ext.height) / 2;
301 set_source_rgb (cr
, text_colour());
302 cairo_move_to (cr
, xoff
+ x
+ name_pad(), yoff
+ name_pad() + off
);
303 cairo_show_text (cr
, b
->name().c_str());
307 PortMatrixRowLabels::render_channel_name (
308 cairo_t
* cr
, Gdk::Color fg_colour
, Gdk::Color bg_colour
, double xoff
, double yoff
, ARDOUR::BundleChannel
const& bc
311 set_source_rgb (cr
, bg_colour
);
312 cairo_rectangle (cr
, port_name_x() + xoff
, yoff
, _longest_port_name
+ name_pad() * 2, grid_spacing());
313 cairo_fill_preserve (cr
);
314 set_source_rgb (cr
, fg_colour
);
315 cairo_set_line_width (cr
, label_border_width ());
318 cairo_text_extents_t ext
;
319 cairo_text_extents (cr
, bc
.bundle
->channel_name(bc
.channel
).c_str(), &ext
);
320 double const off
= (grid_spacing() - ext
.height
) / 2;
322 set_source_rgb (cr
, text_colour());
323 cairo_move_to (cr
, port_name_x() + xoff
+ name_pad(), yoff
+ name_pad() + off
);
324 cairo_show_text (cr
, bc
.bundle
->channel_name(bc
.channel
).c_str());
328 PortMatrixRowLabels::channel_x (ARDOUR::BundleChannel
const &) const
334 PortMatrixRowLabels::channel_y (ARDOUR::BundleChannel
const& bc
) const
336 return channel_to_position (bc
, _matrix
->rows()) * grid_spacing ();
340 PortMatrixRowLabels::queue_draw_for (ARDOUR::BundleChannel
const & bc
)
344 if (_matrix
->show_only_bundles()) {
345 _body
->queue_draw_area (
346 component_to_parent_x (bundle_name_x()) - 1,
347 component_to_parent_y (channel_y (bc
)) - 1,
348 _longest_bundle_name
+ name_pad() * 2 + 2,
352 _body
->queue_draw_area (
353 component_to_parent_x (port_name_x()) - 1,
354 component_to_parent_y (channel_y (bc
)) - 1,
355 _longest_port_name
+ name_pad() * 2 + 2,
364 PortMatrixRowLabels::mouseover_changed (PortMatrixNode
const &)
366 clear_channel_highlights ();
367 if (_body
->mouseover().column
.bundle
&& _body
->mouseover().row
.bundle
) {
368 add_channel_highlight (_body
->mouseover().row
);