/** * Disposes this layer, removing it from its parent layer. Any resources associated with this * layer are freed, and it cannot be reused after being disposed. Disposing a layer that has * children will dispose them as well. */ @Override public void close() { if (parent != null) parent.remove(this); setState(State.DISPOSED); setBatch(null); }
@Override public Layer hitTest(Layer layer, Point p) { if (p.x >= 0 && p.y >= 0 && p.x < this.layer.width() && p.y < this.layer.height()) { return layer.hitTestDefault(p); } return null; } }
/** * 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); }
/** * Adds {@code child} to this group layer, positioning it such that its center is at ({@code tx}, * {@code tx}). The layer must report a non-zero size, thus this will not work on an unclipped * group layer. * * <p>This is equivalent to: {@code add(child.setTranslation(tx - child.width()/2, * ty - child.height()/2))}. */ public void addCenterAt (Layer child, float tx, float ty) { add(child.setTranslation(tx - child.width()/2, ty - child.height()/2)); }
protected void update (Texture tex) { if (tex == null) { // we should never be going back to null but handle it anyway if (_ilayer != null) _ilayer.close(); _ilayer = null; return; } if (_ilayer == null) layer.add(_ilayer = new ImageLayer()); _ilayer.setTile(tex); }
/** Returns the y-component of the layer's origin. */ public float originY () { if (isSet(Flag.ODIRTY)) { float height = height(); if (height > 0) { this.originX = origin.ox(width()); this.originY = origin.oy(height); setFlag(Flag.ODIRTY, false); } } return originY; } /** Writes this layer's origin into {@code into}.
/** * Adds the supplied layer to this group layer, adjusting its translation (relative to this group * layer) to the supplied values. * * <p>This is equivalent to: {@code add(child.setTranslation(tx, ty))}. */ public void addAt(Layer child, float tx, float ty) { add(child.setTranslation(tx, ty)); }
/** * 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); }
@Override public void close() { super.close(); disposeAll(); }
@Override protected void connectionRemoved () { if (!hasConnections() && deactivateOnNoListeners()) setInteractive(false); } };
/** * Creates an image layer with the supplied texture tile. */ public ImageLayer (Tile tile) { setTile(tile); }
/** * 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); }
/** * Configures this layer's visibility: if true, it will be rendered as normal, if false it and * its children will not be rendered. * * @return a reference to this layer for call chaining. */ public Layer setVisible(boolean visible) { setFlag(Flag.VISIBLE, visible); return this; }
/** * Visits this layer and its children, in depth first order, with {@code visitor}. */ public void visit(Visitor visitor) { visit(visitor, 0); }
/** Sets {@link #region}. * @return {@code this}, for convenient call chaining. */ public ImageLayer setRegion (Rectangle region) { this.region = region; checkOrigin(); return this; }
/** Updates the width of this group layer, and hence its clipping rectangle. */ public ClippedLayer setWidth(float width) { this.width = width; checkOrigin(); return this; }
/** Returns the x-component of the layer's origin. */ public float originX () { if (isSet(Flag.ODIRTY)) { float width = width(); if (width > 0) { this.originX = origin.ox(width); this.originY = origin.oy(height()); setFlag(Flag.ODIRTY, false); } } return originX; } /** Returns the y-component of the layer's origin. */