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

The following examples show how to use com.badlogic.gdx.scenes.scene2d.Actor#getHeight() . 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: Scene2dUtils.java    From gdx-vfx with Apache License 2.0 6 votes vote down vote up
public static Vector2 setPositionRelative(Actor srcActor, int srcAlign, Actor dstActor, int dstAlign, float dstX, float dstY, boolean round) {
    Vector2 pos = tmpVec2.set(srcActor.getX(srcAlign), srcActor.getY(srcAlign));

    if ((dstAlign & right) != 0)
        pos.x -= dstActor.getWidth();
    else if ((dstAlign & left) == 0)
        pos.x -= dstActor.getWidth() / 2;

    if ((dstAlign & top) != 0)
        pos.y -= dstActor.getHeight();
    else if ((dstAlign & bottom) == 0)
        pos.y -= dstActor.getHeight() / 2;

    pos.add(dstX, dstY);

    if (round) {
        pos.set(pos.x, pos.y);
    }
    dstActor.setPosition(pos.x, pos.y);
    return pos;
}
 
Example 2
Source File: FilteredTree.java    From talos with Apache License 2.0 5 votes vote down vote up
private void computeSize (Array<Node<T>> nodes, float indent) {
    float ySpacing = this.ySpacing;
    float spacing = iconSpacingLeft + iconSpacingRight;
    for (int i = 0, n = nodes.size; i < n; i++) {
        Node node = nodes.get(i);

        if (node.filtered)
            continue;

        float rowWidth = indent + iconSpacingRight;
        Actor actor = node.actor;
        if (actor instanceof Layout) {
            Layout layout = (Layout)actor;
            rowWidth += layout.getPrefWidth();
            node.height = layout.getPrefHeight();
            layout.pack();
        } else {
            rowWidth += actor.getWidth();
            node.height = actor.getHeight();
        }
        if (node.icon != null) {
            rowWidth += spacing + node.icon.getMinWidth();
            node.height = Math.max(node.height, node.icon.getMinHeight());
        }
        prefWidth = Math.max(prefWidth, rowWidth);
        prefHeight -= node.height + ySpacing;
        if (node.expanded)
            computeSize(node.children, indent + indentSpacing);
    }
}
 
Example 3
Source File: ScrollFocusCaptureInputListener.java    From gdx-texture-packer-gui 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) {
    Actor actor = event.getListenerActor();
    Stage stage = actor.getStage();
    if (stage == null) return;

    // Stage fires "exit" event upon touchUp() even if pointer is still over the actor.
    // This is simple workaround.
    if (x > 0 && y > 0 && x < actor.getWidth() && y < actor.getHeight()) return;

    if (stage.getScrollFocus() == actor) {
        stage.setScrollFocus(null);
    }
}
 
Example 4
Source File: GameScreen.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void setDetails(Actor details, Item item, Actor parent, Actor slot) {
  if (this.details == details) return;
  this.details = details;
  if (slot != null) {
    details.setPosition(slot.getX() + slot.getWidth() / 2, slot.getY() + slot.getHeight(), Align.bottom | Align.center);
    tmpVec2.set(details.getX(), details.getY());
    parent.localToStageCoordinates(tmpVec2);
    tmpVec2.x = MathUtils.clamp(tmpVec2.x, 0, stage.getWidth()  - details.getWidth());
    tmpVec2.y = MathUtils.clamp(tmpVec2.y, 0, stage.getHeight() - details.getHeight());
    details.setPosition(tmpVec2.x, tmpVec2.y);
    tmpVec2.set(slot.getX(), slot.getY());
    parent.localToStageCoordinates(tmpVec2);
    if (details.getY() < tmpVec2.y + slot.getHeight()) {
      details.setPosition(slot.getX() + slot.getWidth() / 2, slot.getY(), Align.top | Align.center);
      tmpVec2.set(details.getX(), details.getY());
      parent.localToStageCoordinates(tmpVec2);
      tmpVec2.x = MathUtils.clamp(tmpVec2.x, 0, stage.getWidth()  - details.getWidth());
      tmpVec2.y = MathUtils.clamp(tmpVec2.y, 0, stage.getHeight() - details.getHeight());
      details.setPosition(tmpVec2.x, tmpVec2.y);
    }
  } else {
    details.setPosition(item.getX() + item.getWidth() / 2, item.getY(), Align.top | Align.center);
    tmpVec2.set(details.getX(), details.getY());
    parent.localToStageCoordinates(tmpVec2);
    tmpVec2.x = MathUtils.clamp(tmpVec2.x, 0, stage.getWidth()  - details.getWidth());
    tmpVec2.y = MathUtils.clamp(tmpVec2.y, 0, stage.getHeight() - details.getHeight());
    details.setPosition(tmpVec2.x, tmpVec2.y);
  }
}
 
Example 5
Source File: MundusMultiSplitPane.java    From Mundus with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefHeight() {
    float height = 0;
    for (Actor actor : getChildren()) {
        height = actor instanceof Layout ? ((Layout) actor).getPrefHeight() : actor.getHeight();

    }
    if (vertical) height += handleBounds.size * style.handle.getMinHeight();
    return height;
}
 
Example 6
Source File: MultiSplitPane.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefHeight () {
	float height = 0;
	for (Actor actor : getChildren()) {
		height = actor instanceof Layout ? ((Layout) actor).getPrefHeight() : actor.getHeight();

	}
	if (vertical) height += handleBounds.size * style.handle.getMinHeight();
	return height;
}
 
Example 7
Source File: VerticalFlowGroup.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void computeSize () {
	prefWidth = 0;
	prefHeight = getHeight();
	sizeInvalid = false;

	SnapshotArray<Actor> children = getChildren();

	float y = 0;
	float columnWidth = 0;

	for (int i = 0; i < children.size; i++) {
		Actor child = children.get(i);
		float width = child.getWidth();
		float height = child.getHeight();
		if (child instanceof Layout) {
			Layout layout = (Layout) child;
			width = layout.getPrefWidth();
			height = layout.getPrefHeight();
		}

		if (y + height > getHeight()) {
			y = 0;
			prefWidth += columnWidth + spacing;
			columnWidth = width;
		} else {
			columnWidth = Math.max(width, columnWidth);
		}

		y += height + spacing;
	}

	//handle last column width
	prefWidth += columnWidth + spacing;
}
 
Example 8
Source File: HorizontalFlowGroup.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void computeSize () {
	prefWidth = getWidth();
	prefHeight = 0;
	sizeInvalid = false;

	SnapshotArray<Actor> children = getChildren();

	float x = 0;
	float rowHeight = 0;

	for (int i = 0; i < children.size; i++) {
		Actor child = children.get(i);
		float width = child.getWidth();
		float height = child.getHeight();
		if (child instanceof Layout) {
			Layout layout = (Layout) child;
			width = layout.getPrefWidth();
			height = layout.getPrefHeight();
		}

		if (x + width > getWidth()) {
			x = 0;
			prefHeight += rowHeight + spacing;
			rowHeight = height;
		} else {
			rowHeight = Math.max(height, rowHeight);
		}

		x += width + spacing;
	}

	//handle last row height
	prefHeight += rowHeight + spacing;
}
 
Example 9
Source File: Scene2dUtils.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
public static boolean containsLocal(Actor actor, float x, float y) {
    return x > 0f && y > 0f && x < actor.getWidth() && y < actor.getHeight();
}