X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fcanvas%2Flookup_table.cc;h=ce986872fb1b35dde8ce3ceb0c7b08da78a848ae;hb=ae0dcdc0c5d13483271065c360e378202d20170a;hp=2396f596354504798f0cdbc625da9c3c8bccd0b5;hpb=ff46a3c3a216afc97fee0c796ac2eaa92d58becb;p=ardour.git diff --git a/libs/canvas/lookup_table.cc b/libs/canvas/lookup_table.cc index 2396f59635..ce986872fb 100644 --- a/libs/canvas/lookup_table.cc +++ b/libs/canvas/lookup_table.cc @@ -41,11 +41,22 @@ DumbLookupTable::DumbLookupTable (Item const & item) } vector -DumbLookupTable::get (Rect const &) +DumbLookupTable::get (Rect const &area) { list const & items = _item.items (); vector vitems; +#if 1 + for (list::const_iterator i = items.begin(); i != items.end(); ++i) { + Rect item_bbox = (*i)->bounding_box (); + if (!item_bbox) continue; + Rect item = (*i)->item_to_window (item_bbox); + if (item.intersection (area)) { + vitems.push_back (*i); + } + } +#else copy (items.begin(), items.end(), back_inserter (vitems)); +#endif return vitems; } @@ -81,11 +92,11 @@ DumbLookupTable::has_item_at_point (Duple const & point) const if (!(*i)->visible()) { continue; } - + if ((*i)->covers (point)) { // std::cerr << "\t\t" << (*i)->whatami() << '/' << (*i)->name << " covers " << point << std::endl; return true; - + } } @@ -110,28 +121,28 @@ OptimizingLookupTable::OptimizingLookupTable (Item const & item, int items_per_c } /* our item's bounding box in its coordinates */ - boost::optional bbox = _item.bounding_box (); + Rect bbox = _item.bounding_box (); if (!bbox) { return; } - _cell_size.x = bbox.get().width() / _dimension; - _cell_size.y = bbox.get().height() / _dimension; - _offset.x = bbox.get().x0; - _offset.y = bbox.get().y0; + _cell_size.x = bbox.width() / _dimension; + _cell_size.y = bbox.height() / _dimension; + _offset.x = bbox.x0; + _offset.y = bbox.y0; -// cout << "BUILD bbox=" << bbox.get() << ", cellsize=" << _cell_size << ", offset=" << _offset << ", dimension=" << _dimension << "\n"; +// cout << "BUILD bbox=" << bbox << ", cellsize=" << _cell_size << ", offset=" << _offset << ", dimension=" << _dimension << "\n"; for (list::const_iterator i = items.begin(); i != items.end(); ++i) { /* item bbox in its own coordinates */ - boost::optional item_bbox = (*i)->bounding_box (); + Rect item_bbox = (*i)->bounding_box (); if (!item_bbox) { continue; } /* and in the item's coordinates */ - Rect const item_bbox_in_item = (*i)->item_to_parent (item_bbox.get ()); + Rect const item_bbox_in_item = (*i)->item_to_parent (item_bbox); int x0, y0, x1, y1; area_to_indices (item_bbox_in_item, x0, y0, x1, y1); @@ -147,19 +158,19 @@ OptimizingLookupTable::OptimizingLookupTable (Item const & item, int items_per_c //assert (y1 <= _dimension); if (x0 > _dimension) { - cout << "WARNING: item outside bbox by " << (item_bbox_in_item.x0 - bbox.get().x0) << "\n"; + cout << "WARNING: item outside bbox by " << (item_bbox_in_item.x0 - bbox.x0) << "\n"; x0 = _dimension; } if (x1 > _dimension) { - cout << "WARNING: item outside bbox by " << (item_bbox_in_item.x1 - bbox.get().x1) << "\n"; + cout << "WARNING: item outside bbox by " << (item_bbox_in_item.x1 - bbox.x1) << "\n"; x1 = _dimension; } if (y0 > _dimension) { - cout << "WARNING: item outside bbox by " << (item_bbox_in_item.y0 - bbox.get().y0) << "\n"; + cout << "WARNING: item outside bbox by " << (item_bbox_in_item.y0 - bbox.y0) << "\n"; y0 = _dimension; } if (y1 > _dimension) { - cout << "WARNING: item outside bbox by " << (item_bbox_in_item.y1 - bbox.get().y1) << "\n"; + cout << "WARNING: item outside bbox by " << (item_bbox_in_item.y1 - bbox.y1) << "\n"; y1 = _dimension; } @@ -224,7 +235,7 @@ OptimizingLookupTable::items_at_point (Duple const & point) const if (y >= _dimension) { cout << "WARNING: y=" << y << ", dim=" << _dimension << ", py=" << point.y << " cellsize=" << _cell_size << "\n"; } - + /* XXX: hmm */ x = min (_dimension - 1, x); y = min (_dimension - 1, y); @@ -235,9 +246,9 @@ OptimizingLookupTable::items_at_point (Duple const & point) const Cell const & cell = _cells[x][y]; vector items; for (Cell::const_iterator i = cell.begin(); i != cell.end(); ++i) { - boost::optional const item_bbox = (*i)->bounding_box (); + Rect const item_bbox = (*i)->bounding_box (); if (item_bbox) { - Rect parent_bbox = (*i)->item_to_parent (item_bbox.get ()); + Rect parent_bbox = (*i)->item_to_parent (item_bbox); if (parent_bbox.contains (point)) { items.push_back (*i); } @@ -261,7 +272,7 @@ OptimizingLookupTable::has_item_at_point (Duple const & point) const if (y >= _dimension) { cout << "WARNING: y=" << y << ", dim=" << _dimension << ", py=" << point.y << " cellsize=" << _cell_size << "\n"; } - + /* XXX: hmm */ x = min (_dimension - 1, x); y = min (_dimension - 1, y); @@ -272,9 +283,9 @@ OptimizingLookupTable::has_item_at_point (Duple const & point) const Cell const & cell = _cells[x][y]; vector items; for (Cell::const_iterator i = cell.begin(); i != cell.end(); ++i) { - boost::optional const item_bbox = (*i)->bounding_box (); + Rect const item_bbox = (*i)->bounding_box (); if (item_bbox) { - Rect parent_bbox = (*i)->item_to_parent (item_bbox.get ()); + Rect parent_bbox = (*i)->item_to_parent (item_bbox); if (parent_bbox.contains (point)) { return true; } @@ -283,7 +294,7 @@ OptimizingLookupTable::has_item_at_point (Duple const & point) const return false; } - + /** @param area Area in our owning item's coordinates */ vector OptimizingLookupTable::get (Rect const & area) @@ -310,7 +321,7 @@ OptimizingLookupTable::get (Rect const & area) vector vitems; copy (items.begin (), items.end (), back_inserter (vitems)); - + return vitems; }