/** * Converts the supplied point from screen coordinates to coordinates * relative to the specified layer. */ public static Point screenToLayer(Layer layer, float x, float y) { Point into = new Point(x, y); return screenToLayer(layer, into, into); }
/** * Converts the supplied point from coordinates relative to the specified layer to screen * coordinates. The results are stored into {@code into}, which is returned for convenience. */ public static Point layerToScreen(Layer layer, XY point, Point into) { return layerToParent(layer, null, point, into); }
/** * Transforms a point from one Layer's coordinate system to another's. */ public static Point transform (IPoint p, Layer from, Layer to, Point result) { LayerUtil.layerToScreen(from, p, result); LayerUtil.screenToLayer(to, result, result); return result; }
/** * Converts the supplied point from screen coordinates to coordinates * relative to the specified layer. The results are stored into {@code into} * , which is returned for convenience. */ public static Point screenToLayer(Layer layer, XY point, Point into) { Layer parent = layer.parent(); XY cur = (parent == null) ? point : screenToLayer(parent, point, into); return parentToLayer(layer, cur, into); }
/** * Converts the supplied point from coordinates relative to the specified * layer to screen coordinates. */ public static Point layerToScreen(Layer layer, float x, float y) { Point into = new Point(x, y); return layerToScreen(layer, into, into); }
@Override public void onEmit (Event[] events) { // each event has an id which defines the interaction of which it is a part for (Event event : events) { // start a new interaction for this id if START and we don't already have one Interaction iact = activeIacts.get(event.id); if (iact == null && event.kind.isStart) { Layer hitLayer = LayerUtil.getHitLayer(root, scratch.set(event.x, event.y)); if (hitLayer != null) activeIacts.put(event.id, iact = new Interaction(hitLayer, bubble)); } // dispatch the event to the interaction if (iact != null) iact.dispatch(event); // if this is END or CANCEL, clear out the interaction for this id if (event.kind.isEnd) activeIacts.remove(event.id); } } }
/** * Prints the layer heirarchy starting at {@code layer}, using {@link Log#debug}. */ public static void print (Log log, Layer layer) { print(log, layer, ""); }
/** * 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); }
/** * Creates an emitter that uses {@code batch} to render its particles. When this emitter's * layer is added to the scene graph, it will connect itself to {@code paint} to drive the * particle animations, and when its layer is removed, it will disconnect from {@code paint}. * * @param batch the particle batch to use when rendering our particles. * @param paint the paint signal which will drive this emitter. * @param maxParticles the maximum number of active particles. * @param tile the texture to use when rendering particles. */ public Emitter (final ParticleBatch batch, final Signal<Clock> paint, final int maxParticles, final Tile tile) { this.layer = new Layer() { @Override protected void paintImpl (Surface surface) { QuadBatch obatch = surface.pushBatch(batch); _buffer.render(batch.prepare(tile, maxParticles), tile.width(), tile.height()); surface.popBatch(obatch); } }; _buffer = new ParticleBuffer(maxParticles); LayerUtil.bind(layer, paint, new Slot<Clock>() { public void onEmit (Clock clock) { paint(clock); } }); }
/** * Converts the supplied point from coordinates relative to the specified parent to coordinates * relative to the specified child layer. The results are stored into {@code into}, which is * returned for convenience. */ public static Point parentToLayer(Layer parent, Layer layer, XY point, Point into) { into.set(point); Layer immediateParent = layer.parent(); if (immediateParent != parent) parentToLayer(parent, immediateParent, into, into); parentToLayer(layer, into, into); return into; }
/** * Returns true if an {@link XY} touches a {@link Layer}. Note: if the supplied layer has no * size, this will always return false. */ public static boolean hitTest(Layer layer, XY pos) { return hitTest(layer, pos.x(), pos.y()); }
/** * Optionally confines the menu area to the given element. By default the menu is confined * by the host's screen area (see {@link MenuHost#getScreenArea()}). */ public Pop inElement (Element<?> elem) { Point tl = LayerUtil.layerToScreen(elem.layer, 0, 0); Point br = LayerUtil.layerToScreen( elem.layer, elem.size().width(), elem.size().height()); bounds = new Rectangle(tl.x(), tl.y(), br.x() - tl.x(), br.y() - tl.y()); return this; }
private void dispatchSolo (Event event) { Layer hitLayer = LayerUtil.getHitLayer(root, scratch.set(event.x, event.y)); if (hitLayer != null) new Interaction(hitLayer, bubble, true).dispatch(event); } }
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); } } } }
/** 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; }
public Stock (SceneGame game) { super(game); add("Shader info:", true); add(_quadShader); add(_trisShader); add("Per second:", true); add("Frames:", _frames); add("Shader creates:", _shaderCreates); add("FB creates:", _fbCreates); add("Tex creates:", _texCreates); add("Per frame:", true); add("Shader binds:", _shaderBinds); add("FB binds:", _fbBinds); add("Tex binds:", _texBinds); add("Quads drawn:", _rQuads); add("Tris drawn:", _rTris); add("Shader flushes:", _shaderFlushes); // receive paint updates while our layer is connected LayerUtil.bind(layer, game.paint, new Slot<Clock>() { public void onEmit (Clock clock) { int now = clock.tick; if (now > _nextUpdate) { willUpdate(); update(); _nextUpdate = now + 1000; } } protected int _nextUpdate; }); }
@Override public void onEmit (Pointer.Event e) { Point pt = LayerUtil.screenToLayer(content.layer, e.x(), e.y()); click.text.update(pt.x + ", " + pt.y); } });
/** * Removes {@code layer} from its current parent and adds it to {@code target}, modifying its * transform in the process so that it stays in the same position on the screen. */ public static void reparent (Layer layer, GroupLayer target) { Point pos = new Point(layer.tx(), layer.ty()); LayerUtil.layerToScreen(layer.parent(), pos, pos); target.add(layer); LayerUtil.screenToLayer(layer.parent(), pos, pos); layer.setTranslation(pos.x, pos.y); }
protected Rectangle getNativeFieldBounds () { Insets insets = resolveStyle(Style.BACKGROUND).insets; Point screenCoords = LayerUtil.layerToScreen(layer, insets.left(), insets.top()); return new Rectangle(screenCoords.x, screenCoords.y, _size.width - insets.width(), _size.height - insets.height()); }
/** * Converts the supplied point from coordinates relative to the specified * child layer to coordinates relative to the specified parent layer. */ public static Point layerToParent(Layer layer, Layer parent, float x, float y) { Point into = new Point(x, y); return layerToParent(layer, parent, into, into); }