Java Code Examples for com.badlogic.gdx.graphics.g2d.Batch#setColor()

The following examples show how to use com.badlogic.gdx.graphics.g2d.Batch#setColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StoreIcon.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override public void draw(Batch batch, float parentAlpha) {
    Color color = getColor();
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    drawable.draw(
        batch,
        (int) (getX() + getWidth() / 2 - drawable.getMinWidth() / 2),
        (int) (getY() + getHeight() / 2 - drawable.getMinHeight() / 2),
        drawable.getMinWidth(),
        drawable.getMinHeight()
    );
    if (highlight != null) {
        highlight.draw(
            batch,
            getX() + getWidth() / 2 - highlight.getMinWidth() / 2,
            getY(),
            highlight.getMinWidth(),
            highlight.getMinHeight()
        );
    }
}
 
Example 2
Source File: AnimationWidget.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
	super.draw(batch, parentAlpha);

	if (renderer == null || ((AnimationRenderer) renderer).getCurrentAnimation() == null)
		return;

	float tmp = batch.getPackedColor();
	batch.setColor(Color.WHITE);

	renderer.update(Gdx.graphics.getDeltaTime());

	RectangleRenderer.draw(batch, getX(), getY(), getWidth(), getHeight(), Color.MAGENTA);

	float scalew = getWidth() / renderer.getWidth();
	float scaleh = getHeight() / renderer.getHeight();
	float scale = scalew > scaleh ? scaleh : scalew;
	renderer.draw((SpriteBatch) batch, getX() + renderer.getWidth() * scale / 2, getY(), scale, scale, 0f, null);
	batch.setPackedColor(tmp);
}
 
Example 3
Source File: Window.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	keepWithinStage();

	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);
}
 
Example 4
Source File: SteeringActor.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	Color color = getColor();
	batch.setColor(color.r, color.g, color.b, parentAlpha);
	batch.draw(region, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(),
		getRotation());
}
 
Example 5
Source File: ParticleActor.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void draw(Batch batch, float parentAlpha) {
    effect.setPosition(getX(), getY());
    Color c = getColor();
    batch.setColor(c.r, c.g, c.b, c.a * parentAlpha);
    effect.draw(batch, Gdx.graphics.getDeltaTime());
    if (effect.isComplete()) {
        ChangeListener.ChangeEvent event = Pools.obtain(ChangeListener.ChangeEvent.class);
        fire(event);
        Pools.free(event);
    }
}
 
Example 6
Source File: BusyBar.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    batch.flush();
    if (clipBegin()) {
        Color c = getColor();
        batch.setColor(c.r, c.g, c.b, c.a * parentAlpha);
        patternDrawable.draw(batch, getX() - shift, getY(), getWidth() + shift, getHeight());
        if (isVisible()) Gdx.graphics.requestRendering();
        batch.flush();
        clipEnd();
    }
}
 
Example 7
Source File: DieInventory.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void draw(Batch batch, float parentAlpha) {
    Color color = getColor();
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    background.draw(
        batch,
        getX(),
        getY(),
        getWidth(),
        getHeight()
    );
    super.draw(batch, parentAlpha);
}
 
Example 8
Source File: SegmentActor.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void draw(Batch batch, float parentAlpha) {
//        batch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE);

        Color c = getColor();
        batch.setColor(c.r, c.g, c.b, c.a * parentAlpha);
        batch.draw(region,
            getX(), getY(),                         //position
            0, region.getRegionHeight() / 2f,       //origins
            len, region.getRegionHeight(),          //size
            1, 1,                                   //scale
            angle                                   //rotation
        );

//        batch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    }
 
Example 9
Source File: DieNet.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void draw(Batch batch, float parentAlpha) {
    validate();
    Color color = getColor();
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);

    back.draw(
        batch,
        getX() + getWidth() / 2 - back.getMinWidth() / 2,
        getY() + getHeight() / 2 - back.getMinHeight() / 2,
        back.getMinWidth(),
        back.getMinHeight()
    );
    super.draw(batch, parentAlpha);
}
 
Example 10
Source File: TutorialUpArrow.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void draw(Batch batch, float parentAlpha) {
    float top = getY() + getHeight();
    float center = getX() + getWidth() / 2;

    batch.setColor(1, 1, 1, parentAlpha * getAlphaForY(top - arrow.getMinHeight() + arrow.getMinHeight() / 2));
    arrow.draw(batch, center - arrow.getMinWidth(), top - arrow.getMinHeight(), arrow.getMinWidth(), arrow.getMinHeight());
    for (float y = top - arrow.getMinHeight() - dot.getMinHeight(); y >= getY(); y -= dot.getMinHeight()) {
        batch.setColor(1, 1, 1, parentAlpha * getAlphaForY(y));
        dot.draw(batch, center - dot.getMinWidth(), y, dot.getMinWidth(), dot.getMinHeight());
    }
}
 
Example 11
Source File: AnimationDrawable.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float x, float y, float width, float height) {
	if (tint != null)
		batch.setColor(tint);

	batch.draw(anim.getKeyFrame(stateTime), x, y, width, height);

	if (tint != null)
		batch.setColor(Color.WHITE);
}
 
Example 12
Source File: CustomList.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
	validate();

	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();
	}
}
 
Example 13
Source File: PatchGrid.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
protected void drawGridNodes(Batch batch, float parentAlpha) {
    if (disabled) return;

    batch.setColor(tmpColor.set(getColor()).mul(1f, 1f, 1f, parentAlpha));

    float width = gridNodeDrawable.getMinWidth();
    float height = gridNodeDrawable.getMinHeight();
    float halfWidth = width * 0.5f;
    float halfHeight = height * 0.5f;
    gridNodeDrawable.draw(batch, getX() + left.getX() - halfWidth, getY() + bottom.getY() - halfHeight, width, height);
    gridNodeDrawable.draw(batch, getX() + right.getX() - halfWidth, getY() + bottom.getY() - halfHeight, width, height);
    gridNodeDrawable.draw(batch, getX() + left.getX() - halfWidth, getY() + top.getY() - halfHeight, width, height);
    gridNodeDrawable.draw(batch, getX() + right.getX() - halfWidth, getY() + top.getY() - halfHeight, width, height);
}
 
Example 14
Source File: ContentGrid.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
    protected void drawAreaGraphics(Batch batch, float parentAlpha) {
        Color color = getColor();
        batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);

//        // Fill outer area
//        contentAreaDrawable.draw(batch, getX(), getY(), left.getX(), getHeight());
//        contentAreaDrawable.draw(batch, getX() + right.getX(), getY(), getWidth() - right.getX(), getHeight());
//        contentAreaDrawable.draw(batch, getX() + left.getX(), getY(), right.getX() - left.getX(), bottom.getY());
//        contentAreaDrawable.draw(batch, getX() + left.getX(), getY() + top.getY(), right.getX() - left.getX(), getHeight() - top.getY());

        // Fill inner area
        contentAreaDrawable.draw(batch, getX() + left.getX(), getY() + bottom.getY(), right.getX() - left.getX(), top.getY() - bottom.getY());
    }
 
Example 15
Source File: ShapeWidget.java    From talos with Apache License 2.0 5 votes vote down vote up
private void drawBg(Batch batch, float parentAlpha) {
    tmpColor.set(0.05f, 0.05f, 0.05f, 1f);
    batch.setColor(tmpColor);
    skin.getDrawable("white").draw(batch, getX(), getY(), getWidth(), getWidth());

    tmpColor.set(0.2f, 0.2f, 0.2f, 1f);
    batch.setColor(tmpColor);
    skin.getDrawable("white").draw(batch, getX()+1, getY()+1, getWidth()-2, getWidth()-2);
}
 
Example 16
Source File: AnimationDrawable.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float x, float y, float originX, float originY, float width, float height,
		float scaleX, float scaleY, float rotation) {

	if (tint != null)
		batch.setColor(tint);

	batch.draw(anim.getKeyFrame(stateTime), x, y, originX, originY, width, height, scaleX, scaleY, rotation);

	if (tint != null)
		batch.setColor(Color.WHITE);
}
 
Example 17
Source File: SimpleListActor.java    From Cubes with MIT License 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
  validate();

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

  float currentY = itemHeight;
  for (T item : items) {
    font.draw(batch, item.toString(), getX(), getY() + currentY);
    currentY += itemHeight;
  }
}
 
Example 18
Source File: Separator.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	Color c = getColor();
	batch.setColor(c.r, c.g, c.b, c.a * parentAlpha);
	style.background.draw(batch, getX(), getY(), getWidth(), getHeight());
}
 
Example 19
Source File: ProgressBar.java    From cocos-ui-libgdx with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    ProgressBarStyle style = this.style;
    final Drawable bg = style.background;
    final Drawable knobBefore = style.progress;

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

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

    if (vertical) {
        bg.draw(batch, x + (int) ((width - bg.getMinWidth()) * 0.5f), y, bg.getMinWidth(), height);

        float progressPosHeight = height - (bg.getTopHeight() + bg.getBottomHeight());
        if (min != max) {
            progressPos = (value - min) / (max - min) * progressPosHeight;
            progressPos = Math.max(0, progressPos);
            progressPos = Math.min(progressPosHeight, progressPos) + bg.getBottomHeight();
        }

        if (knobBefore != null) {
            knobBefore.draw(batch, x + (int) ((width - knobBefore.getMinWidth()) * 0.5f), y, knobBefore.getMinWidth(),
                (int) progressPos);
        }
    } else {
        bg.draw(batch, x, y + (int) ((height - bg.getMinHeight()) * 0.5f), width, bg.getMinHeight());

        float progressPosWidth = width - (bg.getLeftWidth() + bg.getRightWidth());
        if (min != max) {
            progressPos = (value - min) / (max - min) * progressPosWidth;
            progressPos = Math.max(0, progressPos);
            progressPos = Math.min(progressPosWidth, progressPos) + bg.getLeftWidth();
        }

        if (knobBefore != null) {
            knobBefore.draw(batch, x, y + (int) ((height - knobBefore.getMinHeight()) * 0.5f), (int) progressPos,
                knobBefore.getMinHeight());
        }
    }
    super.draw(batch, parentAlpha);
}
 
Example 20
Source File: VisTextField.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	Stage stage = getStage();
	boolean 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;
	Drawable background = (disabled && style.disabledBackground != null) ? style.disabledBackground
			: ((focused && style.focusedBackground != null) ? style.focusedBackground : style.background);

	// vis
	if (!disabled && style.backgroundOver != null && (clickListener.isOver() || focused)) {
		background = style.backgroundOver;
	}

	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 (drawBorder && focused && !disabled) {
		blink();
		if (cursorOn && cursorPatch != null) {
			drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY);
		}
	}

	// vis
	if (isDisabled() == false && inputValid == false && style.errorBorder != null)
		style.errorBorder.draw(batch, getX(), getY(), getWidth(), getHeight());
	else if (focusBorderEnabled && drawBorder && style.focusBorder != null)
		style.focusBorder.draw(batch, getX(), getY(), getWidth(), getHeight());

}