Class ClickListener
- java.lang.Object
-
- com.badlogic.gdx.scenes.scene2d.InputListener
-
- com.badlogic.gdx.scenes.scene2d.utils.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 thetap 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 usinggetTapCount(). Any touch (not just the first) will trigger this listener. While pressed, other touch downs are ignored.
-
-
Field Summary
Fields Modifier and Type Field Description static floatvisualPressedDurationTime in secondsisVisualPressed()reports true after a press resulting in a click is released.
-
Constructor Summary
Constructors Constructor Description ClickListener()Create a listener whereclicked(InputEvent, float, float)is only called for left clicks.ClickListener(int button)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()If a touch down is being monitored, the drag and touch up events are ignored until the next touch up.voidclicked(InputEvent event, float x, float y)voidenter(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.voidexit(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.intgetButton()intgetPressedButton()The button that initially pressed this button or -1 if the button is not pressed.intgetPressedPointer()The pointer that initially pressed this button or -1 if the button is not pressed.intgetTapCount()Returns the number of taps within the tap count interval for the most recent click event.floatgetTapSquareSize()floatgetTouchDownX()floatgetTouchDownY()booleaninTapSquare()Returns true if a touch is within the tap square.booleaninTapSquare(float x, float y)voidinvalidateTapSquare()The tap square will no longer be used for the current touch.booleanisOver()Returns true if the mouse or touch is over the actor or pressed and within the tap square.booleanisOver(Actor actor, float x, float y)Returns true if the specified position is over the specified actor or within the tap square.booleanisPressed()Returns true if a touch is over the actor or within the tap square.booleanisVisualPressed()Returns true if a touch is over the actor or within the tap square or has been very recently.voidsetButton(int button)Sets the button to listen for, all other buttons are ignored.voidsetTapCount(int tapCount)voidsetTapCountInterval(float tapCountInterval)voidsetTapSquareSize(float halfTapSquareSize)voidsetVisualPressed(boolean visualPressed)If true, sets the visual pressed time to now.booleantouchDown(InputEvent event, float x, float y, int pointer, int button)Called when a mouse button or a finger touch goes down on the actor.voidtouchDragged(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.voidtouchUp(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 com.badlogic.gdx.scenes.scene2d.InputListener
handle, keyDown, keyTyped, keyUp, mouseMoved, scrolled
-
-
-
-
Field Detail
-
visualPressedDuration
public static float visualPressedDuration
Time in secondsisVisualPressed()reports true after a press resulting in a click is released.
-
-
Constructor Detail
-
ClickListener
public ClickListener()
Create a listener whereclicked(InputEvent, float, float)is only called for left clicks.- See Also:
ClickListener(int)
-
ClickListener
public ClickListener(int button)
- See Also:
setButton(int)
-
-
Method Detail
-
touchDown
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
Description copied from class:InputListenerCalled when a mouse button or a finger touch goes down on the actor. If true is returned, this listener will havetouch 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 ishandled.- Overrides:
touchDownin classInputListener- See Also:
InputEvent
-
touchDragged
public void touchDragged(InputEvent event, float x, float y, int pointer)
Description copied from class:InputListenerCalled 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 alwayshandled.- Overrides:
touchDraggedin classInputListener- See Also:
InputEvent
-
touchUp
public void touchUp(InputEvent event, float x, float y, int pointer, int button)
Description copied from class:InputListenerCalled 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 alwayshandled.- Overrides:
touchUpin classInputListener- See Also:
InputEvent
-
enter
public void enter(InputEvent event, float x, float y, int pointer, @Null Actor fromActor)
Description copied from class:InputListenerCalled 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:
enterin classInputListenerfromActor- 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:InputListenerCalled 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:
exitin classInputListenertoActor- 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.
-
getButton
public int getButton()
- See Also:
setButton(int)
-
setButton
public void setButton(int button)
Sets the button to listen for, all other buttons are ignored. Default isInput.Buttons.LEFT. Use -1 for any button.
-
-