diff options
author | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-04-22 13:50:48 +0100 |
---|---|---|
committer | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-04-22 13:50:48 +0100 |
commit | b161692ce6a93100ea882061dd9838b2f019d208 (patch) | |
tree | 5174f698af2b82c30f645a772fcc87cd08576190 | |
parent | 260d48126cbedb4341c5c5865bfd8e605f90955a (diff) | |
download | OneConfig-b161692ce6a93100ea882061dd9838b2f019d208.tar.gz OneConfig-b161692ce6a93100ea882061dd9838b2f019d208.tar.bz2 OneConfig-b161692ce6a93100ea882061dd9838b2f019d208.zip |
sidebar stuff and general fixes to gui elements
8 files changed, 277 insertions, 53 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java index 14cad6c..04cc24f 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java +++ b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java @@ -14,26 +14,27 @@ public class OneConfigConfig extends Config { public static String currentProfile = "Default Profile"; // TODO i dont know how this works so this is just gonna be here for now - public static int TRANSPARENT = new Color(0,0,0,0).getRGB(); // Transparent // button sidebar normal + public static final int TRANSPARENT = new Color(0,0,0,0).getRGB(); // Transparent // button sidebar normal - public static int GRAY_900 = new Color(13, 14, 15, 255).getRGB(); // Gray 900 - public static int GRAY_900_80 = new Color(13, 14, 15, 204).getRGB(); // Gray 900 80% + public static final int GRAY_900 = new Color(13, 14, 15, 255).getRGB(); // Gray 900 + public static final int GRAY_900_80 = new Color(13, 14, 15, 204).getRGB(); // Gray 900 80% // im waiting for u to say the gray button colors - public static int GRAY_800 = new Color(21, 22, 23, 255).getRGB(); // Gray 800 - public static int GRAY_700 = new Color(34, 35, 38, 255).getRGB(); // Gray 700 - public static int GRAY_600 = new Color(42, 44, 48, 255).getRGB(); // Gray 600 - public static int GRAY_500 = new Color(49, 51, 56, 255).getRGB(); // Gray 500 // button sidebar hover, button gray normal - public static int GRAY_500_80 = new Color(49, 51, 56, 204).getRGB(); // Gray 500 80% // button sidebar pressed - - public static int GRAY_400 = new Color(55, 59, 69, 255).getRGB(); // Gray 400 // button gray hover - public static int GRAY_400_80 = new Color(55, 59, 69, 204).getRGB(); // Gray 400 80% // button gray pressed - public static int BLUE_700 = new Color(18, 71, 178, 255).getRGB(); // Blue 700 - public static int BLUE_600 = new Color(20, 82, 204, 255).getRGB(); // Blue 600 // button blue normal - public static int BLUE_600_80 = new Color(20, 82, 204, 204).getRGB(); // Blue 600 80% // button blue click - public static int BLUE_500 = new Color(25, 103, 255, 255).getRGB(); // Blue 500 // button blue hover - public static int WHITE_60 = new Color(255, 255, 255, 153).getRGB(); // White 60% - public static int WHITE_90 = new Color(255, 255, 255, 229).getRGB(); // White 90% - public static int WHITE = new Color(255, 255, 255, 255).getRGB(); // White 100% + public static final int GRAY_800 = new Color(21, 22, 23, 255).getRGB(); // Gray 800 + public static final int GRAY_700 = new Color(34, 35, 38, 255).getRGB(); // Gray 700 + public static final int GRAY_600 = new Color(42, 44, 48, 255).getRGB(); // Gray 600 + public static final int GRAY_500 = new Color(49, 51, 56, 255).getRGB(); // Gray 500 // button sidebar hover, button gray normal + public static final int GRAY_500_80 = new Color(49, 51, 56, 204).getRGB(); // Gray 500 80% // button sidebar pressed + + public static final int GRAY_400 = new Color(55, 59, 69, 255).getRGB(); // Gray 400 // button gray hover + public static final int GRAY_400_80 = new Color(55, 59, 69, 204).getRGB(); // Gray 400 80% // button gray pressed + public static final int BLUE_700 = new Color(18, 71, 178, 255).getRGB(); // Blue 700 + public static final int BLUE_600 = new Color(20, 82, 204, 255).getRGB(); // Blue 600 // button blue normal + public static final int BLUE_600_80 = new Color(20, 82, 204, 204).getRGB(); // Blue 600 80% // button blue click + public static final int BLUE_500 = new Color(25, 103, 255, 255).getRGB(); // Blue 500 // button blue hover + public static final int WHITE_60 = new Color(255, 255, 255, 153).getRGB(); // White 60% + public static final int WHITE_80 = new Color(255, 255, 255, 204).getRGB(); // White 80% + public static final int WHITE_90 = new Color(255, 255, 255, 229).getRGB(); // White 90% + public static final int WHITE = new Color(255, 255, 255, 255).getRGB(); // White 100% public static boolean ROUNDED_CORNERS = true; public static float CORNER_RADIUS_WIN = 20f; diff --git a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java index 24bfe19..0879bd4 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java @@ -8,13 +8,20 @@ import io.polyfrost.oneconfig.lwjgl.RenderManager; import io.polyfrost.oneconfig.lwjgl.font.Fonts; import net.minecraft.client.gui.GuiScreen; import org.lwjgl.input.Keyboard; +import org.lwjgl.nanovg.NVGColor; +import org.lwjgl.nanovg.NanoVG; public class OneConfigGui extends GuiScreen { public static OneConfigGui INSTANCE; private final BasicElement element = new BasicElement(200, 200, 1, true); + public final int x = 320; + public final int y = 140; + + private final SideBar sideBar = new SideBar(); + private final TextInputField textInputField = new TextInputField(776, 32, "Search all of OneConfig...", false, false); - private final BasicButton btn = new BasicButton(184, 36, "Socials", "/assets/oneconfig/textures/share.png", "/assets/oneconfig/textures/share2.png", 1, true); + private final BasicButton btn = new BasicButton(184, 36, "Socials", "/assets/oneconfig/textures/share.png", "/assets/oneconfig/textures/share2.png", 1, BasicButton.ALIGNMENT_CENTER); public OneConfigGui() { INSTANCE = this; @@ -27,6 +34,7 @@ public class OneConfigGui extends GuiScreen { RenderManager.drawRoundedRect(vg, 544, 140, 1056, 800, OneConfigConfig.GRAY_800, OneConfigConfig.CORNER_RADIUS_WIN); RenderManager.drawRoundedRect(vg, 320, 140, 244, 800, OneConfigConfig.GRAY_900_80, OneConfigConfig.CORNER_RADIUS_WIN); RenderManager.drawRect(vg, 544, 140, 20, 800, OneConfigConfig.GRAY_800); + //RenderManager.drawDropShadow(vg, 544, 140, 1056, 800, 20f, 32f, OneConfigConfig.GRAY_800); } else { // L; } @@ -34,10 +42,12 @@ public class OneConfigGui extends GuiScreen { RenderManager.drawLine(vg, 544, 212, 1600, 212, 1, OneConfigConfig.GRAY_700); RenderManager.drawLine(vg, 544, 140, 544, 940, 1, OneConfigConfig.GRAY_700); - RenderManager.drawString(vg, "OneConfig", 389, 163, OneConfigConfig.WHITE, 18f, Fonts.INTER_BOLD); + RenderManager.drawImage(vg, "/assets/oneconfig/textures/icon.png", x + 19, y + 19, 42, 42); + RenderManager.drawString(vg, "OneConfig", x + 69, y + 23, OneConfigConfig.WHITE, 18f, Fonts.INTER_BOLD); RenderManager.drawString(vg, "By Polyfrost", 389, 183, OneConfigConfig.WHITE, 12f, Fonts.INTER_REGULAR); //element.setColorPalette(0); try { + sideBar.draw(vg, x, y); //element.draw(vg, 0, 0); textInputField.draw(vg, 792, 548); btn.draw(vg, 976, 870); diff --git a/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java new file mode 100644 index 0000000..0b8659f --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java @@ -0,0 +1,67 @@ +package io.polyfrost.oneconfig.gui; + +import io.polyfrost.oneconfig.config.OneConfigConfig; +import io.polyfrost.oneconfig.gui.elements.BasicButton; +import io.polyfrost.oneconfig.lwjgl.RenderManager; +import io.polyfrost.oneconfig.lwjgl.font.Fonts; +import io.polyfrost.oneconfig.utils.MathUtils; + +import java.util.ArrayList; +import java.util.List; + +public class SideBar { + private final List<BasicButton> btnList = new ArrayList<>(); + + private float targetY = 0, currentY = 0; + + public SideBar() { + btnList.add(new BasicButton(192, 36, "Dashboard", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Global Search", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Mods", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Performance", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Profiles", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Updates", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Screenshots", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "HUD Settings", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "General", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Close", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Minimize", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT)); + btnList.add(new BasicButton(192, 36, "Edit HUD", "/assets/oneconfig/textures/share.png", null, 0, BasicButton.ALIGNMENT_LEFT)); + } + + public void draw(long vg, int x, int y) { + //percentMove = 36f; + + currentY = MathUtils.easeInOutCirc(50, currentY, targetY - currentY, 120); + RenderManager.drawRoundedRect(vg, x + 16, currentY, 192, 36, OneConfigConfig.BLUE_600, OneConfigConfig.CORNER_RADIUS); + int i = 0; + if (targetY == 0) { + targetY = x + 16; + currentY = targetY; + } + for (BasicButton btn : btnList) { + btn.draw(vg, x + 16, y + 96 + i); + i += 44; + if (i == 88) { // +88 + RenderManager.drawString(vg, "MOD CONFIG", x + 16, y + 200, OneConfigConfig.WHITE_90, 12f, Fonts.INTER_SEMIBOLD); + i = 122; + } + if (i == 298) { + RenderManager.drawString(vg, "PERSONALIZATION", x + 16, y + 420, OneConfigConfig.WHITE_90, 12f, Fonts.INTER_SEMIBOLD); + i = 342; + } + if (i == 474) { + i = 518; + } + + if (btn.isClicked()) { + targetY = btn.y; + } + } + + + + + + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java index e918287..39d5e9c 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -1,5 +1,6 @@ package io.polyfrost.oneconfig.gui.elements; +import io.polyfrost.oneconfig.config.OneConfigConfig; import io.polyfrost.oneconfig.lwjgl.RenderManager; import io.polyfrost.oneconfig.lwjgl.font.Fonts; import io.polyfrost.oneconfig.utils.ColorUtils; @@ -12,34 +13,88 @@ public class BasicButton extends BasicElement { protected String text; protected String fileNameLeftIco, fileNameRightIco; + private final int thisAlignment; + private final float fontSize; + private final int colorPalette; - public BasicButton(int width, int height, @NotNull String text, @Nullable String fileNameLeftIco, @Nullable String fileNameRightIco, int colorPalette, boolean hoverFx) { - super(width, height, colorPalette, hoverFx); + public int x, y; + public static final int ALIGNMENT_LEFT = 0; + public static final int ALIGNMENT_CENTER = 1; + + /** + * Create a new basic button. Used mostly on the homepage and the sidebar. Note: The button will not be drawn until you call {@link #draw(long, int, int)}. + * The button's content is centered on its total length, so the text is not always in the middle. + * @param text Text to display on the button. Has to be there. + * @param fileNameLeftIco file path of the icon to display on the left. Can be null if you don't want to display an icon on the left. + * @param fileNameRightIco file path of the icon to display on the right. Can be null if you don't want to display an icon on the right. + * @param colorPalette color palette to use. see {@link io.polyfrost.oneconfig.utils.ColorUtils} for more info. Can support color palette of -2, which is larger font and icons. Also supports -3, which is just the text changing color. + * @param alignment alignment of the button. ALIGNMENT_LEFT or ALIGNMENT_CENTER. + */ + public BasicButton(int width, int height, @NotNull String text, @Nullable String fileNameLeftIco, @Nullable String fileNameRightIco, int colorPalette, int alignment) { + super(width, height, colorPalette, true); this.text = text; this.fileNameLeftIco = fileNameLeftIco; this.fileNameRightIco = fileNameRightIco; + this.thisAlignment = alignment; + if(colorPalette == -2) { + fontSize = 24f; + this.colorPalette = -1; + } else { + fontSize = 14f; + this.colorPalette = colorPalette; + } } @Override public void draw(long vg, int x, int y) { + this.x = x; + this.y = y; + int textColor = -1; RenderManager.drawRectangle(vg, x, y, this.width, this.height, this.currentColor); - final float fontSize; - if(colorPalette == -1) { - fontSize = 24f; - } else fontSize = 14f; - float width = RenderManager.getTextWidth(vg, text, fontSize); - int middle = x + this.width / 2; - RenderManager.drawString(vg, text,middle - width / 2, y + ((float) height / 2),-1, fontSize, Fonts.INTER_MEDIUM); + float contentWidth = RenderManager.getTextWidth(vg, text, fontSize); if(fileNameLeftIco != null) { - RenderManager.drawImage(vg, fileNameLeftIco, middle - width - 8, y + 8, 20, 20); + contentWidth += 28; } if(fileNameRightIco != null) { - RenderManager.drawImage(vg, fileNameRightIco, middle + width - 8, y + 8, 20, 20); + contentWidth += 28; + } + + if(this.colorPalette == -3) { + textColor = OneConfigConfig.WHITE_80; + if(hovered) textColor = OneConfigConfig.WHITE; + if(clicked) textColor = OneConfigConfig.WHITE_80; + } + + if(thisAlignment == ALIGNMENT_CENTER) { + int middle = x + this.width / 2; + RenderManager.drawString(vg, text, middle - contentWidth / 2 + (fileNameLeftIco != null ? 28 : 0), y + ((float) height / 2), textColor, fontSize, Fonts.INTER_MEDIUM); + if (fileNameLeftIco != null) { + RenderManager.drawImage(vg, fileNameLeftIco, middle - contentWidth / 2, y + 8, 20, 20); + } + if (fileNameRightIco != null) { + RenderManager.drawImage(vg, fileNameRightIco, middle + contentWidth / 2 - (fileNameLeftIco != null ? 20 : 24), y + 8, 20, 20); + } + } + if(thisAlignment == ALIGNMENT_LEFT) { + if(fileNameLeftIco != null) { + RenderManager.drawImage(vg, fileNameLeftIco, x + 12, y + 8, 20, 20); + RenderManager.drawString(vg, text, x + 40, y + ((float) height / 2), textColor, fontSize, Fonts.INTER_MEDIUM); + } else { + RenderManager.drawString(vg, text, x + 12, y + ((float) height / 2), textColor, fontSize, Fonts.INTER_MEDIUM); + } + if(fileNameRightIco != null) { + RenderManager.drawImage(vg, fileNameRightIco, x + width - 28, y + 8, 20, 20); + } } this.update(x, y); if(hoverFx) { - currentColor = ColorUtils.getColor(currentColor, 1, hovered, clicked); + if(colorPalette == -3) { + currentColor = OneConfigConfig.TRANSPARENT; + return; + } + currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked); + } } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java index 7b56a40..e2c7602 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java @@ -1,24 +1,30 @@ package io.polyfrost.oneconfig.gui.elements; +import com.google.common.base.Strings; import io.polyfrost.oneconfig.config.OneConfigConfig; import io.polyfrost.oneconfig.lwjgl.RenderManager; import io.polyfrost.oneconfig.lwjgl.font.Fonts; import net.minecraft.client.gui.GuiScreen; +import org.jetbrains.annotations.NotNull; import org.lwjgl.input.Keyboard; +import static org.lwjgl.nanovg.NanoVG.*; + public class TextInputField extends BasicElement { protected final String defaultText; protected String input; - protected final boolean mulitLine; + protected final boolean multiLine; protected boolean password; + protected int caretPos; + public TextInputField(int width, int height, String defaultText, boolean multiLine, boolean password) { super(width, height, false); - this.mulitLine = multiLine; + this.multiLine = multiLine; this.defaultText = defaultText; this.password = password; - this.input = defaultText; + this.input = ""; } public void setInput(String input) { @@ -35,11 +41,20 @@ public class TextInputField extends BasicElement { @Override public void draw(long vg, int x, int y) { - RenderManager.drawRectangle(vg, x, y, width, height, OneConfigConfig.GRAY_700); - RenderManager.drawRectangle(vg, x + 2, y + 2, width - 2, height - 4, OneConfigConfig.GRAY_900); + RenderManager.drawHollowRoundRect(vg, x, y, width, height, OneConfigConfig.GRAY_700, 12f, 2f); super.update(x, y); int color = toggled ? OneConfigConfig.WHITE : OneConfigConfig.WHITE_60; - float width = RenderManager.getTextWidth(vg, input, 14f); + float width; + StringBuilder s = new StringBuilder(); + int offset = 12; + if(!password) { + width = RenderManager.getTextWidth(vg, input.substring(0, caretPos), 14f); + } else { + for(int i = 0; i < input.length(); i++) { + s.append("*"); + } + width = RenderManager.getTextWidth(vg, s.substring(0, caretPos), 14f); + } if(toggled) { RenderManager.drawLine(vg, x + width + 12, (float) y + 7, x + width + 13, (float) y + height - 7, 1, OneConfigConfig.WHITE); @@ -48,8 +63,14 @@ public class TextInputField extends BasicElement { if(input.equals("")){ RenderManager.drawString(vg, defaultText, x + 12, y + 17, color, 14f, Fonts.INTER_REGULAR); } - RenderManager.drawString(vg, input, x + 12, y + 17, color, 14f, Fonts.INTER_REGULAR); + nvgScissor(vg, x, y, this.width, height); + if(!password) { + RenderManager.drawString(vg, input, x + offset, y + 17, color, 14f, Fonts.INTER_REGULAR); + nvgResetScissor(vg); + } else { + RenderManager.drawString(vg, s.toString(), x + offset, y + 17, color, 14f, Fonts.INTER_REGULAR); + } } public void keyTyped(char c, int key) { @@ -58,23 +79,48 @@ public class TextInputField extends BasicElement { if(key == Keyboard.KEY_BACK) { try { input = input.substring(0, input.lastIndexOf(" ")); + caretPos = input.length(); } catch (Exception e) { input = ""; + caretPos = 0; } } return; } if (key == Keyboard.KEY_BACK) { if (input.length() > 0) { - input = input.substring(0, input.length() - 1); - return; + if(caretPos == input.length()) { + input = input.substring(0, input.length() - 1); + } else { + input = input.substring(0, caretPos - 1) + input.substring(caretPos); + } + caretPos--; } + return; } if(key == Keyboard.KEY_TAB) { input += " "; + caretPos += 4; + return; + } + + if (key == Keyboard.KEY_RIGHT) { + caretPos++; + if(caretPos > input.length()) { + caretPos = input.length(); + } + return; + } + if (key == Keyboard.KEY_LEFT) { + caretPos--; + if(caretPos < 0) { + caretPos = 0; + } return; } + + if(key == Keyboard.KEY_RETURN) { toggled = false; } @@ -82,7 +128,12 @@ public class TextInputField extends BasicElement { if(key == Keyboard.KEY_LCONTROL || key == Keyboard.KEY_RCONTROL || key == Keyboard.KEY_LMENU || key == Keyboard.KEY_RMENU || key == Keyboard.KEY_LMETA || key == Keyboard.KEY_RMETA || key == Keyboard.KEY_LSHIFT || key == Keyboard.KEY_RSHIFT || key == Keyboard.KEY_RETURN || key == Keyboard.KEY_CAPITAL || key == 221) { return; } - input += c; + input = addCharAtPoint(caretPos, c); + caretPos++; } } + + private @NotNull String addCharAtPoint(int index, char c) { + return input.substring(0, index) + c + input.substring(index); + } } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/Page.java new file mode 100644 index 0000000..72fa3a3 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/Page.java @@ -0,0 +1,4 @@ +package io.polyfrost.oneconfig.gui.pages; + +public class Page { +} diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java index 2ed8404..55d9fdd 100644 --- a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -66,7 +66,7 @@ public final class RenderManager { } public static void drawRectangle(long vg, float x, float y, float width, float height, int color) { - if(OneConfigConfig.ROUNDED_CORNERS) { + if (OneConfigConfig.ROUNDED_CORNERS) { drawRoundedRect(vg, x, y, width, height, color, OneConfigConfig.CORNER_RADIUS); } else { drawRect(vg, x, y, width, height, color); @@ -74,7 +74,7 @@ public final class RenderManager { } public static void drawGradientRectangle(long vg, float x, float y, float width, float height, int color1, int color2) { - if(OneConfigConfig.ROUNDED_CORNERS) { + if (OneConfigConfig.ROUNDED_CORNERS) { drawGradientRoundedRect(vg, x, y, width, height, color1, color2, OneConfigConfig.CORNER_RADIUS); } else { drawGradientRect(vg, x, y, width, height, color1, color2); @@ -124,6 +124,18 @@ public final class RenderManager { nvgColor.free(); } + public static void drawHollowRoundRect(long vg, float x, float y, float width, float height, int color, float radius, float thickness) { + nvgBeginPath(vg); + nvgRoundedRect(vg, x + thickness, y + thickness, width - thickness, height - thickness, radius); + nvgStrokeWidth(vg, thickness); + nvgPathWinding(vg, NVG_HOLE); + color(vg, color); + NVGColor nvgColor = color(vg, color); + nvgStrokeColor(vg, nvgColor); + nvgStroke(vg); + nvgColor.free(); + } + public static void drawCircle(long vg, float x, float y, float radius, int color) { nvgBeginPath(vg); nvgCircle(vg, x, y, radius); @@ -208,7 +220,7 @@ public final class RenderManager { } - } catch (Exception e ) { + } catch (Exception e) { //e.printStackTrace(); } } @@ -216,7 +228,8 @@ public final class RenderManager { public static float getTextWidth(long vg, String text, float fontSize) { float[] bounds = new float[4]; - return (nvgTextBounds(vg, 0, 0, text, bounds) / 12) * fontSize; + nvgFontSize(vg, fontSize); + return nvgTextBounds(vg, 0, 0, text, bounds); } public static void drawLine(long vg, float x, float y, float endX, float endY, float width, int color) { @@ -230,6 +243,25 @@ public final class RenderManager { nvgColor.free(); } + public static void drawDropShadow(long vg, float x, float y, float w, float h, float cornerRadius, float spread, int color) { // TODO broken + NVGColor color1 = NVGColor.calloc(); + NVGColor color2 = NVGColor.calloc(); + NVGPaint shadowPaint = NVGPaint.calloc(); + nvgRGBA((byte) 0, (byte) 0, (byte) 0, (byte) 128, color1); + nvgRGBA((byte) 0, (byte) 0, (byte) 0, (byte) 0, color2); + nvgBoxGradient(vg, x, y + 2, w, h, cornerRadius * 2, 10f, color2, color1, shadowPaint); + nvgBeginPath(vg); + nvgRect(vg, x - 10, y - 10, w + 20, h + 30); + nvgRoundedRect(vg, x, y, w, h, cornerRadius); + nvgPathWinding(vg, NVG_HOLE); + nvgFillPaint(vg, shadowPaint); + nvgFill(vg); + shadowPaint.free(); + color1.free(); + color2.free(); + + } + public static NVGColor color(long vg, int color) { NVGColor nvgColor = NVGColor.calloc(); diff --git a/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java index 547e286..dc70eea 100644 --- a/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java +++ b/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java @@ -5,13 +5,6 @@ public class MathUtils { return number < (float) 0.0 ? (float) 0.0 : Math.min(number, (float) 1.0); } - public static float easeOut(float current, float goal) { - if (Math.floor(Math.abs(goal - current) / (float) 0.01) > 0) { - return current + (goal - current) / (float) 100.0; - } else { - return goal; - } - } public static float easeOut(float current, float goal, float speed) { if (Math.floor(Math.abs(goal - current) / (float) 0.01) > 0) { return current + (goal - current) / speed; @@ -21,4 +14,15 @@ public class MathUtils { } + public static float easeInQuad(float current) { + return current * current; + } + + /** taken from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a> */ + public static float easeInOutCirc(float t, float b, float c, float d) { + if ((t /= d / 2) < 1) return -c / 2 * ((float) Math.sqrt(1 - t * t) - 1) + b; + return c / 2 * ((float) Math.sqrt(1 - (t -= 2) * t) + 1) + b; + } + + } |