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

import speiger.src.coreengine.math.color.ColorUtils;
import speiger.src.coreengine.rendering.guiOld.GuiComponent;
import speiger.src.coreengine.rendering.guiOld.base.IButtonComponent;
import speiger.src.coreengine.rendering.guiOld.components.icon.IIcon;

public class IconButtonComponent extends GuiComponent implements IButtonComponent
{
	IIcon icon;
	int hoverColor;
	
	public IconButtonComponent(int hoverColor, IIcon icon)
	{
		super(0F, 0F, 0F, 0F);
		this.icon = icon;
		this.hoverColor = hoverColor;
		setFlag(FLAG_SUPPORT_BINDING);
	}
	
	public IconButtonComponent(float x, float y, float width, float height, int hoverColor, IIcon icon)
	{
		super(x, y, width, height);
		this.icon = icon;
		this.hoverColor = hoverColor;
		setFlag(FLAG_SUPPORT_BINDING);
	}

	@Override
	public void init()
	{
		
	}
	
	@Override
	protected boolean renderSelf(int mouseX, int mouseY, float particalTicks)
	{
		if(isTopHovered(mouseX, mouseY) && ColorUtils.getAF(hoverColor) > 0)
		{
			getRenderer().drawQuad(getBox(), hoverColor);
		}
		getRenderer().translate(0F, 0F, 0.001F);
		icon.render(getRenderer(), getBox());
		getRenderer().translate(0F, 0F, -0.001F);
		return true;
	}
	
	@Override
	public boolean onClick(int button, int mouseX, int mouseY)
	{
		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;
	}
}
