Class ClickListener

java.lang.Object
arc.scene.event.InputListener
arc.scene.event.ClickListener
All Implemented Interfaces:
EventListener
Direct Known Subclasses:
HandCursorListener, IbeamCursorListener, TextField.TextFieldClickListener

public class ClickListener extends InputListener
Detects mouse over, mouse or finger touch presses, and clicks on an element. A touch must go down over the element and is considered pressed as long as it is over the element or within the tap square. This behavior makes it easier to press buttons on a touch interface when the initial touch happens near the edge of the element. Double clicks can be detected using getTapCount(). Any touch (not just the first) will trigger this listener. While pressed, other touch downs are ignored.
  • Field Details

    • visualPressedDuration

      public static float visualPressedDuration
      Time in seconds isVisualPressed() reports true after a press resulting in a click is released.
    • clicked

      public static Runnable clicked
    • tapSquareSize

      protected float tapSquareSize
    • touchDownX

      protected float touchDownX
    • touchDownY

      protected float touchDownY
    • pressedPointer

      protected int pressedPointer
    • pressedButton

      protected KeyCode pressedButton
    • button

      protected KeyCode button
    • pressed

      protected boolean pressed
    • over

      protected boolean over
    • overAny

      protected boolean overAny
    • cancelled

      protected boolean cancelled
    • visualPressedTime

      protected long visualPressedTime
    • tapCountInterval

      protected long tapCountInterval
    • tapCount

      protected int tapCount
    • lastTapTime

      protected long lastTapTime
    • stop

      protected boolean stop
  • Constructor Details

  • Method Details

    • touchDown

      public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button)
      Description copied from class: InputListener
      Called when a mouse button or a finger touch goes down on the element. If true is returned, this listener will receive all touchDragged and touchUp events, even those not over this element, until touchUp is received. Also when true is returned, the event is handled.
      Overrides:
      touchDown in class InputListener
      See Also:
    • touchDragged

      public void touchDragged(InputEvent event, float x, float y, int pointer)
      Description copied from class: InputListener
      Called when a mouse button or a finger touch is moved anywhere, but only if touchDown previously returned true for the mouse button or touch. The touchDragged event is always handled.
      Overrides:
      touchDragged in class InputListener
      See Also:
    • touchUp

      public void touchUp(InputEvent event, float x, float y, int pointer, KeyCode button)
      Description copied from class: InputListener
      Called when a mouse button or a finger touch goes up anywhere, but only if touchDown previously returned true for the mouse button or touch. The touchUp event is always handled.
      Overrides:
      touchUp in class InputListener
      See Also:
    • enter

      public void enter(InputEvent event, float x, float y, int pointer, Element fromActor)
      Description copied from class: InputListener
      Called any time the mouse cursor or a finger touch is moved over an element. On the desktop, this event occurs even when no mouse buttons are pressed (pointer will be -1).
      Overrides:
      enter in class InputListener
      fromActor - May be null.
      See Also:
    • exit

      public void exit(InputEvent event, float x, float y, int pointer, Element toActor)
      Description copied from class: InputListener
      Called any time the mouse cursor or a finger touch is moved out of an element. On the desktop, this event occurs even when no mouse buttons are pressed (pointer will be -1).
      Overrides:
      exit in class InputListener
      toActor - May be null.
      See Also:
    • cancel

      public void cancel()
      If a touch down is being monitored, the drag and touch up events are ignored until the next touch up.
    • clicked

      public void clicked(InputEvent event, float x, float y)
    • isOver

      public boolean isOver(Element element, float x, float y)
      Returns true if the specified position is over the specified element or within the tap square.
    • inTapSquare

      public boolean inTapSquare(float x, float y)
    • inTapSquare

      public boolean inTapSquare()
      Returns true if a touch is within the tap square.
    • invalidateTapSquare

      public void invalidateTapSquare()
      The tap square will not longer be used for the current touch.
    • isPressed

      public boolean isPressed()
      Returns true if a touch is over the element or within the tap square.
    • isVisualPressed

      public boolean isVisualPressed()
      Returns true if a touch is over the element or within the tap square or has been very recently. This allows the UI to show a press and release that was so fast it occurred within a single frame.
    • isOver

      public boolean isOver()
      Returns true if the mouse or touch is over the element or pressed and within the tap square.
    • getTapSquareSize

      public float getTapSquareSize()
    • setTapSquareSize

      public void setTapSquareSize(float halfTapSquareSize)
    • 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.
    • getTapCount

      public int getTapCount()
      Returns the number of taps within the tap count interval for the most recent click event.
    • setTapCount

      public void setTapCount(int tapCount)
    • getTouchDownX

      public float getTouchDownX()
    • getTouchDownY

      public float getTouchDownY()
    • getPressedButton

      public KeyCode getPressedButton()
      The button that initially pressed this button or -1 if the button is not pressed.
    • getPressedPointer

      public int getPressedPointer()
      The pointer that initially pressed this button or -1 if the button is not pressed.
    • getButton

      public KeyCode getButton()
    • setButton

      public void setButton(KeyCode button)
      Sets the button to listen for, all other buttons are ignored. Use null for any button.