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

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

Introduction

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

Prototype

public void setColor(float r, float g, float b, float a);

Source Link

Usage

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/* w w  w. j a va  2  s  . c  om*/
    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:coder5560.gdxai.SteeringActor.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    Color color = getColor();/* ww w . ja  v a  2s  .  co m*/
    batch.setColor(color.r, color.g, color.b, parentAlpha);
    batch.draw(region, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(),
            getScaleY(), getRotation());
}

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);/* w  ww  . j a v a  2  s.c  om*/
        batch.setColor(old);
    } else if (zLevel == ZLevel.FLYING) {
        drawFrameBuffer(batch, 0);
    }
}

From source file:com.agateau.ui.menu.GridMenuItem.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    if (mRenderer == null) {
        NLog.e("No renderer");
        return;//from  w  w  w  .j a  v a2s  .  c o  m
    }
    if (mItemWidth <= 0 || mItemHeight <= 0) {
        NLog.e("Invalid item size");
        return;
    }

    Color color = getColor();
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);

    float itemSpacing = getItemSpacing();
    float x = 0;
    float y = getHeight() - mItemHeight;

    for (int idx = 0; idx < mItems.size; idx++) {
        T item = mItems.get(idx);
        Rectangle rect = mRenderer.getItemRectangle(mItemWidth, mItemHeight, item);

        FocusIndicator focusIndicator = mFocusIndicators.get(idx);
        focusIndicator.draw(batch, getX() + x + rect.x, getY() + y + rect.y, rect.width, rect.height);

        if (idx == mSelectedIndex) {
            int padding = mMenu.getMenuStyle().focusPadding;
            mStyle.selected.draw(batch, getX() + x + rect.x - padding, getY() + y + rect.y - padding,
                    rect.width + 2 * padding, rect.height + 2 * padding);
        }
        mRenderer.render(batch, getX() + x, getY() + y, mItemWidth, mItemHeight, item);

        if ((idx + 1) % mColumnCount == 0) {
            // New row
            x = 0;
            y -= mItemHeight;
        } else {
            x += mItemWidth + itemSpacing;
        }
    }
}

From source file:com.aia.hichef.ui.n.MyWindow.java

License:Apache License

public void draw(Batch batch, float parentAlpha) {
    keepWithinStage();//from  w w  w.  j  a  v  a2s.c  o m

    if (style.stageBackground != null) {
        Color color = getColor();
        batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
        Stage stage = getStage();
        stageToLocalCoordinates(/* in/out */tmpPosition.set(0, 0));
        stageToLocalCoordinates(/* in/out */tmpSize.set(stage.getWidth(), stage.getHeight()));
        style.stageBackground.draw(batch, getX() + tmpPosition.x, getY() + tmpPosition.y, getX() + tmpSize.x,
                getY() + tmpSize.y);
    }

    super.draw(batch, parentAlpha);
}

From source file:com.apptogo.roperace.custom.MyTouchpad.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();/*  w w w. j  av a  2  s .c o m*/

    Color c = getColor();
    batch.setColor(c.r, c.g, c.b, c.a * parentAlpha);

    float x = getX();
    float y = getY();
    float w = getWidth();
    float h = getHeight();

    final Drawable bg = style.background;
    if (bg != null)
        bg.draw(batch, x, y, w, h);

    final Drawable knob = style.knob;
    if (knob != null) {
        x += knobPosition.x - knob.getMinWidth() / 2f;
        y += knobPosition.y - knob.getMinHeight() / 2f;
        knob.draw(batch, x, y, knob.getMinWidth(), knob.getMinHeight());
    }
}

From source file:com.bagon.matchteam.mtx.scene2d.AbstractActor.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    // For fade out/in effect
    batch.setColor(this.getColor().r, this.getColor().g, this.getColor().b, parentAlpha * this.getColor().a);

    // DRAW TEXTURE REGION (Draw only if set active and not null)
    // ##################################################################
    if (isTextureRegionActive && textureRegion != null) {
        // Draw it due to actors' settings
        batch.draw(textureRegion, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(),
                getScaleX(), getScaleY(), getRotation());
    }//from   w w  w.j a v a  2s  . c o m

    // DRAW ANIMATION (Draw only if set active and not null)
    // ##################################################################
    if (isAnimationActive && animation != null) {
        // Get frame by frame and animate
        TextureRegion keyFrame = animation.getKeyFrame(stateTime, isAnimationLooping);

        // Draw it due to actors' settings
        batch.draw(keyFrame, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(),
                getScaleY(), getRotation());

        if (animation.isAnimationFinished(stateTime)) {
            if (killAllAnimations) {
                isAnimationActive = false;
            }
        }
    }

    // DRAW ANIMATION MOMENTARY (Draw only if set active and not null)
    // ##################################################################
    if (isAnimationMomentaryActive && animationMomentary != null) {
        if (animationMomentary.isAnimationFinished(stateTime)) {
            if (!killAllAnimations) {
                isAnimationActive = true;
                isAnimationMomentaryActive = false;
                isAnimationMomentaryFinished = true;
                startTime = 0;
            } else {
                isAnimationActive = false;
                isAnimationMomentaryActive = false;
                isAnimationMomentaryFinished = true;
                startTime = 0;
            }
        }

        if (isAnimationMomentaryActive) {
            // Get frame by frame and animate
            TextureRegion keyFrame = animationMomentary.getKeyFrame(stateTime, false);

            // Draw it due to actors' settings
            batch.draw(keyFrame, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(),
                    getScaleX(), getScaleY(), getRotation());
        }
    }

    // PARTICLE
    // #################################################################
    if (isParticleEffectActive) {
        particleEffect.draw(batch, Gdx.graphics.getDeltaTime());
        particleEffect.setPosition(getX() + particlePosX, getY() + particlePosY);
    }
}

From source file:com.bagon.matchteam.mtx.scene2d.AbstractActorLight.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    // For fade out/in effect
    batch.setColor(this.getColor().r, this.getColor().g, this.getColor().b, parentAlpha * this.getColor().a);

    // DRAW TEXTURE REGION (Draw only if set active and not null)
    // ##################################################################
    if (isTextureRegionActive && textureRegion != null) {
        // Draw it due to actors' settings
        batch.draw(textureRegion, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(),
                getScaleX(), getScaleY(), getRotation());
    }/* www .j  a v  a2s  .c  om*/
}

From source file:com.bladecoder.engineeditor.ui.components.CustomList.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();/*from   w  w  w.  j a  v  a  2  s  . co m*/

    Color color = getColor();
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);

    float x = getX(), y = getY(), width = getWidth(), height = getHeight();
    float itemY = height;

    Drawable background = style.background;
    if (background != null) {
        background.draw(batch, x, y, width, height);
        float leftWidth = background.getLeftWidth();
        x += leftWidth;
        itemY -= background.getTopHeight();
        width -= leftWidth + background.getRightWidth();
    }

    for (int i = 0; i < items.size; i++) {
        if (cullingArea == null || (itemY - cellRenderer.getItemHeight() <= cullingArea.y + cullingArea.height
                && itemY >= cullingArea.y)) {
            T item = items.get(i);
            boolean selected = selection.contains(item);

            cellRenderer.draw(batch, parentAlpha, item, selected, x, y + itemY, width,
                    cellRenderer.getItemHeight());

        } else if (itemY < cullingArea.y) {
            break;
        }
        itemY -= cellRenderer.getItemHeight();
    }
}

From source file:com.calanti.androidnativekeyboardinputtest.libgdxModified_1_9_3.CalTextField.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    Stage stage = getStage();// w  w w  . j a va2s. co  m
    focused = stage != null && stage.getKeyboardFocus() == this;
    if (!focused)
        keyRepeatTask.cancel();

    final BitmapFont font = style.font;
    final Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor
            : ((focused && style.focusedFontColor != null) ? style.focusedFontColor : style.fontColor);
    final Drawable selection = style.selection;
    final Drawable cursorPatch = style.cursor;
    final Drawable background = (disabled && style.disabledBackground != null) ? style.disabledBackground
            : ((focused && style.focusedBackground != null) ? style.focusedBackground : style.background);

    Color color = getColor();
    float x = getX();
    float y = getY();
    float width = getWidth();
    float height = getHeight();

    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    float bgLeftWidth = 0, bgRightWidth = 0;
    if (background != null) {
        background.draw(batch, x, y, width, height);
        bgLeftWidth = background.getLeftWidth();
        bgRightWidth = background.getRightWidth();
    }

    float textY = getTextY(font, background);
    calculateOffsets();

    if (focused && hasSelection && selection != null) {
        drawSelection(selection, batch, font, x + bgLeftWidth, y + textY);
    }

    float yOffset = font.isFlipped() ? -textHeight : 0;
    if (displayText.length() == 0) {
        if (!focused && messageText != null) {
            if (style.messageFontColor != null) {
                font.setColor(style.messageFontColor.r, style.messageFontColor.g, style.messageFontColor.b,
                        style.messageFontColor.a * color.a * parentAlpha);
            } else
                font.setColor(0.7f, 0.7f, 0.7f, color.a * parentAlpha);
            BitmapFont messageFont = style.messageFont != null ? style.messageFont : font;
            messageFont.draw(batch, messageText, x + bgLeftWidth, y + textY + yOffset, 0, messageText.length(),
                    width - bgLeftWidth - bgRightWidth, textHAlign, false, "...");
        }
    } else {
        font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * color.a * parentAlpha);
        drawText(batch, font, x + bgLeftWidth, y + textY + yOffset);
    }
    if (focused && !disabled) {
        blink();
        if (cursorOn && cursorPatch != null) {
            drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY);
        }
    }
}