Clean up some GUI code and change magic numbers to GL constants (#4734)

This commit is contained in:
Ben Staddon 2018-02-11 19:48:02 +00:00 committed by mezz
parent d650e454b1
commit d18c03968e
3 changed files with 28 additions and 49 deletions

View file

@ -64,6 +64,7 @@ import static net.minecraft.util.text.TextFormatting.*;
import org.lwjgl.input.Mouse;
import com.google.common.base.Strings;
import org.lwjgl.opengl.GL11;
/**
* @author cpw
@ -555,7 +556,7 @@ public class GuiModList extends GuiScreen
GuiModList.this.mc.renderEngine.bindTexture(logoPath);
BufferBuilder wr = tess.getBuffer();
int offset = (this.left + this.listWidth/2) - (logoDims.width / 2);
wr.begin(7, DefaultVertexFormats.POSITION_TEX);
wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
wr.pos(offset, top + logoDims.height, zLevel).tex(0, 1).endVertex();
wr.pos(offset + logoDims.width, top + logoDims.height, zLevel).tex(1, 1).endVertex();
wr.pos(offset + logoDims.width, top, zLevel).tex(1, 0).endVertex();

View file

@ -27,6 +27,7 @@ import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraftforge.fml.client.config.GuiUtils;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
@ -295,8 +296,8 @@ public abstract class GuiScrollingList
GlStateManager.disableFog();
this.client.renderEngine.bindTexture(Gui.OPTIONS_BACKGROUND);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
float scale = 32.0F;
worldr.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
final float scale = 32.0F;
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
worldr.pos(this.left, this.bottom, 0.0D).tex(this.left / scale, (this.bottom + (int)this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
worldr.pos(this.right, this.bottom, 0.0D).tex(this.right / scale, (this.bottom + (int)this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
worldr.pos(this.right, this.top, 0.0D).tex(this.right / scale, (this.top + (int)this.scrollDistance) / scale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
@ -323,7 +324,7 @@ public abstract class GuiScrollingList
int max = entryRight;
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableTexture2D();
worldr.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
worldr.pos(min, slotTop + slotBuffer + 2, 0).tex(0, 1).color(0x80, 0x80, 0x80, 0xFF).endVertex();
worldr.pos(max, slotTop + slotBuffer + 2, 0).tex(1, 1).color(0x80, 0x80, 0x80, 0xFF).endVertex();
worldr.pos(max, slotTop - 2, 0).tex(1, 0).color(0x80, 0x80, 0x80, 0xFF).endVertex();
@ -359,19 +360,19 @@ public abstract class GuiScrollingList
}
GlStateManager.disableTexture2D();
worldr.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
worldr.pos(scrollBarLeft, this.bottom, 0.0D).tex(0.0D, 1.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
worldr.pos(scrollBarRight, this.bottom, 0.0D).tex(1.0D, 1.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
worldr.pos(scrollBarRight, this.top, 0.0D).tex(1.0D, 0.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
worldr.pos(scrollBarLeft, this.top, 0.0D).tex(0.0D, 0.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
tess.draw();
worldr.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
worldr.pos(scrollBarLeft, barTop + height, 0.0D).tex(0.0D, 1.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
worldr.pos(scrollBarRight, barTop + height, 0.0D).tex(1.0D, 1.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
worldr.pos(scrollBarRight, barTop, 0.0D).tex(1.0D, 0.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
worldr.pos(scrollBarLeft, barTop, 0.0D).tex(0.0D, 0.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
tess.draw();
worldr.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
worldr.pos(scrollBarLeft, barTop + height - 1, 0.0D).tex(0.0D, 1.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
worldr.pos(scrollBarRight - 1, barTop + height - 1, 0.0D).tex(1.0D, 1.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
worldr.pos(scrollBarRight - 1, barTop, 0.0D).tex(1.0D, 0.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
@ -389,30 +390,6 @@ public abstract class GuiScrollingList
protected void drawGradientRect(int left, int top, int right, int bottom, int color1, int color2)
{
float a1 = (float)(color1 >> 24 & 255) / 255.0F;
float r1 = (float)(color1 >> 16 & 255) / 255.0F;
float g1 = (float)(color1 >> 8 & 255) / 255.0F;
float b1 = (float)(color1 & 255) / 255.0F;
float a2 = (float)(color2 >> 24 & 255) / 255.0F;
float r2 = (float)(color2 >> 16 & 255) / 255.0F;
float g2 = (float)(color2 >> 8 & 255) / 255.0F;
float b2 = (float)(color2 & 255) / 255.0F;
GlStateManager.disableTexture2D();
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GlStateManager.shadeModel(GL11.GL_SMOOTH);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(7, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(right, top, 0.0D).color(r1, g1, b1, a1).endVertex();
buffer.pos(left, top, 0.0D).color(r1, g1, b1, a1).endVertex();
buffer.pos(left, bottom, 0.0D).color(r2, g2, b2, a2).endVertex();
buffer.pos(right, bottom, 0.0D).color(r2, g2, b2, a2).endVertex();
tessellator.draw();
GlStateManager.shadeModel(GL11.GL_FLAT);
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
GuiUtils.drawGradientRect(0, left, top, right, bottom, color1, color2);
}
}

View file

@ -198,11 +198,12 @@ public class GuiUtils
public static void drawTexturedModalRect(int x, int y, int u, int v, int width, int height, float zLevel)
{
float uScale = 1f / 0x100;
float vScale = 1f / 0x100;
final float uScale = 1f / 0x100;
final float vScale = 1f / 0x100;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder wr = tessellator.getBuffer();
wr.begin(7, DefaultVertexFormats.POSITION_TEX);
wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
wr.pos(x , y + height, zLevel).tex( u * uScale, ((v + height) * vScale)).endVertex();
wr.pos(x + width, y + height, zLevel).tex((u + width) * uScale, ((v + height) * vScale)).endVertex();
wr.pos(x + width, y , zLevel).tex((u + width) * uScale, ( v * vScale)).endVertex();
@ -417,30 +418,30 @@ public class GuiUtils
public static void drawGradientRect(int zLevel, int left, int top, int right, int bottom, int startColor, int endColor)
{
float startAlpha = (float)(startColor >> 24 & 255) / 255.0F;
float startRed = (float)(startColor >> 16 & 255) / 255.0F;
float startGreen = (float)(startColor >> 8 & 255) / 255.0F;
float startBlue = (float)(startColor & 255) / 255.0F;
float endAlpha = (float)(endColor >> 24 & 255) / 255.0F;
float endRed = (float)(endColor >> 16 & 255) / 255.0F;
float endGreen = (float)(endColor >> 8 & 255) / 255.0F;
float endBlue = (float)(endColor & 255) / 255.0F;
float startRed = (float)(startColor >> 16 & 255) / 255.0F;
float startGreen = (float)(startColor >> 8 & 255) / 255.0F;
float startBlue = (float)(startColor & 255) / 255.0F;
float endAlpha = (float)(endColor >> 24 & 255) / 255.0F;
float endRed = (float)(endColor >> 16 & 255) / 255.0F;
float endGreen = (float)(endColor >> 8 & 255) / 255.0F;
float endBlue = (float)(endColor & 255) / 255.0F;
GlStateManager.disableTexture2D();
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.shadeModel(7425);
GlStateManager.shadeModel(GL11.GL_SMOOTH);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(7, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(right, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex();
buffer.pos(left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex();
buffer.pos(left, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex();
buffer.pos(right, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex();
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(right, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex();
buffer.pos( left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex();
buffer.pos( left, bottom, zLevel).color( endRed, endGreen, endBlue, endAlpha).endVertex();
buffer.pos(right, bottom, zLevel).color( endRed, endGreen, endBlue, endAlpha).endVertex();
tessellator.draw();
GlStateManager.shadeModel(7424);
GlStateManager.shadeModel(GL11.GL_FLAT);
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();