85 lines
2.6 KiB
Java
85 lines
2.6 KiB
Java
/*
|
|
* Forge Mod Loader
|
|
* Copyright (c) 2012-2014 cpw.
|
|
* All rights reserved. This program and the accompanying materials
|
|
* are made available under the terms of the GNU Lesser Public License v2.1
|
|
* which accompanies this distribution, and is available at
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
*
|
|
* Contributors (this class):
|
|
* bspkrs - implementation
|
|
*/
|
|
|
|
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;
|
|
}
|
|
}
|