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(ShapeType type) 

Source Link

Document

Starts a new batch of shapes.

Usage

From source file:pl.kotcrab.jdialogue.editor.components.ConnectionRenderer.java

License:Open Source License

public void render(ShapeRenderer shapeRenderer, Connector selectedConnection, float x2, float y2) {
    shapeRenderer.begin(ShapeType.Line);
    shapeRenderer.setColor(Color.ORANGE);
    float x1 = selectedConnection.getX() + 6;
    float y1 = selectedConnection.getY() + 6;

    float d = 0;/* ww  w  .  j  a  v  a 2  s  .  c om*/

    if (renderCurves) {
        d = Math.abs(y1 - y2);
        if (d > 100)
            d = 100; // limit
    }

    if (selectedConnection.isInput() == true) // swaping values because curve will look weird without this
    {
        float temp = x1;
        x1 = x2;
        x2 = temp;

        temp = y1;
        y1 = y2;
        y2 = temp;
    }

    if (renderCurves)
        shapeRenderer.curve(x1, y1, x1 + d, y1, x2 - d, y2, x2, y2, 32);
    else
        shapeRenderer.line(x1, y1, x2, y2);

    shapeRenderer.end();
}

From source file:pl.kotcrab.jdialogue.editor.components.Connector.java

License:Open Source License

public void renderAsSelected(ShapeRenderer shapeRenderer, Color color) {
    shapeRenderer.begin(ShapeType.Filled);
    shapeRenderer.setColor(color);/*from  w  w w .j  av a2s  . co m*/
    shapeRenderer.rect(x, y, 12, 12);
    shapeRenderer.end();
}

From source file:pl.kotcrab.jdialogue.editor.RectangularSelection.java

License:Open Source License

public void render(ShapeRenderer shapeRenderer) {
    if (rectToDraw != null) {
        Gdx.graphics.getGL20().glEnable(GL10.GL_BLEND);

        shapeRenderer.setColor(Color.RED);
        shapeRenderer.begin(ShapeType.Line);
        shapeRenderer.rect(rectToDraw.getX(), rectToDraw.getY(), rectToDraw.getWidth(), rectToDraw.getHeight());
        shapeRenderer.end();//  w  w  w  . ja  va2s  .c o  m

        shapeRenderer.setColor(0.7f, 0, 0, 0.3f);
        shapeRenderer.begin(ShapeType.Filled);
        shapeRenderer.rect(rectToDraw.getX(), rectToDraw.getY(), rectToDraw.getWidth(), rectToDraw.getHeight());
        shapeRenderer.end();

    }
}

From source file:releasethekraken.entity.seacreature.EntityPlayer.java

@Override
public void renderShapes(ShapeRenderer shapeRenderer, float delta, float runTime) {
    super.renderShapes(shapeRenderer, delta, runTime);

    //Render power up preview
    if (this.powerUpPreview != null) {
        shapeRenderer.end();//  www .j  a v  a 2s.c om

        //Enable OpenGL alpha blending
        Gdx.gl.glEnable(Gdx.gl.GL_BLEND);
        Gdx.gl.glBlendFunc(Gdx.gl.GL_SRC_ALPHA, Gdx.gl.GL_ONE_MINUS_SRC_ALPHA);

        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);

        EntityPowerUp.PowerUpStats powerUpStats = EntityPowerUp.getStats(this.powerUpPreview);

        shapeRenderer.setColor(powerUpStats.previewColor);
        shapeRenderer.circle(this.physBody.getPosition().x, this.physBody.getPosition().y, powerUpStats.radius,
                32);

        shapeRenderer.end();

        //Disable OpenGL blending so everything else doesn't get messed up
        Gdx.gl.glDisable(Gdx.gl.GL_BLEND);

        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    }
    /* shapeRenderer.setColor(Color.BLACK);
     shapeRenderer.rect(this.getPos().x - (this.maxHealth * .25f), this.getPos().y + 1.1f, this.maxHealth * .5f, 0.5f);
            
     shapeRenderer.setColor(Color.RED);
     shapeRenderer.rect(this.getPos().x - (this.maxHealth * .25f), this.getPos().y + 1.1f, this.health * .5f, 0.5f);
    */
    //Draw crosshair
    //shapeRenderer.setColor(Color.RED);
    //shapeRenderer.x(this.aimPos, 1);
}

From source file:releasethekraken.ui.tooltip.PowerUpToolTip.java

@Override
public void renderShapes(ShapeRenderer shapeRenderer, float delta, float runTime) {
    super.renderShapes(shapeRenderer, delta, runTime);

    if (this.visible) {
        //The mouse coordinates
        float mouseX = Gdx.input.getX(0);
        float mouseY = Gdx.input.getY(0);

        float textHeight = GameAssets.fontMain.getCapHeight();

        float boxWidth = (0.25F + 0.005F) * Gdx.graphics.getWidth();
        float boxHeight = this.descriptionHeight + GameAssets.fontMain.getCapHeight()
                + 0.08F * Gdx.graphics.getHeight();

        float boxX = mouseX + 0.05F * Gdx.graphics.getWidth();
        float boxY = Gdx.graphics.getHeight() - mouseY + (boxHeight - textHeight) / 2 + textHeight / 2;

        float triangleAlignX = boxX;

        /*// w w  w  .ja v a  2  s  .c  om
        Starting and stopping the shape renderer multiple times and copying 
        colors might have an impact on performance.  We might want to find
        a more efficient way of doing this.  Maybe tooltips get their own
        render pass?
        */

        shapeRenderer.end(); //End the shape batch, drawing everything it has so far

        //Enable OpenGL alpha blending
        Gdx.gl.glEnable(Gdx.gl.GL_BLEND);
        Gdx.gl.glBlendFunc(Gdx.gl.GL_SRC_ALPHA, Gdx.gl.GL_ONE_MINUS_SRC_ALPHA);

        //Start a new shape batch
        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);

        //Render tooltip background
        shapeRenderer.setColor(this.color.cpy().sub(0, 0, 0, 0.35F)); //Make the color transparent
        shapeRenderer.rect(boxX, boxY - boxHeight, boxWidth, boxHeight); //Tooltip background
        shapeRenderer.triangle(mouseX, Gdx.graphics.getHeight() - mouseY, triangleAlignX, boxY, triangleAlignX,
                boxY - boxHeight); //Triangle part

        shapeRenderer.end(); //End the shape batch, drawing the transparent tooltip

        //Disable OpenGL blending so everything else doesn't get messed up
        Gdx.gl.glDisable(Gdx.gl.GL_BLEND);

        //Start a new shape batch so that it is left in the state it started in
        shapeRenderer.begin(ShapeRenderer.ShapeType.Line);

        //Draw the radius symbol            
        shapeRenderer.setColor(Color.BLUE);
        shapeRenderer.circle(boxX + 0.009F * Gdx.graphics.getWidth(),
                Gdx.graphics.getHeight() - mouseY - 0.04F * Gdx.graphics.getWidth(),
                0.008F * Gdx.graphics.getWidth());

        shapeRenderer.line(boxX + 0.009F * Gdx.graphics.getWidth(),
                Gdx.graphics.getHeight() - mouseY - 0.04F * Gdx.graphics.getWidth(),
                boxX + 0.009F * Gdx.graphics.getWidth() + 0.008F * Gdx.graphics.getWidth(),
                Gdx.graphics.getHeight() - mouseY - 0.04F * Gdx.graphics.getWidth());

        shapeRenderer.end();
        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    }
}

From source file:releasethekraken.ui.tooltip.PurchaseUnitToolTip.java

@Override
public void renderShapes(ShapeRenderer shapeRenderer, float delta, float runTime) {
    super.renderShapes(shapeRenderer, delta, runTime);

    if (this.visible) {
        //The mouse coordinates
        float mouseX = Gdx.input.getX(0);
        float mouseY = Gdx.input.getY(0);

        float textHeight = GameAssets.fontMain.getCapHeight();

        float boxWidth = (0.25F + 0.005F) * Gdx.graphics.getWidth();
        float boxHeight = this.descriptionHeight + GameAssets.fontMain.getCapHeight()
                + 0.16F * Gdx.graphics.getHeight();

        float boxX = mouseX + 0.05F * Gdx.graphics.getWidth();
        float boxY = Gdx.graphics.getHeight() - mouseY + (boxHeight - textHeight) / 2 + textHeight / 2;

        float triangleAlignX = boxX;

        /*/*ww  w .  jav a 2s. com*/
        Starting and stopping the shape renderer multiple times and copying 
        colors might have an impact on performance.  We might want to find
        a more efficient way of doing this.  Maybe tooltips get their own
        render pass?
        */

        shapeRenderer.end(); //End the shape batch, drawing everything it has so far

        //Enable OpenGL alpha blending
        Gdx.gl.glEnable(Gdx.gl.GL_BLEND);
        Gdx.gl.glBlendFunc(Gdx.gl.GL_SRC_ALPHA, Gdx.gl.GL_ONE_MINUS_SRC_ALPHA);

        //Start a new shape batch
        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);

        //Render tooltip background
        shapeRenderer.setColor(this.color.cpy().sub(0, 0, 0, 0.35F)); //Make the color transparent
        shapeRenderer.rect(boxX, boxY - boxHeight, boxWidth, boxHeight); //Tooltip background
        shapeRenderer.triangle(mouseX, Gdx.graphics.getHeight() - mouseY, triangleAlignX, boxY, triangleAlignX,
                boxY - boxHeight); //Triangle part

        shapeRenderer.end(); //End the shape batch, drawing the transparent tooltip

        //Disable OpenGL blending so everything else doesn't get messed up
        Gdx.gl.glDisable(Gdx.gl.GL_BLEND);

        //Start a new shape batch so that it is left in the state it started in
        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    }
}

From source file:releasethekraken.ui.tooltip.TextToolTip.java

@Override
public void renderShapes(ShapeRenderer shapeRenderer, float delta, float runTime) //TODO: Make tool tip display better
{
    super.renderShapes(shapeRenderer, delta, runTime);

    if (this.visible) {
        //The mouse coordinates
        float mouseX = Gdx.input.getX(0);
        float mouseY = Gdx.input.getY(0);

        float textHeight = GameAssets.fontMain.getCapHeight();
        float textWidth = GameAssets.fontMain.getSpaceWidth() * this.text.length();

        float boxWidth = textWidth;
        float boxHeight = textHeight * 1.8F;

        float boxX = mouseX + 0.05F * Gdx.graphics.getWidth();
        float boxY = Gdx.graphics.getHeight() - mouseY + (boxHeight - textHeight) / 2 + textHeight / 2;

        float triangleAlignX = boxX;

        //Swap the tooltip to the other side if it's on the other side of the screen
        if (mouseX > Gdx.graphics.getWidth() / 2) {
            boxX = mouseX - 0.05F * Gdx.graphics.getWidth() - textWidth;
            triangleAlignX = boxX + boxWidth;
        }/*from ww w.ja v a  2  s. c o  m*/

        /*
        Starting and stopping the shape renderer multiple times and copying 
        colors might have an impact on performance.  We might want to find
        a more efficient way of doing this.  Maybe tooltips get their own
        render pass?
        */

        shapeRenderer.end(); //End the shape batch, drawing everything it has so far

        //Enable OpenGL alpha blending
        Gdx.gl.glEnable(Gdx.gl.GL_BLEND);
        Gdx.gl.glBlendFunc(Gdx.gl.GL_SRC_ALPHA, Gdx.gl.GL_ONE_MINUS_SRC_ALPHA);

        //Start a new shape batch
        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);

        //Render tooltip background
        shapeRenderer.setColor(this.color.cpy().sub(0, 0, 0, 0.35F)); //Make the color transparent
        shapeRenderer.rect(boxX, boxY - boxHeight, boxWidth, boxHeight); //Tooltip background
        shapeRenderer.triangle(mouseX, Gdx.graphics.getHeight() - mouseY, triangleAlignX, boxY, triangleAlignX,
                boxY - boxHeight); //Triangle part

        shapeRenderer.end(); //End the shape batch, drawing the transparent tooltip

        //Disable OpenGL blending so everything else doesn't get messed up
        Gdx.gl.glDisable(Gdx.gl.GL_BLEND);

        //Start a new shape batch so that it is left in the state it started in
        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    }
}

From source file:sg.atom2d.game2d.graphics.anim.spine.skeleton.SkeletonRendererDebug.java

License:Open Source License

public void draw(Skeleton skeleton) {
    float skeletonX = skeleton.getX();
    float skeletonY = skeleton.getY();

    Gdx.gl.glEnable(GL10.GL_BLEND);/*  ww  w . j  a va2s .  co m*/
    ShapeRenderer renderer = this.renderer;
    renderer.begin(ShapeType.Line);

    Array<Bone> bones = skeleton.getBones();
    if (drawBones) {
        renderer.setColor(boneLineColor);
        for (int i = 0, n = bones.size; i < n; i++) {
            Bone bone = bones.get(i);
            if (bone.parent == null)
                continue;
            float x = skeletonX + bone.data.length * bone.m00 + bone.worldX;
            float y = skeletonY + bone.data.length * bone.m10 + bone.worldY;
            renderer.line(skeletonX + bone.worldX, skeletonY + bone.worldY, x, y);
        }
    }

    if (drawRegionAttachments) {
        renderer.setColor(regionAttachmentLineColor);
        Array<Slot> slots = skeleton.getSlots();
        for (int i = 0, n = slots.size; i < n; i++) {
            Slot slot = slots.get(i);
            Attachment attachment = slot.attachment;
            if (attachment instanceof RegionAttachment) {
                RegionAttachment regionAttachment = (RegionAttachment) attachment;
                regionAttachment.updateWorldVertices(slot, false);
                float[] vertices = regionAttachment.getWorldVertices();
                renderer.line(vertices[X1], vertices[Y1], vertices[X2], vertices[Y2]);
                renderer.line(vertices[X2], vertices[Y2], vertices[X3], vertices[Y3]);
                renderer.line(vertices[X3], vertices[Y3], vertices[X4], vertices[Y4]);
                renderer.line(vertices[X4], vertices[Y4], vertices[X1], vertices[Y1]);
            }
        }
    }

    if (drawBoundingBoxes) {
        SkeletonBounds bounds = this.bounds;
        bounds.update(skeleton, true);
        renderer.setColor(aabbColor);
        renderer.rect(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight());
        renderer.setColor(boundingBoxColor);
        Array<FloatArray> polygons = bounds.getPolygons();
        for (int i = 0, n = polygons.size; i < n; i++) {
            FloatArray polygon = polygons.get(i);
            renderer.polygon(polygon.items, 0, polygon.size);
        }
    }

    renderer.end();
    renderer.begin(ShapeType.Filled);

    if (drawBones) {
        renderer.setColor(boneOriginColor);
        for (int i = 0, n = bones.size; i < n; i++) {
            Bone bone = bones.get(i);
            renderer.setColor(ColorRGBA.GREEN);
            renderer.circle(skeletonX + bone.worldX, skeletonY + bone.worldY, 3 * scale);
        }
    }

    renderer.end();
}

From source file:spaceisnear.game.ui.TextField.java

@Override
public void paint(Batch batch) {
    if (checkKeys(keycode)) {
        keycode = 0;//from www  .jav  a2s.co m
    }
    ShapeRenderer renderer = getRenderer();
    focused = getStage().getKeyboardFocus() == this;
    int start = 0;
    int end = text.length();
    int startingXText = 0;
    //TODO
    GlyphLayout glyphLayout = new GlyphLayout(font, text);
    if (glyphLayout.width > getWidthWithoutPaddings()) {
        end = text.length();
        start = end - 1;
        glyphLayout.setText(font, text, start, end, textColor, getWidthWithoutPaddings(), 0, false, null);
        while (start > 0 && glyphLayout.width < getWidthWithoutPaddings()) {
            start--;
        }
        glyphLayout.setText(font, text, 0, start, textColor, getWidthWithoutPaddings(), 0, false, null);
        startingXText = (int) -glyphLayout.width;
    }
    //
    {
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
        renderer.setProjectionMatrix(batch.getProjectionMatrix());
        renderer.begin(ShapeRenderer.ShapeType.Filled);
        renderer.setColor(backgroundColor);
        renderer.rect(0, 0, getWidth(), getHeight());
        renderer.end();
        Gdx.gl.glDisable(GL20.GL_BLEND);
    }
    {
        renderer.begin(ShapeRenderer.ShapeType.Line);
        renderer.setColor(borderColor);
        renderer.rect(0, 0, getWidth() + 1, getHeight());
        renderer.end();
    }
    //cursor
    renderer.begin(ShapeRenderer.ShapeType.Line);
    font.setColor(Color.BLACK);
    if (focused) {
        glyphLayout.setText(font, text, 0, currentPosition, textColor, getWidthWithoutPaddings(), 0, false,
                null);
        final float x = 10 + glyphLayout.width + startingXText;
        renderer.line(x, 3, x, font.getLineHeight() + 2);
        renderer.line(x + 1, 3, x + 1, font.getLineHeight() + 2);
    }
    renderer.end();
    batch.begin();
    font.setColor(Color.BLACK);
    font.draw(batch, text.subSequence(start, end), WIDTH_PADDING + getX(), 3 + getY());
    batch.end();
}

From source file:spine.SkeletonRendererDebug.java

License:Open Source License

public void draw(Skeleton skeleton) {
    float skeletonX = skeleton.getX();
    float skeletonY = skeleton.getY();

    Gdx.gl.glEnable(GL20.GL_BLEND);/*from  w  ww  .  j  a  v a  2 s  .c  om*/
    int srcFunc = premultipliedAlpha ? GL20.GL_ONE : GL20.GL_SRC_ALPHA;
    Gdx.gl.glBlendFunc(srcFunc, GL20.GL_ONE_MINUS_SRC_ALPHA);

    ShapeRenderer shapes = this.shapes;

    Array<Bone> bones = skeleton.getBones();
    if (drawBones) {
        shapes.setColor(boneLineColor);
        shapes.begin(ShapeType.Filled);
        for (int i = 0, n = bones.size; i < n; i++) {
            Bone bone = bones.get(i);
            if (bone.parent == null)
                continue;
            float x = skeletonX + bone.data.length * bone.a + bone.worldX;
            float y = skeletonY + bone.data.length * bone.c + bone.worldY;
            shapes.rectLine(skeletonX + bone.worldX, skeletonY + bone.worldY, x, y, boneWidth * scale);
        }
        shapes.end();
        shapes.begin(ShapeType.Line);
        shapes.x(skeletonX, skeletonY, 4 * scale);
    } else
        shapes.begin(ShapeType.Line);

    if (drawRegionAttachments) {
        shapes.setColor(attachmentLineColor);
        Array<Slot> slots = skeleton.getSlots();
        for (int i = 0, n = slots.size; i < n; i++) {
            Slot slot = slots.get(i);
            Attachment attachment = slot.attachment;
            if (attachment instanceof RegionAttachment) {
                RegionAttachment regionAttachment = (RegionAttachment) attachment;
                float[] vertices = regionAttachment.updateWorldVertices(slot, false);
                shapes.line(vertices[X1], vertices[Y1], vertices[X2], vertices[Y2]);
                shapes.line(vertices[X2], vertices[Y2], vertices[X3], vertices[Y3]);
                shapes.line(vertices[X3], vertices[Y3], vertices[X4], vertices[Y4]);
                shapes.line(vertices[X4], vertices[Y4], vertices[X1], vertices[Y1]);
            }
        }
    }

    if (drawMeshHull || drawMeshTriangles) {
        Array<Slot> slots = skeleton.getSlots();
        for (int i = 0, n = slots.size; i < n; i++) {
            Slot slot = slots.get(i);
            Attachment attachment = slot.attachment;
            float[] vertices = null;
            short[] triangles = null;
            int hullLength = 0;
            if (attachment instanceof MeshAttachment) {
                MeshAttachment mesh = (MeshAttachment) attachment;
                mesh.updateWorldVertices(slot, false);
                vertices = mesh.getWorldVertices();
                triangles = mesh.getTriangles();
                hullLength = mesh.getHullLength();
            } else if (attachment instanceof SkinnedMeshAttachment) {
                SkinnedMeshAttachment mesh = (SkinnedMeshAttachment) attachment;
                mesh.updateWorldVertices(slot, false);
                vertices = mesh.getWorldVertices();
                triangles = mesh.getTriangles();
                hullLength = mesh.getHullLength();
            }
            if (vertices == null || triangles == null)
                continue;
            if (drawMeshTriangles) {
                shapes.setColor(triangleLineColor);
                for (int ii = 0, nn = triangles.length; ii < nn; ii += 3) {
                    int v1 = triangles[ii] * 5, v2 = triangles[ii + 1] * 5, v3 = triangles[ii + 2] * 5;
                    shapes.triangle(vertices[v1], vertices[v1 + 1], //
                            vertices[v2], vertices[v2 + 1], //
                            vertices[v3], vertices[v3 + 1] //
                    );
                }
            }
            if (drawMeshHull && hullLength > 0) {
                shapes.setColor(attachmentLineColor);
                hullLength = hullLength / 2 * 5;
                float lastX = vertices[hullLength - 5], lastY = vertices[hullLength - 4];
                for (int ii = 0, nn = hullLength; ii < nn; ii += 5) {
                    float x = vertices[ii], y = vertices[ii + 1];
                    shapes.line(x, y, lastX, lastY);
                    lastX = x;
                    lastY = y;
                }
            }
        }
    }

    if (drawBoundingBoxes) {
        SkeletonBounds bounds = this.bounds;
        bounds.update(skeleton, true);
        shapes.setColor(aabbColor);
        shapes.rect(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight());
        shapes.setColor(boundingBoxColor);
        Array<FloatArray> polygons = bounds.getPolygons();
        for (int i = 0, n = polygons.size; i < n; i++) {
            FloatArray polygon = polygons.get(i);
            shapes.polygon(polygon.items, 0, polygon.size);
        }
    }

    shapes.end();
    shapes.begin(ShapeType.Filled);

    if (drawBones) {
        shapes.setColor(boneOriginColor);
        for (int i = 0, n = bones.size; i < n; i++) {
            Bone bone = bones.get(i);
            shapes.setColor(Color.GREEN);
            shapes.circle(skeletonX + bone.worldX, skeletonY + bone.worldY, 3 * scale, 8);
        }
    }

    shapes.end();
}