protected void toString (StringBuilder buf) { buf.append("tx=").append(transform()); if (hitTester != null) buf.append(", hitTester=").append(hitTester); }
protected void doStart(float x, float y) { _lstart = layer.transform().translation(); _pstart = new Vector(x, y); } protected void doMove(float x, float y) {
@Override public void addTo (GroupLayer parent, float x, float y, float depthAdjust) { _layer.setDepth(BACKGROUND_DEPTH + depthAdjust); _layer.transform().translate(x, y); // adjust any existing transform parent.add(_layer); } @Override public void close () {
/** * Converts the supplied point from coordinates relative to its parent * to coordinates relative to the specified layer. The results are stored * into {@code into}, which is returned for convenience. */ public static Point parentToLayer(Layer layer, XY point, Point into) { layer.transform().inverseTransform(into.set(point), into); into.x += layer.originX(); into.y += layer.originY(); return into; }
/** * Returns the layer hit by (screen) position {@code p} (or null) in the scene graph rooted at * {@code root}, using {@link Layer#hitTest}. Note that {@code p} is mutated by this call. */ public static Layer getHitLayer (Layer root, Point p) { root.transform().inverseTransform(p, p); p.x += root.originX(); p.y += root.originY(); return root.hitTest(p); }
@Override public void willInit (int count) { // concatenate the transform of all layers above our target layer xform.setTransform(1, 0, 0, 1, 0, 0); Layer xlayer = layer; while (xlayer != null) { Transforms.multiply(xlayer.transform(), xform, xform); xlayer = xlayer.parent(); } xform.get(_matrix); } @Override public void init (int index, float[] data, int start) {
/** * Converts the supplied point from coordinates relative to the specified * child layer to coordinates relative to the specified parent layer. The * results are stored into {@code into}, which is returned for convenience. */ public static Point layerToParent(Layer layer, Layer parent, XY point, Point into) { into.set(point); while (layer != parent) { if (layer == null) { throw new IllegalArgumentException( "Failed to find parent, perhaps you passed parent, layer instead of " + "layer, parent?"); } into.x -= layer.originX(); into.y -= layer.originY(); layer.transform().transform(into, into); layer = layer.parent(); } return into; }
/** * Gets the layer underneath the given screen coordinates, ignoring hit testers. This is * useful for inspecting the scene graph for debugging purposes, and is not intended for use * is shipped code. The layer returned is the one that has a size and is the deepest within * the graph and contains the coordinate. */ public static Layer layerUnderPoint (Layer root, float x, float y) { Point p = new Point(x, y); root.transform().inverseTransform(p, p); p.x += root.originX(); p.y += root.originY(); return layerUnderPoint(root, p); }
@Override public Layer hitTestDefault(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--) { Layer 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 && !hasEventListeners()) setInteractive(false); return super.hitTestDefault(point); }
/** * Renders this layer to {@code surf}, including its children. */ public final void paint (Surface surf) { if (!visible()) return; int otint = surf.combineTint(tint); QuadBatch obatch = surf.pushBatch(batch); surf.concatenate(transform(), originX(), originY()); try { paintImpl(surf); if (DEBUG_RECTS) { drawDebugRect(surf); } } finally { surf.popBatch(obatch); surf.setTint(otint); } }
/** 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; }
float m10 = -sinX * scaleY; float m11 = cosX * scaleY; content.transform().setTransform(m00, m01, m10, m11, locX, locY); content.setOrigin(kf.pivot.x(), kf.pivot.y());