/** * Shows menu below (or above if not enough space) given actor. * @param stage stage instance that this menu is being added to * @param actor used to get calculate menu position in stage, menu will be displayed above or below it */ public void showMenu (Stage stage, Actor actor) { Vector2 pos = actor.localToStageCoordinates(tmpVector.setZero()); float menuY; if (pos.y - getHeight() <= 0) { menuY = pos.y + actor.getHeight() + getHeight() - sizes.borderSize; } else { menuY = pos.y + sizes.borderSize; } showMenu(stage, pos.x, menuY); }
/** * Shows menu as given stage coordinates * @param stage stage instance that this menu is being added to * @param x stage x position * @param y stage y position */ public void showMenu (Stage stage, float x, float y) { setPosition(x, y - getHeight()); if (stage.getHeight() - getY() > stage.getHeight()) setY(getY() + getHeight()); ActorUtils.keepWithinStage(stage, this); stage.addActor(this); }
@Override public void draw (Batch batch, float parentAlpha) { super.draw(batch, parentAlpha); if (style.border != null) style.border.draw(batch, getX(), getY(), getWidth(), getHeight()); }
public boolean contains (float x, float y) { return getX() < x && getX() + getWidth() > x && getY() < y && getY() + getHeight() > y; }
void showSubMenu () { Stage stage = getStage(); Vector2 pos = localToStageCoordinates(tmpVector.setZero()); float availableSpaceLeft = pos.x; float availableSpaceRight = stage.getWidth() - (pos.x + getWidth()); boolean canFitOnTheRight = pos.x + getWidth() + subMenu.getWidth() <= stage.getWidth(); float subMenuX; if (canFitOnTheRight || availableSpaceRight > availableSpaceLeft) { subMenuX = pos.x + getWidth() - 1; } else { subMenuX = pos.x - subMenu.getWidth() + 1; } subMenu.setPosition(subMenuX, pos.y - subMenu.getHeight() + getHeight()); if (subMenu.getY() < 0) { subMenu.setY(subMenu.getY() + subMenu.getHeight() - getHeight()); } stage.addActor(subMenu); containerMenu.setActiveSubMenu(subMenu); }