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

import speiger.src.coreengine.math.misc.ColorObject;
import speiger.src.coreengine.rendering.gui.GuiComponent;
import speiger.src.coreengine.rendering.gui.base.IButtonComponent;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constraints;

public class ButtonComponent extends GuiComponent implements IButtonComponent
{
	TextComponent text = new TextComponent();
	ColorObject color;
	
	public ButtonComponent(String text, ColorObject color)
	{
		this(0F, 0F, 0F, 0F, text, color);
	}
	
	public ButtonComponent(float x, float y, float width, float height, String text, ColorObject color)
	{
		super(x, y, width, height);
		this.text.setText(text);
		this.color = color;
		setFlag(FLAG_SUPPORT_BINDING);
	}
	
	@Override
	public void init()
	{
		addChild(text, Constraints.getParentConstrains());
	}
	
	public TextComponent getText()
	{
		return text;
	}
	
	public ButtonComponent setColor(ColorObject 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;
	}
}
