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

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

Introduction

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

Prototype

public Color getColor();

Source Link

Usage

From source file:CB_UI.GL_UI.Activitys.ImportAnimation.java

License:Open Source License

public void render(Batch batch) {
    if (drawableBackground != null) {
        back = drawableBackground;/* w w  w.  j  a  v  a  2s  .  c  o m*/
        drawableBackground = null;
    }

    if (back != null) {
        Color c = batch.getColor();

        float a = c.a;
        float r = c.r;
        float g = c.g;
        float b = c.b;

        Color trans = new Color(0, 0.3f, 0, 0.40f);
        batch.setColor(trans);
        back.draw(batch, 0, 0, this.getWidth(), this.getHeight());

        batch.setColor(new Color(r, g, b, a));

    }
}

From source file:CB_UI.GL_UI.Views.FieldNoteViewItem.java

License:Open Source License

@Override
public void render(Batch batch) {
    if (fieldnote == null) {
        // super.render(batch);
        return;/*from w  ww  .j a v  a2s .  c  o  m*/
    }

    Color color = batch.getColor();
    float oldAlpha = color.a;
    float oldRed = color.r;
    float oldGreen = color.g;
    float oldBlue = color.b;

    boolean uploaded = false;
    if (fieldnote.uploaded)
        uploaded = true;

    if (uploaded) {
        color.a = 0.5f;
        color.r = 0.6f;
        color.g = 0.65f;
        color.b = 0.6f;
        batch.setColor(color);
    }

    super.render(batch);
    if (backheader != null) {
        backheader.draw(batch, 0, this.getHeight() - headHeight, this.getWidth(), headHeight);
    } else {
        resetInitial();
    }

    if (uploaded) {
        ivTyp.setColor(color);
        ivCacheType.setColor(color);

        color.a = oldAlpha;
        color.r = oldRed;
        color.g = oldGreen;
        color.b = oldBlue;
        batch.setColor(color);
    }

}

From source file:CB_UI_Base.GL_UI.Controls.Image.java

License:Open Source License

@Override
protected void render(Batch batch) {

    if (imageLoader == null)
        return;/*from  w  w w .j a v  a  2  s.  com*/

    Color altColor = batch.getColor().cpy();
    batch.setColor(mColor);
    try {
        if (!imageLoader.isDrawableNULL()) {
            if (Wait != null) {
                GL.that.removeRenderView(Wait);
                this.removeChild(Wait);
                Wait = null;
            }
            imageLoader.inLoad = false;
            float drawwidth = getWidth();
            float drawHeight = getHeight();
            float drawX = 0;
            float drawY = 0;

            if (imageLoader.getSpriteWidth() > 0 && imageLoader.getSpriteHeight() > 0) {
                float proportionWidth = getWidth() / imageLoader.getSpriteWidth();
                float proportionHeight = getHeight() / imageLoader.getSpriteHeight();

                float proportion = Math.min(proportionWidth, proportionHeight);

                drawwidth = imageLoader.getSpriteWidth() * proportion;
                drawHeight = imageLoader.getSpriteHeight() * proportion;

                switch (hAlignment) {
                case CENTER:
                    drawX = (getWidth() - drawwidth) / 2;
                    break;
                case LEFT:
                    drawX = 0;
                    break;
                case RIGHT:
                    drawX = getWidth() - drawwidth;
                    break;
                case SCROLL_CENTER:
                    drawX = (getWidth() - drawwidth) / 2;
                    break;
                case SCROLL_LEFT:
                    drawX = 0;
                    break;
                case SCROLL_RIGHT:
                    drawX = getWidth() - drawwidth;
                    break;
                default:
                    drawX = (getWidth() - drawwidth) / 2;
                    break;

                }

                drawY = (getHeight() - drawHeight) / 2;
            }

            imageLoader.getDrawable(Gdx.graphics.getDeltaTime()).draw(batch, drawX, drawY, drawwidth,
                    drawHeight);

            if (!isAsRenderViewRegisted.get() && imageLoader.getAnimDelay() > 0) {
                GL.that.addRenderView(this, imageLoader.getAnimDelay());
                isAsRenderViewRegisted.set(true);
            }
        } else if (imageLoader.inLoad & !imageLoader.ImageLoadError) {
            if (Wait == null) {
                CB_RectF animationRec = new CB_RectF(0, 0, this.getWidth(), this.getHeight());
                Wait = new WorkAnimation();
                GL.that.addRenderView(Wait, GL.FRAME_RATE_ACTION);
                this.addChild(Wait);
            }

            GL.that.renderOnce();
        } else if (imageLoader.ImageLoadError) {
            if (Wait != null) {
                this.removeChild(Wait);

                //set error image
                this.setSprite(new Sprite(Sprites.getSprite(IconName.disabled.name())), false);

            }

            GL.that.renderOnce();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    batch.setColor(altColor);

    //Draw Debug Rec
    //   if (DebugSprite != null) {
    //       batch.flush();
    //       DebugSprite.draw(batch);
    //
    //   } else {
    //       writeDebug();
    //   }

}

From source file:CB_UI_Base.GL_UI.Controls.List.Scrollbar.java

License:Open Source License

@Override
public void render(Batch batch) {
    // Wenn Liste lnger als Clintbereich zeige Slider
    if (ListView.isDragable()) {
        if (mPushSliderFader.isVisible() || mSliderFader.isVisible() || mSliderAlwaysVisible) {
            Color color = batch.getColor();// get current Color, you can't modify directly
            float oldAlpha = color.a; // save its alpha

            if (Slider == null || SliderPushed == null) {
                LoadSliderImagesNew();/*from  ww w .  j ava 2 s . c om*/
            }

            // Draw Slider
            CalcSliderPos();

            mPushSliderAlpha = mPushSliderFader.isVisible() ? mPushSliderFader.getValue() : 0;

            if (mSliderAlwaysVisible) {
                mSliderAlpha = 1f;
            } else {
                mSliderAlpha = mSliderFader.isVisible() ? mSliderFader.getValue() : 0;
            }

            color.a = oldAlpha * mPushSliderAlpha;
            batch.setColor(color); // set it
            SliderPushed.draw(batch, SliderPuchRec.getX(), SliderPuchRec.getY(), SliderPuchRec.getWidth(),
                    SliderPuchRec.getHeight());

            color.a = oldAlpha * mSliderAlpha;
            batch.setColor(color); // set it
            Slider.draw(batch, SliderRec.getX(), SliderRec.getY(), SliderRec.getWidth(), SliderRec.getHeight());

            // Set it back to orginial alpha when you're done with your alpha manipulation
            color.a = oldAlpha;
            batch.setColor(color);
        }
    }
}

From source file:CB_UI_Base.GL_UI.Controls.MultiToggleButton.java

License:Open Source License

@Override
protected void render(Batch batch) {
    super.render(batch); // draw Button with Txt

    // Draw LED/*  www.j a va 2s .c o  m*/
    if (aktState != null) {
        if (led == null) {
            Sprite sprite = Sprites.ToggleBtn.get(2);
            int patch = (int) ((sprite.getWidth() / 2) - 5);
            led = new NinePatchDrawable(new NinePatch(sprite, patch, patch, 1, 1));
        }

        float A = 0, R = 0, G = 0, B = 0; // Farbwerte der batch um diese wieder einzustellen, wenn ein ColorFilter angewandt wurde!

        Color c = batch.getColor();
        A = c.a;
        R = c.r;
        G = c.g;
        B = c.b;

        GL.setBatchColor(aktState.color);

        if (led != null)
            led.draw(batch, 0, 0, getWidth(), getHeight());

        batch.setColor(R, G, B, A);
    }

}

From source file:CB_UI_Base.GL_UI.GL_View_Base.java

License:Open Source License

/**
 * Die renderChilds() Methode wird vom GL_Listener bei jedem Render-Vorgang aufgerufen.
 * Hier wird dann zuerst die render() Methode dieser View aufgerufen.
 * Danach werden alle Childs iteriert und deren renderChilds() Methode aufgerufen, wenn die View sichtbar ist (Visibility).
 *
 * @param batch//  ww  w. j  av  a  2  s. c om
 */
public void renderChilds(final Batch batch, ParentInfo parentInfo) {
    if (myParentInfo == null)
        return;

    if (this.isDisposed)
        return;

    if (thisInvalidate) {
        myParentInfo.setParentInfo(parentInfo);
        CalcMyInfoForChild();
    }

    if (!withoutScissor) {
        if (intersectRec == null || intersectRec.getHeight() + 1 < 0 || intersectRec.getWidth() + 1 < 0)
            return; // hier gibt es nichts zu rendern
        if (!disableScissor)
            Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
        Gdx.gl.glScissor((int) intersectRec.getX(), (int) intersectRec.getY(),
                (int) intersectRec.getWidth() + 1, (int) intersectRec.getHeight() + 1);
    }

    float A = 0, R = 0, G = 0, B = 0; // Farbwerte der batch um diese wieder einzustellen, wenn ein ColorFilter angewandt wurde!

    boolean ColorFilterSeted = false; // Wir benutzen hier dieses Boolean um am ende dieser Methode zu entscheiden, ob wir die alte
    // Farbe des Batches wieder herstellen mssen. Wir verlassen uns hier nicht darauf, das
    // mColorFilter!= null ist, da dies in der zwichenzeit passiert sein kann.

    // Set Colorfilter ?
    if (mColorFilter != null) {
        ColorFilterSeted = true;
        // zuerst alte Farbe abspeichern, um sie Wieder Herstellen zu knnen
        // hier muss jeder Wert einzeln abgespeichert werden, da bei getColor()
        // nur eine Referenz zurck gegeben wird
        Color c = batch.getColor();
        A = c.a;
        R = c.r;
        G = c.g;
        B = c.b;

        batch.setColor(mColorFilter);
    }

    // first Draw Background?

    if (drawableBackground != null) {
        drawableBackground.draw(batch, 0, 0, getWidth(), getHeight());
    }

    // set rotation
    boolean isRotated = false;

    if (mRotate != 0 || mScale != 1) {
        isRotated = true;

        rotateMatrix.idt();
        rotateMatrix.translate(mOriginX, mOriginY, 0);
        rotateMatrix.rotate(0, 0, 1, mRotate);
        rotateMatrix.scale(mScale, mScale, 1);
        rotateMatrix.translate(-mOriginX, -mOriginY, 0);

        batch.setTransformMatrix(rotateMatrix);
    }

    try {
        this.render(batch);
    } catch (IllegalStateException e) {
        e.printStackTrace();
        // reset Colorfilter ?
        if (ColorFilterSeted) {
            // alte abgespeicherte Farbe des Batches wieder herstellen!
            batch.setColor(R, G, B, A);
        }
        return;
    }

    // reverse rotation
    if (isRotated) {
        rotateMatrix.idt();
        // rotateMatrix.rotate(0, 0, 1, 0);
        // rotateMatrix.scale(1, 1, 1);

        batch.setTransformMatrix(rotateMatrix);
    }

    if (childs != null && childs.size() > 0) {
        for (int i = 0, n = childs.size(); i < n; i++) {

            if (i >= childs.size()) {
                break; // ConcurrentModificationException
            }

            // alle renderChilds() der in dieser GL_View_Base
            // enthaltenen Childs auf rufen.

            try {
                GL_View_Base view = childs.get(i);
                // hier nicht view.render(batch) aufrufen, da sonnst die in der
                // view enthaldenen Childs nicht aufgerufen werden.
                try {
                    if (view != null && !view.isDisposed() && view.isVisible()) {
                        synchronized (view) {
                            if (childsInvalidate)
                                view.invalidate();

                            getMyInfoForChild().setParentInfo(myParentInfo);
                            getMyInfoForChild().setWorldDrawRec(intersectRec);

                            getMyInfoForChild().add(view.getX(), view.getY());

                            batch.setProjectionMatrix(getMyInfoForChild().Matrix());
                            nDepthCounter++;

                            view.renderChilds(batch, getMyInfoForChild());
                            nDepthCounter--;
                        }
                    } else {
                        if (view != null && view.isDisposed()) {
                            // Remove disposedView from child list
                            this.removeChild(view);
                        }
                    }
                } catch (java.lang.IllegalStateException e) {
                    if (view != null && view.isDisposed()) {
                        // Remove disposedView from child list
                        this.removeChild(view);
                    }
                }

            } catch (java.util.NoSuchElementException e) {
                break; // da die Liste nicht mehr gltig ist, brechen wir hier den Iterator ab
            } catch (java.util.ConcurrentModificationException e) {
                break; // da die Liste nicht mehr gltig ist, brechen wir hier den Iterator ab
            } catch (java.lang.IndexOutOfBoundsException e) {
                break; // da die Liste nicht mehr gltig ist, brechen wir hier den Iterator ab
            }
        }
        childsInvalidate = false;
    }

    // Draw Debug REC
    if (debug) {

        if (DebugSprite != null) {
            batch.flush();
            DebugSprite.draw(batch);

        }

    }

    // reset Colorfilter ?
    if (ColorFilterSeted) {
        // alte abgespeicherte Farbe des Batches wieder herstellen!
        batch.setColor(R, G, B, A);
    }

}

From source file:CB_UI_Base.graphics.PolygonDrawable.java

License:Open Source License

@Override
public boolean draw(Batch batch, float x, float y, float width, float height, float rotate) {
    synchronized (isDisposed) {

        if (isDisposed.get())
            return true;

        if (po == null) {

            if (this.PAINT.getBitmapShader() == null) {
                if (texReg == null)
                    createTexRegFromPixMap();
                po = new PolygonRegion(texReg, VERTICES, TRIANGLES);
            } else {
                Texture inputTex = this.PAINT.getBitmapShader().getTexture();
                if (inputTex != null) {
                    inputTex.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
                    po = new PolygonRegion(new TextureRegion(inputTex, (int) this.WIDTH, (int) this.HEIGHT),
                            VERTICES, TRIANGLES);
                }//from   ww w.  ja v a 2s. c o  m
            }

        }

        Color c = batch.getColor();
        float a = c.a;
        float r = c.r;
        float g = c.g;
        float b = c.b;

        if (po == null)
            return true;

        if (this.PAINT.getBitmapShader() == null) {
            GL.setBatchColor(PAINT.getGlColor());
        } else {
            batch.setColor(new Color(Color.WHITE));
        }
        batch.flush();
        try {
            ((PolygonSpriteBatch) batch).draw(po, x, y, width, height);
        } catch (Exception e) {
            e.printStackTrace();
        }
        batch.flush();
        // reset color
        batch.setColor(r, g, b, a);
    }
    return true;
}

From source file:com.agateau.pixelwheels.racescreen.Helicopter.java

License:Open Source License

@Override
public void draw(Batch batch, ZLevel zLevel) {
    if (zLevel == ZLevel.SHADOWS) {
        Color old = batch.getColor();
        batch.setColor(0, 0, 0, SHADOW_ALPHA);
        float offset = SHADOW_OFFSET * Constants.UNIT_FOR_PIXEL;
        drawFrameBuffer(batch, offset);//ww  w. j av  a 2 s . c  o m
        batch.setColor(old);
    } else if (zLevel == ZLevel.FLYING) {
        drawFrameBuffer(batch, 0);
    }
}

From source file:com.agateau.pixelwheels.racescreen.HudButton.java

License:Open Source License

@Override
public void draw(Batch batch, float alpha) {
    Color color = batch.getColor();
    float oldA = color.a;
    color.a = alpha * (mEnabled ? HudButton.BUTTON_OPACITY : HudButton.DISABLED_BUTTON_OPACITY);
    batch.setColor(color);/*from  w  w  w .  ja  va  2s .  c  o m*/

    batch.draw(mRegions[isPressed() ? 1 : 0], MathUtils.round(getX()), MathUtils.round(getY()), getWidth(),
            getHeight());

    color.a = oldA;
    batch.setColor(color);
}

From source file:com.agateau.pixelwheels.utils.DrawUtils.java

License:Open Source License

public static float setBatchAlpha(Batch batch, float alpha) {
    Color color = batch.getColor();
    float old = color.a;
    color.a = alpha;/*w w  w  .ja  v  a 2  s  . c  om*/
    batch.setColor(color);
    return old;
}