Package arc.input

Class GestureDetector

java.lang.Object
arc.input.GestureDetector
All Implemented Interfaces:
InputProcessor

public class GestureDetector extends Object implements InputProcessor
InputProcessor implementation that detects gestures (tap, long press, fling, pan, zoom, pinch) and hands them to a GestureDetector.GestureListener.
  • Constructor Details

    • 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
      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
      listener - 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 event
      halfTapRectangleHeight - half height in pixels of the rectangle around an initial touch event
      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
      listener - May be null if the listener will be set later.
  • Method Details

    • getListener

      public GestureDetector.GestureListener getListener()
    • touchDown

      public boolean touchDown(int x, int y, int pointer, KeyCode button)
      Specified by:
      touchDown in interface InputProcessor
      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, KeyCode 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
      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, KeyCode button)
      Specified by:
      touchUp in interface InputProcessor
      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, KeyCode 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)
      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)