@Override public void addLifecycleListener (LifecycleListener listener) { synchronized (lifecycleListeners) { lifecycleListeners.add(listener); } }
/** Returns true if this actor is a target actor for touch focus. * @see Stage#addTouchFocus(EventListener, Actor, Actor, int, int) */ public boolean isTouchFocusTarget () { Stage stage = getStage(); if (stage == null) return false; for (int i = 0, n = stage.touchFocuses.size; i < n; i++) if (stage.touchFocuses.get(i).target == this) return true; return false; }
/** Swaps two actors. Returns false if the swap did not occur because the actors are not children of this group. */ public boolean swapActor (Actor first, Actor second) { int firstIndex = children.indexOf(first, true); int secondIndex = children.indexOf(second, true); if (firstIndex == -1 || secondIndex == -1) return false; children.swap(firstIndex, secondIndex); return true; }
/** Removes touch focus for the specified listener, pointer, and button. Note the listener will not receive a touchUp event * when this method is used. */ public void removeTouchFocus (EventListener listener, Actor listenerActor, Actor target, int pointer, int button) { SnapshotArray<TouchFocus> touchFocuses = this.touchFocuses; for (int i = touchFocuses.size - 1; i >= 0; i--) { TouchFocus focus = touchFocuses.get(i); if (focus.listener == listener && focus.listenerActor == listenerActor && focus.target == target && focus.pointer == pointer && focus.button == button) { touchFocuses.removeIndex(i); Pools.free(focus); } } }
/** Cancels touch focus for all listeners with the specified listener actor. * @see #cancelTouchFocus() */ public void cancelTouchFocus (Actor listenerActor) { InputEvent event = Pools.obtain(InputEvent.class); event.setStage(this); event.setType(InputEvent.Type.touchUp); event.setStageX(Integer.MIN_VALUE); event.setStageY(Integer.MIN_VALUE); // Cancel all current touch focuses for the specified listener, allowing for concurrent modification, and never cancel the // same focus twice. SnapshotArray<TouchFocus> touchFocuses = this.touchFocuses; TouchFocus[] items = touchFocuses.begin(); for (int i = 0, n = touchFocuses.size; i < n; i++) { TouchFocus focus = items[i]; if (focus.listenerActor != listenerActor) continue; if (!touchFocuses.removeValue(focus, true)) continue; // Touch focus already gone. event.setTarget(focus.target); event.setListenerActor(focus.listenerActor); event.setPointer(focus.pointer); event.setButton(focus.button); focus.listener.handle(event); // Cannot return TouchFocus to pool, as it may still be in use (eg if cancelTouchFocus is called from touchDragged). } touchFocuses.end(); Pools.free(event); }
/** Applies a touch moved event to the stage and returns true if an actor in the scene {@link Event#handle() handled} the * event. Only {@link InputListener listeners} that returned true for touchDown will receive this event. */ public boolean touchDragged (int screenX, int screenY, int pointer) { pointerScreenX[pointer] = screenX; pointerScreenY[pointer] = screenY; mouseScreenX = screenX; mouseScreenY = screenY; if (touchFocuses.size == 0) return false; screenToStageCoordinates(tempCoords.set(screenX, screenY)); InputEvent event = Pools.obtain(InputEvent.class); event.setType(Type.touchDragged); event.setStage(this); event.setStageX(tempCoords.x); event.setStageY(tempCoords.y); event.setPointer(pointer); SnapshotArray<TouchFocus> touchFocuses = this.touchFocuses; TouchFocus[] focuses = touchFocuses.begin(); for (int i = 0, n = touchFocuses.size; i < n; i++) { TouchFocus focus = focuses[i]; if (focus.pointer != pointer) continue; if (!touchFocuses.contains(focus, true)) continue; // Touch focus already gone. event.setTarget(focus.target); event.setListenerActor(focus.listenerActor); if (focus.listener.handle(event)) event.handle(); } touchFocuses.end(); boolean handled = event.isHandled(); Pools.free(event); return handled; }
/** Adds an actor as a child of this group immediately after another child actor, removing it from its previous parent. If the * actor is already a child of this group, no changes are made. */ public void addActorAfter (Actor actorAfter, Actor actor) { if (actor.parent != null) { if (actor.parent == this) return; actor.parent.removeActor(actor, false); } int index = children.indexOf(actorAfter, true); if (index == children.size) children.add(actor); else children.insert(index + 1, actor); actor.setParent(this); actor.setStage(getStage()); childrenChanged(); }
@Override public void removeLifecycleListener (LifecycleListener listener) { synchronized (lifecycleListeners) { lifecycleListeners.removeValue(listener, true); } }
private void selectNextItem () { SnapshotArray<Actor> children = getChildren(); if (!hasSelectableMenuItems()) return; int startIndex = activeItem == null ? 0 : children.indexOf(activeItem, true) + 1; for (int i = startIndex; ; i++) { if (i >= children.size) i = 0; Actor actor = children.get(i); if (actor instanceof MenuItem && ((MenuItem) actor).isDisabled() == false) { setActiveItem((MenuItem) actor, true); break; } } }
private void focusChanged (FocusEvent event) { Stage stage = getStage(); if (isModal && stage != null && stage.getRoot().getChildren().size > 0 && stage.getRoot().getChildren().peek() == Dialog.this) { // Dialog is top most actor. Actor newFocusedActor = event.getRelatedActor(); if (newFocusedActor != null && !newFocusedActor.isDescendantOf(Dialog.this) && !(newFocusedActor.equals(previousKeyboardFocus) || newFocusedActor.equals(previousScrollFocus))) event.cancel(); } } };
/** Adds an actor as a child of this group immediately before another child actor, removing it from its previous parent. If the * actor is already a child of this group, no changes are made. */ public void addActorBefore (Actor actorBefore, Actor actor) { if (actor.parent != null) { if (actor.parent == this) return; actor.parent.removeActor(actor, false); } int index = children.indexOf(actorBefore, true); children.insert(index, actor); actor.setParent(this); actor.setStage(getStage()); childrenChanged(); }
/** Adds an actor as a child of this group at a specific index, removing it from its previous parent. If the actor is already a * child of this group, no changes are made. * @param index May be greater than the number of children. */ public void addActorAt (int index, Actor actor) { if (actor.parent != null) { if (actor.parent == this) return; actor.parent.removeActor(actor, false); } if (index >= children.size) children.add(actor); else children.insert(index, actor); actor.setParent(this); actor.setStage(getStage()); childrenChanged(); }
/** Returns the z-index of this actor. * @see #setZIndex(int) */ public int getZIndex () { Group parent = this.parent; if (parent == null) return -1; return parent.children.indexOf(this, true); }
/** * Removes an actor from this group. If the actor will not be used again and has actions, they should be * {@link Actor#clearActions() cleared} so the actions will be returned to their * {@link Action#setPool(com.badlogic.gdx.utils.Pool) pool}, if any. This is not done automatically. * <p> * Note that the direct parent of {@link DragPane}'s children is the internal pane's group accessible through * {@link #getGroup()} - and since this removal method is overridden and extended, pane's children should be deleted with * {@code dragPane.removeActor(child, true)} rather than {@link Actor#remove()} method. * @param unfocus if true, {@link Stage#unfocus(Actor)} is called. * @param actor will be removed, if present in the internal {@link WidgetGroup}. * @return true if the actor was removed from this group. */ @Override public boolean removeActor (final Actor actor, final boolean unfocus) { if (getActor().getChildren().contains(actor, true)) { // Stage input focus causes problems, as touchUp is called in Draggable. Reproducing input unfocus after stage removed. Stage stage = actor.getStage(); getActor().removeActor(actor, false); // Stage is cleared. if (unfocus && stage != null) { stage.unfocus(actor); } return true; } return false; }
/** Cancels touch focus for all listeners except the specified listener. * @see #cancelTouchFocus() */ public void cancelTouchFocusExcept (EventListener exceptListener, Actor exceptActor) { InputEvent event = Pools.obtain(InputEvent.class); event.setStage(this); event.setType(InputEvent.Type.touchUp); event.setStageX(Integer.MIN_VALUE); event.setStageY(Integer.MIN_VALUE); // Cancel all current touch focuses except for the specified listener, allowing for concurrent modification, and never // cancel the same focus twice. SnapshotArray<TouchFocus> touchFocuses = this.touchFocuses; TouchFocus[] items = touchFocuses.begin(); for (int i = 0, n = touchFocuses.size; i < n; i++) { TouchFocus focus = items[i]; if (focus.listener == exceptListener && focus.listenerActor == exceptActor) continue; if (!touchFocuses.removeValue(focus, true)) continue; // Touch focus already gone. event.setTarget(focus.target); event.setListenerActor(focus.listenerActor); event.setPointer(focus.pointer); event.setButton(focus.button); focus.listener.handle(event); // Cannot return TouchFocus to pool, as it may still be in use (eg if cancelTouchFocus is called from touchDragged). } touchFocuses.end(); Pools.free(event); }
/** Applies a touch moved event to the stage and returns true if an actor in the scene {@link Event#handle() handled} the * event. Only {@link InputListener listeners} that returned true for touchDown will receive this event. */ public boolean touchDragged (int screenX, int screenY, int pointer) { pointerScreenX[pointer] = screenX; pointerScreenY[pointer] = screenY; mouseScreenX = screenX; mouseScreenY = screenY; if (touchFocuses.size == 0) return false; screenToStageCoordinates(tempCoords.set(screenX, screenY)); InputEvent event = Pools.obtain(InputEvent.class); event.setType(Type.touchDragged); event.setStage(this); event.setStageX(tempCoords.x); event.setStageY(tempCoords.y); event.setPointer(pointer); SnapshotArray<TouchFocus> touchFocuses = this.touchFocuses; TouchFocus[] focuses = touchFocuses.begin(); for (int i = 0, n = touchFocuses.size; i < n; i++) { TouchFocus focus = focuses[i]; if (focus.pointer != pointer) continue; if (!touchFocuses.contains(focus, true)) continue; // Touch focus already gone. event.setTarget(focus.target); event.setListenerActor(focus.listenerActor); if (focus.listener.handle(event)) event.handle(); } touchFocuses.end(); boolean handled = event.isHandled(); Pools.free(event); return handled; }
/** Adds an actor as a child of this group immediately after another child actor, removing it from its previous parent. If the * actor is already a child of this group, no changes are made. */ public void addActorAfter (Actor actorAfter, Actor actor) { if (actor.parent != null) { if (actor.parent == this) return; actor.parent.removeActor(actor, false); } int index = children.indexOf(actorAfter, true); if (index == children.size) children.add(actor); else children.insert(index + 1, actor); actor.setParent(this); actor.setStage(getStage()); childrenChanged(); }