Package arc.input
Class GestureDetector
java.lang.Object
arc.input.GestureDetector
- All Implemented Interfaces:
InputProcessor
InputProcessor
implementation that detects gestures (tap, long press, fling, pan, zoom, pinch) and hands them to a
GestureDetector.GestureListener
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Register an instance of this class with aGestureDetector
to receive gestures such as taps, long presses, flings, panning or pinch zooming. -
Constructor Summary
ConstructorDescriptionGestureDetector
(float halfTapRectangleWidth, float halfTapRectangleHeight, float tapCountInterval, float longPressDuration, float maxFlingDelay, GestureDetector.GestureListener listener) GestureDetector
(float halfTapSquareSize, float tapCountInterval, float longPressDuration, float maxFlingDelay, GestureDetector.GestureListener listener) Creates a new GestureDetector with default values: halfTapSquareSize=20, tapCountInterval=0.4f, longPressDuration=1.1f, maxFlingDelay=0.15f. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
No further gesture events will be triggered for the current touch, if any.void
The tap square will not longer be used for the current touch.boolean
boolean
isLongPressed
(float duration) boolean
void
reset()
void
setLongPressSeconds
(float longPressSeconds) void
setMaxFlingDelay
(long maxFlingDelay) void
setTapCountInterval
(float tapCountInterval) void
setTapRectangleSize
(float halfTapRectangleWidth, float halfTapRectangleHeight) void
setTapSquareSize
(float halfTapSquareSize) boolean
boolean
boolean
touchDragged
(float x, float y, int pointer) boolean
touchDragged
(int x, int y, int pointer) Called when a finger or the mouse was dragged.boolean
boolean
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface arc.input.InputProcessor
connected, disconnected, keyDown, keyTyped, keyUp, mouseMoved, scrolled
-
Constructor Details
-
GestureDetector
Creates a new GestureDetector with default values: halfTapSquareSize=20, tapCountInterval=0.4f, longPressDuration=1.1f, maxFlingDelay=0.15f. -
GestureDetector
public GestureDetector(float halfTapSquareSize, float tapCountInterval, float longPressDuration, float maxFlingDelay, GestureDetector.GestureListener listener) - Parameters:
halfTapSquareSize
- half width in pixels of the square around an initial touch eventtapCountInterval
- time in seconds that must pass for two touch down/up sequences to be detected as consecutive taps.longPressDuration
- time in seconds that must pass for the detector to fire aGestureDetector.GestureListener.longPress(float, float)
event.maxFlingDelay
- time in seconds the finger must have been dragged for a fling event to be firedlistener
- May be null if the listener will be set later.
-
GestureDetector
public GestureDetector(float halfTapRectangleWidth, float halfTapRectangleHeight, float tapCountInterval, float longPressDuration, float maxFlingDelay, GestureDetector.GestureListener listener) - Parameters:
halfTapRectangleWidth
- half width in pixels of the rectangle around an initial touch eventhalfTapRectangleHeight
- half height in pixels of the rectangle around an initial touch eventtapCountInterval
- time in seconds that must pass for two touch down/up sequences to be detected as consecutive taps.longPressDuration
- time in seconds that must pass for the detector to fire aGestureDetector.GestureListener.longPress(float, float)
event.maxFlingDelay
- time in seconds the finger must have been dragged for a fling event to be firedlistener
- May be null if the listener will be set later.
-
-
Method Details
-
getListener
-
touchDown
- Specified by:
touchDown
in interfaceInputProcessor
- Parameters:
x
- The x coordinate, origin is in the upper left cornery
- The y coordinate, origin is in the upper left cornerpointer
- the pointer for the event.button
- the button- Returns:
- whether the input was processed
-
touchDown
-
touchDragged
public boolean touchDragged(int x, int y, int pointer) Description copied from interface:InputProcessor
Called when a finger or the mouse was dragged.- Specified by:
touchDragged
in interfaceInputProcessor
pointer
- the pointer for the event.- Returns:
- whether the input was processed
-
touchDragged
public boolean touchDragged(float x, float y, int pointer) -
touchUp
- Specified by:
touchUp
in interfaceInputProcessor
pointer
- the pointer for the event.button
- the button- Returns:
- whether the input was processed
-
touchUp
-
cancel
public void cancel()No further gesture events will be triggered for the current touch, if any. -
isLongPressed
public boolean isLongPressed()- Returns:
- whether the user touched the screen long enough to trigger a long press event.
-
isLongPressed
public boolean isLongPressed(float duration) - Returns:
- whether the user touched the screen for as much or more than the given duration.
-
isPanning
public boolean isPanning() -
reset
public void reset() -
invalidateTapSquare
public void invalidateTapSquare()The tap square will not longer be used for the current touch. -
setTapSquareSize
public void setTapSquareSize(float halfTapSquareSize) -
setTapRectangleSize
public void setTapRectangleSize(float halfTapRectangleWidth, float halfTapRectangleHeight) -
setTapCountInterval
public void setTapCountInterval(float tapCountInterval) - Parameters:
tapCountInterval
- time in seconds that must pass for two touch down/up sequences to be detected as consecutive taps.
-
setLongPressSeconds
public void setLongPressSeconds(float longPressSeconds) -
setMaxFlingDelay
public void setMaxFlingDelay(long maxFlingDelay)
-