\r
import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.InputAdapter;\r
+import com.badlogic.gdx.InputProcessor;\r
import com.badlogic.gdx.math.Vector2;\r
import com.badlogic.gdx.utils.TimeUtils;\r
\r
+/**\r
+ * {@link InputProcessor} implementation that detects gestures (tap, long press, fling,\r
+ * pan, zoom, pinch) and hands them to a {@link GestureListener}.\r
+ * @author mzechner\r
+ *\r
+ */\r
public class GestureDetector extends InputAdapter {\r
+ /**\r
+ * Register an instance of this class with a {@link GestureDetector} to \r
+ * receive gestures such as taps, long presses, flings, panning or pinch\r
+ * zooming. Each method returns a boolean indicating if the event should\r
+ * be handed to the next listener (false to hand it to the next listener, true\r
+ * otherwise).\r
+ * @author mzechner\r
+ *\r
+ */\r
public static interface GestureListener {\r
+ /**\r
+ * Called when a finger went down on the screen or a mouse button was\r
+ * pressed.\r
+ * @param x \r
+ * @param y\r
+ * @param pointer\r
+ * @return\r
+ */\r
public boolean touchDown (int x, int y, int pointer);\r
\r
+ /**\r
+ * Called when a tap occured. A tap happens if a finger went down on \r
+ * the screen and was lifted again without moving outside of the tap square.\r
+ * The tap square is a rectangular area around the initial touch position\r
+ * as specified on construction time of the {@link GestureDetector}. \r
+ * @param x\r
+ * @param y\r
+ * @param count the number of taps. \r
+ * @return\r
+ */\r
public boolean tap (int x, int y, int count);\r
\r
public boolean longPress (int x, int y);\r
\r
+ /**\r
+ * Called when the user dragged a finger over the screen and lifted it. Reports\r
+ * the last known velocity of the finger in pixels per second.\r
+ * @param velocityX velocity on x in seconds\r
+ * @param velocityY velocity on y in seconds\r
+ * @return\r
+ */\r
public boolean fling (float velocityX, float velocityY);\r
\r
+ /**\r
+ * Called when the user drags a finger over the screen.\r
+ * @param x\r
+ * @param y\r
+ * @param deltaX the difference in pixels to the last drag event on x.\r
+ * @param deltaY the difference in pixels to the last drag event on y.\r
+ * @return\r
+ */\r
public boolean pan (int x, int y, int deltaX, int deltaY);\r
\r
+ /**\r
+ * Called when the user performs a pinch zoom gesture. The original distance\r
+ * is the distance in pixels when the gesture started.\r
+ * @param originalDistance distance between fingers when the gesture started.\r
+ * @param currentDistance current distance between fingers.\r
+ * @return\r
+ */\r
public boolean zoom (float originalDistance, float currentDistance);\r
\r
+ /**\r
+ * Called when a user performs a pinch zoom gesture. Reports the initial positions\r
+ * of the two involved fingers and their current positions.\r
+ * @param initialFirstPointer\r
+ * @param initialSecondPointer\r
+ * @param firstPointer\r
+ * @param secondPointer\r
+ * @return\r
+ */\r
public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, Vector2 firstPointer, Vector2 secondPointer);\r
}\r
\r
+ /**\r
+ * Derrive from this if you only want to implement a subset of {@link GestureListener}.\r
+ * @author mzechner\r
+ *\r
+ */\r
public static class GestureAdapter implements GestureListener {\r
public boolean touchDown (int x, int y, int pointer) {\r
return false;\r
\r
private final GestureListener listener;\r
\r
+ /**\r
+ * Creates a new GestureDetector that will pass on all gestures\r
+ * to the specified {@link GestureListener}\r
+ * @param listener\r
+ */\r
public GestureDetector (GestureListener listener) {\r
this(20, 0.4f, 1.5f, 0.15f, listener);\r
}\r
\r
+ /**\r
+ * Creates a new GestureDetector that will pass on all gestures\r
+ * to the specified {@link GestureListener}\r
+ * @param halfTapSquareSize half width in pixels of the square around an initial touch event, see {@link GestureListener#tap(int, int, int)} \r
+ * @param tapCountInterval time in seconds that must pass for two touch down/up sequences to be detected as consecutive taps.\r
+ * @param longPressDuration time in seconds that must pass for the detector to fire a {@link GestureListener#longPress(int, int)} event.\r
+ * @param maxFlingDelay time in seconds the finger must have been dragged for a fling event to be fired, see {@link GestureListener#fling(float, float)}\r
+ * @param listener\r
+ */\r
public GestureDetector (int halfTapSquareSize, float tapCountInterval, float longPressDuration, float maxFlingDelay,\r
GestureListener listener) {\r
this.tapSquareSize = halfTapSquareSize;\r