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 com.lucasdnd.ags.system.ResourceLoader; public class CheckBox extends Button { String text; boolean selected; final float marginLeft = 12f; final float padding = 32f; final float ringRadius = 16f; final float circleRadius = 16f; public CheckBox(String text) throws SlickException { super(null, 0f, 0f); this.text = text; width = 42f; height = 26f; } public CheckBox(String text, boolean enabled) throws SlickException { this(text); this.isEnabled = enabled; } public void update(boolean leftMouseClicked, int mouseX, int mouseY) throws SlickException { if (this.gotLeftClicked(leftMouseClicked, mouseX, mouseY) && isEnabled) { selected = !selected; } } @Override public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException { if (visible) { if (isEnabled) { g.setColor(Color.black); ResourceLoader.getInstance().tinyLightGrayFont.drawString(xPos + marginLeft + padding + 1f, yPos + 1f, text); ResourceLoader.getInstance().tinyBlackFont.drawString(xPos + marginLeft + padding, yPos, text); } else { g.setColor(Color.gray); ResourceLoader.getInstance().tinyLightGrayFont.drawString(xPos + marginLeft + padding + 1f, yPos + 1f, text); ResourceLoader.getInstance().tinyGrayFont.drawString(xPos + marginLeft + padding, yPos, text); } g.setLineWidth(2f); g.drawRoundRect(xPos + marginLeft, yPos, ringRadius, ringRadius, 2); if (selected) { g.fillRoundRect(xPos + marginLeft, yPos, circleRadius, circleRadius, 2); } } } public String getText() { return text; } public void setText(String text) { this.text = text; } public boolean isSelected() { return selected; } public void setSelected(boolean selected) { this.selected = selected; } }