Java Code Examples for com.badlogic.gdx.utils.SnapshotArray#get()

The following examples show how to use com.badlogic.gdx.utils.SnapshotArray#get() . 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: CustomizeScreen.java    From Klooni1010 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void render(float delta) {
    Klooni.theme.glClearBackground();
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    stage.act(Math.min(Gdx.graphics.getDeltaTime(), MIN_DELTA));
    stage.draw();

    // After everything is drawn, showcase the current shop item
    SnapshotArray<Actor> children = shopGroup.getChildren();
    if (children.size > 0) {
        final ShopCard card = (ShopCard) children.get(showcaseIndex);

        final Batch batch = stage.getBatch();
        batch.begin();
        // For some really strange reason, we need to displace the particle effect
        // by "buyBand.height", or it will render exactly that height below where
        // it should.
        // TODO Fix this - maybe use the same project matrix as stage.draw()?
        // batch.setProjectionMatrix(stage.getViewport().getCamera().combined)
        if (!card.showcase(batch, buyBand.getHeight())) {
            showcaseIndex = (showcaseIndex + 1) % children.size;
        }
        batch.end();
    }

    if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)) {
        goBack();
    }
}
 
Example 2
Source File: MundusMultiSplitPane.java    From Mundus with Apache License 2.0 5 votes vote down vote up
@Override
public void layout() {
    if (!vertical)
        calculateHorizBoundsAndPositions();
    else
        calculateVertBoundsAndPositions();

    SnapshotArray<Actor> actors = getChildren();
    for (int i = 0; i < actors.size; i++) {
        Actor actor = actors.get(i);
        Rectangle bounds = widgetBounds.get(i);
        actor.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
        if (actor instanceof Layout) ((Layout) actor).validate();
    }
}
 
Example 3
Source File: MundusMultiSplitPane.java    From Mundus with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    validate();

    Color color = getColor();

    applyTransform(batch, computeTransform());

    SnapshotArray<Actor> actors = getChildren();
    for (int i = 0; i < actors.size; i++) {
        Actor actor = actors.get(i);
        Rectangle bounds = widgetBounds.get(i);
        Rectangle scissor = scissors.get(i);
        getStage().calculateScissors(bounds, scissor);
        if (ScissorStack.pushScissors(scissor)) {
            if (actor.isVisible()) actor.draw(batch, parentAlpha * color.a);
            batch.flush();
            ScissorStack.popScissors();
        }
    }

    batch.setColor(color.r, color.g, color.b, parentAlpha * color.a);

    Drawable handle = style.handle;
    Drawable handleOver = style.handle;
    if (isTouchable() && style.handleOver != null) handleOver = style.handleOver;
    for (Rectangle rect : handleBounds) {
        if (this.handleOver == rect) {
            handleOver.draw(batch, rect.x, rect.y, rect.width, rect.height);
        } else {
            handle.draw(batch, rect.x, rect.y, rect.width, rect.height);
        }
    }
    resetTransform(batch);
}
 
Example 4
Source File: PopupMenu.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
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;
		}
	}
}
 
Example 5
Source File: PopupMenu.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void selectPreviousItem () {
	SnapshotArray<Actor> children = getChildren();
	if (!hasSelectableMenuItems()) return;
	int startIndex = activeItem == null ? children.size - 1 : children.indexOf(activeItem, true) - 1;
	for (int i = startIndex; ; i--) {
		if (i <= -1) i = children.size - 1;
		Actor actor = children.get(i);
		if (actor instanceof MenuItem && ((MenuItem) actor).isDisabled() == false) {
			setActiveItem((MenuItem) actor, true);
			break;
		}
	}
}
 
Example 6
Source File: MultiSplitPane.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public void layout () {
	if (!vertical)
		calculateHorizBoundsAndPositions();
	else
		calculateVertBoundsAndPositions();

	SnapshotArray<Actor> actors = getChildren();
	for (int i = 0; i < actors.size; i++) {
		Actor actor = actors.get(i);
		Rectangle bounds = widgetBounds.get(i);
		actor.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
		if (actor instanceof Layout) ((Layout) actor).validate();
	}
}
 
Example 7
Source File: MultiSplitPane.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	validate();

	Color color = getColor();

	applyTransform(batch, computeTransform());

	SnapshotArray<Actor> actors = getChildren();
	for (int i = 0; i < actors.size; i++) {
		Actor actor = actors.get(i);
		Rectangle bounds = widgetBounds.get(i);
		Rectangle scissor = scissors.get(i);
		getStage().calculateScissors(bounds, scissor);
		if (ScissorStack.pushScissors(scissor)) {
			if (actor.isVisible()) actor.draw(batch, parentAlpha * color.a);
			batch.flush();
			ScissorStack.popScissors();
		}
	}

	batch.setColor(color.r, color.g, color.b, parentAlpha * color.a);

	Drawable handle = style.handle;
	Drawable handleOver = style.handle;
	if (isTouchable() && style.handleOver != null) handleOver = style.handleOver;
	for (Rectangle rect : handleBounds) {
		if (this.handleOver == rect) {
			handleOver.draw(batch, rect.x, rect.y, rect.width, rect.height);
		} else {
			handle.draw(batch, rect.x, rect.y, rect.width, rect.height);
		}
	}
	resetTransform(batch);
}
 
Example 8
Source File: IconStack.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void computeSize () {
	sizeInvalid = false;
	prefWidth = 0;
	prefHeight = 0;
	minWidth = 0;
	minHeight = 0;
	maxWidth = 0;
	maxHeight = 0;
	SnapshotArray<Actor> children = getChildren();
	for (int i = 0, n = children.size; i < n; i++) {
		Actor child = children.get(i);
		float childMaxWidth, childMaxHeight;
		if (child instanceof Layout) {
			Layout layout = (Layout) child;
			prefWidth = Math.max(prefWidth, layout.getPrefWidth());
			prefHeight = Math.max(prefHeight, layout.getPrefHeight());
			minWidth = Math.max(minWidth, layout.getMinWidth());
			minHeight = Math.max(minHeight, layout.getMinHeight());
			childMaxWidth = layout.getMaxWidth();
			childMaxHeight = layout.getMaxHeight();
		} else {
			prefWidth = Math.max(prefWidth, child.getWidth());
			prefHeight = Math.max(prefHeight, child.getHeight());
			minWidth = Math.max(minWidth, child.getWidth());
			minHeight = Math.max(minHeight, child.getHeight());
			childMaxWidth = 0;
			childMaxHeight = 0;
		}
		if (childMaxWidth > 0) maxWidth = maxWidth == 0 ? childMaxWidth : Math.min(maxWidth, childMaxWidth);
		if (childMaxHeight > 0) maxHeight = maxHeight == 0 ? childMaxHeight : Math.min(maxHeight, childMaxHeight);
	}
}
 
Example 9
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 10
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 11
Source File: GridGroup.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public void layout () {
	if (sizeInvalid) {
		computeSize();
		if (lastPrefHeight != prefHeight) {
			lastPrefHeight = prefHeight;
			invalidateHierarchy();
		}
	}

	SnapshotArray<Actor> children = getChildren();

	float width = getWidth();
	boolean notEnoughSpace = itemWidth + spacing * 2 > width;

	float x = spacing;
	float y = notEnoughSpace ? (getHeight()) : (getHeight() - itemHeight - spacing);

	for (int i = 0; i < children.size; i++) {
		Actor child = children.get(i);

		if (x + itemWidth + spacing > width) {
			x = spacing;
			y -= itemHeight + spacing;
		}

		child.setBounds(x, y, itemWidth, itemHeight);
		x += itemWidth + spacing;
	}
}