Java Code Examples for com.badlogic.gdx.scenes.scene2d.utils.ScissorStack

The following examples show how to use com.badlogic.gdx.scenes.scene2d.utils.ScissorStack. These examples are extracted from open source projects. 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 Project: gdx-texture-packer-gui   Source File: PagePreviewCanvas.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
	batch.flush();
	getStage().calculateScissors(widgetAreaBounds.set(getX(), getY(), getWidth(), getHeight()), scissorBounds);
	if (ScissorStack.pushScissors(scissorBounds)) {
		super.draw(batch, parentAlpha);
		batch.flush();
		ScissorStack.popScissors();
	}
}
 
Example 2
Source Project: riiablo   Source File: ScrollPane.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	if (widget == null) return;

	validate();

	// Setup transform for this group.
	applyTransform(batch, computeTransform());

	if (scrollX) hKnobBounds.x = hScrollBounds.x + (int)((hScrollBounds.width - hKnobBounds.width) * getVisualScrollPercentX());
	if (scrollY)
		vKnobBounds.y = vScrollBounds.y + (int)((vScrollBounds.height - vKnobBounds.height) * (1 - getVisualScrollPercentY()));

	updateWidgetPosition();

	// Draw the background ninepatch.
	Color color = getColor();
	batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
	if (style.background != null) style.background.draw(batch, 0, 0, getWidth(), getHeight());

	// Caculate the scissor bounds based on the batch transform, the available widget area and the camera transform. We need to
	// project those to screen coordinates for OpenGL ES to consume.
	getStage().calculateScissors(widgetAreaBounds, scissorBounds);

	// Enable scissors for widget area and draw the widget.
	batch.flush();
	if (ScissorStack.pushScissors(scissorBounds)) {
		drawChildren(batch, parentAlpha);
		batch.flush();
		ScissorStack.popScissors();
	}

	// Render scrollbars and knobs on top if they will be visible
	float alpha = color.a * parentAlpha * Interpolation.fade.apply(fadeAlpha / fadeAlphaSeconds);
	drawScrollBars(batch, color.r, color.g, color.b, alpha);

	resetTransform(batch);
}
 
Example 3
Source Project: riiablo   Source File: ScrollPane.java    License: Apache License 2.0 5 votes vote down vote up
public void drawDebug (ShapeRenderer shapes) {
	shapes.flush();
	applyTransform(shapes, computeTransform());
	if (ScissorStack.pushScissors(scissorBounds)) {
		drawDebugChildren(shapes);
		ScissorStack.popScissors();
	}
	resetTransform(shapes);
}
 
Example 4
Source Project: Mundus   Source File: MundusSplitPane.java    License: 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());
    // Matrix4 transform = batch.getTransformMatrix();
    if (firstWidget != null) {
        getStage().calculateScissors(firstWidgetBounds, firstScissors);
        if (ScissorStack.pushScissors(firstScissors)) {
            if (firstWidget.isVisible()) firstWidget.draw(batch, parentAlpha * color.a);
            batch.flush();
            ScissorStack.popScissors();
        }
    }
    if (secondWidget != null) {
        getStage().calculateScissors(secondWidgetBounds, secondScissors);
        if (ScissorStack.pushScissors(secondScissors)) {
            if (secondWidget.isVisible()) secondWidget.draw(batch, parentAlpha * color.a);
            batch.flush();
            ScissorStack.popScissors();
        }
    }

    Drawable handle = style.handle;
    if (mouseOnHandle && isTouchable() && style.handleOver != null) handle = style.handleOver;
    batch.setColor(color.r, color.g, color.b, parentAlpha * color.a);
    handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height);
    resetTransform(batch);

}
 
Example 5
Source Project: Mundus   Source File: MundusMultiSplitPane.java    License: 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 6
Source Project: GdxDemo3D   Source File: GameStage.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void calculateScissors (Rectangle localRect, Rectangle scissorRect) {
	ScissorStack.calculateScissors(cameraUI, viewport.getScreenX(), viewport.getScreenY(), viewport.getScreenWidth(), viewport.getScreenHeight(), batch.getTransformMatrix(), localRect, scissorRect);
	Matrix4 transformMatrix;
	if (shapeRenderer != null && shapeRenderer.isDrawing())
		transformMatrix = shapeRenderer.getTransformMatrix();
	else
		transformMatrix = batch.getTransformMatrix();
	ScissorStack.calculateScissors(cameraUI, viewport.getScreenX(), viewport.getScreenY(), viewport.getScreenWidth(), viewport.getScreenHeight(), transformMatrix, localRect, scissorRect);
}
 
Example 7
Source Project: vis-ui   Source File: MultiSplitPane.java    License: 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 Project: vis-ui   Source File: VisSplitPane.java    License: 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());
	// Matrix4 transform = batch.getTransformMatrix();
	if (firstWidget != null) {
		getStage().calculateScissors(firstWidgetBounds, firstScissors);
		if (ScissorStack.pushScissors(firstScissors)) {
			if (firstWidget.isVisible()) firstWidget.draw(batch, parentAlpha * color.a);
			batch.flush();
			ScissorStack.popScissors();
		}
	}
	if (secondWidget != null) {
		getStage().calculateScissors(secondWidgetBounds, secondScissors);
		if (ScissorStack.pushScissors(secondScissors)) {
			if (secondWidget.isVisible()) secondWidget.draw(batch, parentAlpha * color.a);
			batch.flush();
			ScissorStack.popScissors();
		}
	}

	Drawable handle = style.handle;
	if (mouseOnHandle && isTouchable() && style.handleOver != null) handle = style.handleOver;
	batch.setColor(color.r, color.g, color.b, parentAlpha * color.a);
	handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height);
	resetTransform(batch);

}