Java Code Examples for com.badlogic.gdx.scenes.scene2d.Actor#isDescendantOf()

The following examples show how to use com.badlogic.gdx.scenes.scene2d.Actor#isDescendantOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Dialog.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
/** {@link #pack() Packs} the dialog and adds it to the stage, centered. */
public Dialog show (Stage stage) {
	clearActions();
	removeCaptureListener(ignoreTouchDown);

	previousKeyboardFocus = null;
	Actor actor = stage.getKeyboardFocus();
	if (actor != null && !actor.isDescendantOf(this)) previousKeyboardFocus = actor;

	previousScrollFocus = null;
	actor = stage.getScrollFocus();
	if (actor != null && !actor.isDescendantOf(this)) previousScrollFocus = actor;

	// pack();
	setPosition(Math.round((stage.getWidth() - getWidth()) / 2), Math.round((stage.getHeight() - getHeight()) / 2));
	stage.addActor(this);
	stage.setKeyboardFocus(this);
	stage.setScrollFocus(this);
	if (fadeDuration > 0) {
		getColor().a = 0;
		addAction(Actions.fadeIn(fadeDuration, Interpolation.fade));
	}
	return this;
}
 
Example 2
Source File: Dialog.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
/** Hides the dialog. Called automatically when a button is clicked. The default implementation fades out the dialog over
 * {@link #fadeDuration} seconds and then removes it from the stage. */
public void hide () {
	Stage stage = getStage();
	if (stage != null) {
		if (previousKeyboardFocus != null && previousKeyboardFocus.getStage() == null) previousKeyboardFocus = null;
		Actor actor = stage.getKeyboardFocus();
		if (actor == null || actor.isDescendantOf(this)) stage.setKeyboardFocus(previousKeyboardFocus);

		if (previousScrollFocus != null && previousScrollFocus.getStage() == null) previousScrollFocus = null;
		actor = stage.getScrollFocus();
		if (actor == null || actor.isDescendantOf(this)) stage.setScrollFocus(previousScrollFocus);
	}
	if (fadeDuration > 0) {
		addCaptureListener(ignoreTouchDown);
		addAction(sequence(fadeOut(fadeDuration, Interpolation.fade), Actions.removeListener(ignoreTouchDown, true),
			Actions.removeActor()));
	} else
		remove();
}
 
Example 3
Source File: ControllerMenuStage.java    From gdx-controllerutils with Apache License 2.0 6 votes vote down vote up
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    if (isFocusOnTouchdown()) {
        screenToStageCoordinates(controllerTempCoords.set(screenX, screenY));
        Actor target = hit(controllerTempCoords.x, controllerTempCoords.y, true);
        if (target != null) {
            if (isActorFocusable(target))
                setFocusedActor(target);
            else for (Actor actor : getFocusableActors()) {
                if (target.isDescendantOf(actor))
                    setFocusedActor(actor);
            }
        }
    }

    return super.touchDown(screenX, screenY, pointer, button);
}
 
Example 4
Source File: ControllerMenuDialog.java    From gdx-controllerutils with Apache License 2.0 6 votes vote down vote up
@Override
public void hide(Action action) {
    if (getStage() != null && getStage() instanceof ControllerMenuStage) {
        Actor currentFocusedActor = ((ControllerMenuStage) getStage()).getFocusedActor();
        if (previousFocusedActor != null && previousFocusedActor.getStage() == getStage()
                && (currentFocusedActor == null || !currentFocusedActor.hasParent() ||
                currentFocusedActor.isDescendantOf(this)))
            ((ControllerMenuStage) getStage()).setFocusedActor(previousFocusedActor);
        Actor currentEscapeActor = ((ControllerMenuStage) getStage()).getEscapeActor();
        if (previousEscapeActor != null && previousEscapeActor.getStage() == getStage()
                && (currentEscapeActor == null || !currentEscapeActor.hasParent() ||
                currentEscapeActor.isDescendantOf(this)))
            ((ControllerMenuStage) getStage()).setEscapeActor(previousEscapeActor);
    }

    super.hide(action);
}
 
Example 5
Source File: SplitPaneCursorManager.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public void exit (InputEvent event, float x, float y, int pointer, Actor toActor) {
	super.exit(event, x, y, pointer, toActor);
	if (pointer == -1 && (toActor == null || toActor.isDescendantOf(owner) == false)) {
		clearCustomCursor();
	}
}
 
Example 6
Source File: ControllerMenuStage.java    From gdx-controllerutils with Apache License 2.0 4 votes vote down vote up
protected boolean isActorHittable(Actor actor) {
    Vector2 center = actor.localToStageCoordinates(new Vector2(actor.getWidth() / 2, actor.getHeight() / 2));
    Actor hitActor = hit(center.x, center.y, true);
    return hitActor != null && (hitActor.isDescendantOf(actor));
}
 
Example 7
Source File: EditableSelectBox.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
public void show(Stage stage) {
	if (list.isTouchable())
		return;

	stage.removeCaptureListener(hideListener);
	stage.addCaptureListener(hideListener);
	stage.addActor(this);

	selectBox.localToStageCoordinates(screenPosition.set(0, 0));

	// Show the list above or below the select box, limited to a number
	// of items and the available height in the stage.
	float itemHeight = list.getItemHeight();
	float height = itemHeight
			* (maxListCount <= 0 ? list.getItems().size : Math.min(maxListCount, list.getItems().size));
	Drawable scrollPaneBackground = getStyle().background;
	if (scrollPaneBackground != null)
		height += scrollPaneBackground.getTopHeight() + scrollPaneBackground.getBottomHeight();
	Drawable listBackground = list.getStyle().background;
	if (listBackground != null)
		height += listBackground.getTopHeight() + listBackground.getBottomHeight();

	float heightBelow = screenPosition.y;
	float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight();
	boolean below = true;
	if (height > heightBelow) {
		if (heightAbove > heightBelow) {
			below = false;
			height = Math.min(height, heightAbove);
		} else
			height = heightBelow;
	}

	if (below)
		setY(screenPosition.y - height);
	else
		setY(screenPosition.y + selectBox.getHeight());
	setX(screenPosition.x);
	setSize(Math.max(getPrefWidth(), selectBox.getWidth()), height);

	validate();
	scrollTo(0, list.getHeight() - selectedIndex * itemHeight - itemHeight / 2, 0, 0, true, true);
	updateVisualScroll();

	previousScrollFocus = null;
	Actor actor = stage.getScrollFocus();
	if (actor != null && !actor.isDescendantOf(this))
		previousScrollFocus = actor;
	stage.setScrollFocus(this);

	list.setTouchable(Touchable.enabled);
	clearActions();
	// getColor().a = 0;
	// addAction(fadeIn(0.3f, Interpolation.fade));
}
 
Example 8
Source File: FilteredSelectBox.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
public void show(Stage stage) {
	if (list.isTouchable())
		return;

	stage.removeCaptureListener(hideListener);
	stage.addCaptureListener(hideListener);
	stage.addActor(this);
	stage.addActor(filterField);

	selectBox.localToStageCoordinates(screenPosition.set(0, 0));

	// Show the list above or below the select box, limited to a number of items and
	// the available height in the stage.
	float itemHeight = list.getItemHeight();
	float height = itemHeight
			* (maxListCount <= 0 ? selectBox.items.size : Math.min(maxListCount, selectBox.items.size));
	Drawable scrollPaneBackground = getStyle().background;
	if (scrollPaneBackground != null)
		height += scrollPaneBackground.getTopHeight() + scrollPaneBackground.getBottomHeight();
	Drawable listBackground = list.getStyle().background;
	if (listBackground != null)
		height += listBackground.getTopHeight() + listBackground.getBottomHeight();

	float heightBelow = screenPosition.y - itemHeight;
	float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight();
	boolean below = true;
	if (height > heightBelow) {
		if (heightAbove > heightBelow) {
			below = false;
			height = Math.min(height, heightAbove);
		} else
			height = heightBelow;
	}

	if (below)
		setY(screenPosition.y - height);
	else
		setY(screenPosition.y + selectBox.getHeight());
	setX(screenPosition.x);
	setHeight(height);
	validate();
	float width = Math.max(getPrefWidth(), selectBox.getWidth());
	if (getPrefHeight() > height && !isScrollingDisabledY())
		width += getScrollBarWidth();
	setWidth(width);

	filterField.setX(getX());
	filterField.setWidth(getWidth());
	filterField.setHeight(filterField.getPrefHeight());
	filterField.setY(getY() + getHeight() - filterField.getHeight());
	stage.setKeyboardFocus(filterField);
	filterField.validate();
	setY(getY() - filterField.getHeight());

	validate();
	scrollTo(0, list.getHeight() - selectBox.getSelectedIndex() * itemHeight - itemHeight / 2, 0, 0, true,
			true);
	updateVisualScroll();

	previousScrollFocus = null;
	Actor actor = stage.getScrollFocus();
	if (actor != null && !actor.isDescendantOf(this))
		previousScrollFocus = actor;
	stage.setScrollFocus(this);

	list.getSelection().set(selectBox.getSelected());
	list.setTouchable(Touchable.enabled);
	clearActions();
	selectBox.onShow(this, below);

	filterField.setText("");
	setListItems(items.toArray());
}