aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java38
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java20
-rw-r--r--src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java6
-rw-r--r--src/main/resources/assets/oneconfig/textures/pc.svg1
4 files changed, 62 insertions, 3 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
index 72cb75a..64fbe1f 100644
--- a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
@@ -8,14 +8,14 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.shader.Framebuffer;
-import org.lwjgl.nanovg.NVGColor;
-import org.lwjgl.nanovg.NVGPaint;
+import org.lwjgl.nanovg.*;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.util.function.LongConsumer;
+import static org.lwjgl.nanovg.NanoSVG.NSVG_FLAGS_VISIBLE;
import static org.lwjgl.nanovg.NanoVG.*;
import static org.lwjgl.nanovg.NanoVGGL2.NVG_ANTIALIAS;
import static org.lwjgl.nanovg.NanoVGGL2.nvgCreate;
@@ -130,6 +130,40 @@ 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));
+ }
+ nvgStroke(vg);
+ }
+
+
+ }
+ }
+ }
+
public static void drawLine(long vg, float x, float y, float endX, float endY, float width, int color) {
nvgBeginPath(vg);
nvgMoveTo(vg, x, y);
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 b0cb6d4..4e07215 100644
--- a/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java
@@ -1,6 +1,8 @@
package io.polyfrost.oneconfig.lwjgl.image;
import io.polyfrost.oneconfig.lwjgl.IOUtil;
+import org.lwjgl.nanovg.NSVGImage;
+import org.lwjgl.nanovg.NanoSVG;
import org.lwjgl.nanovg.NanoVG;
import org.lwjgl.stb.STBImage;
@@ -9,6 +11,7 @@ import java.util.HashMap;
public class ImageLoader {
private final HashMap<String, Image> imageHashMap = new HashMap<>();
+ private final HashMap<String, NSVGImage> NSVGImageHashMap = new HashMap<>();
public static ImageLoader INSTANCE = new ImageLoader();
public boolean loadImage(long vg, String fileName) {
@@ -33,7 +36,24 @@ public class ImageLoader {
return true;
}
+ public boolean loadSVGImage(String fileName) {
+ if(!NSVGImageHashMap.containsKey(fileName)) {
+ try {
+ NSVGImageHashMap.put(fileName, NanoSVG.nsvgParseFromFile(fileName, "px", 96f));
+ } catch (Exception e) { // just in case
+ System.err.println("Failed to parse SVG file");
+ return false;
+ }
+ return true;
+ }
+ return true;
+ }
+
public Image getImage(String fileName) {
return imageHashMap.get(fileName);
}
+
+ public NSVGImage getSVG(String fileName) {
+ return NSVGImageHashMap.get(fileName);
+ }
}
diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java b/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java
index c1badc2..9478bc6 100644
--- a/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java
+++ b/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java
@@ -11,14 +11,18 @@ public class TestNanoVGGui extends GuiScreen {
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
drawRect(0, 0, width, height, Color.BLACK.getRGB());
+ long startTime = System.nanoTime();
RenderManager.setupAndDraw((vg) -> {
RenderManager.drawRect(vg, 0, 0, 100, 100, Color.BLUE.getRGB());
RenderManager.drawRoundedRect(vg, 305, 305, 100, 100, Color.YELLOW.getRGB(), 8);
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.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");
});
drawString(fontRendererObj, "Hello!", 0, 0, -1);
- }
+ } // hi
}
diff --git a/src/main/resources/assets/oneconfig/textures/pc.svg b/src/main/resources/assets/oneconfig/textures/pc.svg
new file mode 100644
index 0000000..56a44c0
--- /dev/null
+++ b/src/main/resources/assets/oneconfig/textures/pc.svg
@@ -0,0 +1 @@
+<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg width="32px" height="32px" viewBox="0 0 32 32" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;" version="1.1" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:serif="http://www.serif.com/" xmlns:xlink="http://www.w3.org/1999/xlink"><rect height="32" id="Computer" style="fill:none;" width="32" x="0" y="0"/><path d="M21,29l-10,0c-0.087,-0.004 -0.109,-0.002 -0.195,-0.019c-0.289,-0.058 -0.548,-0.25 -0.687,-0.51c-0.138,-0.259 -0.155,-0.58 -0.042,-0.854c0.137,-0.33 0.462,-0.576 0.826,-0.612c0.033,-0.003 0.065,-0.003 0.098,-0.005l1.153,0l0.861,-5.164c0.019,-0.092 0.044,-0.183 0.084,-0.268c0.148,-0.309 0.463,-0.531 0.808,-0.564c0.032,-0.003 0.063,-0.003 0.094,-0.004l4,0c0.031,0.001 0.062,0.003 0.094,0.004c0.093,0.014 0.185,0.031 0.272,0.065c0.291,0.115 0.52,0.371 0.601,0.675c0.008,0.03 0.013,0.061 0.019,0.092l0.861,5.164l1.153,0c0.033,0.002 0.065,0.003 0.098,0.005c0.032,0.005 0.065,0.008 0.097,0.014c0.385,0.077 0.708,0.394 0.786,0.786c0.064,0.321 -0.042,0.671 -0.274,0.902c-0.139,0.139 -0.319,0.235 -0.512,0.274c-0.086,0.017 -0.108,0.015 -0.195,0.019Z" style="fill:#bdbdbd;"/><path d="M16,21l2,0c0.031,0.001 0.062,0.003 0.094,0.004c0.093,0.014 0.185,0.031 0.272,0.065c0.291,0.115 0.52,0.371 0.601,0.675c0.008,0.03 0.013,0.061 0.019,0.092l0.861,5.164l1.153,0l0.098,0.005c0.032,0.005 0.065,0.008 0.097,0.014c0.385,0.077 0.708,0.394 0.786,0.786c0.064,0.321 -0.042,0.671 -0.274,0.902c-0.139,0.139 -0.319,0.235 -0.512,0.274c-0.086,0.017 -0.108,0.015 -0.195,0.019l-5,0l0,-8Z" style="fill:#9e9e9e;"/><path d="M28.006,3c0.616,0.003 1.228,0.307 1.6,0.808c0.253,0.34 0.392,0.761 0.394,1.186c0.008,5.337 0.008,10.675 0,16.012c-0.003,0.612 -0.3,1.213 -0.788,1.585c-0.344,0.262 -0.771,0.407 -1.206,0.409c-8.004,0.012 -16.008,0.012 -24.012,0c-0.624,-0.003 -1.241,-0.312 -1.614,-0.827c-0.244,-0.337 -0.378,-0.748 -0.38,-1.167c-0.009,-5.337 -0.009,-10.675 0,-16.012c0.002,-0.506 0.204,-1.008 0.552,-1.374c0.37,-0.388 0.899,-0.617 1.442,-0.62c8.004,-0.012 16.008,-0.012 24.012,0Z" style="fill:#e0e0e0;"/><path d="M16,2.991c4.002,0 8.004,0.003 12.006,0.009c0.616,0.003 1.228,0.307 1.6,0.808c0.253,0.34 0.392,0.761 0.394,1.186c0.008,5.337 0.008,10.675 0,16.012c-0.003,0.612 -0.3,1.213 -0.788,1.585c-0.344,0.262 -0.771,0.407 -1.206,0.409c-4.002,0.006 -8.004,0.009 -12.006,0.009l0,-20.018Z" style="fill:#bdbdbd;"/><rect height="14" style="fill:#29b6f6;" width="12" x="4" y="5"/><rect height="14" style="fill:#03a9f4;" width="12" x="16" y="5"/></svg> \ No newline at end of file