Skip to content

Commit

Permalink
fix black background of "terminal style" gui button (#561)
Browse files Browse the repository at this point in the history
* fix black background button in fc

* use actually function code replace super call

* Taking advice from @OneEyeMaker to reduce repeat code

* remove push pop matrix

* use GL11 constants

---------

Co-authored-by: Alexdoru <57050655+Alexdoru@users.noreply.github.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
  • Loading branch information
3 people authored Aug 27, 2024
1 parent e02e0cb commit d278b34
Showing 1 changed file with 23 additions and 44 deletions.
67 changes: 23 additions & 44 deletions src/main/java/appeng/client/gui/widgets/GuiImgButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.util.StatCollector;

import org.lwjgl.opengl.GL11;
Expand Down Expand Up @@ -786,56 +787,34 @@ public void setVisibility(final boolean vis) {
}

@Override
public void drawButton(final Minecraft par1Minecraft, final int par2, final int par3) {
public void drawButton(final Minecraft mc, final int mouseX, final int mouseY) {
if (this.visible) {
final int iconIndex = this.getIconIndex();

if (this.halfSize) {
this.width = 8;
this.height = 8;

GL11.glPushMatrix();
GL11.glTranslatef(this.xPosition, this.yPosition, 0.0F);
GL11.glScalef(0.5f, 0.5f, 0.5f);

if (this.enabled) {
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
} else {
GL11.glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
}

par1Minecraft.renderEngine.bindTexture(ExtraBlockTextures.GuiTexture("guis/states.png"));
this.field_146123_n = par2 >= this.xPosition && par3 >= this.yPosition
&& par2 < this.xPosition + this.width
&& par3 < this.yPosition + this.height;

final int uv_y = (int) Math.floor(iconIndex / 16);
final int uv_x = iconIndex - uv_y * 16;

this.drawTexturedModalRect(0, 0, 256 - 16, 256 - 16, 16, 16);
this.drawTexturedModalRect(0, 0, uv_x * 16, uv_y * 16, 16, 16);
this.mouseDragged(par1Minecraft, par2, par3);

GL11.glPopMatrix();
}
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition
&& mouseX < this.xPosition + this.width
&& mouseY < this.yPosition + this.height;
if (this.enabled) {
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
} else {
if (this.enabled) {
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
} else {
GL11.glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
}

par1Minecraft.renderEngine.bindTexture(ExtraBlockTextures.GuiTexture("guis/states.png"));
this.field_146123_n = par2 >= this.xPosition && par3 >= this.yPosition
&& par2 < this.xPosition + this.width
&& par3 < this.yPosition + this.height;

final int uv_y = (int) Math.floor(iconIndex / 16);
final int uv_x = iconIndex - uv_y * 16;

this.drawTexturedModalRect(this.xPosition, this.yPosition, 256 - 16, 256 - 16, 16, 16);
this.drawTexturedModalRect(this.xPosition, this.yPosition, uv_x * 16, uv_y * 16, 16, 16);
this.mouseDragged(par1Minecraft, par2, par3);
GL11.glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
}
mc.renderEngine.bindTexture(ExtraBlockTextures.GuiTexture("guis/states.png"));
final int iconIndex = this.getIconIndex();
final int uv_y = (int) Math.floor(iconIndex / 16);
final int uv_x = iconIndex - uv_y * 16;
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glTranslatef(this.xPosition, this.yPosition, 0.0F);
if (this.halfSize) GL11.glScalef(0.5f, 0.5f, 0.5f);
this.drawTexturedModalRect(0, 0, 256 - 16, 256 - 16, 16, 16);
this.drawTexturedModalRect(0, 0, uv_x * 16, uv_y * 16, 16, 16);
if (this.halfSize) GL11.glScalef(2f, 2f, 2f);
GL11.glTranslatef(-this.xPosition, -this.yPosition, 0.0F);
this.mouseDragged(mc, mouseX, mouseY);
}
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
Expand Down

0 comments on commit d278b34

Please sign in to comment.