Skip to content

Commit

Permalink
Rename a couple methods and fix some unintended GL color state "leaks"
Browse files Browse the repository at this point in the history
  • Loading branch information
pupnewfster committed Jul 8, 2019
1 parent a872655 commit d8a75fa
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
21 changes: 18 additions & 3 deletions src/main/java/mekanism/client/gui/GuiMekanism.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,17 @@ public void renderScaledText(String text, int x, int y, int color, int maxX) {

@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
int xAxis = mouseX - guiLeft;
int yAxis = mouseY - guiTop;
guiElements.forEach(element -> element.renderForeground(xAxis, yAxis));
//Ensure that the GL color is white, as drawing rectangles, text boxes, or even text might have changed the color from
// what we assume it is at the start. This prevents any unintentional color state leaks. GlStateManager, will ensure that
// GL changes only get ran if it is not already the color we are assuming it is.
GLSMHelper.INSTANCE.resetColor();
guiElements.forEach(element -> {
element.renderForeground(xAxis, yAxis);
//Continue ensuring color is what we are assuming.
GLSMHelper.INSTANCE.resetColor();
});
}

protected boolean isMouseOverSlot(Slot slot, int mouseX, int mouseY) {
Expand All @@ -90,7 +97,15 @@ protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, in
int xAxis = mouseX - guiLeft;
int yAxis = mouseY - guiTop;
drawGuiContainerBackgroundLayer(xAxis, yAxis);
guiElements.forEach(element -> element.renderBackground(xAxis, yAxis, guiLeft, guiTop));
//Ensure that the GL color is white, as drawing rectangles, text boxes, or even text might have changed the color from
// what we assume it is at the start. This prevents any unintentional color state leaks. GlStateManager, will ensure that
// GL changes only get ran if it is not already the color we are assuming it is.
GLSMHelper.INSTANCE.resetColor();
guiElements.forEach(element -> {
element.renderBackground(xAxis, yAxis, guiLeft, guiTop);
//Continue ensuring color is what we are assuming.
GLSMHelper.INSTANCE.resetColor();
});
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mekanism/client/gui/element/gauge/GuiGauge.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public void renderBackground(int xAxis, int yAxis, int guiWidth, int guiHeight)
mc.renderEngine.bindTexture(RESOURCE);
guiObj.drawTexturedRect(guiWidth + xLocation, guiHeight + yLocation, texX, texY, width, height);
if (!dummy) {
renderScale(xAxis, yAxis, guiWidth, guiHeight);
renderScale(guiWidth, guiHeight);
}
mc.renderEngine.bindTexture(defaultLocation);
}

public void renderScale(int xAxis, int yAxis, int guiWidth, int guiHeight) {
public void renderScale(int guiWidth, int guiHeight) {
if (getScaledLevel() == 0 || getIcon() == null) {
guiObj.drawTexturedRect(guiWidth + xLocation, guiHeight + yLocation, width, 0, width, height);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void initGui() {
}
}

protected void drawRect(int xAxis, int yAxis, int xMin, int xMax, int yMin, int yMax) {
protected void drawPositionedRect(int xAxis, int yAxis, int xMin, int xMax, int yMin, int yMax) {
if (xAxis >= xMin && xAxis <= xMax && yAxis >= yMin && yAxis <= yMax) {
int x = guiLeft + xMin;
int y = guiTop + yMin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected void drawGuiContainerBackgroundLayer(int xAxis, int yAxis) {
if (tileEntity instanceof TileEntityDigitalMiner) {
drawTexturedModalRect(guiLeft + 148, guiTop + 45, 199, xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59, 14);
text.drawTextBox();
drawRect(xAxis, yAxis, 149, 165, 19, 35);
drawPositionedRect(xAxis, yAxis, 149, 165, 19, 35);
} else if (tileEntity instanceof TileEntityLogisticalSorter) {
drawTexturedModalRect(guiLeft + 11, guiTop + 64, 199, xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75, 11);
text.drawTextBox();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mekanism/client/gui/filter/GuiTypeFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ protected void drawGuiContainerBackgroundLayer(int xAxis, int yAxis) {
if (tileEntity instanceof TileEntityDigitalMiner) {
drawTexturedModalRect(guiLeft + 148, guiTop + 45, 199, xAxis >= 148 && xAxis <= 162 && yAxis >= 45 && yAxis <= 59, 14);
drawItemStackBackground(xAxis, yAxis);
drawRect(xAxis, yAxis, 149, 165, 19, 35);
drawPositionedRect(xAxis, yAxis, 149, 165, 19, 35);
} else if (tileEntity instanceof TileEntityLogisticalSorter) {
drawTexturedModalRect(guiLeft + 11, guiTop + 64, 198, xAxis >= 11 && xAxis <= 22 && yAxis >= 64 && yAxis <= 75, 11);
drawItemStackBackground(xAxis, yAxis);
}
drawRect(xAxis, yAxis, 12, 28, 19, 35);
drawPositionedRect(xAxis, yAxis, 12, 28, 19, 35);
}

protected abstract void drawForegroundLayer(int mouseX, int mouseY);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/mekanism/client/gui/robit/GuiRobit.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ protected ResourceLocation getGuiLocation() {
@Override
protected void drawGuiContainerBackgroundLayer(int xAxis, int yAxis) {
boolean correctX = xAxis >= 179 && xAxis <= 197;
drawRect(correctX, yAxis, 10, 0);
drawRect(correctX, yAxis, 30, 36);
drawRect(correctX, yAxis, 50, 72);
drawRect(correctX, yAxis, 70, 108);
drawRect(correctX, yAxis, 90, 144);
drawPositionedRect(correctX, yAxis, 10, 0);
drawPositionedRect(correctX, yAxis, 30, 36);
drawPositionedRect(correctX, yAxis, 50, 72);
drawPositionedRect(correctX, yAxis, 70, 108);
drawPositionedRect(correctX, yAxis, 90, 144);
}

private void drawRect(boolean correctX, int yAxis, int heightBonus, int textureY) {
private void drawPositionedRect(boolean correctX, int yAxis, int heightBonus, int textureY) {
int yBonus = correctX && yAxis >= heightBonus && yAxis <= heightBonus + 18 ? 0 : 18;
drawTexturedModalRect(guiLeft + 179, guiTop + heightBonus, 201, textureY + yBonus, 18, 18);
}
Expand Down

0 comments on commit d8a75fa

Please sign in to comment.