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_body.h"
23 #include "port_matrix.h"
25 PortMatrixBody::PortMatrixBody (PortMatrix* p, Arrangement a)
27 _column_labels (this, a == TOP_AND_RIGHT ? PortMatrixColumnLabels::TOP : PortMatrixColumnLabels::BOTTOM),
28 _row_labels (p, this, a == BOTTOM_AND_LEFT ? PortMatrixRowLabels::LEFT : PortMatrixRowLabels::RIGHT),
34 modify_bg (Gtk::STATE_NORMAL, Gdk::Color ("#00000"));
39 PortMatrixBody::on_expose_event (GdkEventExpose* event)
41 Gdk::Rectangle const exposure (
42 event->area.x, event->area.y, event->area.width, event->area.height
46 Gdk::Rectangle r = exposure;
47 r.intersect (_column_labels_rect, intersects);
52 get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(),
53 _column_labels.get_pixmap (get_window()->gobj()),
54 r.get_x() - _column_labels_rect.get_x() + _xoffset,
55 r.get_y() - _column_labels_rect.get_y(),
64 r.intersect (_row_labels_rect, intersects);
69 get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(),
70 _row_labels.get_pixmap (get_window()->gobj()),
71 r.get_x() - _row_labels_rect.get_x(),
72 r.get_y() - _row_labels_rect.get_y() + _yoffset,
81 r.intersect (_grid_rect, intersects);
86 get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(),
87 _grid.get_pixmap (get_window()->gobj()),
88 r.get_x() - _grid_rect.get_x() + _xoffset,
89 r.get_y() - _grid_rect.get_y() + _yoffset,
101 PortMatrixBody::on_size_request (Gtk::Requisition *req)
103 std::pair<int, int> const col = _column_labels.dimensions ();
104 std::pair<int, int> const row = _row_labels.dimensions ();
105 std::pair<int, int> const grid = _grid.dimensions ();
107 req->width = std::max (col.first, grid.first + row.first);
108 req->height = col.second + grid.second;
112 PortMatrixBody::on_size_allocate (Gtk::Allocation& alloc)
114 Gtk::EventBox::on_size_allocate (alloc);
115 set_allocation (alloc);
117 _alloc_width = alloc.get_width ();
118 _alloc_height = alloc.get_height ();
120 compute_rectangles ();
121 _port_matrix->setup_scrollbars ();
125 PortMatrixBody::compute_rectangles ()
127 /* full sizes of components */
128 std::pair<uint32_t, uint32_t> const col = _column_labels.dimensions ();
129 std::pair<uint32_t, uint32_t> const row = _row_labels.dimensions ();
130 std::pair<uint32_t, uint32_t> const grid = _grid.dimensions ();
132 if (_arrangement == TOP_AND_RIGHT) {
134 /* build from top left */
136 _column_labels_rect.set_x (0);
137 _column_labels_rect.set_y (0);
138 _grid_rect.set_x (0);
140 if (_alloc_width > col.first) {
141 _column_labels_rect.set_width (col.first);
143 _column_labels_rect.set_width (_alloc_width);
146 /* move down to y division */
149 if (_alloc_height > col.second) {
155 _column_labels_rect.set_height (y);
156 _row_labels_rect.set_y (y);
157 _row_labels_rect.set_height (_alloc_height - y);
158 _grid_rect.set_y (y);
159 _grid_rect.set_height (_alloc_height - y);
161 /* move right to x division */
164 if (_alloc_width > (grid.first + row.first)) {
166 } else if (_alloc_width > row.first) {
167 x = _alloc_width - row.first;
170 _grid_rect.set_width (x);
171 _row_labels_rect.set_x (x);
172 _row_labels_rect.set_width (_alloc_width - x);
175 } else if (_arrangement == BOTTOM_AND_LEFT) {
177 /* build from bottom right */
179 /* move left to x division */
182 if (_alloc_width > (grid.first + row.first)) {
184 } else if (_alloc_width > row.first) {
185 x = _alloc_width - row.first;
188 _grid_rect.set_x (_alloc_width - x);
189 _grid_rect.set_width (x);
190 _column_labels_rect.set_width (col.first - grid.first + x);
191 _column_labels_rect.set_x (_alloc_width - _column_labels_rect.get_width());
193 _row_labels_rect.set_width (std::min (_alloc_width - x, row.first));
194 _row_labels_rect.set_x (_alloc_width - x - _row_labels_rect.get_width());
196 /* move up to the y division */
199 if (_alloc_height > col.second) {
205 _column_labels_rect.set_y (_alloc_height - y);
206 _column_labels_rect.set_height (y);
208 _grid_rect.set_height (std::min (grid.second, _alloc_height - y));
209 _grid_rect.set_y (_alloc_height - y - _grid_rect.get_height());
211 _row_labels_rect.set_height (_grid_rect.get_height());
212 _row_labels_rect.set_y (_grid_rect.get_y());
218 PortMatrixBody::setup (
219 std::vector<boost::shared_ptr<ARDOUR::Bundle> > const & row,
220 std::vector<boost::shared_ptr<ARDOUR::Bundle> > const & column
223 for (std::list<sigc::connection>::iterator i = _bundle_connections.begin(); i != _bundle_connections.end(); ++i) {
227 _bundle_connections.clear ();
230 _column_bundles = column;
232 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::iterator i = _row_bundles.begin(); i != _row_bundles.end(); ++i) {
234 _bundle_connections.push_back (
235 (*i)->NameChanged.connect (sigc::mem_fun (*this, &PortMatrixBody::rebuild_and_draw_row_labels))
240 for (std::vector<boost::shared_ptr<ARDOUR::Bundle> >::iterator i = _column_bundles.begin(); i != _column_bundles.end(); ++i) {
241 _bundle_connections.push_back (
242 (*i)->NameChanged.connect (sigc::mem_fun (*this, &PortMatrixBody::rebuild_and_draw_column_labels))
246 _column_labels.setup ();
247 _row_labels.setup ();
250 compute_rectangles ();
254 PortMatrixBody::full_scroll_width ()
256 return _grid.dimensions().first;
261 PortMatrixBody::alloc_scroll_width ()
263 return _grid_rect.get_width();
267 PortMatrixBody::full_scroll_height ()
269 return _grid.dimensions().second;
273 PortMatrixBody::alloc_scroll_height ()
275 return _grid_rect.get_height();
279 PortMatrixBody::set_xoffset (uint32_t xo)
286 PortMatrixBody::set_yoffset (uint32_t yo)
293 PortMatrixBody::on_button_press_event (GdkEventButton* ev)
295 if (Gdk::Region (_grid_rect).point_in (ev->x, ev->y)) {
298 ev->x - _grid_rect.get_x() + _xoffset,
299 ev->y - _grid_rect.get_y() + _yoffset,
303 } else if (Gdk::Region (_row_labels_rect).point_in (ev->x, ev->y)) {
305 _row_labels.button_press (
306 ev->x - _row_labels_rect.get_x(),
307 ev->y - _row_labels_rect.get_y() + _yoffset,
321 PortMatrixBody::rebuild_and_draw_grid ()
323 _grid.require_rebuild ();
328 PortMatrixBody::rebuild_and_draw_column_labels ()
330 _column_labels.require_rebuild ();
335 PortMatrixBody::rebuild_and_draw_row_labels ()
337 _row_labels.require_rebuild ();