package com.lucasdnd.ags.ui; import org.newdawn.slick.Color; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; import org.newdawn.slick.SlickException; import org.newdawn.slick.state.StateBasedGame; import org.newdawn.slick.util.FontUtils; import com.lucasdnd.ags.system.ResourceLoader; /** * A button with just text * * @author lucas.tulio * */ public class TextButton extends Button { private String text; private float padding = 8f; public TextButton(String text, float xPos, float yPos, float width, float height) throws SlickException { super(null, xPos, yPos); this.text = text; this.width = width; this.height = height; } @Override public void update(GameContainer container, StateBasedGame game, int delta, boolean leftMouseClicked, boolean leftMouseDown, int mouseX,int mouseY) throws SlickException { super.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY); } @Override public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException { if (visible) { g.setLineWidth(2f); if (isEnabled) { g.setColor(Color.black); } else { g.setColor(Color.lightGray); } g.fillRoundRect(xPos + 2f, yPos + 2f, width, height, 2); g.setColor(Color.white); g.fillRoundRect(xPos, yPos, width, height, 2); if(isEnabled) { FontUtils.drawCenter(ResourceLoader.getInstance().tinyLightGrayFont, text, (int)(xPos + 1f), (int)(yPos + 1f + padding), (int)(width)); FontUtils.drawCenter(ResourceLoader.getInstance().tinyBlackFont, text, (int)(xPos), (int)(yPos + padding), (int)(width)); g.setColor(Color.black); } else { FontUtils.drawCenter(ResourceLoader.getInstance().tinyLightGrayFont, text, (int)(xPos + 1f), (int)(yPos + 1f + padding), (int)(width)); FontUtils.drawCenter(ResourceLoader.getInstance().tinyGrayFont, text, (int)(xPos), (int)(yPos + padding), (int)(width)); g.setColor(Color.lightGray); } g.drawRoundRect(xPos, yPos, width, height, 2); } } public String getText() { return text; } public void setText(String text) { this.text = text; } }