/* * Minecraft Forge * Copyright (c) 2016. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation version 2.1 * of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ package net.minecraftforge.fml.client.config; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; /** * This class provides a checkbox style control. * * @author bspkrs */ public class GuiCheckBox extends GuiButton { private boolean isChecked; private int boxWidth; public GuiCheckBox(int id, int xPos, int yPos, String displayString, boolean isChecked) { super(id, xPos, yPos, displayString); this.isChecked = isChecked; this.boxWidth = 11; this.height = 11; this.width = this.boxWidth + 2 + Minecraft.getMinecraft().fontRendererObj.getStringWidth(displayString); } @Override public void drawButton(Minecraft mc, int mouseX, int mouseY) { if (this.visible) { this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.boxWidth && mouseY < this.yPosition + this.height; GuiUtils.drawContinuousTexturedBox(BUTTON_TEXTURES, this.xPosition, this.yPosition, 0, 46, this.boxWidth, this.height, 200, 20, 2, 3, 2, 2, this.zLevel); this.mouseDragged(mc, mouseX, mouseY); int color = 14737632; if (packedFGColour != 0) { color = packedFGColour; } else if (!this.enabled) { color = 10526880; } if (this.isChecked) this.drawCenteredString(mc.fontRendererObj, "x", this.xPosition + this.boxWidth / 2 + 1, this.yPosition + 1, 14737632); this.drawString(mc.fontRendererObj, displayString, xPosition + this.boxWidth + 2, yPosition + 2, color); } } @Override public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) { if (this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height) { this.isChecked = !this.isChecked; return true; } return false; } public boolean isChecked() { return this.isChecked; } public void setIsChecked(boolean isChecked) { this.isChecked = isChecked; } }