aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authornextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-04-19 17:09:13 +0100
committernextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-04-19 17:09:26 +0100
commit9986f445b89fc866265dade49b8356f87199a01e (patch)
tree43bd51d5a9519bd5943adacdfdee18871ca494f3 /src/main/java
parent1d20fe41ea7d25cc0322cb297760b18a60d665a7 (diff)
downloadOneConfig-9986f445b89fc866265dade49b8356f87199a01e.tar.gz
OneConfig-9986f445b89fc866265dade49b8356f87199a01e.tar.bz2
OneConfig-9986f445b89fc866265dade49b8356f87199a01e.zip
i am so sad ive wasted an entire day and made literally no progress (plz try and fix)
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java59
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java14
-rw-r--r--src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java2
3 files changed, 48 insertions, 27 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
index 64fbe1f..dcfc348 100644
--- a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
@@ -13,6 +13,7 @@ import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import java.awt.*;
+import java.nio.FloatBuffer;
import java.util.function.LongConsumer;
import static org.lwjgl.nanovg.NanoSVG.NSVG_FLAGS_VISIBLE;
@@ -132,34 +133,42 @@ public final class RenderManager {
public static void drawSVGImage(long vg, String fileName, float x, float y, float width, float height) {
if (ImageLoader.INSTANCE.loadSVGImage(fileName)) {
- NSVGImage image = ImageLoader.INSTANCE.getSVG(fileName);
- NSVGShape shape;
- NSVGPath path;
- int i;
- for(shape = image.shapes(); shape != null; shape.next()) { // throws npe
- if (!(shape.flags() == NSVG_FLAGS_VISIBLE)) {
- continue;
- }
-
- nvgFillColor(vg, color(vg, shape.fill().color()));
- nvgStrokeColor(vg, color(vg, shape.stroke().color()));
- nvgStrokeWidth(vg, shape.strokeWidth());
-
- for(path = shape.paths(); path != null; path.next()) {
- nvgBeginPath(vg);
- nvgMoveTo(vg, path.pts().get(0), path.pts().get(1));
- for(i = 0; i < path.npts() - 1; i += 3) {
- float[] p = new float[100]; // INSta CRASH POGGERS
- path.pts().get(p, i * 2, 100);
- nvgBezierTo(vg, p[2], p[3], p[4], p[5], p[6], p[7]);
- } //hello imma add the svg i got from wikipedia
- if(path.closed() == 1) {
- nvgLineTo(vg, path.pts().get(0), path.pts().get(1));
+ try {
+ NSVGImage image = ImageLoader.INSTANCE.getSVG(fileName);
+ NSVGShape shape;
+ NSVGPath path;
+ int i;
+ for (shape = image.shapes(); shape != null; shape.next()) {
+ //if ((shape.flags() == NSVG_FLAGS_VISIBLE)) {
+ // continue;
+ //}
+
+ nvgFillColor(vg, color(vg, shape.fill().color()));
+ nvgStrokeColor(vg, color(vg, shape.stroke().color()));
+ nvgStrokeWidth(vg, shape.strokeWidth());
+
+ for (path = shape.paths(); path != null; path.next()) {
+ nvgBeginPath(vg);
+ FloatBuffer points = path.pts();
+ nvgMoveTo(vg, points.get(0), points.get(1));
+ for (i = 0; i < path.npts() - 1; i += 3) {
+ float[] p = new float[10];
+ for (int j = 0; j < i * 2 + 3; j++) { // THIS WONT WORK WHy why why why
+ p[j] = points.get(j);
+ System.out.println(j + " " + p[j]);
+ }
+ nvgBezierTo(vg, p[2], p[3], p[4], p[5], p[6], p[7]);
+ }
+ if (path.closed() == 1) {
+ nvgLineTo(vg, points.get(0), points.get(1));
+ }
+ nvgStroke(vg);
}
- nvgStroke(vg);
- }
+ }
+ } catch (Exception e ) {
+ //e.printStackTrace();
}
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java
index 4e07215..6fbd27f 100644
--- a/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java
@@ -1,12 +1,19 @@
package io.polyfrost.oneconfig.lwjgl.image;
import io.polyfrost.oneconfig.lwjgl.IOUtil;
+import net.minecraft.client.Minecraft;
+import net.minecraft.util.ResourceLocation;
import org.lwjgl.nanovg.NSVGImage;
import org.lwjgl.nanovg.NanoSVG;
import org.lwjgl.nanovg.NanoVG;
import org.lwjgl.stb.STBImage;
+import org.lwjgl.system.MemoryStack;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.HashMap;
public class ImageLoader {
@@ -39,9 +46,14 @@ public class ImageLoader {
public boolean loadSVGImage(String fileName) {
if(!NSVGImageHashMap.containsKey(fileName)) {
try {
- NSVGImageHashMap.put(fileName, NanoSVG.nsvgParseFromFile(fileName, "px", 96f));
+ CharSequence s = new BufferedReader(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation("oneconfig", fileName)).getInputStream())).readLine();
+ System.out.println(s);
+ NSVGImage image = NanoSVG.nsvgParse(s, "px", 96f);
+ NSVGImageHashMap.put(fileName, image);
+ System.out.println("Loaded SVG: " + fileName);
} catch (Exception e) { // just in case
System.err.println("Failed to parse SVG file");
+ e.printStackTrace();
return false;
}
return true;
diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java b/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java
index 9478bc6..862ff35 100644
--- a/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java
+++ b/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java
@@ -18,7 +18,7 @@ public class TestNanoVGGui extends GuiScreen {
RenderManager.drawString(vg, "Hello!", 80, 20, Color.WHITE.getRGB(), 50, "mc-regular");
RenderManager.drawString(vg, "Hello!", 100, 100, Color.WHITE.getRGB(), 50, "inter-bold");
RenderManager.drawImage(vg, "/assets/oneconfig/textures/hudsettings.png", 10, 10, 400, 400);
- RenderManager.drawSVGImage(vg, "/assets/oneconfig/textures/pc.svg", 1000, 1000, 500, 500);
+ RenderManager.drawSVGImage(vg, "textures/pc.svg", 1000, 1000, 500, 500);
RenderManager.drawLine(vg, 0, 0, 100, 100, 7, Color.PINK.getRGB());
RenderManager.drawCircle(vg, 200, 200, 50, Color.WHITE.getRGB());
RenderManager.drawString(vg, (float) (System.nanoTime() - startTime) / 1000000f + "ms", 500, 500, Color.WHITE.getRGB(), 100, "inter-bold");