diff options
author | nextdaydelivery <12willettsh@gmail.com> | 2022-03-20 11:37:24 +0000 |
---|---|---|
committer | nextdaydelivery <12willettsh@gmail.com> | 2022-03-20 11:37:24 +0000 |
commit | 72118423d214b964ea9bd3d2a1411c72941c5f90 (patch) | |
tree | 90569b2d1a5fb2b6ac64fcf9141aeec518a8ddfc /src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java | |
parent | fe04136d705ca5f946ee8353c7f7c67e284c9ca5 (diff) | |
download | OneConfig-72118423d214b964ea9bd3d2a1411c72941c5f90.tar.gz OneConfig-72118423d214b964ea9bd3d2a1411c72941c5f90.tar.bz2 OneConfig-72118423d214b964ea9bd3d2a1411c72941c5f90.zip |
a few small things and a couple GUI starting things
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java')
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java index 180215c..7b4fd99 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java @@ -5,7 +5,6 @@ import io.polyfrost.oneconfig.themes.Theme; import io.polyfrost.oneconfig.themes.Themes; import io.polyfrost.oneconfig.themes.textures.ThemeElement; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; import org.jetbrains.annotations.NotNull; import org.lwjgl.input.Keyboard; @@ -38,12 +37,19 @@ public class OCBlock { private boolean rightClicked = false; private int mouseX, mouseY; private boolean hovered; + private float percentHoveredRed = 0f; + private float percentHoveredGreen = 0f; + private float percentHoveredBlue = 0f; + private float percentHoveredAlpha = 0f; + private final Color elementColor = theme.getElementColor(); + private final Color hoverColor = theme.getHoverColor(); + private final Runnable draw; /** - * Create a basic element with nothing. Used for extended classes. + * Create a basic element. */ public OCBlock(int width, int height) { - this(null, false, -1, width, height); + this(null, false, theme.getElementColor().getRGB(), width, height); } /** @@ -51,7 +57,10 @@ public class OCBlock { * @param color color of the element * @param width width of the element * @param height height of the element + * @deprecated + * This method DOES NOT respect the theme colors for the element. Use of {@link #OCBlock(int, int)} is recommended instead. */ + @Deprecated() public OCBlock(int color, int width, int height) { this(null, false, color, width, height); } @@ -60,7 +69,7 @@ public class OCBlock { * Create a new element with the specified text, and automatic width/height + padding. * @param text text to use * @param bold weather or not to use bold text - * @param color color of the background to use + * @param color color for the text */ public OCBlock(@NotNull String text, boolean bold, int color) { this(text, bold, color, theme.getFont().getWidth(text) + 6, theme.getFont().getHeight() + 4); @@ -70,9 +79,10 @@ public class OCBlock { * Create a new element with the specified text, and custom width/height. * @param text text to use * @param bold weather or not to use bold text - * @param color color of the background to use + * @param color color for the text (use {@link Theme#getTextColor()} or {@link Theme#getAccentTextColor()} for default colors) */ public OCBlock(String text, boolean bold, int color, int width, int height) { + this.draw = null; this.text = text; this.bold = bold; this.color = Renderer.getColorFromInt(color); @@ -86,6 +96,7 @@ public class OCBlock { * @param colorMask color mast to use (-1 for default) */ public OCBlock(ThemeElement element, int colorMask, int width, int height) { + this.draw = null; this.element = element; this.color = Renderer.getColorFromInt(colorMask); this.width = width; @@ -94,26 +105,48 @@ public class OCBlock { } /** + * Create a new Element with a custom render script. The {@link Runnable} should ONLY contain #draw() calls or equivalent. + * @param whatToDraw a {@link Runnable}, containing draw scripts for elements. You will need to instantiate the objects first, if they are sub-elements. + */ + public OCBlock(Runnable whatToDraw, int width, int height) { + this.draw = whatToDraw; + this.bold = false; + this.width = width; + this.height = height; + } + + /** * Draw the element at the specified coordinates. */ public void draw(int x, int y) { + GlStateManager.enableBlend(); + percentHoveredRed = smooth(percentHoveredRed, elementColor.getRed() / 255f, hoverColor.getRed() / 255f); + percentHoveredGreen = smooth(percentHoveredGreen, elementColor.getGreen() / 255f, hoverColor.getGreen() / 255f); + percentHoveredBlue = smooth(percentHoveredBlue, elementColor.getBlue() / 255f, hoverColor.getBlue() / 255f); + percentHoveredAlpha = smooth(percentHoveredAlpha, elementColor.getAlpha() / 255f, hoverColor.getAlpha() / 255f); + GlStateManager.color(percentHoveredRed, percentHoveredGreen, percentHoveredBlue, percentHoveredAlpha); update(x, y); + if(draw != null) { + draw.run(); + } if(element != null) { - Gui.drawRect(x, y, x + width, y + height, color.getRGB()); + theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height); GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); theme.getTextureManager().draw(element, x, y, width, height); } if(text == null) { - Gui.drawRect(x, y, x + width, y + height, color.getRGB()); + theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height); } else { - Gui.drawRect(x, y, x + width, y + height, color.getRGB()); + theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height); if(bold) { - theme.getBoldFont().drawString(text, x + 3, y + 2, 1f, 1f, -1); + theme.getBoldFont().drawString(text, x + 3, y + 2, 1f, 1f, color.getRGB()); } else { - theme.getFont().drawString(text, x + 3, y + 2, 1.1f, 1f, -1); + theme.getFont().drawString(text, x + 3, y + 2, 1.1f, 1f, color.getRGB()); } } + GlStateManager.disableBlend(); + } @@ -137,6 +170,9 @@ public class OCBlock { rightClicked = Mouse.isButtonDown(1); onKeyPress(Keyboard.getEventKey()); } + if(clicked) { + Renderer.color(theme.getClickColor()); + } if(!hovered && clicked) clicked = false; } @@ -174,6 +210,19 @@ public class OCBlock { } + + private float smooth(float current, float min, float max) { + current = Renderer.easeOut(current, isHovered() ? 1f : 0f); + if(current <= min) { + current = min; + } + + if(current >= max) { + current = max; + } + return current; + } + public void setText(String text) { this.text = text; } |