Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include "canvas/item.h"
#include "canvas/lookup_table.h"
-#include "canvas/group.h"
using namespace std;
using namespace ArdourCanvas;
-LookupTable::LookupTable (Group const & group)
- : _group (group)
+LookupTable::LookupTable (Item const & item)
+ : _item (item)
{
}
}
-DumbLookupTable::DumbLookupTable (Group const & group)
- : LookupTable (group)
+DumbLookupTable::DumbLookupTable (Item const & item)
+ : LookupTable (item)
{
}
vector<Item *>
-DumbLookupTable::get (Rect const &)
+DumbLookupTable::get (Rect const &area)
{
- list<Item *> const & items = _group.items ();
+ list<Item *> const & items = _item.items ();
vector<Item *> vitems;
+#if 1
+ for (list<Item *>::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;
}
-/* 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 window coordinate system */
+
+ list<Item *> const & items (_item.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;
}
-OptimizingLookupTable::OptimizingLookupTable (Group const & group, int items_per_cell)
- : LookupTable (group)
+bool
+DumbLookupTable::has_item_at_point (Duple const & point) const
+{
+ /* Point is in window coordinate system */
+
+ list<Item *> const & items (_item.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 (Item const & item, int items_per_cell)
+ : LookupTable (item)
, _items_per_cell (items_per_cell)
, _added (false)
{
- list<Item*> const & items = _group.items ();
+ list<Item*> const & items = _item.items ();
/* number of cells */
int const cells = items.size() / _items_per_cell;
/* hence number down each side of the table's square */
- _dimension = max (1, int (rint (sqrt (cells))));
+ _dimension = max (1, int (rint (sqrt ((double)cells))));
_cells = new Cell*[_dimension];
for (int i = 0; i < _dimension; ++i) {
_cells[i] = new Cell[_dimension];
}
- /* our group's bounding box in its coordinates */
- boost::optional<Rect> bbox = _group.bounding_box ();
+ /* our item's bounding box in its coordinates */
+ 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<Item*>::const_iterator i = items.begin(); i != items.end(); ++i) {
/* item bbox in its own coordinates */
- boost::optional<Rect> item_bbox = (*i)->bounding_box ();
+ Rect item_bbox = (*i)->bounding_box ();
if (!item_bbox) {
continue;
}
- /* and in the group's coordinates */
- Rect const item_bbox_in_group = (*i)->item_to_parent (item_bbox.get ());
+ /* and in the item's coordinates */
+ Rect const item_bbox_in_item = (*i)->item_to_parent (item_bbox);
int x0, y0, x1, y1;
- area_to_indices (item_bbox_in_group, x0, y0, x1, y1);
+ area_to_indices (item_bbox_in_item, x0, y0, x1, y1);
/* XXX */
assert (x0 >= 0);
//assert (y1 <= _dimension);
if (x0 > _dimension) {
- cout << "WARNING: item outside bbox by " << (item_bbox_in_group.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_group.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_group.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_group.y1 - bbox.get().y1) << "\n";
+ cout << "WARNING: item outside bbox by " << (item_bbox_in_item.y1 - bbox.y1) << "\n";
y1 = _dimension;
}
}
vector<Item*>
-OptimizingLookupTable::items_at_point (Duple point) const
+OptimizingLookupTable::items_at_point (Duple const & point) const
{
int x;
int y;
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);
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 ();
+ 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);
}
return items;
}
-
-/** @param area Area in our owning group's coordinates */
+
+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) {
+ Rect const item_bbox = (*i)->bounding_box ();
+ if (item_bbox) {
+ Rect parent_bbox = (*i)->item_to_parent (item_bbox);
+ if (parent_bbox.contains (point)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+/** @param area Area in our owning item's coordinates */
vector<Item*>
OptimizingLookupTable::get (Rect const & area)
{
vector<Item*> vitems;
copy (items.begin (), items.end (), back_inserter (vitems));
-
+
return vitems;
}