@Override public Layer setInteractive(boolean interactive) { if (interactive() != interactive) { // if we're being made interactive, active our parent as well, if we have one if (interactive && parent != null) parent.setInteractive(interactive); setFlag(Flag.INTERACTIVE, interactive); } return this; }
public Layer hitTest(GroupLayer self, Point point) { float x = point.x, y = point.y; boolean sawInteractiveChild = false; // we check back to front as children are ordered "lowest" first for (int ii = children.size()-1; ii >= 0; ii--) { L child = children.get(ii); if (!child.interactive()) continue; // ignore non-interactive children sawInteractiveChild = true; // note that we saw an interactive child if (!child.visible()) continue; // ignore invisible children try { // transform the point into the child's coordinate system child.transform().inverseTransform(point.set(x, y), point); point.x += child.originX(); point.y += child.originY(); Layer l = child.hitTest(point); if (l != null) return l; } catch (NoninvertibleTransformException nte) { // Degenerate transform means no hit continue; } } // if we saw no interactive children and we don't have listeners registered directly on this // group, clear our own interactive flag; this lazily deactivates this group after its // interactive children have been deactivated or removed if (!sawInteractiveChild && !((AbstractLayer)self).hasInteractors()) self.setInteractive(false); return null; }
/** * @return the index into the children array at which the layer was inserted (based on depth). */ public int add(GroupLayer self, L child) { // optimization if we're requested to add a child that's already added GroupLayer parent = child.parent(); if (parent == self) { return findChild(child, child.depth()); } // if this child has equal or greater depth to the last child, we can append directly and avoid // a log(N) search; this is helpful when all children have the same depth int count = children.size(), index; if (count == 0 || children.get(count-1).depth() <= child.depth()) { index = count; } else { // otherwise find the appropriate insertion point via binary search index = findInsertion(child.depth()); } // remove the child from any existing parent, preventing multiple parents if (parent != null) { child.parent().remove(child); } children.add(index, child); child.setParent(self); child.onAdd(); // if this child is active, we need to become active if (child.interactive()) self.setInteractive(true); return index; }