Skip to content

Commit

Permalink
Implement drawRectangleWithContours() in DrawContext
Browse files Browse the repository at this point in the history
  • Loading branch information
SmylerMC committed Jan 19, 2024
1 parent 83636fb commit 5796d1d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
14 changes: 6 additions & 8 deletions forge/src/main/java/fr/thesmyler/smylibgui/util/RenderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
14 changes: 14 additions & 0 deletions smylib/core/src/main/java/net/smyler/smylib/gui/DrawContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5796d1d

Please sign in to comment.