libgdx API

com.badlogic.gdx.scenes.scene2d.utils
Class ClickListener

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.InputListener
      extended by com.badlogic.gdx.scenes.scene2d.utils.ClickListener
All Implemented Interfaces:
EventListener

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.

Author:
Nathan Sweet

Constructor Summary
ClickListener()
           
ClickListener(int button)
           
 
Method Summary
 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 drag(InputEvent event, float x, float y, int pointer)
           
 void dragStart(InputEvent event, float x, float y, int pointer)
           
 void dragStop(InputEvent event, float x, float y, int pointer)
           
 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 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(float x, float y)
           
 void invalidateTapSquare()
          The tap square will not 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.
 void setButton(int button)
          Sets the button to listen for, all other buttons are ignored.
 void setTapCountInterval(float tapCountInterval)
           
 void setTapSquareSize(float halfTapSquareSize)
           
 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 com.badlogic.gdx.scenes.scene2d.InputListener
handle, keyDown, keyTyped, keyUp, mouseMoved, scrolled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClickListener

public ClickListener()

ClickListener

public ClickListener(int button)
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 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,
                  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
See Also:
InputEvent

exit

public void exit(InputEvent event,
                 float x,
                 float y,
                 int pointer,
                 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
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)

dragStart

public void dragStart(InputEvent event,
                      float x,
                      float y,
                      int pointer)

drag

public void drag(InputEvent event,
                 float x,
                 float y,
                 int pointer)

dragStop

public void dragStop(InputEvent event,
                     float x,
                     float y,
                     int pointer)

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)

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 actor or within the tap square.


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.


getTouchDownX

public float getTouchDownX()

getTouchDownY

public float getTouchDownY()

getButton

public int getButton()

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.


libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)