From 4476461443061703e9ef268ade72511dff3e3ae5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 21 Jan 2009 01:55:46 +0000 Subject: More logical arrangement of port matrix inputs and outputs, hopefully; signal show notionally "flow" from left to bottom or from top to right. Some layout cleanups. git-svn-id: svn://localhost/ardour2/branches/3.0@4416 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/port_matrix.cc | 2 +- gtk2_ardour/port_matrix_body.cc | 172 ++++++++++++++++++++++--------- gtk2_ardour/port_matrix_body.h | 15 ++- gtk2_ardour/port_matrix_column_labels.cc | 100 ++++++++++++------ gtk2_ardour/port_matrix_column_labels.h | 17 ++- gtk2_ardour/port_matrix_row_labels.cc | 43 +++++--- gtk2_ardour/port_matrix_row_labels.h | 8 +- 7 files changed, 247 insertions(+), 110 deletions(-) diff --git a/gtk2_ardour/port_matrix.cc b/gtk2_ardour/port_matrix.cc index 1e9227a525..66d9f41be0 100644 --- a/gtk2_ardour/port_matrix.cc +++ b/gtk2_ardour/port_matrix.cc @@ -35,7 +35,7 @@ PortMatrix::PortMatrix (ARDOUR::Session& session, ARDOUR::DataType type, bool of : _offer_inputs (offer_inputs), _port_group_list (session, type, offer_inputs, mask), _type (type), - _body (this) + _body (this, offer_inputs ? PortMatrixBody::BOTTOM_AND_LEFT : PortMatrixBody::TOP_AND_RIGHT) { /* checkbuttons for visibility of groups */ Gtk::HBox* visibility_buttons = Gtk::manage (new Gtk::HBox); diff --git a/gtk2_ardour/port_matrix_body.cc b/gtk2_ardour/port_matrix_body.cc index d30dca5e85..3a69c4ccf2 100644 --- a/gtk2_ardour/port_matrix_body.cc +++ b/gtk2_ardour/port_matrix_body.cc @@ -22,19 +22,16 @@ #include "port_matrix_body.h" #include "port_matrix.h" -PortMatrixBody::PortMatrixBody (PortMatrix* p) +PortMatrixBody::PortMatrixBody (PortMatrix* p, Arrangement a) : _port_matrix (p), - _column_labels (this), - _row_labels (p, this), + _column_labels (this, a == TOP_AND_RIGHT ? PortMatrixColumnLabels::TOP : PortMatrixColumnLabels::BOTTOM), + _row_labels (p, this, a == BOTTOM_AND_LEFT ? PortMatrixRowLabels::LEFT : PortMatrixRowLabels::RIGHT), _grid (p, this), - _alloc_width (0), - _alloc_height (0), - _alloc_xdiv (0), - _alloc_ydiv (0), + _arrangement (a), _xoffset (0), _yoffset (0) { - + modify_bg (Gtk::STATE_NORMAL, Gdk::Color ("#00000")); } @@ -45,21 +42,17 @@ PortMatrixBody::on_expose_event (GdkEventExpose* event) event->area.x, event->area.y, event->area.width, event->area.height ); - Gdk::Rectangle const col (0, 0, _alloc_width, _alloc_ydiv); - Gdk::Rectangle const row (_alloc_xdiv, _alloc_ydiv, _alloc_width - _alloc_xdiv, _alloc_height - _alloc_ydiv); - Gdk::Rectangle const grid (0, _alloc_ydiv, _alloc_xdiv, _alloc_height - _alloc_ydiv); - bool intersects; Gdk::Rectangle r = exposure; - r.intersect (col, intersects); + r.intersect (_column_labels_rect, intersects); if (intersects) { gdk_draw_drawable ( get_window()->gobj(), get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(), _column_labels.get_pixmap (get_window()->gobj()), - r.get_x() + _xoffset, - r.get_y(), + r.get_x() - _column_labels_rect.get_x() + _xoffset, + r.get_y() - _column_labels_rect.get_y(), r.get_x(), r.get_y(), r.get_width(), @@ -68,15 +61,15 @@ PortMatrixBody::on_expose_event (GdkEventExpose* event) } r = exposure; - r.intersect (row, intersects); + r.intersect (_row_labels_rect, intersects); if (intersects) { gdk_draw_drawable ( get_window()->gobj(), get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(), _row_labels.get_pixmap (get_window()->gobj()), - r.get_x() - _alloc_xdiv, - r.get_y() + _yoffset - _alloc_ydiv, + r.get_x() - _row_labels_rect.get_x(), + r.get_y() - _row_labels_rect.get_y() + _yoffset, r.get_x(), r.get_y(), r.get_width(), @@ -85,15 +78,15 @@ PortMatrixBody::on_expose_event (GdkEventExpose* event) } r = exposure; - r.intersect (grid, intersects); + r.intersect (_grid_rect, intersects); if (intersects) { gdk_draw_drawable ( get_window()->gobj(), get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(), _grid.get_pixmap (get_window()->gobj()), - r.get_x() + _xoffset, - r.get_y() + _yoffset - _alloc_ydiv, + r.get_x() - _grid_rect.get_x() + _xoffset, + r.get_y() - _grid_rect.get_y() + _yoffset, r.get_x(), r.get_y(), r.get_width(), @@ -124,37 +117,100 @@ PortMatrixBody::on_size_allocate (Gtk::Allocation& alloc) _alloc_width = alloc.get_width (); _alloc_height = alloc.get_height (); - compute_divs (); + compute_rectangles (); _port_matrix->setup_scrollbars (); } void -PortMatrixBody::compute_divs () +PortMatrixBody::compute_rectangles () { + /* full sizes of components */ std::pair const col = _column_labels.dimensions (); - if (_alloc_height > col.second) { - /* allocated height is enough for the column labels */ - _alloc_ydiv = col.second; - } else { - /* not enough space for the column labels */ - _alloc_ydiv = _alloc_height; - } - - std::pair const grid = _grid.dimensions (); std::pair const row = _row_labels.dimensions (); + std::pair const grid = _grid.dimensions (); + + if (_arrangement == TOP_AND_RIGHT) { + + /* build from top left */ + + _column_labels_rect.set_x (0); + _column_labels_rect.set_y (0); + _grid_rect.set_x (0); + + if (_alloc_width > col.first) { + _column_labels_rect.set_width (col.first); + } else { + _column_labels_rect.set_width (_alloc_width); + } + + /* move down to y division */ + + uint32_t y = 0; + if (_alloc_height > col.second) { + y = col.second; + } else { + y = _alloc_height; + } + + _column_labels_rect.set_height (y); + _row_labels_rect.set_y (y); + _row_labels_rect.set_height (_alloc_height - y); + _grid_rect.set_y (y); + _grid_rect.set_height (_alloc_height - y); + + /* move right to x division */ + + uint32_t x = 0; + if (_alloc_width > (grid.first + row.first)) { + x = grid.first; + } else if (_alloc_width > row.first) { + x = _alloc_width - row.first; + } + + _grid_rect.set_width (x); + _row_labels_rect.set_x (x); + _row_labels_rect.set_width (_alloc_width - x); + + + } else if (_arrangement == BOTTOM_AND_LEFT) { + + /* build from bottom right */ + + /* move left to x division */ + + uint32_t x = 0; + if (_alloc_width > (grid.first + row.first)) { + x = grid.first; + } else if (_alloc_width > row.first) { + x = _alloc_width - row.first; + } + + _grid_rect.set_x (_alloc_width - x); + _grid_rect.set_width (x); + _column_labels_rect.set_width (std::min (_alloc_width, col.first)); + _column_labels_rect.set_x (_alloc_width - _column_labels_rect.get_width()); + + _row_labels_rect.set_width (std::min (_alloc_width - x, row.first)); + _row_labels_rect.set_x (_alloc_width - x - _row_labels_rect.get_width()); + + /* move up to the y division */ + + uint32_t y = 0; + if (_alloc_height > col.second) { + y = col.second; + } else { + y = _alloc_height; + } + + _column_labels_rect.set_y (_alloc_height - y); + _column_labels_rect.set_height (y); + + _grid_rect.set_height (std::min (grid.second, _alloc_height - y)); + _grid_rect.set_y (_alloc_height - y - _grid_rect.get_height()); + + _row_labels_rect.set_height (_grid_rect.get_height()); + _row_labels_rect.set_y (_grid_rect.get_y()); - if (_alloc_width > (grid.first + row.first)) { - /* allocated width is larger than we need, so - put the x division at the extent of the grid */ - _alloc_xdiv = grid.first; - } else if (_alloc_width > row.first) { - /* allocated width is large enough for the row labels - but not for the whole grid, so display the whole - row label section and cut part of the grid off */ - _alloc_xdiv = _alloc_width - row.first; - } else { - /* allocated width isn't even enough for the row labels */ - _alloc_xdiv = 0; } } @@ -191,7 +247,7 @@ PortMatrixBody::setup ( _row_labels.setup (); _grid.setup (); - compute_divs (); + compute_rectangles (); } uint32_t @@ -204,7 +260,7 @@ PortMatrixBody::full_scroll_width () uint32_t PortMatrixBody::alloc_scroll_width () { - return _alloc_xdiv; + return _grid_rect.get_width(); } uint32_t @@ -216,7 +272,7 @@ PortMatrixBody::full_scroll_height () uint32_t PortMatrixBody::alloc_scroll_height () { - return _alloc_height - _alloc_ydiv; + return _grid_rect.get_height(); } void @@ -236,12 +292,26 @@ PortMatrixBody::set_yoffset (uint32_t yo) bool PortMatrixBody::on_button_press_event (GdkEventButton* ev) { - if (ev->x < _alloc_xdiv && ev->y > _alloc_ydiv) { - _grid.button_press (ev->x + _xoffset, ev->y + _yoffset - _alloc_ydiv, ev->button); - } else if (ev->x > _alloc_xdiv && ev->y > _alloc_ydiv) { - _row_labels.button_press (ev->x - _alloc_xdiv, ev->y + _yoffset - _alloc_ydiv, ev->button, ev->time); + if (Gdk::Region (_grid_rect).point_in (ev->x, ev->y)) { + + _grid.button_press ( + ev->x - _grid_rect.get_x() + _xoffset, + ev->y - _grid_rect.get_y() + _yoffset, + ev->button + ); + + } else if (Gdk::Region (_row_labels_rect).point_in (ev->x, ev->y)) { + + _row_labels.button_press ( + ev->x - _row_labels_rect.get_x(), + ev->y - _row_labels_rect.get_y() + _yoffset, + ev->button, ev->time + ); + } else { + return false; + } return true; diff --git a/gtk2_ardour/port_matrix_body.h b/gtk2_ardour/port_matrix_body.h index 503bb3ab62..bb2d592fe8 100644 --- a/gtk2_ardour/port_matrix_body.h +++ b/gtk2_ardour/port_matrix_body.h @@ -33,7 +33,12 @@ class PortMatrix; class PortMatrixBody : public Gtk::EventBox { public: - PortMatrixBody (PortMatrix *); + enum Arrangement { + TOP_AND_RIGHT, + BOTTOM_AND_LEFT + }; + + PortMatrixBody (PortMatrix *, Arrangement); /** @return bundles to offer for columns */ std::vector > const & column_bundles () { @@ -67,7 +72,7 @@ protected: bool on_button_press_event (GdkEventButton *); private: - void compute_divs (); + void compute_rectangles (); void repaint_column_labels (); void repaint_row_labels (); @@ -76,10 +81,12 @@ private: PortMatrixRowLabels _row_labels; PortMatrixGrid _grid; + Arrangement _arrangement; uint32_t _alloc_width; ///< allocated width uint32_t _alloc_height; ///< allocated height - uint32_t _alloc_xdiv; ///< position of the division between grid and row labels - uint32_t _alloc_ydiv; ///< position of the division between column labels and grid + Gdk::Rectangle _column_labels_rect; + Gdk::Rectangle _row_labels_rect; + Gdk::Rectangle _grid_rect; uint32_t _xoffset; uint32_t _yoffset; diff --git a/gtk2_ardour/port_matrix_column_labels.cc b/gtk2_ardour/port_matrix_column_labels.cc index 343d225b55..90099eb1e5 100644 --- a/gtk2_ardour/port_matrix_column_labels.cc +++ b/gtk2_ardour/port_matrix_column_labels.cc @@ -22,10 +22,10 @@ #include "port_matrix_column_labels.h" #include "port_matrix.h" -PortMatrixColumnLabels::PortMatrixColumnLabels (PortMatrixBody* b) - : PortMatrixComponent (b) +PortMatrixColumnLabels::PortMatrixColumnLabels (PortMatrixBody* b, Location l) + : PortMatrixComponent (b), _location (l) { - + } void @@ -87,7 +87,7 @@ PortMatrixColumnLabels::compute_dimensions () _width += _height / tan (angle ()); } -uint32_t +double PortMatrixColumnLabels::basic_text_x_pos (int c) const { return column_width() / 2 + @@ -105,16 +105,16 @@ PortMatrixColumnLabels::render (cairo_t* cr) /* BUNDLE PARALLELOGRAM-TYPE-THING AND NAME */ - uint32_t x = 0; + double x = 0; for (std::vector >::const_iterator i = _body->column_bundles().begin (); i != _body->column_bundles().end(); ++i) { Gdk::Color colour = get_a_bundle_colour (i - _body->column_bundles().begin ()); set_source_rgb (cr, colour); - uint32_t const w = (*i)->nchannels() * column_width(); + double const w = (*i)->nchannels() * column_width(); - uint32_t x_ = x; - uint32_t y_ = _height; + double x_ = x; + double y_ = _height; cairo_move_to (cr, x_, y_); x_ += w; @@ -132,14 +132,25 @@ PortMatrixColumnLabels::render (cairo_t* cr) set_source_rgb (cr, text_colour()); - uint32_t const rl = 3 * name_pad() + _longest_channel_name; - cairo_move_to ( - cr, - x + basic_text_x_pos (0) + rl * cos (angle()), - _height - rl * sin (angle()) - ); - + if (_location == TOP) { + + double const rl = 3 * name_pad() + _longest_channel_name; + cairo_move_to ( + cr, + x + basic_text_x_pos (0) + rl * cos (angle()), + _height - rl * sin (angle()) + ); + + } else if (_location == BOTTOM) { + + cairo_move_to ( + cr, + x + basic_text_x_pos (0), + _height - name_pad() * sin (angle()) + ); + } + cairo_save (cr); cairo_rotate (cr, -angle()); cairo_show_text (cr, (*i)->name().c_str()); @@ -156,21 +167,42 @@ PortMatrixColumnLabels::render (cairo_t* cr) for (uint32_t j = 0; j < (*i)->nchannels(); ++j) { - uint32_t const p = _longest_channel_name + (2 * name_pad()); - uint32_t const w = column_width(); - - uint32_t x_ = x; - uint32_t y_ = _height; - cairo_move_to (cr, x_, y_); - x_ += w; - cairo_line_to (cr, x_, y_); - x_ += p * cos (angle()); - y_ -= p * sin (angle()); - cairo_line_to (cr, x_, y_); - x_ -= column_width() * pow (sin (angle()), 2); - y_ -= column_width() * sin (angle()) * cos (angle()); - cairo_line_to (cr, x_, y_); - cairo_line_to (cr, x, _height); + double const lc = _longest_channel_name + (2 * name_pad()); + double const lb = _longest_bundle_name + (2 * name_pad()); + double const w = column_width(); + + if (_location == BOTTOM) { + + double x_ = x + _height / tan (angle()) + w; + double const ix = x_; + double y_ = 0; + cairo_move_to (cr, x_, y_); + x_ -= w; + cairo_line_to (cr, x_, y_); + x_ -= lb * cos (angle()); + y_ += lb * sin (angle()); + cairo_line_to (cr, x_, y_); + x_ += w * pow (sin (angle()), 2); + y_ += w * sin (angle()) * cos (angle()); + cairo_line_to (cr, x_, y_); + cairo_line_to (cr, ix, 0); + + } else if (_location == TOP) { + + double x_ = x; + double y_ = _height; + cairo_move_to (cr, x_, y_); + x_ += w; + cairo_line_to (cr, x_, y_); + x_ += lc * cos (angle()); + y_ -= lc * sin (angle()); + cairo_line_to (cr, x_, y_); + x_ -= column_width() * pow (sin (angle()), 2); + y_ -= column_width() * sin (angle()) * cos (angle()); + cairo_line_to (cr, x_, y_); + cairo_line_to (cr, x, _height); + + } Gdk::Color colour = get_a_bundle_colour (i - _body->column_bundles().begin()); set_source_rgb (cr, colour); @@ -180,7 +212,13 @@ PortMatrixColumnLabels::render (cairo_t* cr) cairo_stroke (cr); set_source_rgb (cr, text_colour()); - cairo_move_to (cr, x + basic_text_x_pos(j), _height - name_pad() * sin (angle())); + + if (_location == TOP) { + cairo_move_to (cr, x + basic_text_x_pos(j), _height - name_pad() * sin (angle())); + } else if (_location == BOTTOM) { + double const rl = 3 * name_pad() + _longest_bundle_name; + cairo_move_to (cr, x + basic_text_x_pos(j) + rl * cos (angle ()), _height - rl * sin (angle())); + } cairo_save (cr); cairo_rotate (cr, -angle()); diff --git a/gtk2_ardour/port_matrix_column_labels.h b/gtk2_ardour/port_matrix_column_labels.h index 3c9ff41838..76510073ec 100644 --- a/gtk2_ardour/port_matrix_column_labels.h +++ b/gtk2_ardour/port_matrix_column_labels.h @@ -33,17 +33,24 @@ namespace ARDOUR { class PortMatrixColumnLabels : public PortMatrixComponent { public: - PortMatrixColumnLabels (PortMatrixBody *); + + enum Location { + TOP, + BOTTOM + }; + + PortMatrixColumnLabels (PortMatrixBody *, Location); private: void render (cairo_t *); void compute_dimensions (); - uint32_t basic_text_x_pos (int) const; + double basic_text_x_pos (int) const; std::vector > _bundles; - uint32_t _longest_bundle_name; - uint32_t _longest_channel_name; - uint32_t _highest_text; + double _longest_bundle_name; + double _longest_channel_name; + double _highest_text; + Location _location; }; #endif diff --git a/gtk2_ardour/port_matrix_row_labels.cc b/gtk2_ardour/port_matrix_row_labels.cc index 18e479942e..55c760f441 100644 --- a/gtk2_ardour/port_matrix_row_labels.cc +++ b/gtk2_ardour/port_matrix_row_labels.cc @@ -28,8 +28,8 @@ #include "port_matrix.h" #include "i18n.h" -PortMatrixRowLabels::PortMatrixRowLabels (PortMatrix* p, PortMatrixBody* b) - : PortMatrixComponent (b), _port_matrix (p), _menu (0) +PortMatrixRowLabels::PortMatrixRowLabels (PortMatrix* p, PortMatrixBody* b, Location l) + : PortMatrixComponent (b), _port_matrix (p), _menu (0), _location (l) { } @@ -74,9 +74,7 @@ PortMatrixRowLabels::compute_dimensions () _height += (*i)->nchannels() * row_height(); } - _width = _longest_port_name + - name_pad() * 4 + - _longest_bundle_name + name_pad() * 2; + _width = _longest_port_name + name_pad() * 4 + _longest_bundle_name; } @@ -91,20 +89,19 @@ PortMatrixRowLabels::render (cairo_t* cr) /* SIDE BUNDLE NAMES */ - uint32_t x = _longest_port_name + name_pad() * 3; + uint32_t x; + if (_location == LEFT) { + x = name_pad(); + } else if (_location == RIGHT) { + x = _longest_port_name + name_pad() * 3; + } uint32_t y = 0; for (std::vector >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) { Gdk::Color const colour = get_a_bundle_colour (i - _body->row_bundles().begin ()); set_source_rgb (cr, colour); - cairo_rectangle ( - cr, - 0, - y, - _longest_port_name + name_pad() * 4 + _longest_bundle_name + name_pad() * 2, - row_height() * (*i)->nchannels() - ); + cairo_rectangle (cr, 0, y, _width, row_height() * (*i)->nchannels()); cairo_fill_preserve (cr); set_source_rgb (cr, background_colour()); cairo_set_line_width (cr, label_border_width ()); @@ -134,11 +131,18 @@ PortMatrixRowLabels::render (cairo_t* cr) for (std::vector >::const_iterator i = _body->row_bundles().begin(); i != _body->row_bundles().end(); ++i) { for (uint32_t j = 0; j < (*i)->nchannels(); ++j) { + uint32_t x; + if (_location == LEFT) { + x = _longest_bundle_name + name_pad() * 2; + } else if (_location == RIGHT) { + x = 0; + } + Gdk::Color const colour = get_a_bundle_colour (i - _body->row_bundles().begin ()); set_source_rgb (cr, colour); cairo_rectangle ( cr, - 0, + x, y, _longest_port_name + (name_pad() * 2), row_height() @@ -153,7 +157,7 @@ PortMatrixRowLabels::render (cairo_t* cr) uint32_t const off = (row_height() - ext.height) / 2; set_source_rgb (cr, text_colour()); - cairo_move_to (cr, name_pad(), y + name_pad() + off); + cairo_move_to (cr, x + name_pad(), y + name_pad() + off); cairo_show_text (cr, (*i)->channel_name(j).c_str()); y += row_height(); @@ -164,7 +168,13 @@ PortMatrixRowLabels::render (cairo_t* cr) void PortMatrixRowLabels::button_press (double x, double y, int b, uint32_t t) { - if (b == 3 && x < (_longest_port_name + name_pad() * 2) ) { + if (b != 3) { + return; + } + + if ( (_location == LEFT && x > (_longest_bundle_name + name_pad() * 2)) || + (_location == RIGHT && x < (_longest_port_name + name_pad() * 2)) + ) { delete _menu; @@ -172,7 +182,6 @@ PortMatrixRowLabels::button_press (double x, double y, int b, uint32_t t) _menu->set_name ("ArdourContextMenu"); Gtk::Menu_Helpers::MenuList& items = _menu->items (); - uint32_t row = y / row_height (); diff --git a/gtk2_ardour/port_matrix_row_labels.h b/gtk2_ardour/port_matrix_row_labels.h index 74af1092c2..dd3d2a9348 100644 --- a/gtk2_ardour/port_matrix_row_labels.h +++ b/gtk2_ardour/port_matrix_row_labels.h @@ -37,7 +37,12 @@ namespace Gtk { class PortMatrixRowLabels : public PortMatrixComponent { public: - PortMatrixRowLabels (PortMatrix *, PortMatrixBody *); + enum Location { + LEFT, + RIGHT + }; + + PortMatrixRowLabels (PortMatrix *, PortMatrixBody *, Location); ~PortMatrixRowLabels (); void button_press (double, double, int, uint32_t); @@ -52,6 +57,7 @@ private: uint32_t _longest_port_name; uint32_t _longest_bundle_name; Gtk::Menu* _menu; + Location _location; }; #endif -- cgit v1.2.3