diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/screen/TestScreen.java b/forge/src/main/java/fr/thesmyler/smylibgui/screen/TestScreen.java index cec3ac7c..1a9cdb42 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/screen/TestScreen.java +++ b/forge/src/main/java/fr/thesmyler/smylibgui/screen/TestScreen.java @@ -11,9 +11,9 @@ import fr.thesmyler.smylibgui.widgets.buttons.TexturedButtonWidget; import fr.thesmyler.smylibgui.widgets.buttons.TexturedButtonWidget.IncludedTexturedButtons; import fr.thesmyler.smylibgui.widgets.buttons.ToggleButtonWidget; -import fr.thesmyler.smylibgui.widgets.sliders.FloatSliderWidget; -import fr.thesmyler.smylibgui.widgets.sliders.IntegerSliderWidget; -import fr.thesmyler.smylibgui.widgets.sliders.OptionSliderWidget; +import net.smyler.smylib.gui.widgets.sliders.FloatSliderWidget; +import net.smyler.smylib.gui.widgets.sliders.IntegerSliderWidget; +import net.smyler.smylib.gui.widgets.sliders.OptionSliderWidget; import fr.thesmyler.smylibgui.widgets.text.TextAlignment; import fr.thesmyler.smylibgui.widgets.text.TextFieldWidget; import fr.thesmyler.smylibgui.widgets.text.TextWidget; 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 5cb60862..45afcdab 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/util/RenderUtil.java +++ b/forge/src/main/java/fr/thesmyler/smylibgui/util/RenderUtil.java @@ -11,6 +11,7 @@ import static net.smyler.smylib.SmyLib.getGameClient; +@Deprecated public final class RenderUtil { @Deprecated @@ -45,6 +46,7 @@ public static void drawGradientRect(double xLeft, double yTop, double xRight, do drawGradientRect(0, xLeft, yTop, xRight, yBottom, upperLeftColor, lowerLeftColor, lowerRightColor, upperRightColor); } + @Deprecated public static void drawModalRectWithCustomSizedTexture(double x, double y, double z, double u, double v, double width, double height, double textureWidth, double textureHeight) { double f = 1.0f / textureWidth; double f1 = 1.0f / textureHeight; @@ -62,10 +64,12 @@ public static void drawModalRectWithCustomSizedTexture(double x, double y, doubl GlStateManager.disableBlend(); } + @Deprecated public static void drawModalRectWithCustomSizedTexture(double x, double y, double u, double v, double width, double height, double textureWidth, double textureHeight) { drawModalRectWithCustomSizedTexture(x, y, 0d, u, v, width, height, textureWidth, textureHeight); } + @Deprecated public static void drawTexturedModalRect(double x, double y, double z, double minU, double minV, double maxU, double maxV) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder builder = tessellator.getBuffer(); @@ -81,6 +85,7 @@ public static void drawTexturedModalRect(double x, double y, double z, double mi GlStateManager.disableBlend(); } + @Deprecated public static void drawTexturedModalRect(double x, double y, double minU, double minV, double maxU, double maxV) { drawTexturedModalRect(x, y, 0, minU, minV, maxU, maxV); } diff --git a/forge/src/main/java/fr/thesmyler/terramap/eventhandlers/ClientTerramapEventHandler.java b/forge/src/main/java/fr/thesmyler/terramap/eventhandlers/ClientTerramapEventHandler.java index ea29eb06..5ec30b96 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/eventhandlers/ClientTerramapEventHandler.java +++ b/forge/src/main/java/fr/thesmyler/terramap/eventhandlers/ClientTerramapEventHandler.java @@ -1,6 +1,7 @@ package fr.thesmyler.terramap.eventhandlers; import fr.thesmyler.smylibgui.event.HudScreenInitEvent; +import fr.thesmyler.smylibgui.screen.TestScreen; import fr.thesmyler.terramap.TerramapClientContext; import fr.thesmyler.terramap.TerramapMod; import fr.thesmyler.terramap.gui.HudScreenHandler; @@ -14,6 +15,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiChat; import net.minecraft.client.gui.GuiDownloadTerrain; +import net.minecraft.client.gui.GuiMainMenu; import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/screens/LayerListContainer.java b/forge/src/main/java/fr/thesmyler/terramap/gui/screens/LayerListContainer.java index 9e22634f..18a5e9bb 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/screens/LayerListContainer.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/screens/LayerListContainer.java @@ -9,7 +9,7 @@ import net.smyler.smylib.Color; import fr.thesmyler.smylibgui.widgets.buttons.TexturedButtonWidget; import fr.thesmyler.smylibgui.widgets.buttons.ToggleButtonWidget; -import fr.thesmyler.smylibgui.widgets.sliders.FloatSliderWidget; +import net.smyler.smylib.gui.widgets.sliders.FloatSliderWidget; import fr.thesmyler.smylibgui.widgets.text.TextAlignment; import fr.thesmyler.smylibgui.widgets.text.TextWidget; import fr.thesmyler.terramap.gui.screens.config.LayerConfigurationPopup; diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/screens/config/HudConfigScreen.java b/forge/src/main/java/fr/thesmyler/terramap/gui/screens/config/HudConfigScreen.java index d43c797f..b597b599 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/screens/config/HudConfigScreen.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/screens/config/HudConfigScreen.java @@ -14,8 +14,8 @@ import fr.thesmyler.smylibgui.widgets.buttons.TexturedButtonWidget; import fr.thesmyler.smylibgui.widgets.buttons.TexturedButtonWidget.IncludedTexturedButtons; import fr.thesmyler.smylibgui.widgets.buttons.ToggleButtonWidget; -import fr.thesmyler.smylibgui.widgets.sliders.IntegerSliderWidget; -import fr.thesmyler.smylibgui.widgets.sliders.OptionSliderWidget; +import net.smyler.smylib.gui.widgets.sliders.IntegerSliderWidget; +import net.smyler.smylib.gui.widgets.sliders.OptionSliderWidget; import fr.thesmyler.smylibgui.widgets.text.TextAlignment; import fr.thesmyler.smylibgui.widgets.text.TextWidget; import fr.thesmyler.terramap.MapContext; diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/screens/config/TerramapConfigScreen.java b/forge/src/main/java/fr/thesmyler/terramap/gui/screens/config/TerramapConfigScreen.java index f00c9322..d24090c9 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/screens/config/TerramapConfigScreen.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/screens/config/TerramapConfigScreen.java @@ -16,8 +16,8 @@ import fr.thesmyler.smylibgui.widgets.buttons.TexturedButtonWidget; import fr.thesmyler.smylibgui.widgets.buttons.TexturedButtonWidget.IncludedTexturedButtons; import fr.thesmyler.smylibgui.widgets.buttons.ToggleButtonWidget; -import fr.thesmyler.smylibgui.widgets.sliders.IntegerSliderWidget; -import fr.thesmyler.smylibgui.widgets.sliders.OptionSliderWidget; +import net.smyler.smylib.gui.widgets.sliders.IntegerSliderWidget; +import net.smyler.smylib.gui.widgets.sliders.OptionSliderWidget; import fr.thesmyler.smylibgui.widgets.text.TextAlignment; import fr.thesmyler.smylibgui.widgets.text.TextFieldWidget; import fr.thesmyler.smylibgui.widgets.text.TextWidget; diff --git a/smylib/core/src/main/java/net/smyler/smylib/gui/DrawContext.java b/smylib/core/src/main/java/net/smyler/smylib/gui/DrawContext.java index d48eb8c5..5ba44bf2 100644 --- a/smylib/core/src/main/java/net/smyler/smylib/gui/DrawContext.java +++ b/smylib/core/src/main/java/net/smyler/smylib/gui/DrawContext.java @@ -54,10 +54,18 @@ default void drawClosedStrokeLine(Color color, float size, double... points) { this.drawClosedStrokeLine(0d, color, size, points); } - void drawSprite(double x, double y, double z, Sprite sprite); + default void drawSprite(double x, double y, double z, Sprite sprite) { + this.drawSpriteCropped(x, y, z, sprite, 0d, 0d, 0d, 0d); + } default void drawSprite(double x, double y, Sprite sprite) { - this.drawSprite(x, y, 0d, sprite); + this.drawSpriteCropped(x, y, 0d, sprite, 0d, 0d, 0d, 0d); + } + + void drawSpriteCropped(double x, double y, double z, Sprite sprite, double leftCrop, double topCrop, double rightCrop, double bottomCrop); + + default void drawSpriteCropped(double x, double y, Sprite sprite, double leftCrop, double topCrop, double rightCrop, double bottomCrop) { + this.drawSpriteCropped(x, y, 0d, sprite, leftCrop, topCrop, rightCrop, bottomCrop); } } diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/AbstractSliderWidget.java b/smylib/core/src/main/java/net/smyler/smylib/gui/widgets/sliders/AbstractSliderWidget.java similarity index 73% rename from forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/AbstractSliderWidget.java rename to smylib/core/src/main/java/net/smyler/smylib/gui/widgets/sliders/AbstractSliderWidget.java index 41a18932..ff8e6bc3 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/AbstractSliderWidget.java +++ b/smylib/core/src/main/java/net/smyler/smylib/gui/widgets/sliders/AbstractSliderWidget.java @@ -1,22 +1,19 @@ -package fr.thesmyler.smylibgui.widgets.sliders; +package net.smyler.smylib.gui.widgets.sliders; +import net.smyler.smylib.Identifier; import net.smyler.smylib.gui.DrawContext; -import net.smyler.smylib.gui.GlState; +import net.smyler.smylib.gui.Sprite; import org.jetbrains.annotations.Nullable; -import fr.thesmyler.smylibgui.SmyLibGuiTextures; import net.smyler.smylib.game.GameClient; import net.smyler.smylib.game.Key; import net.smyler.smylib.gui.containers.WidgetContainer; import net.smyler.smylib.Color; -import fr.thesmyler.smylibgui.util.RenderUtil; import net.smyler.smylib.gui.widgets.Widget; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; import net.smyler.smylib.gui.Font; -import static net.smyler.smylib.Color.WHITE; +import static java.lang.Math.min; import static net.smyler.smylib.SmyLib.getGameClient; import static net.smyler.smylib.math.Math.saturate; @@ -30,6 +27,10 @@ */ public abstract class AbstractSliderWidget implements Widget { + private static final Identifier TEXTURE = new Identifier("minecraft", "textures/gui/widgets.png"); + private static final Sprite BACKGROUND = new Sprite(TEXTURE, 256d, 256d, 0d, 46d, 200d, 66d); + private static final Sprite SLIDER = new Sprite(TEXTURE, 256d, 256d, 0d, 66d, 200d, 86d); + protected float x, y, width, height; private final int z; @@ -117,47 +118,46 @@ 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); - 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); - float leftWidth = this.width / 2; - float rightWidth = this.width - leftWidth; - float splitHeight = Math.min(10, this.height / 2); - RenderUtil.drawTexturedModalRect(x, y, 0, 46, leftWidth, splitHeight); - RenderUtil.drawTexturedModalRect(x + leftWidth, y, 200 - rightWidth, 46, rightWidth, splitHeight); + + double leftWidth = this.width / 2; + double splitHeight = min(10, this.height / 2); + double xCrop = BACKGROUND.width() - this.width / 2d; + double yCrop = BACKGROUND.height() - min(10d, this.height / 2); + context.drawSpriteCropped(x, y, BACKGROUND, 0d, 0d, xCrop, yCrop); + context.drawSpriteCropped(x + leftWidth, y, BACKGROUND, xCrop, 0, 0, yCrop); for(int i=0; i*18 < this.height - 20; i++) { - RenderUtil.drawTexturedModalRect(x, y + splitHeight + 18*i, 0, 47, leftWidth, 18); - RenderUtil.drawTexturedModalRect(x + leftWidth, y + splitHeight + 18*i, 200 - rightWidth, 47, rightWidth, 18); + context.drawSpriteCropped(x, y + splitHeight + 16d * i, BACKGROUND, 0d, 2d, xCrop, 2d); + context.drawSpriteCropped(x + leftWidth, y + splitHeight + 16d * i, BACKGROUND, xCrop, 2d, 0d, 2d); } - RenderUtil.drawTexturedModalRect(x, y + this.height - splitHeight, 0, 46 + 20 - splitHeight, leftWidth, splitHeight); - RenderUtil.drawTexturedModalRect(x + leftWidth, y + this.height - splitHeight, 200 - rightWidth, 46 + 20 - splitHeight, rightWidth, splitHeight); + context.drawSpriteCropped(x, y + this.height - splitHeight, BACKGROUND, 0, yCrop, xCrop, 0); + context.drawSpriteCropped(x + leftWidth, y + this.height - splitHeight, BACKGROUND, xCrop, yCrop, 0, 0); float sliderPosition = this.getPosition(); - Minecraft.getMinecraft().getTextureManager().bindTexture(SmyLibGuiTextures.BUTTON_TEXTURES); - glState.setColor(WHITE); float sliderX = x + sliderPosition * (this.width - 8); - RenderUtil.drawTexturedModalRect(sliderX, y, 0, 66, 4, splitHeight); - RenderUtil.drawTexturedModalRect(sliderX + 4, y, 196, 66, 4, splitHeight); + context.drawSpriteCropped(sliderX, y, SLIDER, 0, 0, SLIDER.width() - 4d, SLIDER.height() - splitHeight); + context.drawSpriteCropped(sliderX + 4, y, SLIDER, SLIDER.width() - 4d, 0d, 0d, SLIDER.height() - splitHeight); for(int i=0; i*18 < this.height - 20; i++) { - RenderUtil.drawTexturedModalRect(sliderX, y + splitHeight + 18*i, 0, 68, 4, 15); - RenderUtil.drawTexturedModalRect(sliderX + 4, y + splitHeight + 18*i, 196, 68, 4, 15); + context.drawSpriteCropped(sliderX, y + splitHeight + 16*i, SLIDER, 0d, 2d, SLIDER.width() - 4d, 2d); + context.drawSpriteCropped(sliderX + 4d, y + splitHeight + 16*i, SLIDER, SLIDER.width() - 4d, 2d, 0d, 2d); } - RenderUtil.drawTexturedModalRect(sliderX, y + this.height - splitHeight, 0, 66 + 20 - splitHeight, 4, splitHeight); - RenderUtil.drawTexturedModalRect(sliderX + 4, y + this.height - splitHeight, 196, 66 + 20 -splitHeight, 4, splitHeight); + context.drawSpriteCropped(sliderX, y + this.height - splitHeight, SLIDER, 0d, SLIDER.height() - splitHeight, SLIDER.width() - 4d, 0d); + context.drawSpriteCropped(sliderX + 4d, y + this.height - splitHeight, SLIDER, SLIDER.width() - 4d, SLIDER.height() - splitHeight, 0d, 0d); Color textColor = this.enabledTextColor; - if (!this.isEnabled()) textColor = this.disabledTextColor; - else if (hovered || hasFocus) textColor = this.activeTextColor; + if (!this.isEnabled()) { + textColor = this.disabledTextColor; + } else if (hovered || hasFocus) { + textColor = this.activeTextColor; + } + GameClient game = getGameClient(); float fontSize = game.defaultFont().height(); double gameScale = game.scaleFactor(); float fontScale = 1f; - while(fontSize / fontScale > this.height - 1 && fontScale < gameScale) fontScale++; + while(fontSize / fontScale > this.height - 1 && fontScale < gameScale) { + fontScale++; + } Font font = game.defaultFont().withScale(1 / fontScale + 0.0001f); font.drawCenteredString(x + this.width / 2, y + (this.height - font.height() + 1) / 2, this.getDisplayPrefix() + this.getDisplayString(), textColor, false); diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/FloatSliderWidget.java b/smylib/core/src/main/java/net/smyler/smylib/gui/widgets/sliders/FloatSliderWidget.java similarity index 98% rename from forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/FloatSliderWidget.java rename to smylib/core/src/main/java/net/smyler/smylib/gui/widgets/sliders/FloatSliderWidget.java index 9e82b3a0..d91b87b9 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/FloatSliderWidget.java +++ b/smylib/core/src/main/java/net/smyler/smylib/gui/widgets/sliders/FloatSliderWidget.java @@ -1,4 +1,4 @@ -package fr.thesmyler.smylibgui.widgets.sliders; +package net.smyler.smylib.gui.widgets.sliders; import java.util.function.Consumer; diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/IntegerSliderWidget.java b/smylib/core/src/main/java/net/smyler/smylib/gui/widgets/sliders/IntegerSliderWidget.java similarity index 97% rename from forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/IntegerSliderWidget.java rename to smylib/core/src/main/java/net/smyler/smylib/gui/widgets/sliders/IntegerSliderWidget.java index a3cc9f44..28782d1e 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/IntegerSliderWidget.java +++ b/smylib/core/src/main/java/net/smyler/smylib/gui/widgets/sliders/IntegerSliderWidget.java @@ -1,4 +1,4 @@ -package fr.thesmyler.smylibgui.widgets.sliders; +package net.smyler.smylib.gui.widgets.sliders; import java.util.function.Consumer; diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/OptionSliderWidget.java b/smylib/core/src/main/java/net/smyler/smylib/gui/widgets/sliders/OptionSliderWidget.java similarity index 98% rename from forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/OptionSliderWidget.java rename to smylib/core/src/main/java/net/smyler/smylib/gui/widgets/sliders/OptionSliderWidget.java index dc2316e4..2e3372fb 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/widgets/sliders/OptionSliderWidget.java +++ b/smylib/core/src/main/java/net/smyler/smylib/gui/widgets/sliders/OptionSliderWidget.java @@ -1,4 +1,4 @@ -package fr.thesmyler.smylibgui.widgets.sliders; +package net.smyler.smylib.gui.widgets.sliders; import java.util.ArrayList; import java.util.Arrays; diff --git a/forge/src/test/java/fr/thesmyler/smylibgui/widgets/sliders/OptionSliderWidgetTest.java b/smylib/core/src/test/java/net/smyler/smylib/gui/widgets/sliders/OptionSliderWidgetTest.java similarity index 97% rename from forge/src/test/java/fr/thesmyler/smylibgui/widgets/sliders/OptionSliderWidgetTest.java rename to smylib/core/src/test/java/net/smyler/smylib/gui/widgets/sliders/OptionSliderWidgetTest.java index b832ed10..b114ea67 100644 --- a/forge/src/test/java/fr/thesmyler/smylibgui/widgets/sliders/OptionSliderWidgetTest.java +++ b/smylib/core/src/test/java/net/smyler/smylib/gui/widgets/sliders/OptionSliderWidgetTest.java @@ -1,4 +1,4 @@ -package fr.thesmyler.smylibgui.widgets.sliders; +package net.smyler.smylib.gui.widgets.sliders; import net.smyler.smylib.gui.TestingWidgetContainer; import net.smyler.smylib.SmyLibTest; diff --git a/smylib/forge/src/main/java/net/smyler/smylib/gui/Lwjgl2DrawContext.java b/smylib/forge/src/main/java/net/smyler/smylib/gui/Lwjgl2DrawContext.java index 0e7d192a..173d1dc3 100644 --- a/smylib/forge/src/main/java/net/smyler/smylib/gui/Lwjgl2DrawContext.java +++ b/smylib/forge/src/main/java/net/smyler/smylib/gui/Lwjgl2DrawContext.java @@ -64,19 +64,21 @@ public void drawClosedStrokeLine(double z, Color color, float size, double... po } @Override - public void drawSprite(double x, double y, double z, Sprite sprite) { + public void drawSpriteCropped(double x, double y, double z, Sprite sprite, double leftCrop, double topCrop, double rightCrop, double bottomCrop) { final ResourceLocation location = new ResourceLocation(sprite.texture.namespace, sprite.texture.path); Minecraft.getMinecraft().getTextureManager().bindTexture(location); - double uLeft = sprite.xLeft / sprite.textureWidth; - double uRight = sprite.xRight / sprite.textureWidth; - double vTop = sprite.yTop / sprite.textureHeight; - double vBottom = sprite.yBottom / sprite.textureHeight; - double width = sprite.width(); - double height = sprite.height(); + double uLeft = (sprite.xLeft + leftCrop) / sprite.textureWidth; + double uRight = (sprite.xRight - rightCrop) / sprite.textureWidth; + double vTop = (sprite.yTop + topCrop) / sprite.textureHeight; + double vBottom = (sprite.yBottom - bottomCrop) / sprite.textureHeight; + double width = sprite.width() - leftCrop - rightCrop; + double height = sprite.height() - topCrop - bottomCrop; GlStateManager.color(1f, 1f, 1f, 1f); GlStateManager.enableAlpha(); 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); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder builder = tessellator.getBuffer();