package speiger.src.coreengine.rendering.gui.renderer;

import speiger.src.coreengine.rendering.guiOld.helper.box.IGuiBox;
import speiger.src.coreengine.rendering.textures.base.ITexture;
import speiger.src.coreengine.rendering.textures.base.UVRect;

public class TexturedRect {
	private static final TexturedRect CACHED = new TexturedRect();
	float minX;
	float minY;
	float maxX;
	float maxY;
	float zLevel;
	int texture;
	float minU;
	float minV;
	float maxU;
	float maxV;
	int color;
	
	public static TexturedRect of() {
		CACHED.reset();
		return CACHED;
	}
	
	public void draw(IUIRenderer renderer) {
		renderer.drawTexturedRect(minX, minY, maxX, maxY, zLevel, texture, minU, minV, maxU, maxV, color);
	}
	
	public TexturedRect area(IGuiBox box) {
		this.minX = box.getMinX();
		this.minY = box.getMinY();
		this.maxX = box.getMaxX();
		this.maxY = box.getMaxY();
		return this;
	}
	
	public TexturedRect area(float minX, float minY, float maxX, float maxY) {
		this.minX = minX;
		this.minY = minY;
		this.maxX = maxX;
		this.maxY = maxY;
		return this;
	}
	
	public TexturedRect z(float zLevel) {
		this.zLevel = zLevel;
		return this;
	}
	
	public TexturedRect tex(ITexture texture) {
		this.texture = texture.id();
		return this;
	}
	
	public TexturedRect tex(int texture) {
		this.texture = texture;
		return this;
	}
	
	public TexturedRect color(int color) {
		this.color = color;
		return this;
	}
	
	public TexturedRect uv() {
		this.minU = 0F;
		this.minV = 0F;
		this.maxU = 1F;
		this.maxV = 1F;
		return this;
	}
	
	public TexturedRect uv(ITexture texture) {
		this.minU = texture.minU();
		this.minV = texture.minV();
		this.maxU = texture.maxU();
		this.maxV = texture.maxV();
		return this;
	}
	
	public TexturedRect uv(UVRect rect) {
		this.minU = rect.minU();
		this.minV = rect.minV();
		this.maxU = rect.maxU();
		this.maxV = rect.maxV();
		return this;
	}
	
	public TexturedRect uv(float minU, float minV, float maxU, float maxV) {
		this.minU = minU;
		this.minV = minV;
		this.maxU = maxU;
		this.maxV = maxV;
		return this;
	}
	
	public void reset() {
		minX = 0;
		minY = 0;
		maxX = 0;
		maxY = 0;
		zLevel = 0;
		texture = 0;
		minU = 0F;
		minV = 0F;
		maxU = 1F;
		maxV = 1F;
		color = -1;
	}
}