Example usage for com.badlogic.gdx.graphics.g2d Batch getTransformMatrix

List of usage examples for com.badlogic.gdx.graphics.g2d Batch getTransformMatrix

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d Batch getTransformMatrix.

Prototype

public Matrix4 getTransformMatrix();

Source Link

Document

Returns the current transform matrix.

Usage

From source file:com.bladecoder.engineeditor.scneditor.ScnWidget.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();/*w w w  .ja  v a2  s . co m*/

    Color tmp = batch.getColor();
    batch.setColor(Color.WHITE);

    if (scn != null && !loading && !loadingError) {
        // BACKGROUND
        batch.disableBlending();
        tile.draw(batch, getX(), getY(), getWidth(), getHeight());
        batch.enableBlending();

        Vector3 v = new Vector3(getX(), getY(), 0);
        v = v.prj(batch.getTransformMatrix());

        batch.end();

        HdpiUtils.glViewport((int) v.x, (int) v.y, (int) getWidth(), (int) (getHeight()));

        getStage().calculateScissors(bounds, scissors);

        if (ScissorStack.pushScissors(scissors)) {
            // WORLD CAMERA
            sceneBatch.setProjectionMatrix(camera.combined);
            sceneBatch.begin();

            Array<AtlasRegion> scnBackground = scn.getBackground();

            if (scnBackground != null) {
                sceneBatch.disableBlending();

                float x = 0;

                for (AtlasRegion tile : scnBackground) {
                    sceneBatch.draw(tile, x, 0f);
                    x += tile.getRegionWidth();
                }

                sceneBatch.enableBlending();
            }

            // draw layers from bottom to top
            List<SceneLayer> layers = scn.getLayers();
            for (int i = layers.size() - 1; i >= 0; i--) {
                SceneLayer layer = layers.get(i);

                if (!layer.isVisible())
                    continue;

                List<InteractiveActor> actors = layer.getActors();

                for (InteractiveActor a : actors) {
                    if (a instanceof SpriteActor) {
                        boolean visibility = a.isVisible();
                        a.setVisible(true);
                        ((SpriteActor) a).draw(sceneBatch);
                        a.setVisible(visibility);
                    }
                }
            }

            sceneBatch.end();
            ScissorStack.popScissors();
        }

        drawer.drawBGBounds();

        if (showWalkZone && scn.getPolygonalNavGraph() != null) {
            drawer.drawBBoxWalkZone(scn, false);

            drawer.drawPolygonVertices(scn.getPolygonalNavGraph().getWalkZone(), Color.GREEN);
        }

        drawer.drawBBoxActors(scn);

        if (selectedActor != null) {
            drawer.drawSelectedActor(selectedActor);
        }

        getStage().getViewport().apply();

        // SCREEN CAMERA
        batch.begin();

        drawFakeDepthMarkers((SpriteBatch) batch);

        if (!inScene) {
            faRenderer.draw((SpriteBatch) batch);
        }

        // DRAW COORDS
        Vector2 coords = new Vector2(Gdx.input.getX(), Gdx.input.getY());
        screenToWorldCoords(coords);
        String str = MessageFormat.format("({0}, {1})", (int) coords.x, (int) coords.y);

        textLayout.setText(defaultFont, str);

        RectangleRenderer.draw((SpriteBatch) batch, 0f, getY() + getHeight() - textLayout.height - 15,
                textLayout.width + 10, textLayout.height + 10, BLACK_TRANSPARENT);
        defaultFont.draw(batch, textLayout, 5, getHeight() + getY() - 10);

        batch.setColor(tmp);

    } else {
        background.draw(batch, getX(), getY(), getWidth(), getHeight());

        String s;

        if (loading) {
            s = "LOADING...";

            try {
                if (!EngineAssetManager.getInstance().isLoading()) {
                    loading = false;

                    scn.retrieveAssets();

                    drawer.setCamera(camera);

                    invalidate();
                }
            } catch (Exception e) {
                Message.showMsg(getStage(), "Could not load assets for scene", 4);
                e.printStackTrace();
                loadingError = true;
                loading = false;
            }

        } else if (loadingError) {
            s = "ERROR IN SCENE DATA. CANNOT DISPLAY SCENE";
        } else if (Ctx.project.getProjectDir() == null) {
            s = "CREATE OR LOAD A PROJECT";
        } else {
            s = "THERE ARE NO SCENES IN THIS CHAPTER YET";
        }

        textLayout.setText(bigFont, s);

        bigFont.draw(batch, textLayout, (getWidth() - textLayout.width) / 2,
                getHeight() / 2 + bigFont.getLineHeight() * 3);

    }

}

From source file:com.github.mkjensen.breakall.actor.Box2DActor.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    batch.end();//from   www  . j av  a 2  s  . co  m
    renderer.setProjectionMatrix(batch.getProjectionMatrix());
    renderer.setTransformMatrix(batch.getTransformMatrix());
    draw(renderer);
    batch.begin();
}

From source file:com.idp.engine.ui.graphics.actors.listview.ListView.java

@Override
public void drawChildren(Batch batch, float parentAlpha) {
    ScissorStack.calculateScissors(getStage().getCamera(), batch.getTransformMatrix(), bounds, scissors);
    batch.flush();//from  w w  w  .  j a v  a  2  s.  co  m
    boolean pushed = ScissorStack.pushScissors(scissors);
    super.drawChildren(batch, parentAlpha);
    if (pushed) {
        batch.flush();
        ScissorStack.popScissors();
    }
}

From source file:com.luongbui.gdx.libpd.pianotest.character.PianoKey.java

License:Apache License

@Override
public void draw(Batch batch, float delta) {

    batch.end();/*from ww w .j a  va2s .co  m*/

    renderer.setProjectionMatrix(batch.getProjectionMatrix());
    renderer.setTransformMatrix(batch.getTransformMatrix());
    renderer.translate(getX(), getY(), 0);

    if (isLight) {
        if (!isPressed)
            renderer.begin(ShapeType.Line);
        else
            renderer.begin(ShapeType.Filled);
    } else {
        if (isPressed)
            renderer.begin(ShapeType.Line);
        else
            renderer.begin(ShapeType.Filled);
    }

    renderer.setColor(Color.BLACK);
    renderer.rect(0, 0, getWidth(), getHeight());
    renderer.end();

    batch.begin();

}

From source file:com.o2d.pkayjava.editor.plugins.ninepatch.EditingZone.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    Rectangle scissors = new Rectangle();
    Rectangle clipBounds = new Rectangle(getX(), getY(), getWidth(), getHeight());
    ScissorStack.calculateScissors(getStage().getCamera(), batch.getTransformMatrix(), clipBounds, scissors);
    ScissorStack.pushScissors(scissors);

    drawBg(batch, parentAlpha);/*w  w  w. j ava  2  s  .  com*/

    batch.draw(texture, getX() + getWidth() / 2 - texture.getRegionWidth() / 2 + shift.x,
            getY() + getHeight() / 2 - texture.getRegionHeight() / 2 + shift.y, texture.getRegionWidth() / 2f,
            texture.getRegionHeight() / 2f, texture.getRegionWidth(), texture.getRegionHeight(), currZoom,
            currZoom, 0);

    drawSplits(batch, parentAlpha);

    batch.flush();
    ScissorStack.popScissors();
}

From source file:com.o2d.pkayjava.editor.plugins.ninepatch.EditingZone.java

License:Apache License

public void drawBg(Batch batch, float parentAlpha) {
    batch.end();//from   w w  w  .  jav a 2 s . com
    Gdx.gl.glLineWidth(1.0f);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    shapeRenderer.setProjectionMatrix(getStage().getCamera().combined);
    Matrix4 matrix = batch.getTransformMatrix();
    shapeRenderer.setTransformMatrix(matrix);

    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    BG.a = parentAlpha;
    shapeRenderer.setColor(BG);
    shapeRenderer.rect(getX(), getY(), getWidth(), getHeight());
    shapeRenderer.end();

    Gdx.gl.glDisable(GL20.GL_BLEND);
    batch.begin();
    batch.setColor(Color.WHITE.r, Color.WHITE.g, Color.WHITE.b, Color.WHITE.a * parentAlpha);
}

From source file:com.o2d.pkayjava.editor.plugins.ninepatch.EditingZone.java

License:Apache License

public void drawSplits(Batch batch, float parentAlpha) {
    batch.end();/*from  ww w  .j a  va 2s.  co  m*/
    Gdx.gl.glLineWidth(1.0f);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    shapeRenderer.setProjectionMatrix(getStage().getCamera().combined);
    Matrix4 matrix = batch.getTransformMatrix();
    shapeRenderer.setTransformMatrix(matrix);

    shapeRenderer.begin(ShapeRenderer.ShapeType.Line);

    // left, right, top , bottom
    Color guideColor = new Color(GUIDE_COLOR);
    guideColor.a *= parentAlpha;
    Color overColor = new Color(OVER_GUIDE_COLOR);
    overColor.a *= parentAlpha;

    splitPositions[0] = shift.x + getWidth() / 2f + (-texture.getRegionWidth() / 2f + splits[0]) * currZoom;
    splitPositions[1] = shift.x + getWidth() / 2f + (texture.getRegionWidth() / 2f - splits[1]) * currZoom;
    splitPositions[2] = shift.y + getHeight() / 2f + (texture.getRegionHeight() / 2 - splits[2]) * currZoom;
    splitPositions[3] = shift.y + getHeight() / 2f + (-texture.getRegionHeight() / 2 + splits[3]) * currZoom;

    if (mouseOverSplit == 0)
        shapeRenderer.setColor(overColor);
    else
        shapeRenderer.setColor(guideColor);
    shapeRenderer.line(getX() + splitPositions[0], getY(), getX() + splitPositions[0], getY() + getHeight());

    if (mouseOverSplit == 1)
        shapeRenderer.setColor(overColor);
    else
        shapeRenderer.setColor(guideColor);
    shapeRenderer.line(getX() + splitPositions[1], getY(), getX() + splitPositions[1], getY() + getHeight());

    if (mouseOverSplit == 2)
        shapeRenderer.setColor(overColor);
    else
        shapeRenderer.setColor(guideColor);
    shapeRenderer.line(getX(), getY() + splitPositions[2], getX() + getWidth(), getY() + splitPositions[2]);

    if (mouseOverSplit == 3)
        shapeRenderer.setColor(overColor);
    else
        shapeRenderer.setColor(guideColor);
    shapeRenderer.line(getX(), getY() + splitPositions[3], getX() + getWidth(), getY() + splitPositions[3]);

    shapeRenderer.end();
    Gdx.gl.glDisable(GL20.GL_BLEND);
    batch.begin();
    batch.setColor(Color.WHITE.r, Color.WHITE.g, Color.WHITE.b, Color.WHITE.a * parentAlpha);
}

From source file:com.o2d.pkayjava.editor.view.ui.followers.PolygonFollower.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    if (polygonComponent != null && polygonComponent.vertices != null) {
        batch.end();//from  w  w  w  .  ja  va  2 s .  com

        Gdx.gl.glLineWidth(1.7f);
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

        shapeRenderer.setProjectionMatrix(getStage().getCamera().combined);
        Matrix4 matrix = batch.getTransformMatrix();
        matrix.scale(pixelsPerWU / runtimeCamera.zoom, pixelsPerWU / runtimeCamera.zoom, 1f);
        shapeRenderer.setTransformMatrix(matrix);

        drawTriangulatedPolygons();
        drawOutlines();
        drawPoints();

        Gdx.gl.glDisable(GL20.GL_BLEND);

        batch.begin();
    }
}

From source file:com.ray3k.skincomposer.GradientDrawable.java

License:Open Source License

@Override
public void draw(Batch batch, float x, float y, float width, float height) {
    float[] alphas = { col1.a, col2.a, col3.a, col4.a };
    col1.a = batch.getColor().a * col1.a;
    col2.a = batch.getColor().a * col2.a;
    col3.a = batch.getColor().a * col3.a;
    col4.a = batch.getColor().a * col4.a;

    g.begin(ShapeRenderer.ShapeType.Filled);
    g.setProjectionMatrix(batch.getProjectionMatrix());
    g.setTransformMatrix(batch.getTransformMatrix());
    batch.end();//from  w w w  .  j  av  a  2s  .c o m
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    g.rect(x + borderLeft, y + borderBottom, width - borderLeft - borderRight,
            height - borderBottom - borderTop, col1, col2, col3, col4);
    g.end();
    Gdx.gl.glDisable(GL20.GL_BLEND);
    batch.begin();

    col1.a = alphas[0];
    col2.a = alphas[1];
    col3.a = alphas[2];
    col4.a = alphas[3];
}

From source file:com.trgk.touchwave.tgengine.ui.TGText.java

License:Open Source License

@Override
public void draw(Batch batch, float parentAlpha) {
    Matrix4 oldTransform = new Matrix4(batch.getTransformMatrix());
    Affine2 localTransform = new Affine2();
    localTransform.setToTrnScl(getX() + getOriginX(), getY() + getOriginY(), getScaleX(), getScaleY());
    localTransform.translate(-getOriginX(), -getOriginY());
    localTransform.scale(1f / TGResources.baseFontSize, 1f / TGResources.baseFontSize);

    Matrix4 localTransformMatrix = new Matrix4();
    localTransformMatrix.set(localTransform);

    Matrix4 newTransform = new Matrix4(oldTransform);
    newTransform.mul(localTransformMatrix);
    batch.setTransformMatrix(newTransform);

    Color alphaMultipliedColor = new Color(getColor());
    alphaMultipliedColor.a *= parentAlpha;
    drawCache.tint(alphaMultipliedColor);
    drawCache.draw(batch);/*from w w  w  . jav a 2s . c  o  m*/

    batch.setTransformMatrix(oldTransform);
}