diff --git a/CHANGES b/CHANGES index f5145017f29..ca27e708c77 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,5 @@ [1.2.1] +- API change: Added a new Scene2DDebugRenderer and removed the old Table debug rendering, see https://github.com/libgdx/libgdx/pull/2011 - Files#getLocalStoragePath now returns the actual path instead of the empty string synonym on desktop (LWJGL and JGLFW). - Fixed and improved xorshift128+ PRNG implementation. - Added support for Tiled's animated tiles, and varying frame duration tile animations. diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 3e9ea9101a2..e318e42a50b 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -169,4 +169,5 @@ mbforbes https://github.com/mbforbes Unkn0wn0ne https://github.com/Unkn0wn0ne davebaol https://github.com/davebaol CodePoKE https://github.com/codepoke -Konijnendijk https://github.com/Konijnendijk \ No newline at end of file +Konijnendijk https://github.com/Konijnendijk +nooone https://github.com/nooone \ No newline at end of file diff --git a/gdx/src/com/badlogic/gdx/scenes/scene2d/Actor.java b/gdx/src/com/badlogic/gdx/scenes/scene2d/Actor.java index 68b002c03c7..27fc1e7783a 100644 --- a/gdx/src/com/badlogic/gdx/scenes/scene2d/Actor.java +++ b/gdx/src/com/badlogic/gdx/scenes/scene2d/Actor.java @@ -24,6 +24,8 @@ import com.badlogic.gdx.scenes.scene2d.InputEvent.Type; import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; +import com.badlogic.gdx.scenes.scene2d.utils.Scene2DDebugRenderer; +import com.badlogic.gdx.scenes.scene2d.utils.Scene2DDebugRenderer.DebugRect; import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.DelayedRemovalArray; @@ -65,6 +67,9 @@ public class Actor { final Color color = new Color(1, 1, 1, 1); private Object userObject; + private boolean debuggingEnabled = true; + public static Color debugColor = new Color(0, 1, 0, 1); + /** Draws the actor. The Batch is configured to draw in the parent's coordinate system. * {@link Batch#draw(com.badlogic.gdx.graphics.g2d.TextureRegion, float, float, float, float, float, float, float, float, float) * This draw method} is convenient to draw a rotated and scaled TextureRegion. {@link Batch#begin()} has already been called on @@ -379,16 +384,16 @@ public void setPosition (float x, float y) { } /** Set position of Actor centered on x, y */ - public void setCenterPosition(float x, float y) { + public void setCenterPosition (float x, float y) { this.x = x - width / 2; this.y = y - height / 2; } - public float getCenterX() { + public float getCenterX () { return this.x + width / 2; } - public float getCenterY() { + public float getCenterY () { return this.y + height / 2; } @@ -554,8 +559,7 @@ public Color getColor () { return color; } - /** Retrieve custom actor name set with {@link Actor#setName(String)}, - * used for easier identification */ + /** Retrieve custom actor name set with {@link Actor#setName(String)}, used for easier identification */ public String getName () { return name; } @@ -566,6 +570,28 @@ public void setName (String name) { this.name = name; } + /** The {@link Scene2DDebugRenderer} will ask every actor of a stage for their debugging rectangles. To fill the given array you + * can obtain fresh {@link DebugRect}s via the {@link Scene2DDebugRenderer#debugRectPool}. To avoid the garbage collection you + * should make sure to free them later, but it's not a strict requirement. */ + public void getDebugRects (Array debugRects) { + DebugRect debugRect = Scene2DDebugRenderer.debugRectPool.obtain(); + debugRect.bottomLeft.set(0, 0); + debugRect.topRight.set(width, height); + debugRect.color.set(Actor.debugColor); + debugRects.add(debugRect); + } + + /** Used only in combination with a {@link Scene2DDebugRenderer}. It does only influence this particular actor, not its + * children, in case we have a {@link Group}. */ + public void setDebuggingEnabled (boolean enabled) { + debuggingEnabled = enabled; + } + + /** Used only in combination with a {@link Scene2DDebugRenderer}. */ + public boolean isDebuggingEnabled () { + return debuggingEnabled; + } + /** Changes the z-order for this actor so it is in front of all siblings. */ public void toFront () { setZIndex(Integer.MAX_VALUE); diff --git a/gdx/src/com/badlogic/gdx/scenes/scene2d/Group.java b/gdx/src/com/badlogic/gdx/scenes/scene2d/Group.java index bda642c5949..1b8b493a867 100644 --- a/gdx/src/com/badlogic/gdx/scenes/scene2d/Group.java +++ b/gdx/src/com/badlogic/gdx/scenes/scene2d/Group.java @@ -22,6 +22,7 @@ import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.utils.Cullable; +import com.badlogic.gdx.scenes.scene2d.utils.Scene2DDebugRenderer; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.SnapshotArray; @@ -289,12 +290,12 @@ public void clear () { public T findActor (String name) { Array children = this.children; for (int i = 0, n = children.size; i < n; i++) - if (name.equals(children.get(i).getName())) return (T) children.get(i); + if (name.equals(children.get(i).getName())) return (T)children.get(i); for (int i = 0, n = children.size; i < n; i++) { Actor child = children.get(i); if (child instanceof Group) { Actor actor = ((Group)child).findActor(name); - if (actor != null) return (T) actor; + if (actor != null) return (T)actor; } } return null; @@ -364,6 +365,21 @@ public void print () { print(""); } + /** Used only in combination with a {@link Scene2DDebugRenderer}. + * @param recursively If {@code true} it will also recursively disable all children of this group. */ + public void setDebuggingEnabled (boolean enabled, boolean recursively) { + setDebuggingEnabled(enabled); + if (recursively) { + for (Actor child : children) { + if (child instanceof Group) { + ((Group)child).setDebuggingEnabled(enabled, recursively); + } else { + child.setDebuggingEnabled(enabled); + } + } + } + } + private void print (String indent) { Actor[] actors = children.begin(); for (int i = 0, n = children.size; i < n; i++) { diff --git a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Table.java b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Table.java index 6866462b797..1787377e042 100644 --- a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Table.java +++ b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Table.java @@ -16,23 +16,17 @@ package com.badlogic.gdx.scenes.scene2d.ui; -import com.badlogic.gdx.Application; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer; -import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20; -import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.scenes.scene2d.Actor; -import com.badlogic.gdx.scenes.scene2d.Group; -import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.Touchable; import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle; import com.badlogic.gdx.scenes.scene2d.ui.Value.Fixed; import com.badlogic.gdx.scenes.scene2d.utils.Align; import com.badlogic.gdx.scenes.scene2d.utils.Drawable; import com.badlogic.gdx.scenes.scene2d.utils.Layout; +import com.badlogic.gdx.scenes.scene2d.utils.Scene2DDebugRenderer; +import com.badlogic.gdx.scenes.scene2d.utils.Scene2DDebugRenderer.DebugRect; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Pool; @@ -42,6 +36,10 @@ * The preferred and minimum sizes are that of the children when laid out in columns and rows. * @author Nathan Sweet */ public class Table extends WidgetGroup { + + public static Color debugColor = new Color(0, 0, 1, 1); + public static Color debugCellColor = new Color(1, 0, 0, 1); + static Pool cellPool = new Pool() { protected Cell newObject () { return new Cell(); @@ -68,7 +66,7 @@ protected Cell newObject () { int align = Align.center; Debug debug = Debug.none; - Array debugRects; + Array debugRects = new Array(); private Drawable background; private boolean clip; @@ -281,7 +279,7 @@ public Cell