aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/lwjgl
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-22 14:31:13 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-22 14:31:13 +0200
commit89af4c9fe007e0c4d8ed8edae541b9377e12d8d0 (patch)
treebd8507b25fbcda577fa54596db10ff9878994570 /src/main/java/cc/polyfrost/oneconfig/lwjgl
parent54c3c18d1ac4347a35f449f77995e16b0740ec16 (diff)
downloadOneConfig-89af4c9fe007e0c4d8ed8edae541b9377e12d8d0.tar.gz
OneConfig-89af4c9fe007e0c4d8ed8edae541b9377e12d8d0.tar.bz2
OneConfig-89af4c9fe007e0c4d8ed8edae541b9377e12d8d0.zip
OC-19 semi-working shadow
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/lwjgl')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java56
1 files changed, 40 insertions, 16 deletions
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);
}