don't go through ::deliver_enter_leave() unnecessarily
[ardour.git] / libs / canvas / lookup_table.cc
index 9697ba81039ef6ac577945f147120598bb7ab889..f88531537aebb0544d85a792f6c749e8e9199dad 100644 (file)
@@ -49,26 +49,49 @@ DumbLookupTable::get (Rect const &)
        return vitems;
 }
 
-/* XXX: what coordinate system is the point in? parent of our group I think */
 vector<Item *>
-DumbLookupTable::items_at_point (Duple point) const
+DumbLookupTable::items_at_point (Duple const & point) const
 {
-       list<Item *> items = _group.items ();
+       /* Point is in canvas coordinate system */
+
+       list<Item *> const & items (_group.items ());
        vector<Item *> vitems;
 
        for (list<Item *>::const_iterator i = items.begin(); i != items.end(); ++i) {
-               boost::optional<Rect> item_bbox = (*i)->bounding_box ();
-               if (item_bbox) {
-                       Rect parent_bbox = (*i)->item_to_parent (item_bbox.get ());
-                       if (parent_bbox.contains (point)) {
-                               vitems.push_back (*i);
-                       }
+
+               if ((*i)->covers (point)) {
+                       // std::cerr << "\t\t" << (*i)->whatami() << '/' << (*i)->name << " covers " << point << std::endl;
+                       vitems.push_back (*i);
                }
        }
 
        return vitems;
 }
 
+bool
+DumbLookupTable::has_item_at_point (Duple const & point) const
+{
+       /* Point is in canvas coordinate system */
+
+       list<Item *> const & items (_group.items ());
+       vector<Item *> vitems;
+
+       for (list<Item *>::const_iterator i = items.begin(); i != items.end(); ++i) {
+
+               if (!(*i)->visible()) {
+                       continue;
+               }
+               
+               if ((*i)->covers (point)) {
+                       // std::cerr << "\t\t" << (*i)->whatami() << '/' << (*i)->name << " covers " << point << std::endl;
+                       return true;
+                       
+               }
+       }
+
+       return false;
+}
+
 OptimizingLookupTable::OptimizingLookupTable (Group const & group, int items_per_cell)
        : LookupTable (group)
        , _items_per_cell (items_per_cell)
@@ -188,7 +211,7 @@ OptimizingLookupTable::point_to_indices (Duple point, int& x, int& y) const
 }
 
 vector<Item*>
-OptimizingLookupTable::items_at_point (Duple point) const
+OptimizingLookupTable::items_at_point (Duple const & point) const
 {
        int x;
        int y;
@@ -223,6 +246,43 @@ OptimizingLookupTable::items_at_point (Duple point) const
 
        return items;
 }
+
+bool
+OptimizingLookupTable::has_item_at_point (Duple const & point) const
+{
+       int x;
+       int y;
+       point_to_indices (point, x, y);
+
+       if (x >= _dimension) {
+               cout << "WARNING: x=" << x << ", dim=" << _dimension << ", px=" << point.x << " cellsize=" << _cell_size << "\n";
+       }
+
+       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);
+
+       assert (x >= 0);
+       assert (y >= 0);
+
+       Cell const & cell = _cells[x][y];
+       vector<Item*> items;
+       for (Cell::const_iterator i = cell.begin(); i != cell.end(); ++i) {
+               boost::optional<Rect> const item_bbox = (*i)->bounding_box ();
+               if (item_bbox) {
+                       Rect parent_bbox = (*i)->item_to_parent (item_bbox.get ());
+                       if (parent_bbox.contains (point)) {
+                               return true;
+                       }
+               }
+       }
+
+       return false;
+}
        
 /** @param area Area in our owning group's coordinates */
 vector<Item*>