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_body.h"
24 #include "port_matrix.h"
26 PortMatrixBody::PortMatrixBody (PortMatrix* p, Arrangement a)
28 _column_labels (this, a == TOP_AND_RIGHT ? PortMatrixColumnLabels::TOP : PortMatrixColumnLabels::BOTTOM),
29 _row_labels (p, this, a == BOTTOM_AND_LEFT ? PortMatrixRowLabels::LEFT : PortMatrixRowLabels::RIGHT),
34 _column_ports (_port_matrix->type(), _port_matrix->offering_input()),
35 _row_ports (_port_matrix->type(), !_port_matrix->offering_input())
37 modify_bg (Gtk::STATE_NORMAL, Gdk::Color ("#00000"));
42 PortMatrixBody::on_expose_event (GdkEventExpose* event)
44 Gdk::Rectangle const exposure (
45 event->area.x, event->area.y, event->area.width, event->area.height
49 Gdk::Rectangle r = exposure;
50 r.intersect (_column_labels_rect, intersects);
55 get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(),
56 _column_labels.get_pixmap (get_window()->gobj()),
57 r.get_x() - _column_labels_rect.get_x() + _xoffset,
58 r.get_y() - _column_labels_rect.get_y(),
67 r.intersect (_row_labels_rect, intersects);
72 get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(),
73 _row_labels.get_pixmap (get_window()->gobj()),
74 r.get_x() - _row_labels_rect.get_x(),
75 r.get_y() - _row_labels_rect.get_y() + _yoffset,
84 r.intersect (_grid_rect, intersects);
89 get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(),
90 _grid.get_pixmap (get_window()->gobj()),
91 r.get_x() - _grid_rect.get_x() + _xoffset,
92 r.get_y() - _grid_rect.get_y() + _yoffset,
104 PortMatrixBody::on_size_request (Gtk::Requisition *req)
106 std::pair<int, int> const col = _column_labels.dimensions ();
107 std::pair<int, int> const row = _row_labels.dimensions ();
108 std::pair<int, int> const grid = _grid.dimensions ();
110 req->width = std::max (col.first, grid.first + row.first);
111 req->height = col.second + grid.second;
115 PortMatrixBody::on_size_allocate (Gtk::Allocation& alloc)
117 Gtk::EventBox::on_size_allocate (alloc);
118 set_allocation (alloc);
120 _alloc_width = alloc.get_width ();
121 _alloc_height = alloc.get_height ();
123 compute_rectangles ();
124 _port_matrix->setup_scrollbars ();
128 PortMatrixBody::compute_rectangles ()
130 /* full sizes of components */
131 std::pair<uint32_t, uint32_t> const col = _column_labels.dimensions ();
132 std::pair<uint32_t, uint32_t> const row = _row_labels.dimensions ();
133 std::pair<uint32_t, uint32_t> const grid = _grid.dimensions ();
135 if (_arrangement == TOP_AND_RIGHT) {
137 /* build from top left */
139 _column_labels_rect.set_x (0);
140 _column_labels_rect.set_y (0);
141 _grid_rect.set_x (0);
143 if (_alloc_width > col.first) {
144 _column_labels_rect.set_width (col.first);
146 _column_labels_rect.set_width (_alloc_width);
149 /* move down to y division */
152 if (_alloc_height > col.second) {
158 _column_labels_rect.set_height (y);
159 _row_labels_rect.set_y (y);
160 _row_labels_rect.set_height (_alloc_height - y);
161 _grid_rect.set_y (y);
162 _grid_rect.set_height (_alloc_height - y);
164 /* move right to x division */
167 if (_alloc_width > (grid.first + row.first)) {
169 } else if (_alloc_width > row.first) {
170 x = _alloc_width - row.first;
173 _grid_rect.set_width (x);
174 _row_labels_rect.set_x (x);
175 _row_labels_rect.set_width (_alloc_width - x);
178 } else if (_arrangement == BOTTOM_AND_LEFT) {
180 /* build from bottom right */
182 /* move left to x division */
185 if (_alloc_width > (grid.first + row.first)) {
187 } else if (_alloc_width > row.first) {
188 x = _alloc_width - row.first;
191 _grid_rect.set_x (_alloc_width - x);
192 _grid_rect.set_width (x);
193 _column_labels_rect.set_width (col.first - grid.first + x);
194 _column_labels_rect.set_x (_alloc_width - _column_labels_rect.get_width());
196 _row_labels_rect.set_width (std::min (_alloc_width - x, row.first));
197 _row_labels_rect.set_x (_alloc_width - x - _row_labels_rect.get_width());
199 /* move up to the y division */
202 if (_alloc_height > col.second) {
208 _column_labels_rect.set_y (_alloc_height - y);
209 _column_labels_rect.set_height (y);
211 _grid_rect.set_height (std::min (grid.second, _alloc_height - y));
212 _grid_rect.set_y (_alloc_height - y - _grid_rect.get_height());
214 _row_labels_rect.set_height (_grid_rect.get_height());
215 _row_labels_rect.set_y (_grid_rect.get_y());
221 PortMatrixBody::setup (PortGroupList const& row, PortGroupList const& column)
223 for (std::list<sigc::connection>::iterator i = _bundle_connections.begin(); i != _bundle_connections.end(); ++i) {
227 _bundle_connections.clear ();
230 _column_ports = column;
232 ARDOUR::BundleList r = _row_ports.bundles ();
233 for (ARDOUR::BundleList::iterator i = r.begin(); i != r.end(); ++i) {
235 _bundle_connections.push_back (
236 (*i)->NameChanged.connect (sigc::mem_fun (*this, &PortMatrixBody::rebuild_and_draw_row_labels))
241 ARDOUR::BundleList c = _column_ports.bundles ();
242 for (ARDOUR::BundleList::iterator i = c.begin(); i != c.end(); ++i) {
243 _bundle_connections.push_back (
244 (*i)->NameChanged.connect (sigc::mem_fun (*this, &PortMatrixBody::rebuild_and_draw_column_labels))
248 _column_labels.setup ();
249 _row_labels.setup ();
252 compute_rectangles ();
256 PortMatrixBody::full_scroll_width ()
258 return _grid.dimensions().first;
263 PortMatrixBody::alloc_scroll_width ()
265 return _grid_rect.get_width();
269 PortMatrixBody::full_scroll_height ()
271 return _grid.dimensions().second;
275 PortMatrixBody::alloc_scroll_height ()
277 return _grid_rect.get_height();
281 PortMatrixBody::set_xoffset (uint32_t xo)
288 PortMatrixBody::set_yoffset (uint32_t yo)
295 PortMatrixBody::on_button_press_event (GdkEventButton* ev)
297 if (Gdk::Region (_grid_rect).point_in (ev->x, ev->y)) {
300 ev->x - _grid_rect.get_x() + _xoffset,
301 ev->y - _grid_rect.get_y() + _yoffset,
305 } else if (Gdk::Region (_row_labels_rect).point_in (ev->x, ev->y)) {
307 _row_labels.button_press (
308 ev->x - _row_labels_rect.get_x(),
309 ev->y - _row_labels_rect.get_y() + _yoffset,
323 PortMatrixBody::rebuild_and_draw_grid ()
325 _grid.require_rebuild ();
330 PortMatrixBody::rebuild_and_draw_column_labels ()
332 _column_labels.require_rebuild ();
337 PortMatrixBody::rebuild_and_draw_row_labels ()
339 _row_labels.require_rebuild ();