64 lines
1.4 KiB
Java
64 lines
1.4 KiB
Java
package speiger.src.coreengine.rendering.gui.components;
|
|
|
|
import speiger.src.coreengine.rendering.gui.GuiComponent;
|
|
import speiger.src.coreengine.rendering.gui.base.IButtonComponent;
|
|
import speiger.src.coreengine.rendering.gui.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);
|
|
}
|
|
|
|
public ButtonComponent(float x, float y, float width, float height, String text, int color)
|
|
{
|
|
super(x, y, width, height);
|
|
this.text.setText(text);
|
|
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;
|
|
}
|
|
}
|