APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.scenes.scene2d.utils

public Class DragAndDrop

extends Object
Class Inheritance
Imports
com.badlogic.gdx.Input.Buttons, com.badlogic.gdx.math.Vector2, com.badlogic.gdx.scenes.scene2d.Actor, .InputEvent, .Stage, com.badlogic.gdx.scenes.scene2d.ui.ScrollPane, com.badlogic.gdx.utils.Array, .Null, .ObjectMap, .ObjectMap.Entry

Manages drag and drop operations through registered drag sources and drop targets.
Author
Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
DragAndDrop.Payload

The payload of a drag and drop operation.

public abstract static class
DragAndDrop.Source

A source where a payload can be dragged from.

public abstract static class
DragAndDrop.Target

A target where a payload can be dropped to.

Field Summary

Modifier and TypeField and Description
pack-priv int
private int
pack-priv boolean
pack-priv Actor
pack-priv float
pack-priv float
pack-priv DragAndDrop.Source
pack-priv int
pack-priv long
pack-priv boolean
pack-priv boolean
pack-priv DragAndDrop.Payload
pack-priv boolean
pack-priv final ObjectMap<DragAndDrop.Source, DragListener>
private float
pack-priv DragAndDrop.Target
pack-priv final Array<DragAndDrop.Target>
pack-priv static final Vector2
pack-priv float
pack-priv float

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
cancelTouchFocusExcept(DragAndDrop.Source except)

Cancels the touch focus for everything except the specified source.

public void
clear()

Removes all targets and sources.

public Actor
getDragActor()

Returns the current drag actor, or null.

public DragAndDrop.Payload
getDragPayload()

Returns the current drag payload, or null.

public DragAndDrop.Source
getDragSource()

Returns the current drag source, or null.

public int
public boolean
public boolean
isDragValid()

Returns true if a drag is in progress and the drag time has elapsed since the drag started.

public void
public void
public void
setButton(int button)

Sets the button to listen for, all other buttons are ignored.

public void
setCancelTouchFocus(boolean cancelTouchFocus)

When true (default), the Stage#cancelTouchFocus() touch focus} is cancelled if dragStart returns non-null.

public void
setDragActorPosition(float dragActorX, float dragActorY)

public void
setDragTime(int dragMillis)

Time in milliseconds that a drag must take before a drop will be considered valid.

public void
setKeepWithinStage(boolean keepWithinStage)

public void
setTapSquareSize(float halfTapSquareSize)

Sets the distance a touch must travel before being considered a drag.

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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activePointerback to summary
pack-priv int activePointer
buttonback to summary
private int button
cancelTouchFocusback to summary
pack-priv boolean cancelTouchFocus
dragActorback to summary
pack-priv Actor dragActor
dragActorXback to summary
pack-priv float dragActorX
dragActorYback to summary
pack-priv float dragActorY
dragSourceback to summary
pack-priv DragAndDrop.Source dragSource
dragTimeback to summary
pack-priv int dragTime
dragValidTimeback to summary
pack-priv long dragValidTime
isValidTargetback to summary
pack-priv boolean isValidTarget
keepWithinStageback to summary
pack-priv boolean keepWithinStage
payloadback to summary
pack-priv DragAndDrop.Payload payload
removeDragActorback to summary
pack-priv boolean removeDragActor
sourceListenersback to summary
pack-priv final ObjectMap<DragAndDrop.Source, DragListener> sourceListeners
tapSquareSizeback to summary
private float tapSquareSize
targetback to summary
pack-priv DragAndDrop.Target target
targetsback to summary
pack-priv final Array<DragAndDrop.Target> targets
tmpVectorback to summary
pack-priv static final Vector2 tmpVector
touchOffsetXback to summary
pack-priv float touchOffsetX
touchOffsetYback to summary
pack-priv float touchOffsetY

Constructor Detail

DragAndDropback to summary
public DragAndDrop()

Method Detail

addSourceback to summary
public void addSource(final DragAndDrop.Source source)
addTargetback to summary
public void addTarget(DragAndDrop.Target target)
cancelTouchFocusExceptback to summary
public void cancelTouchFocusExcept(DragAndDrop.Source except)

Cancels the touch focus for everything except the specified source.

clearback to summary
public void clear()

Removes all targets and sources.

getDragActorback to summary
public Actor getDragActor()

Returns the current drag actor, or null.

Annotations
@Null
getDragPayloadback to summary
public DragAndDrop.Payload getDragPayload()

Returns the current drag payload, or null.

Annotations
@Null
getDragSourceback to summary
public DragAndDrop.Source getDragSource()

Returns the current drag source, or null.

Annotations
@Null
getDragTimeback to summary
public int getDragTime()
isDraggingback to summary
public boolean isDragging()
isDragValidback to summary
public boolean isDragValid()

Returns true if a drag is in progress and the drag time has elapsed since the drag started.

removeSourceback to summary
public void removeSource(DragAndDrop.Source source)
removeTargetback to summary
public void removeTarget(DragAndDrop.Target target)
setButtonback to summary
public void setButton(int button)

Sets the button to listen for, all other buttons are ignored. Default is Buttons#LEFT. Use -1 for any button.

setCancelTouchFocusback to summary
public void setCancelTouchFocus(boolean cancelTouchFocus)

When true (default), the Stage#cancelTouchFocus() touch focus} is cancelled if dragStart returns non-null. This ensures the DragAndDrop is the only touch focus listener, eg when the source is inside a ScrollPane with flick scroll enabled.

setDragActorPositionback to summary
public void setDragActorPosition(float dragActorX, float dragActorY)
setDragTimeback to summary
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.

setKeepWithinStageback to summary
public void setKeepWithinStage(boolean keepWithinStage)
setTapSquareSizeback to summary
public void setTapSquareSize(float halfTapSquareSize)

Sets the distance a touch must travel before being considered a drag.

setTouchOffsetback to summary
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.

com.badlogic.gdx.scenes.scene2d.utils back to summary

public Class DragAndDrop.Payload

extends Object
Class Inheritance

The payload of a drag and drop operation. Actors can be optionally provided to follow the cursor and change when over a target. Such actors will be added the stage automatically during the drag operation as necessary and they will only be removed from the stage if they were added automatically. A source actor can be used as a payload drag actor.

Field Summary

Modifier and TypeField and Description
pack-priv Actor
pack-priv Actor
pack-priv Object
pack-priv Actor

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Actor
public Actor
public Object
public Actor
public void
setDragActor(Actor dragActor)

public void
setInvalidDragActor(Actor invalidDragActor)

public void
setObject(Object object)

public void
setValidDragActor(Actor validDragActor)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dragActorback to summary
pack-priv Actor dragActor
Annotations
@Null
invalidDragActorback to summary
pack-priv Actor invalidDragActor
Annotations
@Null
objectback to summary
pack-priv Object object
Annotations
@Null
validDragActorback to summary
pack-priv Actor validDragActor
Annotations
@Null

Constructor Detail

Payloadback to summary
public Payload()

Method Detail

getDragActorback to summary
public Actor getDragActor()
Annotations
@Null
getInvalidDragActorback to summary
public Actor getInvalidDragActor()
Annotations
@Null
getObjectback to summary
public Object getObject()
Annotations
@Null
getValidDragActorback to summary
public Actor getValidDragActor()
Annotations
@Null
setDragActorback to summary
public void setDragActor(Actor dragActor)
setInvalidDragActorback to summary
public void setInvalidDragActor(Actor invalidDragActor)
setObjectback to summary
public void setObject(Object object)
setValidDragActorback to summary
public void setValidDragActor(Actor validDragActor)
com.badlogic.gdx.scenes.scene2d.utils back to summary

public abstract Class DragAndDrop.Source

extends Object
Class Inheritance

A source where a payload can be dragged from.
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
pack-priv final Actor

Constructor Summary

AccessConstructor and Description
public
Source(Actor actor)

Method Summary

Modifier and TypeMethod and Description
public void
drag(InputEvent event, float x, float y, int pointer)

Called repeatedly during a drag which started on this source.

public abstract DragAndDrop.Payload

Returns:

If null the drag will not affect any targets.
dragStart
(InputEvent event, float x, float y, int pointer)

Called when a drag is started on the source.

public void
dragStop(InputEvent event, float x, float y, int pointer, DragAndDrop.Payload
null if dragStart returned null.
payload
,
DragAndDrop.Target
null if not dropped on a valid target.
target
)

Called when a drag for the source is stopped.

public Actor
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actorback to summary
pack-priv final Actor actor

Constructor Detail

Sourceback to summary
public Source(Actor actor)

Method Detail

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

Called repeatedly during a drag which started on this source.

dragStartback to summary
public abstract DragAndDrop.Payload dragStart(InputEvent event, float x, float y, int pointer)

Called when a drag is started on the source. The coordinates are in the source's local coordinate system.

Returns:DragAndDrop.Payload

If null the drag will not affect any targets.

Annotations
@Null
dragStopback to summary
public void dragStop(InputEvent event, float x, float y, int pointer, DragAndDrop.Payload payload, DragAndDrop.Target target)

Called when a drag for the source is stopped. The coordinates are in the source's local coordinate system.

Parameters
payload:DragAndDrop.Payload

null if dragStart returned null.

target:DragAndDrop.Target

null if not dropped on a valid target.

getActorback to summary
public Actor getActor()
com.badlogic.gdx.scenes.scene2d.utils back to summary

public abstract Class DragAndDrop.Target

extends Object
Class Inheritance

A target where a payload can be dropped to.
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
pack-priv final Actor

Constructor Summary

AccessConstructor and Description
public
Target(Actor actor)

Method Summary

Modifier and TypeMethod and Description
public abstract boolean

Returns:

true if this is a valid target for the payload.
drag
(DragAndDrop.Source source, DragAndDrop.Payload payload, float x, float y, int pointer)

Called when the payload is dragged over the target.

public abstract void
drop(DragAndDrop.Source source, DragAndDrop.Payload payload, float x, float y, int pointer)

Called when the payload is dropped on the target.

public Actor
public void
reset(DragAndDrop.Source source, DragAndDrop.Payload payload)

Called when the payload is no longer over the target, whether because the touch was moved or a drop occurred.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actorback to summary
pack-priv final Actor actor

Constructor Detail

Targetback to summary
public Target(Actor actor)

Method Detail

dragback to summary
public abstract boolean drag(DragAndDrop.Source source, DragAndDrop.Payload payload, float x, float y, int pointer)

Called when the payload is dragged over the target. The coordinates are in the target's local coordinate system.

Returns:boolean

true if this is a valid target for the payload.

dropback to summary
public abstract void drop(DragAndDrop.Source source, DragAndDrop.Payload payload, float x, float y, int pointer)

Called when the payload is dropped on the target. The coordinates are in the target's local coordinate system. This is not called if drag(Source, Payload, float, float, int) returned false.

getActorback to summary
public Actor getActor()
resetback to summary
public void reset(DragAndDrop.Source source, DragAndDrop.Payload payload)

Called when the payload is no longer over the target, whether because the touch was moved or a drop occurred. This is called even if drag(Source, Payload, float, float, int) returned false.