diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/screen/HudScreen.java b/forge/src/main/java/fr/thesmyler/smylibgui/screen/HudScreen.java index bdc453b1..721a1b5e 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/screen/HudScreen.java +++ b/forge/src/main/java/fr/thesmyler/smylibgui/screen/HudScreen.java @@ -4,6 +4,7 @@ import java.util.List; import fr.thesmyler.smylibgui.container.RootContainer; +import net.smyler.smylib.gui.GlState; import net.smyler.smylib.gui.containers.WidgetContainer; import fr.thesmyler.smylibgui.event.HudScreenInitEvent; import net.smyler.smylib.Color; @@ -58,6 +59,7 @@ public static void onRenderHUD(RenderGameOverlayEvent.Pre e) { GameClient game = getGameClient(); Mouse mouse = game.mouse(); DrawContext drawContext = game.guiDrawContext(); + GlState glState = drawContext.glState(); Scissor scissor = drawContext.scissor(); boolean chatOpen = Minecraft.getMinecraft().currentScreen instanceof GuiChat; float width = game.windowWidth(); @@ -70,12 +72,12 @@ public static void onRenderHUD(RenderGameOverlayEvent.Pre e) { float mouseX = mouse.x(); float mouseY = mouse.y(); CONTAINER.onUpdate(mouseX, mouseY, null); - Color color = currentColor(); + Color color = glState.getColor(); scissor.push(); scissor.cropScreen(-1f, -1f, renderWidth + 1f, renderHeight + 1f); CONTAINER.draw(drawContext, 0, 0, mouseX, mouseY, chatOpen && !isOverChat(mouseX, mouseY), false, null); drawContext.glState().enableAlpha(); - applyColor(color); // Reset color to what it was + glState.setColor(color); // Reset color to what it was } @SubscribeEvent diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/util/RenderUtil.java b/forge/src/main/java/fr/thesmyler/smylibgui/util/RenderUtil.java index b97a02b0..5cb60862 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/util/RenderUtil.java +++ b/forge/src/main/java/fr/thesmyler/smylibgui/util/RenderUtil.java @@ -118,17 +118,4 @@ public static void drawClosedStrokeLine(Color color, float size, double... point drawClosedStrokeLine(0d, color, size, points); } - public static void applyColor(Color color) { - GlStateManager.color( - color.redf(), - color.greenf(), - color.bluef(), - color.alphaf() - ); - } - - public static Color currentColor() { - return new Color(GL11.glGetInteger(GL11.GL_CURRENT_COLOR)); - } - } diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/WarningWidget.java b/forge/src/main/java/fr/thesmyler/smylibgui/widgets/WarningWidget.java index 6ef8c28f..c10e941a 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/WarningWidget.java +++ b/forge/src/main/java/fr/thesmyler/smylibgui/widgets/WarningWidget.java @@ -8,7 +8,6 @@ import net.smyler.smylib.gui.widgets.AbstractSolidWidget; import static net.smyler.smylib.Color.WHITE; -import static fr.thesmyler.smylibgui.util.RenderUtil.applyColor; public class WarningWidget extends AbstractSolidWidget { @@ -18,7 +17,7 @@ public WarningWidget(float x, float y, int z) { @Override public void draw(DrawContext context, float x, float y, float mouseX, float mouseY, boolean hovered, boolean focused, WidgetContainer parent) { - applyColor(WHITE); + context.glState().setColor(WHITE); Minecraft.getMinecraft().getTextureManager().bindTexture(SmyLibGuiTextures.WIDGET_TEXTURES); RenderUtil.drawModalRectWithCustomSizedTexture(x, y, 15, 54, this.width, this.height, 256, 256); } diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/buttons/TextButtonWidget.java b/forge/src/main/java/fr/thesmyler/smylibgui/widgets/buttons/TextButtonWidget.java index 45c1eb6a..0938bd37 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/buttons/TextButtonWidget.java +++ b/forge/src/main/java/fr/thesmyler/smylibgui/widgets/buttons/TextButtonWidget.java @@ -9,7 +9,6 @@ import net.smyler.smylib.gui.DrawContext; import static net.smyler.smylib.Color.WHITE; -import static fr.thesmyler.smylibgui.util.RenderUtil.applyColor; import static net.smyler.smylib.SmyLib.getGameClient; public class TextButtonWidget extends AbstractButtonWidget { @@ -50,7 +49,7 @@ public TextButtonWidget(int z, String str) { public void draw(DrawContext context, float x, float y, float mouseX, float mouseY, boolean hovered, boolean hasFocus, WidgetContainer parent) { Minecraft mc = Minecraft.getMinecraft(); mc.getTextureManager().bindTexture(SmyLibGuiTextures.BUTTON_TEXTURES); - applyColor(WHITE); + context.glState().setColor(WHITE); int textureDelta = 1; Color textColor = this.enabledTextColor; if (!this.isEnabled()) { diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/buttons/TexturedButtonWidget.java b/forge/src/main/java/fr/thesmyler/smylibgui/widgets/buttons/TexturedButtonWidget.java index b0930f47..4df984f8 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/buttons/TexturedButtonWidget.java +++ b/forge/src/main/java/fr/thesmyler/smylibgui/widgets/buttons/TexturedButtonWidget.java @@ -11,7 +11,6 @@ import net.minecraft.util.ResourceLocation; import static net.smyler.smylib.Color.WHITE; -import static fr.thesmyler.smylibgui.util.RenderUtil.applyColor; public class TexturedButtonWidget extends AbstractButtonWidget { @@ -86,7 +85,7 @@ public TexturedButtonWidget(int z, IncludedTexturedButtons properties) { public void draw(DrawContext context, float x, float y, float mouseX, float mouseY, boolean hovered, boolean hasFocus, WidgetContainer parent) { Minecraft mc = Minecraft.getMinecraft(); mc.getTextureManager().bindTexture(this.texture); - applyColor(WHITE); + context.glState().setColor(WHITE); int u = this.u; int v = this.v; if(!this.isEnabled()) { diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/buttons/ToggleButtonWidget.java b/forge/src/main/java/fr/thesmyler/smylibgui/widgets/buttons/ToggleButtonWidget.java index 263be877..d4e8e894 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/buttons/ToggleButtonWidget.java +++ b/forge/src/main/java/fr/thesmyler/smylibgui/widgets/buttons/ToggleButtonWidget.java @@ -10,7 +10,6 @@ import net.smyler.smylib.gui.DrawContext; import static net.smyler.smylib.Color.WHITE; -import static fr.thesmyler.smylibgui.util.RenderUtil.applyColor; public class ToggleButtonWidget extends AbstractButtonWidget { @@ -88,7 +87,7 @@ public ToggleButtonWidget(int z, boolean startValue) { public void draw(DrawContext context, float x, float y, float mouseX, float mouseY, boolean hovered, boolean hasFocus, WidgetContainer parent) { Minecraft mc = Minecraft.getMinecraft(); mc.getTextureManager().bindTexture(SmyLibGuiTextures.WIDGET_TEXTURES); - applyColor(WHITE); + context.glState().setColor(WHITE); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/AbstractSliderWidget.java b/forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/AbstractSliderWidget.java index 3049b66c..41a18932 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/AbstractSliderWidget.java +++ b/forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/AbstractSliderWidget.java @@ -1,6 +1,7 @@ package fr.thesmyler.smylibgui.widgets.sliders; import net.smyler.smylib.gui.DrawContext; +import net.smyler.smylib.gui.GlState; import org.jetbrains.annotations.Nullable; import fr.thesmyler.smylibgui.SmyLibGuiTextures; @@ -16,7 +17,6 @@ import net.smyler.smylib.gui.Font; import static net.smyler.smylib.Color.WHITE; -import static fr.thesmyler.smylibgui.util.RenderUtil.applyColor; import static net.smyler.smylib.SmyLib.getGameClient; import static net.smyler.smylib.math.Math.saturate; @@ -118,8 +118,9 @@ public void onKeyTyped(char typedChar, @Nullable Key key, @Nullable WidgetContai @Override public void draw(DrawContext context, float x, float y, float mouseX, float mouseY, boolean hovered, boolean hasFocus, WidgetContainer parent) { GameClient game = getGameClient(); + GlState glState = context.glState(); Minecraft.getMinecraft().getTextureManager().bindTexture(SmyLibGuiTextures.BUTTON_TEXTURES); - applyColor(WHITE); + glState.setColor(WHITE); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); @@ -137,7 +138,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous float sliderPosition = this.getPosition(); Minecraft.getMinecraft().getTextureManager().bindTexture(SmyLibGuiTextures.BUTTON_TEXTURES); - applyColor(WHITE); + glState.setColor(WHITE); float sliderX = x + sliderPosition * (this.width - 8); RenderUtil.drawTexturedModalRect(sliderX, y, 0, 66, 4, splitHeight); diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/text/TextFieldWidget.java b/forge/src/main/java/fr/thesmyler/smylibgui/widgets/text/TextFieldWidget.java index 2f227500..c3a2af4c 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/text/TextFieldWidget.java +++ b/forge/src/main/java/fr/thesmyler/smylibgui/widgets/text/TextFieldWidget.java @@ -3,7 +3,9 @@ import java.util.function.Consumer; import java.util.function.Predicate; +import net.smyler.smylib.gui.ColorLogic; import net.smyler.smylib.gui.DrawContext; +import net.smyler.smylib.gui.GlState; import org.jetbrains.annotations.Nullable; import fr.thesmyler.smylibgui.SmyLibGuiTextures; @@ -18,15 +20,11 @@ import net.smyler.smylib.gui.widgets.Widget; import net.smyler.smylib.gui.widgets.MenuWidget; import net.minecraft.client.Minecraft; -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.smyler.smylib.gui.Font; import static net.smyler.smylib.Color.BLUE; import static net.smyler.smylib.Color.WHITE; -import static fr.thesmyler.smylibgui.util.RenderUtil.applyColor; import static net.smyler.smylib.SmyLib.getGameClient; import static net.smyler.smylib.game.Key.*; import static net.smyler.smylib.math.Math.clamp; @@ -127,6 +125,8 @@ public TextFieldWidget(int z) { @Override public void draw(DrawContext context, float x, float y, float mouseX, float mouseY, boolean hovered, boolean focused, WidgetContainer parent) { + GlState glState = context.glState(); + this.cursorAnimation.update(); Color borderColor = this.borderColorNormal; @@ -146,9 +146,9 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous } if(this.isSearchBar) { - applyColor(WHITE); + glState.setColor(WHITE); Minecraft.getMinecraft().getTextureManager().bindTexture(SmyLibGuiTextures.WIDGET_TEXTURES); - context.glState().enableAlpha(); + glState.enableAlpha(); GlStateManager.enableBlend(); RenderUtil.drawModalRectWithCustomSizedTexture(x + this.width - 17, y + 2, 131, 0, 15, 15, 256, 256); } @@ -192,32 +192,24 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous if (displaySelectionEnd != displaySelectionStart) { float selectionBoxRenderRight = textRenderX + this.font.getStringWidth(string.substring(0, displaySelectionEnd)); - this.drawSelectionHighlight(x, y, cursorX, textRenderY - 1, selectionBoxRenderRight - 1, textRenderY + 1 + 9); + this.drawSelectionHighlight(context, x, y, cursorX, textRenderY - 1, selectionBoxRenderRight - 1, textRenderY + 1 + 9); } } - private void drawSelectionHighlight(float x, float y, float x1, float y1, float x2, float y2) { - float dispX1 = Math.max(x1, x2); - float dispY1 = Math.max(y1, y2); - float dispX2 = Math.min(x1, x2); - float dispY2 = Math.min(y1, y2); - dispX2 = Math.min(dispX2, x + this.getEffectiveWidth()); - dispX1 = Math.min(dispX1, x + this.getEffectiveWidth()); - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder bufferBuilder = tessellator.getBuffer(); - applyColor(BLUE); + private void drawSelectionHighlight(DrawContext context, float x, float y, float x1, float y1, float x2, float y2) { + float xRight = Math.max(x1, x2); + float yBottom = Math.max(y1, y2); + float xLeft = Math.min(x1, x2); + float yTop = Math.min(y1, y2); + xLeft = Math.min(xLeft, x + this.getEffectiveWidth()); + xRight = Math.min(xRight, x + this.getEffectiveWidth()); GlStateManager.disableTexture2D(); - GlStateManager.enableColorLogic(); - GlStateManager.colorLogicOp(GlStateManager.LogicOp.OR_REVERSE); - bufferBuilder.begin(7, DefaultVertexFormats.POSITION); - bufferBuilder.pos(dispX1, dispY2, 0.0D).endVertex(); - bufferBuilder.pos(dispX2, dispY2, 0.0D).endVertex(); - bufferBuilder.pos(dispX2, dispY1, 0.0D).endVertex(); - bufferBuilder.pos(dispX1, dispY1, 0.0D).endVertex(); - tessellator.draw(); - GlStateManager.disableColorLogic(); + GlState state = context.glState(); + state.enableColorLogic(ColorLogic.OR_REVERSE); + context.drawRectangle(xLeft, yTop, xRight, yBottom, BLUE); + state.disableColorLogic(); GlStateManager.enableTexture2D(); } diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/CircularCompassWidget.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/CircularCompassWidget.java index 7a2b1110..aaefa434 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/CircularCompassWidget.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/CircularCompassWidget.java @@ -1,6 +1,7 @@ package fr.thesmyler.terramap.gui.widgets; import net.smyler.smylib.gui.DrawContext; +import net.smyler.smylib.gui.GlState; import net.smyler.smylib.math.Vec2dMutable; import org.lwjgl.opengl.GL11; @@ -16,7 +17,6 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import static net.smyler.smylib.Color.WHITE; -import static fr.thesmyler.smylibgui.util.RenderUtil.applyColor; public class CircularCompassWidget implements Widget { @@ -64,6 +64,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous float radius = this.size / 2; + GlState glState = context.glState(); GlStateManager.pushMatrix(); GlStateManager.translate(x + radius, y + radius, 0); context.drawPolygon(background, this.vertices); @@ -71,7 +72,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous GlStateManager.rotate(this.azimuth, 0, 0, 1); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder builder = tessellator.getBuffer(); - applyColor(WHITE); + glState.setColor(WHITE); GlStateManager.shadeModel(7425); context.glState().enableAlpha(); GlStateManager.enableBlend(); diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/RibbonCompassWidget.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/RibbonCompassWidget.java index 09a04439..f3a2235f 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/RibbonCompassWidget.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/RibbonCompassWidget.java @@ -1,6 +1,7 @@ package fr.thesmyler.terramap.gui.widgets; import net.smyler.smylib.gui.DrawContext; +import net.smyler.smylib.gui.GlState; import org.lwjgl.opengl.GL11; import net.smyler.smylib.gui.containers.WidgetContainer; @@ -17,7 +18,6 @@ import net.minecraft.util.ResourceLocation; import static net.smyler.smylib.Color.WHITE; -import static fr.thesmyler.smylibgui.util.RenderUtil.applyColor; public class RibbonCompassWidget implements Widget { @@ -61,11 +61,12 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous double rightU = leftU + (double) this.width / this.textureWidth; double rightCU = rightU - blendBorder/this.textureWidth; + GlState glState = context.glState(); Tessellator tess = Tessellator.getInstance(); BufferBuilder buff = tess.getBuffer(); GlStateManager.enableTexture2D(); - context.glState().enableAlpha(); + glState.enableAlpha(); GlStateManager.enableBlend(); Minecraft.getMinecraft().getTextureManager().bindTexture(COMPASS_BACKGROUND_TEXTURE); GlStateManager.shadeModel(GL11.GL_SMOOTH); @@ -90,7 +91,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous tess.draw(); Minecraft.getMinecraft().getTextureManager().bindTexture(COMPASS_INDICATOR_TEXTURE); - applyColor(WHITE); + glState.setColor(WHITE); buff.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); double indX = x + (double)(this.width - this.indicatorWidth) / 2; double indY = y + (double)(this.height - this.indicatorHeight) / 2; diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java index a7702e0b..83aa6cc1 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java @@ -3,6 +3,7 @@ import java.util.HashSet; import java.util.Set; +import net.smyler.smylib.gui.GlState; import net.smyler.smylib.gui.containers.WidgetContainer; import fr.thesmyler.smylibgui.util.*; import fr.thesmyler.terramap.gui.widgets.map.MapLayer; @@ -28,7 +29,6 @@ import net.smyler.terramap.util.geo.WebMercatorUtil; import static net.smyler.smylib.Color.WHITE; -import static fr.thesmyler.smylibgui.util.RenderUtil.applyColor; import static net.smyler.smylib.SmyLib.getGameClient; abstract public class RasterMapLayer extends MapLayer { @@ -65,6 +65,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous Font smallFont = getGameClient().smallestFont(); Minecraft mc = Minecraft.getMinecraft(); TextureManager textureManager = mc.getTextureManager(); + GlState glState = context.glState(); float rotation = this.getRotation(); boolean perfectDraw = true; @@ -216,7 +217,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous dY += factorY * renderSizedSize; } - applyColor(WHITE); + glState.setColor(WHITE); ResourceLocation texture = defaultTexture; try { if(tile.isTextureAvailable()) texture = tile.getTexture(); @@ -249,7 +250,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous smallFont.drawString((float)dispX + 2, (float)(dispY + displayHeight/2), GeoServices.formatGeoCoordForDisplay(dispX), lineColor, false); smallFont.drawCenteredString((float)(dispX + displayWidth/2), (float)dispY + 2, GeoServices.formatGeoCoordForDisplay(dispY), lineColor, false); } - applyColor(WHITE); + glState.setColor(WHITE); } } diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/markers/entities/AbstractLivingMarker.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/markers/entities/AbstractLivingMarker.java index 3cc3f375..8e4f1c28 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/markers/entities/AbstractLivingMarker.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/markers/entities/AbstractLivingMarker.java @@ -1,5 +1,6 @@ package fr.thesmyler.terramap.gui.widgets.markers.markers.entities; +import net.smyler.smylib.gui.GlState; import net.smyler.smylib.gui.containers.WidgetContainer; import net.smyler.smylib.Color; import fr.thesmyler.smylibgui.util.RenderUtil; @@ -20,7 +21,6 @@ import net.minecraft.util.text.ITextComponent; import static net.smyler.smylib.Color.WHITE; -import static fr.thesmyler.smylibgui.util.RenderUtil.applyColor; public abstract class AbstractLivingMarker extends AbstractMovingMarker { @@ -44,16 +44,16 @@ public AbstractLivingMarker(MarkerController controller, float width, float h @Override public void draw(DrawContext context, float x, float y, float mouseX, float mouseY, boolean hovered, boolean focused, WidgetContainer parent) { - applyColor(WHITE); + GlState glState = context.glState(); boolean drawName = hovered; if(parent instanceof MapWidget) { MapWidget map = (MapWidget) parent; drawName = drawName && !map.getContext().equals(MapContext.MINIMAP); } - context.glState().enableAlpha(); + glState.enableAlpha(); if(hovered) context.drawRectangle(x +1, y +1, x + 1 + this.width, y + 1 + this.height, Color.LIGHT_OVERLAY); Minecraft.getMinecraft().getTextureManager().bindTexture(this.texture); - applyColor(WHITE); + glState.setColor(WHITE); GlStateManager.enableBlend(); RenderUtil.drawModalRectWithCustomSizedTexture(x, y, this.u, this.v, this.width, this.height, this.textureWidth, this.textureHeight); diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/markers/entities/AbstractPlayerMarker.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/markers/entities/AbstractPlayerMarker.java index 669264f8..223b20bf 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/markers/entities/AbstractPlayerMarker.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/markers/markers/entities/AbstractPlayerMarker.java @@ -1,6 +1,7 @@ package fr.thesmyler.terramap.gui.widgets.markers.markers.entities; import net.smyler.smylib.gui.DrawContext; +import net.smyler.smylib.gui.GlState; import org.lwjgl.opengl.GL11; import net.smyler.smylib.gui.containers.WidgetContainer; @@ -18,7 +19,6 @@ import net.minecraft.util.ResourceLocation; import static net.smyler.smylib.Color.WHITE; -import static fr.thesmyler.smylibgui.util.RenderUtil.applyColor; public abstract class AbstractPlayerMarker extends AbstractMovingMarker { @@ -31,9 +31,11 @@ public AbstractPlayerMarker(MarkerController controller, int downscaleFactor) @Override public void draw(DrawContext context, float x, float y, float mouseX, float mouseY, boolean hovered, boolean focused, WidgetContainer parent) { + GlState glState = context.glState(); + boolean drawName = this.showName(hovered); float textureSize = 128f / this.downScaleFactor; - context.glState().enableAlpha(); + glState.enableAlpha(); if(hovered) context.drawRectangle(x +1, y +1, x + this.getWidth() + 1, y + this.getHeight() + 1, Color.DARK_OVERLAY); // Draw the direction arrow @@ -64,7 +66,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous } Minecraft.getMinecraft().getTextureManager().bindTexture(this.getSkin()); - applyColor(WHITE.withAlpha(this.getTransparency())); + glState.setColor(WHITE.withAlpha(this.getTransparency())); RenderUtil.drawModalRectWithCustomSizedTexture(x, y, this.getWidth(), this.getHeight(), this.getWidth(), this.getHeight(), textureSize, textureSize); RenderUtil.drawModalRectWithCustomSizedTexture(x, y, 80f / this.downScaleFactor, this.getHeight(), this.getWidth(), this.getHeight(), textureSize, textureSize); @@ -77,7 +79,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous parent.getFont().drawCenteredString(x + halfSize, nameY, name, WHITE, false); } - applyColor(WHITE); + glState.setColor(WHITE); } protected abstract ResourceLocation getSkin(); diff --git a/smylib/core/src/main/java/net/smyler/smylib/gui/ColorLogic.java b/smylib/core/src/main/java/net/smyler/smylib/gui/ColorLogic.java new file mode 100644 index 00000000..920add86 --- /dev/null +++ b/smylib/core/src/main/java/net/smyler/smylib/gui/ColorLogic.java @@ -0,0 +1,20 @@ +package net.smyler.smylib.gui; + +public enum ColorLogic { + CLEAR, // 0 + SET, // 1 + COPY, // s + COPY_INVERTED, // ~s + NOOP, // d + INVERT, // ~d + AND, // s & d + NAND, // ~(s & d) + OR, // s | d + NOR, // ~(s | d) + XOR, // s ^ d + EQUIV, // ~(s ^ d) + AND_REVERSE, // s & ~d + AND_INVERTED, // ~s & d + OR_REVERSE, // s | ~d + OR_INVERTED // ~s | d +} diff --git a/smylib/core/src/main/java/net/smyler/smylib/gui/GlState.java b/smylib/core/src/main/java/net/smyler/smylib/gui/GlState.java index df4cb8c4..b8673c99 100644 --- a/smylib/core/src/main/java/net/smyler/smylib/gui/GlState.java +++ b/smylib/core/src/main/java/net/smyler/smylib/gui/GlState.java @@ -1,9 +1,19 @@ package net.smyler.smylib.gui; +import net.smyler.smylib.Color; + public interface GlState { void enableAlpha(); void disableAlpha(); + void setColor(Color color); + + Color getColor(); + + void enableColorLogic(ColorLogic colorLogic); + + void disableColorLogic(); + } diff --git a/smylib/forge/src/main/java/net/smyler/smylib/gui/LwjglState.java b/smylib/forge/src/main/java/net/smyler/smylib/gui/LwjglState.java index 233a9ab3..c884d7ef 100644 --- a/smylib/forge/src/main/java/net/smyler/smylib/gui/LwjglState.java +++ b/smylib/forge/src/main/java/net/smyler/smylib/gui/LwjglState.java @@ -1,6 +1,8 @@ package net.smyler.smylib.gui; import net.minecraft.client.renderer.GlStateManager; +import net.smyler.smylib.Color; +import org.lwjgl.opengl.GL11; public class LwjglState implements GlState { @Override @@ -13,4 +15,67 @@ public void disableAlpha() { GlStateManager.disableAlpha(); } + @Override + public void setColor(Color color) { + GlStateManager.color( + color.redf(), + color.greenf(), + color.bluef(), + color.alphaf() + ); + } + + @Override + public Color getColor() { + return new Color(GL11.glGetInteger(GL11.GL_CURRENT_COLOR)); + } + + @Override + public void enableColorLogic(ColorLogic colorLogic) { + GlStateManager.LogicOp op = this.getGlColorLogic(colorLogic); + GlStateManager.colorLogicOp(op); + GlStateManager.enableColorLogic(); + } + + private GlStateManager.LogicOp getGlColorLogic(ColorLogic logic) { + switch (logic) { + case CLEAR: + return GlStateManager.LogicOp.CLEAR; + case SET: + return GlStateManager.LogicOp.SET; + case COPY: + return GlStateManager.LogicOp.COPY; + case COPY_INVERTED: + return GlStateManager.LogicOp.COPY_INVERTED; + case NOOP: + return GlStateManager.LogicOp.NOOP; + case INVERT: + return GlStateManager.LogicOp.INVERT; + case AND: + return GlStateManager.LogicOp.AND; + case NAND: + return GlStateManager.LogicOp.NAND; + case OR: + return GlStateManager.LogicOp.OR; + case NOR: + return GlStateManager.LogicOp.NOR; + case XOR: + return GlStateManager.LogicOp.XOR; + case EQUIV: + return GlStateManager.LogicOp.EQUIV; + case AND_REVERSE: + return GlStateManager.LogicOp.AND_REVERSE; + case OR_REVERSE: + return GlStateManager.LogicOp.OR_REVERSE; + case OR_INVERTED: + return GlStateManager.LogicOp.OR_INVERTED; + } + throw new IllegalStateException("Illegal enum value"); + } + + @Override + public void disableColorLogic() { + GlStateManager.disableColorLogic(); + } + }