Example usage for com.badlogic.gdx.graphics.glutils ShapeRenderer begin

List of usage examples for com.badlogic.gdx.graphics.glutils ShapeRenderer begin

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.glutils ShapeRenderer begin.

Prototype

public void begin() 

Source Link

Document

Begins a new batch without specifying a shape type.

Usage

From source file:net.team2xh.environment.widgets.graphs.BarChart.java

@Override
public void render(ShapeRenderer renderer, Batch batch) {

    Gdx.gl.glEnable(GL20.GL_BLEND);/*w  ww  .  java2 s . com*/
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    renderer.setAutoShapeType(true);
    renderer.begin();
    {
        //Gdx.gl.glLineWidth(1.0f);
        renderer.translate(getX(), getY(), 0);

        renderer.set(ShapeType.Line);
        renderer.setColor(Color.GRAY);
        renderer.rect(0, 0, getWidth(), getHeight());

        // TODO: Grid

        renderer.set(ShapeType.Line);
        renderer.setColor(Color.WHITE);
        if (showAxis) {
            // Vertical
            renderer.line(yAxisMargin, xAxisMargin, yAxisMargin, getHeight() - padding);
            // Horizontal
            renderer.line(yAxisMargin, xAxisMargin, getWidth() - padding, xAxisMargin);
        }

        // Bars
        renderer.translate(0, 0, -1);
        int i = 1;
        for (Map.Entry<String, Number> e : data) {
            float length = maxLength * (e.getValue().floatValue() / maxValue);
            Colors c = colors[color];
            renderer.set(ShapeType.Filled);
            renderer.setColor(c.transparent());
            if (horizontal) {
                renderer.rect(yAxisMargin, getHeight() - (i + 1) * padding - i * thickness, length, thickness);
            } else {
                renderer.rect(yAxisMargin + i * padding + (i - 1) * thickness, xAxisMargin, thickness, length);
            }
            renderer.set(ShapeType.Line);
            renderer.setColor(c.color());
            if (horizontal) {
                renderer.rect(yAxisMargin, getHeight() - (i + 1) * padding - i * thickness,
                        maxLength * (e.getValue().floatValue() / maxValue), thickness);
            } else {
                renderer.rect(yAxisMargin + i * padding + (i - 1) * thickness, xAxisMargin, thickness, length);
            }
            ++i;
            nextColor();
        }
        renderer.translate(0, 0, +1);

        renderer.translate(-getX(), -getY(), 0);
    }
    renderer.end();

    batch.begin();
    {
        int i = 0;
        for (Map.Entry<String, Number> e : data) {
            if (horizontal) {
                font.draw(batch, e.getKey(), getX() + yAxisMargin - padding - font.getBounds(e.getKey()).width,
                        getY() + getHeight() + font.getCapHeight() / 2
                                - (xAxisMargin + 2 * padding + i * (thickness + padding)));
                // TODO: Values axis    
            }
            // TODO: Vertical
            ++i;
        }
    }
    batch.end();

    Gdx.gl.glDisable(GL20.GL_BLEND);

}