Package arc.scene.event
Class ClickListener
java.lang.Object
arc.scene.event.InputListener
arc.scene.event.ClickListener
- All Implemented Interfaces:
EventListener
- Direct Known Subclasses:
HandCursorListener
,IbeamCursorListener
,TextField.TextFieldClickListener
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 Summary
Modifier and TypeFieldDescriptionprotected KeyCode
protected boolean
static Runnable
protected long
protected boolean
protected boolean
protected boolean
protected KeyCode
protected int
protected boolean
protected int
protected long
protected float
protected float
protected float
static float
Time in secondsisVisualPressed()
reports true after a press resulting in a click is released.protected long
-
Constructor Summary
ConstructorDescriptionCreate a listener whereclicked(InputEvent, float, float)
is only called for left clicks.ClickListener
(KeyCode button) -
Method Summary
Modifier and TypeMethodDescriptionvoid
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, Element fromActor) Called any time the mouse cursor or a finger touch is moved over an element.void
exit
(InputEvent event, float x, float y, int pointer, Element toActor) Called any time the mouse cursor or a finger touch is moved out of an element.The button that initially pressed this button or -1 if the button is not pressed.int
The pointer that initially pressed this button or -1 if the button is not pressed.int
Returns the number of taps within the tap count interval for the most recent click event.float
float
float
boolean
Returns true if a touch is within the tap square.boolean
inTapSquare
(float x, float y) void
The tap square will not longer be used for the current touch.boolean
isOver()
Returns true if the mouse or touch is over the element or pressed and within the tap square.boolean
Returns true if the specified position is over the specified element or within the tap square.boolean
Returns true if a touch is over the element or within the tap square.boolean
Returns true if a touch is over the element or within the tap square or has been very recently.void
Sets the button to listen for, all other buttons are ignored.void
setTapCount
(int tapCount) void
setTapCountInterval
(float tapCountInterval) void
setTapSquareSize
(float halfTapSquareSize) boolean
touchDown
(InputEvent event, float x, float y, int pointer, KeyCode button) Called when a mouse button or a finger touch goes down on the element.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, KeyCode 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 arc.scene.event.InputListener
handle, keyDown, keyTyped, keyUp, mouseMoved, scrolled
-
Field Details
-
visualPressedDuration
public static float visualPressedDurationTime in secondsisVisualPressed()
reports true after a press resulting in a click is released. -
clicked
-
tapSquareSize
protected float tapSquareSize -
touchDownX
protected float touchDownX -
touchDownY
protected float touchDownY -
pressedPointer
protected int pressedPointer -
pressedButton
-
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
-
ClickListener
public ClickListener()Create a listener whereclicked(InputEvent, float, float)
is only called for left clicks. -
ClickListener
-
-
Method Details
-
touchDown
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 ishandled
.- Overrides:
touchDown
in classInputListener
- See Also:
-
touchDragged
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 alwayshandled
.- Overrides:
touchDragged
in classInputListener
- See Also:
-
touchUp
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 alwayshandled
.- Overrides:
touchUp
in classInputListener
- See Also:
-
enter
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 classInputListener
fromActor
- May be null.- See Also:
-
exit
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 classInputListener
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
-
isOver
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
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
-
setButton
Sets the button to listen for, all other buttons are ignored. Use null for any button.
-