From 52718b341163dab439596049392b9c80fb8635ec Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 30 Jan 2017 14:46:14 +0100 Subject: [PATCH] some initial bits of work on canvas allocation --- gtk2_ardour/canvas_test.cc | 55 ++++++++++++++++++++++++++++++++++-- libs/canvas/box.cc | 50 ++++++++++++++++---------------- libs/canvas/grid.cc | 58 +++++++++++++++++++++++++++++--------- 3 files changed, 122 insertions(+), 41 deletions(-) diff --git a/gtk2_ardour/canvas_test.cc b/gtk2_ardour/canvas_test.cc index ff1063a837..3e922c2344 100644 --- a/gtk2_ardour/canvas_test.cc +++ b/gtk2_ardour/canvas_test.cc @@ -23,6 +23,8 @@ #include "canvas/canvas.h" #include "canvas/container.h" #include "canvas/colors.h" +#include "canvas/debug.h" +#include "canvas/grid.h" #include "canvas/scroll_group.h" #include "canvas/text.h" #include "canvas/widget.h" @@ -110,6 +112,7 @@ private: ArdourCanvas::GtkCanvas* canvas; ArdourCanvas::Container* group; + ArdourCanvas::Grid* grid; ArdourButton test_button; }; @@ -163,12 +166,60 @@ ArdourCanvas::Container* CANVAS_UI::initialize_canvas (ArdourCanvas::Canvas& canvas) { using namespace ArdourCanvas; - canvas.set_background_color (rgba_to_color (0.0, 0.0, 1.0, 1.0)); + canvas.set_background_color (rgba_to_color (0.0, 0.0, 0.4, 1.0)); ScrollGroup* scroll_group = new ScrollGroup (canvas.root(), ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally)); - ArdourCanvas::Widget* w = new ArdourCanvas::Widget (scroll_group, test_button); + grid = new ArdourCanvas::Grid (scroll_group); + grid->set_padding (10.0); + grid->set_margin (20.0); + grid->set_outline_width (3.0); + grid->set_outline_color (Color (0x3daec1ff)); + grid->set_outline (true); + + ArdourCanvas::Text* text1 = new ArdourCanvas::Text (&canvas); + text1->set ("hello, world"); + text1->set_color (Color (0xff0000ff)); + + ArdourCanvas::Text* text2 = new ArdourCanvas::Text (&canvas); + text2->set ("goodbye, cruel world"); + text2->set_color (Color (0x00ff00ff)); + + ArdourCanvas::Text* text3 = new ArdourCanvas::Text (&canvas); + text3->set ("I am the third"); + text3->set_color (Color (0xff00ffff)); + + ArdourCanvas::Text* text4 = new ArdourCanvas::Text (&canvas); + text4->set ("I am fourth"); + text4->set_color (Color (0xffff00ff)); + +#if 0 + grid->place (text1, ArdourCanvas::Duple (0, 0)); + grid->place (text2, ArdourCanvas::Duple (1, 0)); + grid->place (text3, ArdourCanvas::Duple (0, 1)); + grid->place (text4, ArdourCanvas::Duple (1, 1)); +#endif + ArdourButton* button1 = new ArdourButton ("auto-return"); + ArdourButton* button2 = new ArdourButton ("auto-play"); + ArdourButton* button3 = new ArdourButton ("follow range"); + ArdourButton* button4 = new ArdourButton ("auto-input"); + + ArdourCanvas::Widget* w1 = new ArdourCanvas::Widget (&canvas, *button1); + CANVAS_DEBUG_NAME (w1, "w1"); + grid->place (w1, ArdourCanvas::Duple (3, 0)); + ArdourCanvas::Widget* w2 = new ArdourCanvas::Widget (&canvas, *button2); + CANVAS_DEBUG_NAME (w2, "w2"); + grid->place (w2, ArdourCanvas::Duple (4, 0)); + ArdourCanvas::Widget* w3 = new ArdourCanvas::Widget (&canvas, *button3); + CANVAS_DEBUG_NAME (w3, "w3"); + grid->place (w3, ArdourCanvas::Duple (3, 1)); + ArdourCanvas::Widget* w4 = new ArdourCanvas::Widget (&canvas, *button4); + CANVAS_DEBUG_NAME (w4, "w4"); + grid->place (w4, ArdourCanvas::Duple (4, 1)); + + //ArdourCanvas::Widget* w = new ArdourCanvas::Widget (scroll_group, test_button); + //CANVAS_DEBUG_NAME (w, "TheW"); return new ArdourCanvas::Container (scroll_group); } diff --git a/libs/canvas/box.cc b/libs/canvas/box.cc index c75bee5770..f32aeab020 100644 --- a/libs/canvas/box.cc +++ b/libs/canvas/box.cc @@ -165,6 +165,7 @@ Box::reposition_children () Duple previous_edge (0, 0); Distance largest_width = 0; Distance largest_height = 0; + Rect uniform_size; if (homogenous) { @@ -175,33 +176,35 @@ Box::reposition_children () largest_width = std::max (largest_width, bb.width()); } } + + uniform_size = Rect (0, 0, largest_width, largest_height); } for (std::list::iterator i = _items.begin(); ++i != _items.end(); ++i) { (*i)->set_position (previous_edge); + if (homogenous) { + (*i)->size_allocate (uniform_size); + } + if (orientation == Vertical) { Distance shift = 0; - if (homogenous) { - shift = largest_height; - } else { - Rect bb = (*i)->bounding_box(); + Rect bb = (*i)->bounding_box(); - if (!(*i)->visible()) { - /* invisible child */ - if (!collapse_on_hide) { - /* still add in its size */ - if (bb) { - shift += bb.height(); - } - } - } else { + if (!(*i)->visible()) { + /* invisible child */ + if (!collapse_on_hide) { + /* still add in its size */ if (bb) { shift += bb.height(); - } + } + } + } else { + if (bb) { + shift += bb.height(); } } @@ -210,23 +213,18 @@ Box::reposition_children () } else { Distance shift = 0; + Rect bb = (*i)->bounding_box(); - if (homogenous) { - shift = largest_width; - } else { - Rect bb = (*i)->bounding_box(); - - if (!(*i)->visible()) { - if (!collapse_on_hide) { - if (bb) { - shift += bb.width(); - } - } - } else { + if (!(*i)->visible()) { + if (!collapse_on_hide) { if (bb) { shift += bb.width(); } } + } else { + if (bb) { + shift += bb.width(); + } } previous_edge = previous_edge.translate (Duple (spacing + shift, 0)); diff --git a/libs/canvas/grid.cc b/libs/canvas/grid.cc index 02e18f79b8..fe23ea3aec 100644 --- a/libs/canvas/grid.cc +++ b/libs/canvas/grid.cc @@ -33,7 +33,7 @@ Grid::Grid (Canvas* canvas) , spacing (0) , top_padding (0), right_padding (0), bottom_padding (0), left_padding (0) , top_margin (0), right_margin (0), bottom_margin (0), left_margin (0) - , homogenous (false) + , homogenous (true) { self = new Rectangle (this); self->set_outline (false); @@ -45,7 +45,7 @@ Grid::Grid (Item* parent) , spacing (0) , top_padding (0), right_padding (0), bottom_padding (0), left_padding (0) , top_margin (0), right_margin (0), bottom_margin (0), left_margin (0) - , homogenous (false) + , homogenous (true) { self = new Rectangle (this); self->set_outline (false); @@ -57,7 +57,7 @@ Grid::Grid (Item* parent, Duple const & p) , spacing (0) , top_padding (0), right_padding (0), bottom_padding (0), left_padding (0) , top_margin (0), right_margin (0), bottom_margin (0), left_margin (0) - , homogenous (false) + , homogenous (true) { self = new Rectangle (this); self->set_outline (false); @@ -188,23 +188,55 @@ Grid::reposition_children () row_dimens.assign (max_row, 0); col_dimens.assign (max_col, 0); - for (std::list::iterator i = _items.begin(); i != _items.end(); ++i) { + Rect uniform_size; - if (*i == self) { - /* self-rect is not a normal child */ - continue; + if (homogenous) { + for (std::list::iterator i = _items.begin(); i != _items.end(); ++i) { + + Rect bb = (*i)->bounding_box(); + + if (!bb) { + continue; + } + cerr << "\tbb is " << bb << endl; + uniform_size.y1 = max (uniform_size.y1, bb.height()); + uniform_size.x1 = max (uniform_size.x1, bb.width()); } - Rect bb = (*i)->bounding_box(); + cerr << "Uniform size will be " << uniform_size << endl; - if (!bb) { - continue; + for (std::list::iterator i = _items.begin(); i != _items.end(); ++i) { + if (*i == self) { + /* self-rect is not a normal child */ + continue; + } + (*i)->size_allocate (uniform_size); + for (uint32_t n = 0; n < max_row; ++n) { + col_dimens[n] = uniform_size.width(); + } + for (uint32_t n = 0; n < max_col; ++n) { + row_dimens[n] = uniform_size.height(); + } } + } else { + for (std::list::iterator i = _items.begin(); i != _items.end(); ++i) { - CoordsByItem::const_iterator c = coords_by_item.find (*i); + if (*i == self) { + /* self-rect is not a normal child */ + continue; + } - row_dimens[c->second.y] = max (row_dimens[c->second.y], bb.height()); - col_dimens[c->second.x] = max (col_dimens[c->second.x] , bb.width()); + Rect bb = (*i)->bounding_box(); + + if (!bb) { + continue; + } + + CoordsByItem::const_iterator c = coords_by_item.find (*i); + + row_dimens[c->second.y] = max (row_dimens[c->second.y], bb.height()); + col_dimens[c->second.x] = max (col_dimens[c->second.x] , bb.width()); + } } /* now sum the row and column widths, so that row_dimens is transformed