/** * Returns the index of the given layer within its parent, or -1 if the parent is null. */ public static int indexInParent (Layer layer) { GroupLayer parent = layer.parent(); if (parent == null) return -1; for (int ii = parent.children()-1; ii >= 0; ii--) { if (parent.childAt(ii) == layer) return ii; } throw new AssertionError(); }
@Override protected void visit(Visitor visitor, int depth) { super.visit(visitor, depth); int childDepth = depth+1; for (int ii = 0, ll = children(); ii < ll; ii++) { childAt(ii).visit(visitor, childDepth); } }
private static void print (Log log, Layer layer, String prefix) { log.debug(prefix + layer); if (layer instanceof GroupLayer) { String gprefix = prefix + " "; GroupLayer glayer = (GroupLayer)layer; for (int ii = 0, ll = glayer.children(); ii < ll; ii++) { print(log, glayer.childAt(ii), gprefix); } } } }
/** Helper function for {@link #totalBounds}. */ protected static void addBounds (Layer root, Layer l, Rectangle bounds, Point scratch) { float w = l.width(), h = l.height(); if (w != 0 || h != 0) { // grow bounds bounds.add(LayerUtil.layerToParent(l, root, scratch.set(0, 0), scratch)); bounds.add(LayerUtil.layerToParent(l, root, scratch.set(w, h), scratch)); } if (l instanceof GroupLayer) { GroupLayer group = (GroupLayer) l; for (int ii = 0, ll = group.children(); ii < ll; ++ii) { addBounds(root, group.childAt(ii), bounds, scratch); } } } }
/** Performs the recursion for {@link #layerUnderPoint(Layer,float,float)}. */ protected static Layer layerUnderPoint (Layer layer, Point pt) { float x = pt.x, y = pt.y; if (layer instanceof GroupLayer) { GroupLayer gl = (GroupLayer)layer; for (int ii = gl.children()-1; ii >= 0; ii--) { Layer child = gl.childAt(ii); if (!child.visible()) continue; // ignore invisible children try { // transform the point into the child's coordinate system child.transform().inverseTransform(pt.set(x, y), pt); pt.x += child.originX(); pt.y += child.originY(); Layer l = layerUnderPoint(child, pt); if (l != null) return l; } catch (NoninvertibleTransformException nte) { continue; } } } if (x >= 0 && x < layer.width() && y >= 0 && y < layer.height()) { return layer; } return null; }
Layer[] temp = new Layer[layer.children()]; for (int ii = 0, nn = temp.length; ii < nn; ii++) { temp[ii] = layer.childAt(ii);