diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-22 14:31:13 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-22 14:31:13 +0200 |
commit | 89af4c9fe007e0c4d8ed8edae541b9377e12d8d0 (patch) | |
tree | bd8507b25fbcda577fa54596db10ff9878994570 /src/main/java/cc | |
parent | 54c3c18d1ac4347a35f449f77995e16b0740ec16 (diff) | |
download | OneConfig-89af4c9fe007e0c4d8ed8edae541b9377e12d8d0.tar.gz OneConfig-89af4c9fe007e0c4d8ed8edae541b9377e12d8d0.tar.bz2 OneConfig-89af4c9fe007e0c4d8ed8edae541b9377e12d8d0.zip |
OC-19 semi-working shadow
Diffstat (limited to 'src/main/java/cc')
3 files changed, 55 insertions, 20 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index 21686cd..7e12a74 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -64,6 +64,8 @@ public class OneConfigGui extends UScreen { public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); long start = System.nanoTime(); + int x2 = 0; + int y2 = 0; RenderManager.setupAndDraw((vg) -> { if (currentPage == null) { currentPage = new HomePage(); @@ -82,10 +84,11 @@ public class OneConfigGui extends UScreen { int y = (int) ((UResolution.getWindowHeight() - 800 * scale) / 2f / scale); RenderManager.scale(vg, scale, scale); if (OneConfigConfig.ROUNDED_CORNERS) { + // TODO: Fix issue with white surroundings, related to font rendering + RenderManager.drawDropShadow(vg, x, y, 1280, 800, 32, 16, 20); RenderManager.drawRoundedRect(vg, x + 224, y, 1056, 800, OneConfigConfig.GRAY_800, OneConfigConfig.CORNER_RADIUS_WIN); RenderManager.drawRoundedRect(vg, x, y, 244, 800, OneConfigConfig.GRAY_900_80, OneConfigConfig.CORNER_RADIUS_WIN); RenderManager.drawRect(vg, x + 224, y, 20, 800, OneConfigConfig.GRAY_800); - //RenderManager.drawDropShadow(vg, 544, 140, 1056, 800, 20f, 32f, OneConfigConfig.GRAY_800); } RenderManager.drawLine(vg, x + 224, y + 72, x + 1280, y + 72, 1, OneConfigConfig.GRAY_700); RenderManager.drawLine(vg, x + 224, y, x + 222, y + 800, 1, OneConfigConfig.GRAY_700); @@ -222,7 +225,7 @@ public class OneConfigGui extends UScreen { /** * initialize a new ColorSelector and add it to the draw script. This method is used to make sure it is always rendered on top. - * + * <p> * Correct usage: <code>OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY()));</code> */ public void initColorSelector(ColorSelector colorSelector) { diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java index a04d287..8f8fadf 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -272,22 +272,46 @@ 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 void drawDropShadow(long vg, float x, float y, float w, float h, float blur, float spread, float cornerRadius) { + try ( + NVGPaint shadowPaint = NVGPaint.calloc(); // allocating memory to pass color to nanovg wrapper + NVGColor firstColor = NVGColor.calloc(); // allocating memory to pass color to nanovg wrapper + NVGColor secondColor = NVGColor.calloc() // allocating memory to pass color to nanovg wrapper + ) { + fillNvgColorWithRGBA(0, 0, 0, 0.5f, firstColor); // filling allocated memory + fillNvgColorWithRGBA(0, 0, 0, 0, secondColor); // filling allocated memory + + // creating gradient and put it to shadowPaint + nvgBoxGradient(vg, + x - spread, + y - spread, + w + 2 * spread, + h + 2 * spread, + cornerRadius + spread, + blur, + firstColor, + secondColor, + shadowPaint); + nvgBeginPath(vg); + nvgRoundedRect(vg, + x - spread - blur, + y - spread - blur, + w + 2 * spread + 2 * blur, + h + 2 * spread + 2 * blur, + cornerRadius + spread + ); + nvgRoundedRect(vg, x, y, w, h, cornerRadius); + nvgPathWinding(vg, NVG_HOLE); + nvgFillPaint(vg, shadowPaint); + nvgFill(vg); + } + } + + public static void fillNvgColorWithRGBA(float r, float g, float b, float a, NVGColor color) { + color.r(r); + color.g(g); + color.b(b); + color.a(a); } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java index a09b398..fcfca02 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java @@ -28,12 +28,20 @@ public class MathUtils { * 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) { - float deltaTime = OneConfigGui.INSTANCE == null ? 16 : OneConfigGui.INSTANCE.getDeltaTime(); - c *= deltaTime; + c *= OneConfigGui.INSTANCE == null ? 16 : OneConfigGui.INSTANCE.getDeltaTime(); 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; } + /** + * taken from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a> + */ + public static float easeInOutQuad(float t,float b , float c, float d) { + c *= OneConfigGui.INSTANCE == null ? 16 : OneConfigGui.INSTANCE.getDeltaTime(); + if ((t/=d/2) < 1) return c/2*t*t + b; + return -c/2 * ((--t)*(t-2) - 1) + b; + } + public static float map(float value, float start1, float stop1, float start2, float stop2) { return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1)); } |