Example #1
0
 /**
  * @param actor is being dragged.
  * @param dragPane is under the actor. Stores a {@link GridGroup} or unknown group.
  * @param directPaneChild actor under the cursor.
  * @return true if actor was accepted by the group.
  */
 protected boolean addToOtherGroup(
     final Actor actor, final DragPane dragPane, final Actor directPaneChild) {
   final Array<Actor> children = dragPane.getChildren();
   final int indexOfDirectChild = children.indexOf(directPaneChild, true);
   final int indexOfDraggedActor = children.indexOf(actor, true);
   if (indexOfDraggedActor >= 0) { // Dragging own actor.
     if (indexOfDraggedActor > indexOfDirectChild) { // Dropped after current position.
       dragPane.addActorBefore(directPaneChild, actor);
     } else { // Dropped before current position.
       dragPane.addActorAfter(directPaneChild, actor);
     }
   } else if (indexOfDirectChild == children.size - 1) { // Dragged into last element.
     if (DRAG_POSITION.y < directPaneChild.getHeight() / 2f
         || DRAG_POSITION.x > directPaneChild.getWidth() / 2f) {
       // Adding last:																																	// last:
       dragPane.addActor(actor);
     } else {
       dragPane.addActorBefore(directPaneChild, actor);
     }
   } else if (indexOfDirectChild == 0) { // Dragged into first element.
     if (DRAG_POSITION.y < directPaneChild.getHeight() / 2f
         || DRAG_POSITION.x > directPaneChild.getWidth() / 2f) {
       dragPane.addActorAfter(directPaneChild, actor);
     } else { // Adding first:
       dragPane.addActorBefore(directPaneChild, actor);
     }
   } else { // Replacing hovered actor:
     dragPane.addActorBefore(directPaneChild, actor);
   }
   return APPROVE;
 }
Example #2
0
 /**
  * @param draggable is attached to the actor.
  * @param actor dragged actor.
  * @param dragPane is directly under the dragged actor. If accepts the actor, it should be added
  *     to its content.
  * @return true if actor was accepted.
  */
 protected boolean addDirectlyToPane(
     final Draggable draggable, final Actor actor, final DragPane dragPane) {
   if (accept(actor, dragPane)) {
     if (dragPane.isFloating()) {
       return addToFloatingGroup(draggable, actor, dragPane);
     }
     // Dragged directly to a pane. Assuming no padding, adding last:
     dragPane.addActor(actor);
     return APPROVE;
   }
   return CANCEL;
 }