mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 07:14:56 +01:00
Canvas: re-use Solver as much as possible, with possible (but not substantive) speedup; remove debug output
This commit is contained in:
parent
24d83266a3
commit
2fd8174cfe
9 changed files with 85 additions and 48 deletions
|
|
@ -109,7 +109,7 @@ Canvas::zoomed ()
|
|||
pick_current_item (0); // no current mouse position
|
||||
}
|
||||
|
||||
static bool debug_render = true;
|
||||
static bool debug_render = false;
|
||||
#define CANVAS_DEBUG
|
||||
|
||||
/** Render an area of the canvas.
|
||||
|
|
@ -148,7 +148,6 @@ Canvas::render (Rect const & area, Cairo::RefPtr<Cairo::Context> const & context
|
|||
area, so render it.
|
||||
*/
|
||||
|
||||
cerr << "root draw\n";
|
||||
_root.render (draw, context);
|
||||
|
||||
#if defined CANVAS_DEBUG && !PLATFORM_WINDOWS
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ public:
|
|||
BoxConstrainedItem* pack_start (Item*, PackOptions primary_axis_packing = PackOptions (0), PackOptions secondary_axis_packing = PackOptions (PackExpand|PackFill));
|
||||
BoxConstrainedItem* pack_end (Item*, PackOptions primary_axis_packing = PackOptions (0), PackOptions secondary_axis_packing = PackOptions (PackExpand|PackFill));
|
||||
|
||||
void add_vertical_box_constraints (kiwi::Solver& solver, BoxConstrainedItem* ci, BoxConstrainedItem* prev, double expanded_size, double main_dimenion, double second_dimension, double alloc_dimension);
|
||||
void add_horizontal_box_constraints (kiwi::Solver& solver, BoxConstrainedItem* ci, BoxConstrainedItem* prev, double expanded_size, double main_dimenion, double second_dimension, double alloc_dimension);
|
||||
void add_vertical_box_constraints (kiwi::Solver& solver, BoxConstrainedItem* ci, BoxConstrainedItem* prev, double main_dimenion, double second_dimension, kiwi::Variable& alloc_var);
|
||||
void add_horizontal_box_constraints (kiwi::Solver& solver, BoxConstrainedItem* ci, BoxConstrainedItem* prev, double main_dimenion, double second_dimension, kiwi::Variable& alloc_var);
|
||||
|
||||
void set_collapse_on_hide (bool);
|
||||
void set_homogenous (bool);
|
||||
|
|
@ -75,12 +75,14 @@ public:
|
|||
double _right_margin;
|
||||
|
||||
void child_changed (bool bbox_changed);
|
||||
void update_constraints ();
|
||||
|
||||
private:
|
||||
typedef std::list<BoxConstrainedItem*> Order;
|
||||
Order order;
|
||||
bool collapse_on_hide;
|
||||
bool homogenous;
|
||||
kiwi::Variable expanded_item_size;
|
||||
|
||||
BoxConstrainedItem* pack (Item*, PackOptions primary_axis_packing, PackOptions secondary_axis_packing);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -62,12 +62,15 @@ public:
|
|||
ConstrainedItemMap constrained_map;
|
||||
typedef std::list<kiwi::Constraint> ConstraintList;
|
||||
ConstraintList constraint_list;
|
||||
|
||||
kiwi::Solver _solver;
|
||||
bool in_alloc;
|
||||
bool _need_constraint_update;
|
||||
|
||||
void add_constrained_internal (Item*, ConstrainedItem*);
|
||||
|
||||
void add_constraints (kiwi::Solver&, ConstrainedItem*) const;
|
||||
|
||||
virtual void update_constraints ();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -333,6 +333,7 @@ protected:
|
|||
void prepare_for_render_children (Rect const & area) const;
|
||||
|
||||
Duple scroll_offset() const;
|
||||
public:
|
||||
Duple position_offset() const;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ cBox::cBox (Canvas* c, Orientation o)
|
|||
, collapse_on_hide (false)
|
||||
, homogenous (true)
|
||||
{
|
||||
_solver.addEditVariable (expanded_item_size, kiwi::strength::strong);
|
||||
}
|
||||
|
||||
cBox::cBox (Item* i, Orientation o)
|
||||
|
|
@ -61,6 +62,7 @@ cBox::cBox (Item* i, Orientation o)
|
|||
, collapse_on_hide (false)
|
||||
, homogenous (true)
|
||||
{
|
||||
_solver.addEditVariable (expanded_item_size, kiwi::strength::strong);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -236,8 +238,6 @@ cBox::size_allocate (Rect const & r)
|
|||
|
||||
Item::size_allocate (r);
|
||||
|
||||
kiwi::Solver solver;
|
||||
|
||||
double expanded_size;
|
||||
Order::size_type n_expanding = 0;
|
||||
Order::size_type n_nonexpanding = 0;
|
||||
|
|
@ -270,13 +270,43 @@ cBox::size_allocate (Rect const & r)
|
|||
expanded_size = (r.width() - _left_margin - _right_margin - ((total - 1) * _spacing) - non_expanding_used) / n_expanding;
|
||||
}
|
||||
|
||||
cerr << "\n\n\n" << whoami() << " SIZE-ALLOC " << r << " expanded items (" << n_expanding << ")will be " << expanded_size << " neu " << non_expanding_used << " t = " << total << " s " << _spacing
|
||||
<< " t " << _top_margin << " b " << _bottom_margin << " l " << _left_margin << " r " << _right_margin
|
||||
<< endl;
|
||||
// cerr << "\n\n\n" << whoami() << " SIZE-ALLOC " << r << " NCU ? " << _need_constraint_update << " expanded items (" << n_expanding << ")will be " << expanded_size << " neu " << non_expanding_used << " t = " << total << " s " << _spacing
|
||||
// << " t " << _top_margin << " b " << _bottom_margin << " l " << _left_margin << " r " << _right_margin
|
||||
// << endl;
|
||||
|
||||
Order::iterator prev = order.end();
|
||||
|
||||
if (_need_constraint_update) {
|
||||
update_constraints ();
|
||||
}
|
||||
|
||||
_solver.suggestValue (width, r.width());
|
||||
_solver.suggestValue (height, r.height());
|
||||
_solver.suggestValue (expanded_item_size, expanded_size);
|
||||
|
||||
_solver.updateVariables ();
|
||||
//solver.dump (cerr);
|
||||
|
||||
//for (ConstrainedItemMap::const_iterator o = constrained_map.begin(); o != constrained_map.end(); ++o) {
|
||||
//o->second->dump (cerr);
|
||||
//}
|
||||
|
||||
apply (&_solver);
|
||||
|
||||
_bounding_box_dirty = true;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
cBox::update_constraints ()
|
||||
{
|
||||
ConstraintPacker::update_constraints ();
|
||||
|
||||
_solver.addEditVariable (expanded_item_size, kiwi::strength::strong);
|
||||
|
||||
try {
|
||||
|
||||
Order::iterator prev = order.end();
|
||||
|
||||
for (Order::iterator o = order.begin(); o != order.end(); ++o) {
|
||||
|
||||
Duple min, natural;
|
||||
|
|
@ -284,9 +314,9 @@ cBox::size_allocate (Rect const & r)
|
|||
(*o)->item().preferred_size (min, natural);
|
||||
|
||||
if (orientation == Vertical) {
|
||||
add_vertical_box_constraints (solver, *o, prev == order.end() ? 0 : *prev, expanded_size, natural.height(), natural.width(), r.width());
|
||||
add_vertical_box_constraints (_solver, *o, prev == order.end() ? 0 : *prev, natural.height(), natural.width(), width);
|
||||
} else {
|
||||
add_horizontal_box_constraints (solver, *o, prev == order.end() ? 0 : *prev, expanded_size, natural.width(), natural.height(), r.height());
|
||||
add_horizontal_box_constraints (_solver, *o, prev == order.end() ? 0 : *prev, natural.width(), natural.height(), height);
|
||||
}
|
||||
|
||||
prev = o;
|
||||
|
|
@ -303,7 +333,7 @@ cBox::size_allocate (Rect const & r)
|
|||
std::vector<Constraint> const & constraints (x->second->constraints());
|
||||
|
||||
for (std::vector<Constraint>::const_iterator c = constraints.begin(); c != constraints.end(); ++c) {
|
||||
solver.addConstraint (*c);
|
||||
_solver.addConstraint (*c);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -313,17 +343,7 @@ cBox::size_allocate (Rect const & r)
|
|||
return;
|
||||
}
|
||||
|
||||
solver.updateVariables ();
|
||||
//solver.dump (cerr);
|
||||
|
||||
//for (ConstrainedItemMap::const_iterator o = constrained_map.begin(); o != constrained_map.end(); ++o) {
|
||||
//o->second->dump (cerr);
|
||||
//}
|
||||
|
||||
apply (&solver);
|
||||
|
||||
_bounding_box_dirty = true;
|
||||
|
||||
_need_constraint_update = false;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -341,10 +361,9 @@ cBox::child_changed (bool bbox_changed)
|
|||
solver, \
|
||||
bci, \
|
||||
prev, \
|
||||
expanded_size, \
|
||||
natural_main_dimension, \
|
||||
natural_second_dimension, \
|
||||
alloc_second_dimension, \
|
||||
alloc_var, \
|
||||
m_main_dimension, \
|
||||
m_second_dimension, \
|
||||
m_trailing, \
|
||||
|
|
@ -379,7 +398,7 @@ cBox::child_changed (bool bbox_changed)
|
|||
* for itself. \
|
||||
*/ \
|
||||
\
|
||||
solver.addConstraint (bci->m_main_dimension() == expanded_size | kiwi::strength::strong); \
|
||||
solver.addConstraint (bci->m_main_dimension() == expanded_item_size | kiwi::strength::strong); \
|
||||
solver.addConstraint (bci->m_trailing_padding() == 0. | kiwi::strength::strong); \
|
||||
solver.addConstraint (bci->m_leading_padding() == 0. | kiwi::strength::strong); \
|
||||
\
|
||||
|
|
@ -391,7 +410,7 @@ cBox::child_changed (bool bbox_changed)
|
|||
*/ \
|
||||
\
|
||||
solver.addConstraint (bci->m_main_dimension() == natural_main_dimension); \
|
||||
solver.addConstraint (bci->m_trailing_padding() + bci->m_leading_padding() + bci->m_main_dimension() == expanded_size | kiwi::strength::strong); \
|
||||
solver.addConstraint (bci->m_trailing_padding() + bci->m_leading_padding() + bci->m_main_dimension() == expanded_item_size | kiwi::strength::strong); \
|
||||
solver.addConstraint (bci->m_leading_padding() == bci->m_trailing_padding() | kiwi::strength::strong); \
|
||||
} \
|
||||
\
|
||||
|
|
@ -436,14 +455,14 @@ cBox::child_changed (bool bbox_changed)
|
|||
if (!(bci->secondary_axis_pack_options() & PackExpand) && natural_second_dimension > 0) { \
|
||||
solver.addConstraint (bci->m_second_dimension() == natural_second_dimension); \
|
||||
} else { \
|
||||
solver.addConstraint (bci->m_second_dimension() == alloc_second_dimension - (m_second_trailing_margin + m_second_leading_margin + bci->m_second_leading_padding()) | kiwi::strength::strong); \
|
||||
solver.addConstraint (bci->m_second_dimension() == alloc_var - (m_second_trailing_margin + m_second_leading_margin + bci->m_second_leading_padding()) | kiwi::strength::strong); \
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
cBox::add_vertical_box_constraints (kiwi::Solver& solver, BoxConstrainedItem* ci, BoxConstrainedItem* prev, double expanded_size, double main_dimension, double second_dimension, double alloc_dimension)
|
||||
cBox::add_vertical_box_constraints (kiwi::Solver& solver, BoxConstrainedItem* ci, BoxConstrainedItem* prev, double main_dimension, double second_dimension, kiwi::Variable & alloc_var)
|
||||
{
|
||||
add_box_constraints (solver, ci, prev, expanded_size, main_dimension, second_dimension, alloc_dimension,
|
||||
add_box_constraints (solver, ci, prev, main_dimension, second_dimension, alloc_var,
|
||||
height, width,
|
||||
top, bottom, top_padding, bottom_padding,
|
||||
left, right, left_padding, right_padding,
|
||||
|
|
@ -452,9 +471,9 @@ cBox::add_vertical_box_constraints (kiwi::Solver& solver, BoxConstrainedItem* ci
|
|||
}
|
||||
|
||||
void
|
||||
cBox::add_horizontal_box_constraints (kiwi::Solver& solver, BoxConstrainedItem* ci, BoxConstrainedItem* prev, double expanded_size, double main_dimension, double second_dimension, double alloc_dimension)
|
||||
cBox::add_horizontal_box_constraints (kiwi::Solver& solver, BoxConstrainedItem* ci, BoxConstrainedItem* prev, double main_dimension, double second_dimension, kiwi::Variable& alloc_var)
|
||||
{
|
||||
add_box_constraints (solver, ci, prev, expanded_size, main_dimension, second_dimension, alloc_dimension,
|
||||
add_box_constraints (solver, ci, prev, main_dimension, second_dimension, alloc_var,
|
||||
width, height,
|
||||
left, right, left_padding, right_padding,
|
||||
top, bottom, top_padding, bottom_padding,
|
||||
|
|
@ -464,8 +483,6 @@ cBox::add_horizontal_box_constraints (kiwi::Solver& solver, BoxConstrainedItem*
|
|||
void
|
||||
cBox::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
|
||||
{
|
||||
cerr << whoami() << " render f " << fill() << " o " << outline() << " a " << _allocation << endl;
|
||||
|
||||
if (fill() || outline() && _allocation) {
|
||||
|
||||
Rect contents = _allocation;
|
||||
|
|
|
|||
|
|
@ -42,10 +42,14 @@ ConstraintPacker::ConstraintPacker (Canvas* canvas)
|
|||
, width (X_("packer width"))
|
||||
, height (X_("packer height"))
|
||||
, in_alloc (false)
|
||||
, _need_constraint_update (false)
|
||||
{
|
||||
set_fill (false);
|
||||
set_outline (false);
|
||||
set_layout_sensitive (true);
|
||||
|
||||
_solver.addEditVariable (width, kiwi::strength::strong);
|
||||
_solver.addEditVariable (height, kiwi::strength::strong);
|
||||
}
|
||||
|
||||
ConstraintPacker::ConstraintPacker (Item* parent)
|
||||
|
|
@ -53,16 +57,19 @@ ConstraintPacker::ConstraintPacker (Item* parent)
|
|||
, width (X_("packer width"))
|
||||
, height (X_("packer height"))
|
||||
, in_alloc (false)
|
||||
, _need_constraint_update (false)
|
||||
{
|
||||
set_fill (false);
|
||||
set_outline (false);
|
||||
set_layout_sensitive (true);
|
||||
|
||||
_solver.addEditVariable (width, kiwi::strength::strong);
|
||||
_solver.addEditVariable (height, kiwi::strength::strong);
|
||||
}
|
||||
|
||||
void
|
||||
ConstraintPacker::compute_bounding_box () const
|
||||
{
|
||||
cerr << whoami() << " CBB from " << _allocation << endl;
|
||||
_bounding_box = _allocation;
|
||||
_bounding_box_dirty = false;
|
||||
}
|
||||
|
|
@ -268,6 +275,7 @@ ConstraintPacker::add_constrained_internal (Item* item, ConstrainedItem* ci)
|
|||
Item::add (item);
|
||||
item->set_layout_sensitive (true);
|
||||
constrained_map.insert (std::make_pair (item, ci));
|
||||
_need_constraint_update = true;
|
||||
child_changed (true);
|
||||
}
|
||||
|
||||
|
|
@ -299,6 +307,7 @@ ConstraintPacker::remove (Item* item)
|
|||
|
||||
}
|
||||
|
||||
_need_constraint_update = true;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -308,3 +317,11 @@ ConstraintPacker::apply (Solver* s)
|
|||
x->second->constrained (*this);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ConstraintPacker::update_constraints ()
|
||||
{
|
||||
_solver.reset ();
|
||||
_solver.addEditVariable (width, kiwi::strength::strong);
|
||||
_solver.addEditVariable (height, kiwi::strength::strong);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@ main (int argc, char* argv[])
|
|||
vbox->name = "vbox";
|
||||
vbox->set_fill (true);
|
||||
vbox->set_fill_color (0xff0000ff);
|
||||
// vbox->set_margin (10, 20, 30, 40);
|
||||
vbox->set_margin (20);
|
||||
|
||||
#if 1
|
||||
vbox->pack_start (r1, PackOptions(PackExpand|PackFill));
|
||||
vbox->pack_start (r2, PackOptions(PackExpand|PackFill));
|
||||
vbox->pack_start (r3, PackOptions(PackExpand|PackFill));
|
||||
|
|
@ -71,7 +71,7 @@ main (int argc, char* argv[])
|
|||
hbox1->set_fill (true);
|
||||
hbox1->set_fill_color (0x00ff00ff);
|
||||
|
||||
hbox1->set_margin (10, 10, 10, 10);
|
||||
hbox1->set_margin (10);
|
||||
|
||||
Rectangle* r4 = new Rectangle (c);
|
||||
Rectangle* r5 = new Rectangle (c);
|
||||
|
|
@ -110,6 +110,7 @@ main (int argc, char* argv[])
|
|||
hbox2->name = "hbox2";
|
||||
hbox2->set_fill (true);
|
||||
hbox2->set_fill_color (Gtkmm2ext::random_color());
|
||||
hbox2->set_outline (true);
|
||||
|
||||
Text* txt = new Text (c);
|
||||
txt->name = "text";
|
||||
|
|
@ -119,11 +120,12 @@ main (int argc, char* argv[])
|
|||
txt->set_font_description (font);
|
||||
txt->set ("hello world");
|
||||
|
||||
ConstrainedItem* ti = hbox2->pack_start (txt, PackExpand);
|
||||
ti->add_constraint (ti->left() == 50);
|
||||
|
||||
vbox->pack_start (hbox2, PackOptions (PackExpand|PackFill));
|
||||
ConstrainedItem* hb2 = vbox->pack_start (hbox2, PackOptions (PackExpand|PackFill));
|
||||
|
||||
ConstrainedItem* ti = hbox2->pack_start (txt, PackOptions (PackExpand|PackFill));
|
||||
ti->add_constraint (ti->center_x() == hb2->center_x());
|
||||
ti->add_constraint (ti->center_y() == hb2->center_y() + 20);
|
||||
#endif
|
||||
win.show_all ();
|
||||
app.run ();
|
||||
|
||||
|
|
|
|||
|
|
@ -747,14 +747,12 @@ Item::covers (Duple const & point) const
|
|||
|
||||
/* nesting/grouping API */
|
||||
|
||||
static bool debug_render = true;
|
||||
static bool debug_render = false;
|
||||
#define CANVAS_DEBUG 1
|
||||
|
||||
void
|
||||
Item::render_children (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
|
||||
{
|
||||
cerr << "I::rc\n";
|
||||
|
||||
if (_items.empty()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,8 +53,6 @@ Root::size_allocate (Rect const & r)
|
|||
{
|
||||
bool have_constraint_container = false;
|
||||
|
||||
cerr << "ROOT alloc " << r << endl;
|
||||
|
||||
for (list<Item*>::const_iterator i = _items.begin(); i != _items.end(); ++i) {
|
||||
if (dynamic_cast<ConstraintPacker*> (*i)) {
|
||||
(*i)->size_allocate (r);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue