com.badlogic.gdx.input
Class GestureDetector

java.lang.Object
  extended by com.badlogic.gdx.InputAdapter
      extended by com.badlogic.gdx.input.GestureDetector
All Implemented Interfaces:
InputProcessor
Direct Known Subclasses:
CameraInputController

public class GestureDetector
extends InputAdapter

InputProcessor implementation that detects gestures (tap, long press, fling, pan, zoom, pinch) and hands them to a GestureDetector.GestureListener.

Author:
mzechner

Nested Class Summary
static class GestureDetector.GestureAdapter
          Derrive from this if you only want to implement a subset of GestureDetector.GestureListener.
static interface GestureDetector.GestureListener
          Register an instance of this class with a GestureDetector to receive gestures such as taps, long presses, flings, panning or pinch zooming.
 
Constructor Summary
GestureDetector(float halfTapSquareSize, float tapCountInterval, float longPressDuration, float maxFlingDelay, GestureDetector.GestureListener listener)
           
GestureDetector(GestureDetector.GestureListener listener)
          Creates a new GestureDetector with default values: halfTapSquareSize=20, tapCountInterval=0.4f, longPressDuration=1.1f, maxFlingDelay=0.15f.
 
Method Summary
 void cancel()
          No further gesture events will be triggered for the current touch, if any.
 void invalidateTapSquare()
          The tap square will not longer be used for the current touch.
 boolean isLongPressed()
           
 boolean isLongPressed(float duration)
           
 boolean isPanning()
           
 void reset()
           
 void setLongPressSeconds(float longPressSeconds)
           
 void setMaxFlingDelay(long maxFlingDelay)
           
 void setTapCountInterval(float tapCountInterval)
           
 void setTapSquareSize(float tapSquareSize)
           
 boolean touchDown(float x, float y, int pointer, int button)
           
 boolean touchDown(int x, int y, int pointer, int button)
          Called when the screen was touched or a mouse button was pressed.
 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 touchUp(float x, float y, int pointer, int button)
           
 boolean touchUp(int x, int y, int pointer, int button)
          Called when a finger was lifted or a mouse button was released.
 
Methods inherited from class com.badlogic.gdx.InputAdapter
keyDown, keyTyped, keyUp, mouseMoved, scrolled
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GestureDetector

public GestureDetector(GestureDetector.GestureListener listener)
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 event, see GestureDetector.GestureListener.tap(float, float, int, int).
tapCountInterval - 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 a GestureDetector.GestureListener.longPress(float, float) event.
maxFlingDelay - time in seconds the finger must have been dragged for a fling event to be fired, see GestureDetector.GestureListener.fling(float, float, int)
listener - May be null if the listener will be set later.
Method Detail

touchDown

public boolean touchDown(int x,
                         int y,
                         int pointer,
                         int button)
Description copied from interface: InputProcessor
Called when the screen was touched or a mouse button was pressed. The button parameter will be Input.Buttons.LEFT on Android and iOS.

Specified by:
touchDown in interface InputProcessor
Overrides:
touchDown in class InputAdapter
Parameters:
x - The x coordinate, origin is in the upper left corner
y - The y coordinate, origin is in the upper left corner
pointer - the pointer for the event.
button - the button
Returns:
whether the input was processed

touchDown

public boolean touchDown(float x,
                         float y,
                         int pointer,
                         int button)

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 interface InputProcessor
Overrides:
touchDragged in class InputAdapter
pointer - the pointer for the event.
Returns:
whether the input was processed

touchDragged

public boolean touchDragged(float x,
                            float y,
                            int pointer)

touchUp

public boolean touchUp(int x,
                       int y,
                       int pointer,
                       int button)
Description copied from interface: InputProcessor
Called when a finger was lifted or a mouse button was released. The button parameter will be Input.Buttons.LEFT on Android and iOS.

Specified by:
touchUp in interface InputProcessor
Overrides:
touchUp in class InputAdapter
pointer - the pointer for the event.
button - the button
Returns:
whether the input was processed

touchUp

public boolean touchUp(float x,
                       float y,
                       int pointer,
                       int button)

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)
Parameters:
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 tapSquareSize)

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)


Copyright © 2014. All Rights Reserved.