Class DragAndDrop
- java.lang.Object
-
- com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop
-
public class DragAndDrop extends java.lang.Object
Manages drag and drop operations through registered drag sources and drop targets.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DragAndDrop.Payload
The payload of a drag and drop operation.static class
DragAndDrop.Source
A source where a payload can be dragged from.static class
DragAndDrop.Target
A target where a payload can be dropped to.
-
Constructor Summary
Constructors Constructor Description DragAndDrop()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSource(DragAndDrop.Source source)
void
addTarget(DragAndDrop.Target target)
void
cancelTouchFocusExcept(DragAndDrop.Source except)
Cancels the touch focus for everything except the specified source.void
clear()
Removes all targets and sources.Actor
getDragActor()
Returns the current drag actor, or null.DragAndDrop.Payload
getDragPayload()
Returns the current drag payload, or null.DragAndDrop.Source
getDragSource()
Returns the current drag source, or null.int
getDragTime()
boolean
isDragging()
boolean
isDragValid()
Returns true if a drag is in progress and thedrag time
has elapsed since the drag started.void
removeSource(DragAndDrop.Source source)
void
removeTarget(DragAndDrop.Target target)
void
setButton(int button)
Sets the button to listen for, all other buttons are ignored.void
setCancelTouchFocus(boolean cancelTouchFocus)
When true (default), theStage.cancelTouchFocus()
touch focus} is cancelled ifdragStart
returns non-null.void
setDragActorPosition(float dragActorX, float dragActorY)
void
setDragTime(int dragMillis)
Time in milliseconds that a drag must take before a drop will be considered valid.void
setKeepWithinStage(boolean keepWithinStage)
void
setTapSquareSize(float halfTapSquareSize)
Sets the distance a touch must travel before being considered a drag.void
setTouchOffset(float touchOffsetX, float touchOffsetY)
Sets an offset in stage coordinates from the touch position which is used to determine the drop location.
-
-
-
Method Detail
-
addSource
public void addSource(DragAndDrop.Source source)
-
removeSource
public void removeSource(DragAndDrop.Source source)
-
addTarget
public void addTarget(DragAndDrop.Target target)
-
removeTarget
public void removeTarget(DragAndDrop.Target target)
-
clear
public void clear()
Removes all targets and sources.
-
cancelTouchFocusExcept
public void cancelTouchFocusExcept(DragAndDrop.Source except)
Cancels the touch focus for everything except the specified source.
-
setTapSquareSize
public void setTapSquareSize(float halfTapSquareSize)
Sets the distance a touch must travel before being considered a drag.
-
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.
-
setDragActorPosition
public void setDragActorPosition(float dragActorX, float dragActorY)
-
setTouchOffset
public void setTouchOffset(float touchOffsetX, float touchOffsetY)
Sets an offset in stage coordinates from the touch position which is used to determine the drop location. Default is 0,0.
-
isDragging
public boolean isDragging()
-
getDragPayload
@Null public DragAndDrop.Payload getDragPayload()
Returns the current drag payload, or null.
-
getDragSource
@Null public DragAndDrop.Source getDragSource()
Returns the current drag source, or null.
-
setDragTime
public void setDragTime(int dragMillis)
Time in milliseconds that a drag must take before a drop will be considered valid. This ignores an accidental drag and drop that was meant to be a click. Default is 250.
-
getDragTime
public int getDragTime()
-
isDragValid
public boolean isDragValid()
Returns true if a drag is in progress and thedrag time
has elapsed since the drag started.
-
setCancelTouchFocus
public void setCancelTouchFocus(boolean cancelTouchFocus)
When true (default), theStage.cancelTouchFocus()
touch focus} is cancelled ifdragStart
returns non-null. This ensures the DragAndDrop is the only touch focus listener, eg when the source is inside aScrollPane
with flick scroll enabled.
-
setKeepWithinStage
public void setKeepWithinStage(boolean keepWithinStage)
-
-