Minor updates.
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
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
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();
+ }
}
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
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
/** 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
\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("Example", "touch started at (" + x + ", " + y + ")");\r
+ * }\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
* });\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
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
}\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
}\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
}\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
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) {
/** 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
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
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
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
}\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
}\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
}\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
}\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
}\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
}\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
}\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
}\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