Class ClickListener

  • All Implemented Interfaces:
    EventListener
    Direct Known Subclasses:
    TextField.TextFieldClickListener

    public class ClickListener
    extends InputListener
    Detects mouse over, mouse or finger touch presses, and clicks on an actor. A touch must go down over the actor and is considered pressed as long as it is over the actor 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 actor. Double clicks can be detected using getTapCount(). Any touch (not just the first) will trigger this listener. While pressed, other touch downs are ignored.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()
      If a touch down is being monitored, the drag and touch up events are ignored until the next touch up.
      void clicked​(InputEvent event, float x, float y)  
      void enter​(InputEvent event, float x, float y, int pointer, Actor fromActor)
      Called any time the mouse cursor or a finger touch is moved over an actor.
      void exit​(InputEvent event, float x, float y, int pointer, Actor toActor)
      Called any time the mouse cursor or a finger touch is moved out of an actor.
      int getButton()  
      int getPressedButton()
      The button that initially pressed this button or -1 if the button is not pressed.
      int getPressedPointer()
      The pointer that initially pressed this button or -1 if the button is not pressed.
      int getTapCount()
      Returns the number of taps within the tap count interval for the most recent click event.
      float getTapSquareSize()  
      float getTouchDownX()  
      float getTouchDownY()  
      boolean inTapSquare()
      Returns true if a touch is within the tap square.
      boolean inTapSquare​(float x, float y)  
      void invalidateTapSquare()
      The tap square will no longer be used for the current touch.
      boolean isOver()
      Returns true if the mouse or touch is over the actor or pressed and within the tap square.
      boolean isOver​(Actor actor, float x, float y)
      Returns true if the specified position is over the specified actor or within the tap square.
      boolean isPressed()
      Returns true if a touch is over the actor or within the tap square.
      boolean isVisualPressed()
      Returns true if a touch is over the actor or within the tap square or has been very recently.
      void setButton​(int button)
      Sets the button to listen for, all other buttons are ignored.
      void setTapCount​(int tapCount)  
      void setTapCountInterval​(float tapCountInterval)  
      void setTapSquareSize​(float halfTapSquareSize)  
      void setVisualPressed​(boolean visualPressed)
      If true, sets the visual pressed time to now.
      boolean touchDown​(InputEvent event, float x, float y, int pointer, int button)
      Called when a mouse button or a finger touch goes down on the actor.
      void touchDragged​(InputEvent event, float x, float y, int pointer)
      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.
      void touchUp​(InputEvent event, float x, float y, int pointer, int button)
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • visualPressedDuration

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

      • touchDown

        public boolean touchDown​(InputEvent event,
                                 float x,
                                 float y,
                                 int pointer,
                                 int button)
        Description copied from class: InputListener
        Called when a mouse button or a finger touch goes down on the actor. If true is returned, this listener will have touch focus, so it will receive all touchDragged and touchUp events, even those not over this actor, until touchUp is received. Also when true is returned, the event is handled.
        Overrides:
        touchDown in class InputListener
        See Also:
        InputEvent
      • 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:
        InputEvent
      • touchUp

        public void touchUp​(InputEvent event,
                            float x,
                            float y,
                            int pointer,
                            int 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:
        InputEvent
      • enter

        public void enter​(InputEvent event,
                          float x,
                          float y,
                          int pointer,
                          @Null
                          Actor fromActor)
        Description copied from class: InputListener
        Called any time the mouse cursor or a finger touch is moved over an actor. 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:
        InputEvent
      • exit

        public void exit​(InputEvent event,
                         float x,
                         float y,
                         int pointer,
                         @Null
                         Actor toActor)
        Description copied from class: InputListener
        Called any time the mouse cursor or a finger touch is moved out of an actor. 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:
        InputEvent
      • 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​(Actor actor,
                              float x,
                              float y)
        Returns true if the specified position is over the specified actor 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 no longer be used for the current touch.
      • isPressed

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

        public boolean isVisualPressed()
        Returns true if a touch is over the actor 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.
      • setVisualPressed

        public void setVisualPressed​(boolean visualPressed)
        If true, sets the visual pressed time to now. If false, clears the visual pressed time.
      • isOver

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

        public void setTapSquareSize​(float halfTapSquareSize)
      • getTapSquareSize

        public float getTapSquareSize()
      • 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 int 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.
      • setButton

        public void setButton​(int button)
        Sets the button to listen for, all other buttons are ignored. Default is Input.Buttons.LEFT. Use -1 for any button.