Gui .java

net.minecraft.client.gui.Gui (class, 218 lines): members: drawModalRectWithCustomSizedTexture, drawScaledCustomSizeModalRect, drawHorizontalLine, drawRect.

net.minecraft.client.guiclass218 linesclient11.1 KB

API Surface (11)

void drawHorizontalLine(int startX, int endX, int y, int color)
void drawVerticalLine(int x, int startY, int endY, int color)
void drawRect(int left, int top, int right, int bottom, int color)
void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor)
void drawCenteredString(FontRenderer fontRendererIn, String text, int x, int y, int color)
void drawString(FontRenderer fontRendererIn, String text, int x, int y, int color)
void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height)
void drawTexturedModalRect(float xCoord, float yCoord, int minU, int minV, int maxU, int maxV)
void drawTexturedModalRect(int xCoord, int yCoord, TextureAtlasSprite textureSprite, int widthIn, int heightIn)
void drawModalRectWithCustomSizedTexture(int x, int y, float u, float v, int width, int height, float textureWidth, float textureHeight)
void drawScaledCustomSizeModalRect(int x, int y, float u, float v, int uWidth, int vHeight, int width, int height, float tileWidth, float tileHeight)

Fields & Constants (4)

optionsBackground
statIcons
icons
zLevel

String literals (3)

"textures/gui/options_background.png"
"textures/gui/container/stats_icons.png"
"textures/gui/icons.png"

Full Source

Gui.java218 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.gui;
2
3
import net.minecraft.client.renderer.GlStateManager;
4
import net.minecraft.client.renderer.Tessellator;
5
import net.minecraft.client.renderer.WorldRenderer;
6
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
7
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
8
import net.minecraft.util.ResourceLocation;
9
10
public class Gui
11
{
12
    public static final ResourceLocation optionsBackground = new ResourceLocation("textures/gui/options_background.png");
13
    public static final ResourceLocation statIcons = new ResourceLocation("textures/gui/container/stats_icons.png");
14
    public static final ResourceLocation icons = new ResourceLocation("textures/gui/icons.png");
15
    protected float zLevel;
16
17
    /**
18
     * Draw a 1 pixel wide horizontal line. Args: x1, x2, y, color
19
     */
20
    protected void drawHorizontalLine(int startX, int endX, int y, int color)
21
    {
22
        if (endX < startX)
23
        {
24
            int i = startX;
25
            startX = endX;
26
            endX = i;
27
        }
28
29
        drawRect(startX, y, endX + 1, y + 1, color);
30
    }
31
32
    /**
33
     * Draw a 1 pixel wide vertical line. Args : x, y1, y2, color
34
     */
35
    protected void drawVerticalLine(int x, int startY, int endY, int color)
36
    {
37
        if (endY < startY)
38
        {
39
            int i = startY;
40
            startY = endY;
41
            endY = i;
42
        }
43
44
        drawRect(x, startY + 1, x + 1, endY, color);
45
    }
46
47
    /**
48
     * Draws a solid color rectangle with the specified coordinates and color (ARGB format). Args: x1, y1, x2, y2, color
49
     */
50
    public static void drawRect(int left, int top, int right, int bottom, int color)
51
    {
52
        if (left < right)
53
        {
54
            int i = left;
55
            left = right;
56
            right = i;
57
        }
58
59
        if (top < bottom)
60
        {
61
            int j = top;
62
            top = bottom;
63
            bottom = j;
64
        }
65
66
        float f3 = (float)(color >> 24 & 255) / 255.0F;
67
        float f = (float)(color >> 16 & 255) / 255.0F;
68
        float f1 = (float)(color >> 8 & 255) / 255.0F;
69
        float f2 = (float)(color & 255) / 255.0F;
70
        Tessellator tessellator = Tessellator.getInstance();
71
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
72
        GlStateManager.enableBlend();
73
        GlStateManager.disableTexture2D();
74
        GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
75
        GlStateManager.color(f, f1, f2, f3);
76
        worldrenderer.begin(7, DefaultVertexFormats.POSITION);
77
        worldrenderer.pos((double)left, (double)bottom, 0.0D).endVertex();
78
        worldrenderer.pos((double)right, (double)bottom, 0.0D).endVertex();
79
        worldrenderer.pos((double)right, (double)top, 0.0D).endVertex();
80
        worldrenderer.pos((double)left, (double)top, 0.0D).endVertex();
81
        tessellator.draw();
82
        GlStateManager.enableTexture2D();
83
        GlStateManager.disableBlend();
84
    }
85
86
    /**
87
     * Draws a rectangle with a vertical gradient between the specified colors (ARGB format). Args : x1, y1, x2, y2,
88
     * topColor, bottomColor
89
     */
90
    protected void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor)
91
    {
92
        float f = (float)(startColor >> 24 & 255) / 255.0F;
93
        float f1 = (float)(startColor >> 16 & 255) / 255.0F;
94
        float f2 = (float)(startColor >> 8 & 255) / 255.0F;
95
        float f3 = (float)(startColor & 255) / 255.0F;
96
        float f4 = (float)(endColor >> 24 & 255) / 255.0F;
97
        float f5 = (float)(endColor >> 16 & 255) / 255.0F;
98
        float f6 = (float)(endColor >> 8 & 255) / 255.0F;
99
        float f7 = (float)(endColor & 255) / 255.0F;
100
        GlStateManager.disableTexture2D();
101
        GlStateManager.enableBlend();
102
        GlStateManager.disableAlpha();
103
        GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
104
        GlStateManager.shadeModel(7425);
105
        Tessellator tessellator = Tessellator.getInstance();
106
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
107
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
108
        worldrenderer.pos((double)right, (double)top, (double)this.zLevel).color(f1, f2, f3, f).endVertex();
109
        worldrenderer.pos((double)left, (double)top, (double)this.zLevel).color(f1, f2, f3, f).endVertex();
110
        worldrenderer.pos((double)left, (double)bottom, (double)this.zLevel).color(f5, f6, f7, f4).endVertex();
111
        worldrenderer.pos((double)right, (double)bottom, (double)this.zLevel).color(f5, f6, f7, f4).endVertex();
112
        tessellator.draw();
113
        GlStateManager.shadeModel(7424);
114
        GlStateManager.disableBlend();
115
        GlStateManager.enableAlpha();
116
        GlStateManager.enableTexture2D();
117
    }
118
119
    /**
120
     * Renders the specified text to the screen, center-aligned. Args : renderer, string, x, y, color
121
     */
122
    public void drawCenteredString(FontRenderer fontRendererIn, String text, int x, int y, int color)
123
    {
124
        fontRendererIn.drawStringWithShadow(text, (float)(x - fontRendererIn.getStringWidth(text) / 2), (float)y, color);
125
    }
126
127
    /**
128
     * Renders the specified text to the screen. Args : renderer, string, x, y, color
129
     */
130
    public void drawString(FontRenderer fontRendererIn, String text, int x, int y, int color)
131
    {
132
        fontRendererIn.drawStringWithShadow(text, (float)x, (float)y, color);
133
    }
134
135
    /**
136
     * Draws a textured rectangle at the stored z-value. Args: x, y, u, v, width, height
137
     */
138
    public void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height)
139
    {
140
        float f = 0.00390625F;
141
        float f1 = 0.00390625F;
142
        Tessellator tessellator = Tessellator.getInstance();
143
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
144
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
145
        worldrenderer.pos((double)(x + 0), (double)(y + height), (double)this.zLevel).tex((double)((float)(textureX + 0) * f), (double)((float)(textureY + height) * f1)).endVertex();
146
        worldrenderer.pos((double)(x + width), (double)(y + height), (double)this.zLevel).tex((double)((float)(textureX + width) * f), (double)((float)(textureY + height) * f1)).endVertex();
147
        worldrenderer.pos((double)(x + width), (double)(y + 0), (double)this.zLevel).tex((double)((float)(textureX + width) * f), (double)((float)(textureY + 0) * f1)).endVertex();
148
        worldrenderer.pos((double)(x + 0), (double)(y + 0), (double)this.zLevel).tex((double)((float)(textureX + 0) * f), (double)((float)(textureY + 0) * f1)).endVertex();
149
        tessellator.draw();
150
    }
151
152
    /**
153
     * Draws a textured rectangle using the texture currently bound to the TextureManager
154
     */
155
    public void drawTexturedModalRect(float xCoord, float yCoord, int minU, int minV, int maxU, int maxV)
156
    {
157
        float f = 0.00390625F;
158
        float f1 = 0.00390625F;
159
        Tessellator tessellator = Tessellator.getInstance();
160
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
161
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
162
        worldrenderer.pos((double)(xCoord + 0.0F), (double)(yCoord + (float)maxV), (double)this.zLevel).tex((double)((float)(minU + 0) * f), (double)((float)(minV + maxV) * f1)).endVertex();
163
        worldrenderer.pos((double)(xCoord + (float)maxU), (double)(yCoord + (float)maxV), (double)this.zLevel).tex((double)((float)(minU + maxU) * f), (double)((float)(minV + maxV) * f1)).endVertex();
164
        worldrenderer.pos((double)(xCoord + (float)maxU), (double)(yCoord + 0.0F), (double)this.zLevel).tex((double)((float)(minU + maxU) * f), (double)((float)(minV + 0) * f1)).endVertex();
165
        worldrenderer.pos((double)(xCoord + 0.0F), (double)(yCoord + 0.0F), (double)this.zLevel).tex((double)((float)(minU + 0) * f), (double)((float)(minV + 0) * f1)).endVertex();
166
        tessellator.draw();
167
    }
168
169
    /**
170
     * Draws a texture rectangle using the texture currently bound to the TextureManager
171
     */
172
    public void drawTexturedModalRect(int xCoord, int yCoord, TextureAtlasSprite textureSprite, int widthIn, int heightIn)
173
    {
174
        Tessellator tessellator = Tessellator.getInstance();
175
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
176
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
177
        worldrenderer.pos((double)(xCoord + 0), (double)(yCoord + heightIn), (double)this.zLevel).tex((double)textureSprite.getMinU(), (double)textureSprite.getMaxV()).endVertex();
178
        worldrenderer.pos((double)(xCoord + widthIn), (double)(yCoord + heightIn), (double)this.zLevel).tex((double)textureSprite.getMaxU(), (double)textureSprite.getMaxV()).endVertex();
179
        worldrenderer.pos((double)(xCoord + widthIn), (double)(yCoord + 0), (double)this.zLevel).tex((double)textureSprite.getMaxU(), (double)textureSprite.getMinV()).endVertex();
180
        worldrenderer.pos((double)(xCoord + 0), (double)(yCoord + 0), (double)this.zLevel).tex((double)textureSprite.getMinU(), (double)textureSprite.getMinV()).endVertex();
181
        tessellator.draw();
182
    }
183
184
    /**
185
     * Draws a textured rectangle at z = 0. Args: x, y, u, v, width, height, textureWidth, textureHeight
186
     */
187
    public static void drawModalRectWithCustomSizedTexture(int x, int y, float u, float v, int width, int height, float textureWidth, float textureHeight)
188
    {
189
        float f = 1.0F / textureWidth;
190
        float f1 = 1.0F / textureHeight;
191
        Tessellator tessellator = Tessellator.getInstance();
192
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
193
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
194
        worldrenderer.pos((double)x, (double)(y + height), 0.0D).tex((double)(u * f), (double)((v + (float)height) * f1)).endVertex();
195
        worldrenderer.pos((double)(x + width), (double)(y + height), 0.0D).tex((double)((u + (float)width) * f), (double)((v + (float)height) * f1)).endVertex();
196
        worldrenderer.pos((double)(x + width), (double)y, 0.0D).tex((double)((u + (float)width) * f), (double)(v * f1)).endVertex();
197
        worldrenderer.pos((double)x, (double)y, 0.0D).tex((double)(u * f), (double)(v * f1)).endVertex();
198
        tessellator.draw();
199
    }
200
201
    /**
202
     * Draws a scaled, textured, tiled modal rect at z = 0. This method isn't used anywhere in vanilla code.
203
     */
204
    public static void drawScaledCustomSizeModalRect(int x, int y, float u, float v, int uWidth, int vHeight, int width, int height, float tileWidth, float tileHeight)
205
    {
206
        float f = 1.0F / tileWidth;
207
        float f1 = 1.0F / tileHeight;
208
        Tessellator tessellator = Tessellator.getInstance();
209
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
210
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
211
        worldrenderer.pos((double)x, (double)(y + height), 0.0D).tex((double)(u * f), (double)((v + (float)vHeight) * f1)).endVertex();
212
        worldrenderer.pos((double)(x + width), (double)(y + height), 0.0D).tex((double)((u + (float)uWidth) * f), (double)((v + (float)vHeight) * f1)).endVertex();
213
        worldrenderer.pos((double)(x + width), (double)y, 0.0D).tex((double)((u + (float)uWidth) * f), (double)(v * f1)).endVertex();
214
        worldrenderer.pos((double)x, (double)y, 0.0D).tex((double)(u * f), (double)(v * f1)).endVertex();
215
        tessellator.draw();
216
    }
217
}
218

Deobfuscated MCP 1.8.9 source of Gui from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/gui/Gui.java), stored verbatim.