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

import speiger.src.coreengine.rendering.guiOld.GuiComponent;
import speiger.src.coreengine.rendering.guiOld.base.IButtonComponent;
import speiger.src.coreengine.rendering.guiOld.helper.constrains.Constrains;

public class ButtonComponent extends GuiComponent implements IButtonComponent
{
	TextComponent text = new TextComponent();
	int color;
	
	public ButtonComponent(String text, int color)
	{
		this(0F, 0F, 0F, 0F, text, color, 1F);
	}
	
	public ButtonComponent(String text, int color, float textScale)
	{
		this(0F, 0F, 0F, 0F, text, color, textScale);
	}
	
	public ButtonComponent(float x, float y, float width, float height, String text, int color)
	{
		this(x, y, width, height, text, color, 1F);
	}
	
	public ButtonComponent(float x, float y, float width, float height, String text, int color, float textScale)
	{
		super(x, y, width, height);
		this.text.setText(text).setTextScale(textScale);
		this.color = color;
		setFlag(FLAG_SUPPORT_BINDING);
	}
	
	@Override
	public void init()
	{
		addChild(text, Constrains.parent());
	}
	
	public TextComponent getText()
	{
		return text;
	}
	
	public ButtonComponent setColor(int color)
	{
		this.color = color;
		return this;
	}
	
	@Override
	public boolean renderSelf(int mouseX, int mouseY, float particalTicks)
	{
		float brigthness = getBrightness(mouseX, mouseY);
		getRenderer().setBrightness(brigthness).drawQuad(getBox(), color);
		text.setBrightness(brigthness);
		return true;
	}
	
	@Override
	public void onRelease(int button, int mouseX, int mouseY)
	{
		notifyListeners(LISTENER_USER_ACTION);
	}
	
	@Override
	protected boolean onUserKey()
	{
		notifyListeners(LISTENER_USER_ACTION);
		return true;
	}
}
