OSDN Git Service

Bounds checking for array insert.
authorNathanSweet <nathan.sweet@gmail.com>
Sat, 23 Mar 2013 14:58:38 +0000 (15:58 +0100)
committerNathanSweet <nathan.sweet@gmail.com>
Sat, 23 Mar 2013 14:58:38 +0000 (15:58 +0100)
Minor updates.

18 files changed:
gdx/src/com/badlogic/gdx/scenes/scene2d/Actor.java
gdx/src/com/badlogic/gdx/scenes/scene2d/Group.java
gdx/src/com/badlogic/gdx/scenes/scene2d/InputEvent.java
gdx/src/com/badlogic/gdx/scenes/scene2d/InputListener.java
gdx/src/com/badlogic/gdx/scenes/scene2d/Stage.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Image.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/ImageTextButton.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/ScrollPane.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/SelectBox.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/TextButton.java
gdx/src/com/badlogic/gdx/utils/Array.java
gdx/src/com/badlogic/gdx/utils/ArrayMap.java
gdx/src/com/badlogic/gdx/utils/BooleanArray.java
gdx/src/com/badlogic/gdx/utils/CharArray.java
gdx/src/com/badlogic/gdx/utils/FloatArray.java
gdx/src/com/badlogic/gdx/utils/IntArray.java
gdx/src/com/badlogic/gdx/utils/LongArray.java
gdx/src/com/badlogic/gdx/utils/ShortArray.java

index d3a07fe..578f3ea 100644 (file)
@@ -713,6 +713,6 @@ public class Actor {
                        int dotIndex = name.lastIndexOf('.');\r
                        if (dotIndex != -1) name = name.substring(dotIndex + 1);\r
                }\r
-               return name + " " + x + "," + y + " " + width + "x" + height;\r
+               return name;\r
        }\r
 }\r
index 3c37a0e..feb675d 100644 (file)
@@ -331,6 +331,10 @@ public class Group extends Actor implements Cullable {
                return children;
        }
 
+       public boolean hasChildren () {
+               return children.size > 0;
+       }
+
        /** When true (the default), the SpriteBatch is transformed so children are drawn in their parent's coordinate system. This has
         * a performance impact because {@link SpriteBatch#flush()} must be done before and after the transform. If the actors in a
         * group are not rotated or scaled, then the transform for the group can be set to false. In this case, each child's position
@@ -355,4 +359,18 @@ public class Group extends Actor implements Cullable {
                descendant.parentToLocalCoordinates(localCoords);
                return localCoords;
        }
+
+       /** Prints the actor hierarchy recursively for debugging purposes. */
+       public void print () {
+               print("");
+       }
+
+       private void print (String indent) {
+               Actor[] actors = children.begin();
+               for (int i = 0, n = children.size; i < n; i++) {
+                       System.out.println(indent + actors[i]);
+                       if (actors[i] instanceof Group) ((Group)actors[i]).print(indent + "|  ");
+               }
+               children.end();
+       }
 }
index 62b2cb5..121f67f 100644 (file)
@@ -17,6 +17,7 @@
 package com.badlogic.gdx.scenes.scene2d;\r
 \r
 import com.badlogic.gdx.Input.Buttons;\r
+import com.badlogic.gdx.math.Vector2;\r
 \r
 /** Event for actor input: touch, mouse, keyboard, and scroll.\r
  * @see InputListener */\r
@@ -118,6 +119,14 @@ public class InputEvent extends Event {
                this.relatedActor = relatedActor;\r
        }\r
 \r
+       /** Sets actorCoords to this event's coordinates relative to the specified actor.\r
+        * @param actorCoords Output for resulting coordinates. */\r
+       public Vector2 toCoordinates (Actor actor, Vector2 actorCoords) {\r
+               actorCoords.set(stageX, stageY);\r
+               actor.stageToLocalCoordinates(actorCoords);\r
+               return actorCoords;\r
+       }\r
+\r
        public String toString () {\r
                return type.toString();\r
        }\r
@@ -125,23 +134,23 @@ public class InputEvent extends Event {
        /** Types of low-level input events supported by stage2d. */\r
        static public enum Type {\r
                /** A new touch for a pointer on the stage was detected */\r
-               touchDown, \r
+               touchDown,\r
                /** A pointer has stopped touching the stage. */\r
-               touchUp, \r
+               touchUp,\r
                /** A pointer that is touching the stage has moved. */\r
-               touchDragged, \r
+               touchDragged,\r
                /** The mouse pointer has moved (without a mouse button being active). */\r
-               mouseMoved, \r
-               /** The mouse pointer or an active touch have entered (i.e., {@link Actor#hit(float, float, boolean) hit}) an actor. */ \r
-               enter, \r
-               /** The mouse pointer or an active touch have exited an actor. */ \r
-               exit, \r
+               mouseMoved,\r
+               /** The mouse pointer or an active touch have entered (i.e., {@link Actor#hit(float, float, boolean) hit}) an actor. */\r
+               enter,\r
+               /** The mouse pointer or an active touch have exited an actor. */\r
+               exit,\r
                /** The mouse scroll wheel has changed. */\r
-               scrolled, \r
+               scrolled,\r
                /** A keyboard key has been pressed. */\r
-               keyDown, \r
+               keyDown,\r
                /** A keyboard key has been released. */\r
-               keyUp, \r
+               keyUp,\r
                /** A keyboard key has been pressed and released. */\r
                keyTyped\r
        }\r
index ef95e43..30a4688 100644 (file)
@@ -18,23 +18,23 @@ package com.badlogic.gdx.scenes.scene2d;
 \r
 import com.badlogic.gdx.math.Vector2;\r
 \r
-/** EventListener for low-level input events.  Unpacks {@link InputEvent}s and calls the appropriate method.  By default\r
- * the methods here do nothing with the event.  Users are expected to override the methods they are interested in, like this:\r
+/** EventListener for low-level input events. Unpacks {@link InputEvent}s and calls the appropriate method. By default the methods\r
+ * here do nothing with the event. Users are expected to override the methods they are interested in, like this:\r
  * \r
  * <pre>\r
  * actor.addListener(new InputListener() {\r
- *    public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {\r
- *       Gdx.app.log("Example", "touch started at (" +x+ ", " +y+ ")");\r
- *    }\r
- *    public void touchUp(InputEvent event, float x, float y, int pointer, int button) {\r
- *       Gdx.app.log("Example", "touch done at (" +x+ ", " +y+ ")");\r
- *    }\r
+ *     public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {\r
+ *             Gdx.app.log(&quot;Example&quot;, &quot;touch started at (&quot; + x + &quot;, &quot; + y + &quot;)&quot;);\r
+ *     }\r
+ * \r
+ *     public void touchUp (InputEvent event, float x, float y, int pointer, int button) {\r
+ *             Gdx.app.log(&quot;Example&quot;, &quot;touch done at (&quot; + x + &quot;, &quot; + y + &quot;)&quot;);\r
+ *     }\r
  * });\r
- * </pre>\r
- */\r
+ * </pre> */\r
 public class InputListener implements EventListener {\r
        static private final Vector2 tmpCoords = new Vector2();\r
-       \r
+\r
        public boolean handle (Event e) {\r
                if (!(e instanceof InputEvent)) return false;\r
                InputEvent event = (InputEvent)e;\r
@@ -48,8 +48,7 @@ public class InputListener implements EventListener {
                        return keyTyped(event, event.getCharacter());\r
                }\r
 \r
-               tmpCoords.set(event.getStageX(), event.getStageY());\r
-               event.getListenerActor().stageToLocalCoordinates(tmpCoords);\r
+               event.toCoordinates(event.getListenerActor(), tmpCoords);\r
 \r
                switch (event.getType()) {\r
                case touchDown:\r
index 38de320..94b4573 100644 (file)
@@ -650,8 +650,7 @@ public class Stage extends InputAdapter implements Disposable {
        }\r
 \r
        /** Transforms the screen coordinates to stage coordinates.\r
-        * \r
-        * @param screenCoords input screen coordinates and output for resulting stage coordinates. */\r
+        * @param screenCoords Input screen coordinates and output for resulting stage coordinates. */\r
        public Vector2 screenToStageCoordinates (Vector2 screenCoords) {\r
                camera.unproject(cameraCoords.set(screenCoords.x, screenCoords.y, 0));\r
                screenCoords.x = cameraCoords.x;\r
@@ -660,18 +659,17 @@ public class Stage extends InputAdapter implements Disposable {
        }\r
 \r
        /** Transforms the stage coordinates to screen coordinates.\r
-        * \r
-        * @param stageCoords input stage coordinates and output for resulting screen coordinates */\r
+        * @param stageCoords Input stage coordinates and output for resulting screen coordinates. */\r
        public Vector2 stageToScreenCoordinates (Vector2 stageCoords) {\r
-               cameraCoords.set(stageCoords.x, stageCoords.y, 0);\r
-               camera.project(cameraCoords);\r
+               camera.project(cameraCoords.set(stageCoords.x, stageCoords.y, 0));\r
                stageCoords.x = cameraCoords.x;\r
-               stageCoords.y = cameraCoords.y;\r
+               stageCoords.y = Gdx.graphics.getHeight() - cameraCoords.y;\r
                return stageCoords;\r
        }\r
 \r
        /** Transforms the coordinates to screen coordinates. The coordinates can be anywhere in the stage since the transform matrix\r
-        * describes how to convert them. The transform matrix is typically obtained from {@link SpriteBatch#getTransformMatrix()}. */\r
+        * describes how to convert them. The transform matrix is typically obtained from {@link SpriteBatch#getTransformMatrix()}\r
+        * during {@link Actor#draw(SpriteBatch, float)}. */\r
        public Vector2 toScreenCoordinates (Vector2 coords, Matrix4 transformMatrix) {\r
                ScissorStack.toWindowCoordinates(camera, transformMatrix, coords);\r
                return coords;\r
index 2f217a9..0250f25 100644 (file)
@@ -86,13 +86,10 @@ public class Image extends Widget {
        }\r
 \r
        public void layout () {\r
-               float regionWidth, regionHeight;\r
-               if (drawable != null) {\r
-                       regionWidth = drawable.getMinWidth();\r
-                       regionHeight = drawable.getMinHeight();\r
-               } else\r
-                       return;\r
+               if (drawable == null) return;\r
 \r
+               float regionWidth = drawable.getMinWidth();\r
+               float regionHeight = drawable.getMinHeight();\r
                float width = getWidth();\r
                float height = getHeight();\r
 \r
index 32f0ef9..a3c9b50 100644 (file)
@@ -146,8 +146,8 @@ public class ImageTextButton extends Button {
                public ImageTextButtonStyle () {
                }
 
-               public ImageTextButtonStyle (Drawable up, Drawable down, Drawable checked) {
-                       super(up, down, checked);
+               public ImageTextButtonStyle (Drawable up, Drawable down, Drawable checked, BitmapFont font) {
+                       super(up, down, checked, font);
                }
 
                public ImageTextButtonStyle (ImageTextButtonStyle style) {
index caea4a2..7103c67 100644 (file)
@@ -567,7 +567,7 @@ public class ScrollPane extends WidgetGroup {
        /** Sets the {@link Actor} embedded in this scroll pane.\r
         * @param widget May be null to remove any current actor. */\r
        public void setWidget (Actor widget) {\r
-               if(widget == this) throw new IllegalArgumentException("widget cannot be same object");\r
+               if (widget == this) throw new IllegalArgumentException("widget cannot be same object");\r
                if (this.widget != null) super.removeActor(this.widget);\r
                this.widget = widget;\r
                if (widget != null) super.addActor(widget);\r
@@ -578,18 +578,26 @@ public class ScrollPane extends WidgetGroup {
                return widget;\r
        }\r
 \r
+       /** @deprecated */\r
        public void addActor (Actor actor) {\r
                throw new UnsupportedOperationException("Use ScrollPane#setWidget.");\r
        }\r
 \r
+       /** @deprecated */\r
        public void addActorAt (int index, Actor actor) {\r
                throw new UnsupportedOperationException("Use ScrollPane#setWidget.");\r
        }\r
 \r
+       /** @deprecated */\r
        public void addActorBefore (Actor actorBefore, Actor actor) {\r
                throw new UnsupportedOperationException("Use ScrollPane#setWidget.");\r
        }\r
 \r
+       /** @deprecated */\r
+       public void addActorAfter (Actor actorAfter, Actor actor) {\r
+               throw new UnsupportedOperationException("Use ScrollPane#setWidget.");\r
+       }\r
+\r
        public boolean removeActor (Actor actor) {\r
                if (actor != widget) return false;\r
                setWidget(null);\r
index 6e0a7cc..d231f37 100644 (file)
@@ -214,7 +214,7 @@ public class SelectBox extends Widget {
                                x = tmpCoords.x;\r
                                y = tmpCoords.y;\r
                                if (x > 0 && x < getWidth() && y > 0 && y < getHeight()) {\r
-                                       listSelectedIndex = (int) ((getHeight() - style.listBackground.getTopHeight() - y) / itemHeight);\r
+                                       listSelectedIndex = (int)((getHeight() - style.listBackground.getTopHeight() - y) / itemHeight);\r
                                        listSelectedIndex = Math.max(0, listSelectedIndex);\r
                                        listSelectedIndex = Math.min(items.length - 1, listSelectedIndex);\r
                                        selectedIndex = listSelectedIndex;\r
index 238295a..1590aa0 100644 (file)
@@ -109,8 +109,9 @@ public class TextButton extends Button {
                public TextButtonStyle () {\r
                }\r
 \r
-               public TextButtonStyle (Drawable up, Drawable down, Drawable checked) {\r
+               public TextButtonStyle (Drawable up, Drawable down, Drawable checked, BitmapFont font) {\r
                        super(up, down, checked);\r
+                       this.font = font;\r
                }\r
 \r
                public TextButtonStyle (TextButtonStyle style) {\r
index 6bbca3f..480e85f 100644 (file)
@@ -132,6 +132,7 @@ public class Array<T> implements Iterable<T> {
        }\r
 \r
        public void insert (int index, T value) {\r
+               if (index > size) throw new IndexOutOfBoundsException(String.valueOf(index));\r
                T[] items = this.items;\r
                if (size == items.length) items = resize(Math.max(8, (int)(size * 1.75f)));\r
                if (ordered)\r
index 642e620..8a5826d 100644 (file)
@@ -177,6 +177,7 @@ public class ArrayMap<K, V> {
        }\r
 \r
        public void insert (int index, K key, V value) {\r
+               if (index > size) throw new IndexOutOfBoundsException(String.valueOf(index));\r
                if (size == keys.length) resize(Math.max(8, (int)(size * 1.75f)));\r
                if (ordered) {\r
                        System.arraycopy(keys, index, keys, index + 1, size - index);\r
index a3da3d6..ba5ab0e 100644 (file)
@@ -113,6 +113,7 @@ public class BooleanArray {
        }\r
 \r
        public void insert (int index, boolean value) {\r
+               if (index > size) throw new IndexOutOfBoundsException(String.valueOf(index));\r
                boolean[] items = this.items;\r
                if (size == items.length) items = resize(Math.max(8, (int)(size * 1.75f)));\r
                if (ordered)\r
index a99b25b..cdc1dfa 100644 (file)
@@ -111,6 +111,7 @@ public class CharArray {
        }\r
 \r
        public void insert (int index, char value) {\r
+               if (index > size) throw new IndexOutOfBoundsException(String.valueOf(index));\r
                char[] items = this.items;\r
                if (size == items.length) items = resize(Math.max(8, (int)(size * 1.75f)));\r
                if (ordered)\r
index 9522552..d3e1810 100644 (file)
@@ -111,6 +111,7 @@ public class FloatArray {
        }\r
 \r
        public void insert (int index, float value) {\r
+               if (index > size) throw new IndexOutOfBoundsException(String.valueOf(index));\r
                float[] items = this.items;\r
                if (size == items.length) items = resize(Math.max(8, (int)(size * 1.75f)));\r
                if (ordered)\r
index a60788d..fec522b 100644 (file)
@@ -111,6 +111,7 @@ public class IntArray {
        }\r
 \r
        public void insert (int index, int value) {\r
+               if (index > size) throw new IndexOutOfBoundsException(String.valueOf(index));\r
                int[] items = this.items;\r
                if (size == items.length) items = resize(Math.max(8, (int)(size * 1.75f)));\r
                if (ordered)\r
index 60cf13f..18cdd38 100644 (file)
@@ -111,6 +111,7 @@ public class LongArray {
        }\r
 \r
        public void insert (int index, long value) {\r
+               if (index > size) throw new IndexOutOfBoundsException(String.valueOf(index));\r
                long[] items = this.items;\r
                if (size == items.length) items = resize(Math.max(8, (int)(size * 1.75f)));\r
                if (ordered)\r
index cc3cc9c..972c47c 100644 (file)
@@ -111,6 +111,7 @@ public class ShortArray {
        }\r
 \r
        public void insert (int index, short value) {\r
+               if (index > size) throw new IndexOutOfBoundsException(String.valueOf(index));\r
                short[] items = this.items;\r
                if (size == items.length) items = resize(Math.max(8, (int)(size * 1.75f)));\r
                if (ordered)\r