package speiger.src.coreengine.rendering.guiOld.components.icon;

import speiger.src.coreengine.math.color.ColorUtils;
import speiger.src.coreengine.rendering.guiOld.renderer.UIRenderer;
import speiger.src.coreengine.rendering.texturesOld.base.ITexture;

public class TexturedIcon implements IIcon
{
	int color = ColorUtils.WHITE;
	ITexture texture;
	boolean forceBounds = false;
	
	public TexturedIcon(ITexture texture)
	{
		this.texture = texture;
	}
	
	public TexturedIcon(int color, ITexture texture)
	{
		this.color = color;
		this.texture = texture;
	}
	
	public void setTexture(ITexture newTexture)
	{
		if(texture != null)
		{
			texture.deleteTexture();
			texture = null;
		}
		texture = newTexture;
	}
	
	public TexturedIcon forceBounds(boolean value)
	{
		forceBounds = value;
		return this;
	}
	
	@Override
	public void render(UIRenderer render, float minX, float minY, float maxX, float maxY, float scale)
	{
		if(forceBounds)
		{
			float width = texture.getWidth();
			float height = texture.getHeight();
			float ratio = height / width;
			maxY = Math.min(minY + ((maxY - minY) * ratio), maxY);
		}
		render.setActiveTexture(texture).drawTexturedQuad(minX, minY, maxX, maxY, color, texture.getUMin(), texture.getVMin(), texture.getUMax(), texture.getVMax());
	}
	
}
