001package net.minecraft.client.gui;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import net.minecraft.client.renderer.Tessellator;
006import net.minecraft.util.Icon;
007import org.lwjgl.opengl.GL11;
008
009@SideOnly(Side.CLIENT)
010public class Gui
011{
012    protected float zLevel = 0.0F;
013
014    protected void drawHorizontalLine(int par1, int par2, int par3, int par4)
015    {
016        if (par2 < par1)
017        {
018            int i1 = par1;
019            par1 = par2;
020            par2 = i1;
021        }
022
023        drawRect(par1, par3, par2 + 1, par3 + 1, par4);
024    }
025
026    protected void drawVerticalLine(int par1, int par2, int par3, int par4)
027    {
028        if (par3 < par2)
029        {
030            int i1 = par2;
031            par2 = par3;
032            par3 = i1;
033        }
034
035        drawRect(par1, par2 + 1, par1 + 1, par3, par4);
036    }
037
038    /**
039     * Draws a solid color rectangle with the specified coordinates and color. Args: x1, y1, x2, y2, color
040     */
041    public static void drawRect(int par0, int par1, int par2, int par3, int par4)
042    {
043        int j1;
044
045        if (par0 < par2)
046        {
047            j1 = par0;
048            par0 = par2;
049            par2 = j1;
050        }
051
052        if (par1 < par3)
053        {
054            j1 = par1;
055            par1 = par3;
056            par3 = j1;
057        }
058
059        float f = (float)(par4 >> 24 & 255) / 255.0F;
060        float f1 = (float)(par4 >> 16 & 255) / 255.0F;
061        float f2 = (float)(par4 >> 8 & 255) / 255.0F;
062        float f3 = (float)(par4 & 255) / 255.0F;
063        Tessellator tessellator = Tessellator.instance;
064        GL11.glEnable(GL11.GL_BLEND);
065        GL11.glDisable(GL11.GL_TEXTURE_2D);
066        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
067        GL11.glColor4f(f1, f2, f3, f);
068        tessellator.startDrawingQuads();
069        tessellator.addVertex((double)par0, (double)par3, 0.0D);
070        tessellator.addVertex((double)par2, (double)par3, 0.0D);
071        tessellator.addVertex((double)par2, (double)par1, 0.0D);
072        tessellator.addVertex((double)par0, (double)par1, 0.0D);
073        tessellator.draw();
074        GL11.glEnable(GL11.GL_TEXTURE_2D);
075        GL11.glDisable(GL11.GL_BLEND);
076    }
077
078    /**
079     * Draws a rectangle with a vertical gradient between the specified colors.
080     */
081    protected void drawGradientRect(int par1, int par2, int par3, int par4, int par5, int par6)
082    {
083        float f = (float)(par5 >> 24 & 255) / 255.0F;
084        float f1 = (float)(par5 >> 16 & 255) / 255.0F;
085        float f2 = (float)(par5 >> 8 & 255) / 255.0F;
086        float f3 = (float)(par5 & 255) / 255.0F;
087        float f4 = (float)(par6 >> 24 & 255) / 255.0F;
088        float f5 = (float)(par6 >> 16 & 255) / 255.0F;
089        float f6 = (float)(par6 >> 8 & 255) / 255.0F;
090        float f7 = (float)(par6 & 255) / 255.0F;
091        GL11.glDisable(GL11.GL_TEXTURE_2D);
092        GL11.glEnable(GL11.GL_BLEND);
093        GL11.glDisable(GL11.GL_ALPHA_TEST);
094        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
095        GL11.glShadeModel(GL11.GL_SMOOTH);
096        Tessellator tessellator = Tessellator.instance;
097        tessellator.startDrawingQuads();
098        tessellator.setColorRGBA_F(f1, f2, f3, f);
099        tessellator.addVertex((double)par3, (double)par2, (double)this.zLevel);
100        tessellator.addVertex((double)par1, (double)par2, (double)this.zLevel);
101        tessellator.setColorRGBA_F(f5, f6, f7, f4);
102        tessellator.addVertex((double)par1, (double)par4, (double)this.zLevel);
103        tessellator.addVertex((double)par3, (double)par4, (double)this.zLevel);
104        tessellator.draw();
105        GL11.glShadeModel(GL11.GL_FLAT);
106        GL11.glDisable(GL11.GL_BLEND);
107        GL11.glEnable(GL11.GL_ALPHA_TEST);
108        GL11.glEnable(GL11.GL_TEXTURE_2D);
109    }
110
111    /**
112     * Renders the specified text to the screen, center-aligned.
113     */
114    public void drawCenteredString(FontRenderer par1FontRenderer, String par2Str, int par3, int par4, int par5)
115    {
116        par1FontRenderer.drawStringWithShadow(par2Str, par3 - par1FontRenderer.getStringWidth(par2Str) / 2, par4, par5);
117    }
118
119    /**
120     * Renders the specified text to the screen.
121     */
122    public void drawString(FontRenderer par1FontRenderer, String par2Str, int par3, int par4, int par5)
123    {
124        par1FontRenderer.drawStringWithShadow(par2Str, par3, par4, par5);
125    }
126
127    /**
128     * Draws a textured rectangle at the stored z-value. Args: x, y, u, v, width, height
129     */
130    public void drawTexturedModalRect(int par1, int par2, int par3, int par4, int par5, int par6)
131    {
132        float f = 0.00390625F;
133        float f1 = 0.00390625F;
134        Tessellator tessellator = Tessellator.instance;
135        tessellator.startDrawingQuads();
136        tessellator.addVertexWithUV((double)(par1 + 0), (double)(par2 + par6), (double)this.zLevel, (double)((float)(par3 + 0) * f), (double)((float)(par4 + par6) * f1));
137        tessellator.addVertexWithUV((double)(par1 + par5), (double)(par2 + par6), (double)this.zLevel, (double)((float)(par3 + par5) * f), (double)((float)(par4 + par6) * f1));
138        tessellator.addVertexWithUV((double)(par1 + par5), (double)(par2 + 0), (double)this.zLevel, (double)((float)(par3 + par5) * f), (double)((float)(par4 + 0) * f1));
139        tessellator.addVertexWithUV((double)(par1 + 0), (double)(par2 + 0), (double)this.zLevel, (double)((float)(par3 + 0) * f), (double)((float)(par4 + 0) * f1));
140        tessellator.draw();
141    }
142
143    public void func_94065_a(int par1, int par2, Icon par3Icon, int par4, int par5)
144    {
145        Tessellator tessellator = Tessellator.instance;
146        tessellator.startDrawingQuads();
147        tessellator.addVertexWithUV((double)(par1 + 0), (double)(par2 + par5), (double)this.zLevel, (double)par3Icon.func_94209_e(), (double)par3Icon.func_94210_h());
148        tessellator.addVertexWithUV((double)(par1 + par4), (double)(par2 + par5), (double)this.zLevel, (double)par3Icon.func_94212_f(), (double)par3Icon.func_94210_h());
149        tessellator.addVertexWithUV((double)(par1 + par4), (double)(par2 + 0), (double)this.zLevel, (double)par3Icon.func_94212_f(), (double)par3Icon.func_94206_g());
150        tessellator.addVertexWithUV((double)(par1 + 0), (double)(par2 + 0), (double)this.zLevel, (double)par3Icon.func_94209_e(), (double)par3Icon.func_94206_g());
151        tessellator.draw();
152    }
153}