From 5796d1dd866af2a9594e53255e7b130906c24a57 Mon Sep 17 00:00:00 2001 From: Smyler Date: Fri, 19 Jan 2024 21:31:37 +0100 Subject: [PATCH] Implement drawRectangleWithContours() in DrawContext --- .../container/ScrollableWidgetContainer.java | 3 +-- .../smylibgui/container/SlidingPanelWidget.java | 3 +-- .../fr/thesmyler/smylibgui/util/RenderUtil.java | 14 ++++++-------- .../terramap/gui/screens/LayerListContainer.java | 4 +--- .../widgets/map/layer/OnlineRasterMapLayer.java | 3 +-- .../java/net/smyler/smylib/gui/DrawContext.java | 14 ++++++++++++++ 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/container/ScrollableWidgetContainer.java b/forge/src/main/java/fr/thesmyler/smylibgui/container/ScrollableWidgetContainer.java index 4d6f3bdb..3c246f3e 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/container/ScrollableWidgetContainer.java +++ b/forge/src/main/java/fr/thesmyler/smylibgui/container/ScrollableWidgetContainer.java @@ -1,7 +1,6 @@ package fr.thesmyler.smylibgui.container; import net.smyler.smylib.Color; -import fr.thesmyler.smylibgui.util.RenderUtil; import net.smyler.smylib.gui.containers.FlexibleWidgetContainer; import net.smyler.smylib.gui.widgets.Widget; import fr.thesmyler.smylibgui.widgets.ScrollbarWidget; @@ -98,7 +97,7 @@ public void updateScrollbars() { public void draw(DrawContext context, float x, float y, float mouseX, float mouseY, boolean screenHovered, boolean screenFocused, WidgetContainer parent) { context.drawRectangle(x, y, x + this.getWidth(), y + this.getHeight(), this.backgroundColor); super.draw(context, x, y, mouseX, mouseY, screenHovered, screenFocused, parent); - RenderUtil.drawRectWithContour(x, y, x + this.getWidth(), y + this.getHeight(), Color.TRANSPARENT, this.contourSize, this.contourColor); + context.drawRectangleWithContours(x, y, x + this.getWidth(), y + this.getHeight(), Color.TRANSPARENT, this.contourSize, this.contourColor); } public Color getBackgroundColor() { diff --git a/forge/src/main/java/fr/thesmyler/smylibgui/container/SlidingPanelWidget.java b/forge/src/main/java/fr/thesmyler/smylibgui/container/SlidingPanelWidget.java index 5a0259c4..41f0aece 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/container/SlidingPanelWidget.java +++ b/forge/src/main/java/fr/thesmyler/smylibgui/container/SlidingPanelWidget.java @@ -3,7 +3,6 @@ import net.smyler.smylib.Animation; import net.smyler.smylib.Animation.AnimationState; import net.smyler.smylib.Color; -import fr.thesmyler.smylibgui.util.RenderUtil; import net.smyler.smylib.gui.DrawContext; import net.smyler.smylib.gui.containers.FlexibleWidgetContainer; import net.smyler.smylib.gui.containers.WidgetContainer; @@ -34,7 +33,7 @@ public SlidingPanelWidget(int z, long delay) { @Override public void draw(DrawContext context, float x, float y, float mouseX, float mouseY, boolean hovered, boolean focused, @Nullable WidgetContainer parent){ - RenderUtil.drawRectWithContour(x, y, x + this.getWidth(), y + this.getHeight(), this.backgroundColor, this.contourSize, this.contourColor); + context.drawRectangleWithContours(x, y, x + this.getWidth(), y + this.getHeight(), this.backgroundColor, this.contourSize, this.contourColor); super.draw(context, x, y, mouseX, mouseY, hovered, focused, parent); this.mainAnimation.update(); } 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 e3a0b076..b97a02b0 100644 --- a/forge/src/main/java/fr/thesmyler/smylibgui/util/RenderUtil.java +++ b/forge/src/main/java/fr/thesmyler/smylibgui/util/RenderUtil.java @@ -23,15 +23,13 @@ public static void drawRect(double xLeft, double yTop, double xRight, double yBo drawGradientRect(0, xLeft, yTop, xRight, yBottom, color, color, color, color); } + @Deprecated public static void drawRectWithContour(int z, double xLeft, double yTop, double xRight, double yBottom, Color color, float contourSize, Color contourColor) { - drawRect(z, xLeft, yTop, xRight, yBottom, color); - drawClosedStrokeLine(z, contourColor, contourSize, - xLeft, yTop, - xLeft, yBottom, - xRight, yBottom, - xRight, yTop); - } - + DrawContext context = getGameClient().guiDrawContext(); + context.drawRectangleWithContours(z, xLeft, yTop, xRight, yBottom, color, contourSize, contourColor); + } + + @Deprecated public static void drawRectWithContour(double xLeft, double yTop, double xRight, double yBottom, Color color, float contourSize, Color contourColor) { drawRectWithContour(0, xLeft, yTop, xRight, yBottom, color, contourSize, contourColor); } 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 80a781ea..9e22634f 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 @@ -7,7 +7,6 @@ import net.smyler.smylib.gui.containers.WidgetContainer; import net.smyler.smylib.Animation; import net.smyler.smylib.Color; -import fr.thesmyler.smylibgui.util.RenderUtil; import fr.thesmyler.smylibgui.widgets.buttons.TexturedButtonWidget; import fr.thesmyler.smylibgui.widgets.buttons.ToggleButtonWidget; import fr.thesmyler.smylibgui.widgets.sliders.FloatSliderWidget; @@ -28,7 +27,6 @@ import static java.util.Comparator.comparing; import static net.smyler.smylib.SmyLib.getGameClient; -//TODO localize class LayerListContainer extends FlexibleWidgetContainer { private final MapWidget map; @@ -104,7 +102,7 @@ public LayerEntry(MapLayer layer, float y, float height) { @Override public void draw(DrawContext context, float x, float y, float mouseX, float mouseY, boolean screenHovered, boolean screenFocused, WidgetContainer parent) { - RenderUtil.drawRectWithContour(x, y, x + this.getWidth(), y + this.getHeight(), Color.LIGHT_OVERLAY , 1f, Color.DARK_GRAY); + context.drawRectangleWithContours(x, y, x + this.getWidth(), y + this.getHeight(), Color.LIGHT_OVERLAY , 1f, Color.DARK_GRAY); super.draw(context, x, y, mouseX, mouseY, screenHovered, screenFocused, parent); } diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/OnlineRasterMapLayer.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/OnlineRasterMapLayer.java index 4c52dd83..9af7f9ae 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/OnlineRasterMapLayer.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/OnlineRasterMapLayer.java @@ -6,7 +6,6 @@ import net.smyler.smylib.gui.containers.WidgetContainer; import net.smyler.smylib.Animation; import net.smyler.smylib.Color; -import fr.thesmyler.smylibgui.util.RenderUtil; import fr.thesmyler.smylibgui.widgets.text.TextWidget; import fr.thesmyler.terramap.TerramapClientContext; import fr.thesmyler.terramap.TerramapConfig; @@ -176,7 +175,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous if (this.selected) { background = selectedColor; } - RenderUtil.drawRectWithContour(x, y, x + width, y + height, background , 1f, Color.DARK_GRAY); + context.drawRectangleWithContours(x, y, x + width, y + height, background , 1f, Color.DARK_GRAY); super.draw(context, x, y, mouseX, mouseY, screenHovered, screenFocused, parent); } 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 5b3efdeb..9148e088 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 @@ -16,6 +16,20 @@ default void drawRectangle(double xLeft, double yTop, double xRight, double yBot this.drawGradientRectangle(0d, xLeft, yTop, xRight, yBottom, color, color, color, color); } + default void drawRectangleWithContours(double z, double xLeft, double yTop, double xRight, double yBottom, Color color, float contoursSize, Color contoursColor) { + this.drawRectangle(z, xLeft, yTop, xRight, yBottom, color); + this.drawClosedStrokeLine(z, contoursColor, contoursSize, + xLeft, yTop, + xLeft, yBottom, + xRight, yBottom, + xRight, yTop + ); + } + + default void drawRectangleWithContours(double xLeft, double yTop, double xRight, double yBottom, Color color, float contoursSize, Color contoursColor) { + this.drawRectangleWithContours(0, xLeft, yTop, xRight, yBottom, color, contoursSize, contoursColor); + } + void drawGradientRectangle(double z, double xLeft, double yTop, double xRight, double yBottom, Color upperLeftColor, Color lowerLeftColor, Color lowerRightColor, Color upperRightColor); default void drawGradientRectangle(double xLeft, double yTop, double xRight, double yBottom, Color upperLeftColor, Color lowerLeftColor, Color lowerRightColor, Color upperRightColor) {