aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/lwjgl
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/lwjgl')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java13
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java9
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/font/Fonts.java18
3 files changed, 28 insertions, 12 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
index d728670..2ed8404 100644
--- a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
@@ -3,6 +3,7 @@ package io.polyfrost.oneconfig.lwjgl;
import io.polyfrost.oneconfig.config.OneConfigConfig;
import io.polyfrost.oneconfig.lwjgl.font.Font;
import io.polyfrost.oneconfig.lwjgl.font.FontManager;
+import io.polyfrost.oneconfig.lwjgl.font.Fonts;
import io.polyfrost.oneconfig.lwjgl.image.Image;
import io.polyfrost.oneconfig.lwjgl.image.ImageLoader;
import net.minecraft.client.Minecraft;
@@ -131,14 +132,11 @@ public final class RenderManager {
nvgColor.free();
}
- public static void drawString(long vg, String text, float x, float y, int color, float size, Font font) {
- drawString(vg, text, x, y, color, size, font.getName());
- }
- public static void drawString(long vg, String text, float x, float y, int color, float size, String fontName) {
+ public static void drawString(long vg, String text, float x, float y, int color, float size, Fonts font) {
nvgBeginPath(vg);
nvgFontSize(vg, size);
- nvgFontFace(vg, fontName);
+ nvgFontFace(vg, font.font.getName());
nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
NVGColor nvgColor = color(vg, color);
nvgText(vg, x, y, text);
@@ -216,6 +214,11 @@ 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;
+ }
+
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/font/FontManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java
index 08d108b..0ec2b87 100644
--- a/src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java
@@ -4,20 +4,15 @@ import io.polyfrost.oneconfig.lwjgl.IOUtil;
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.util.ArrayList;
import static org.lwjgl.nanovg.NanoVG.nvgCreateFontMem;
public class FontManager {
public static FontManager INSTANCE = new FontManager();
- private final ArrayList<Font> fonts = new ArrayList<>();
public void initialize(long vg) {
- fonts.add(new Font("inter-bold", "/assets/oneconfig/font/Inter-Bold.ttf"));
- fonts.add(new Font("inter-regular", "/assets/oneconfig/font/Inter-Regular.otf"));
- fonts.add(new Font("inter-semibold", "/assets/oneconfig/font/Inter-SemiBold.otf"));
- fonts.add(new Font("mc-regular", "/assets/oneconfig/font/Minecraft-Regular.otf"));
- for (Font font : fonts) {
+ for (Fonts fonts : Fonts.values()) {
+ Font font = fonts.font;
int loaded = -1;
try {
ByteBuffer buffer = IOUtil.resourceToByteBuffer(font.getFileName());
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/font/Fonts.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/Fonts.java
new file mode 100644
index 0000000..5d36271
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/Fonts.java
@@ -0,0 +1,18 @@
+package io.polyfrost.oneconfig.lwjgl.font;
+
+public enum Fonts {
+
+ INTER_BOLD(new Font("inter-bold", "/assets/oneconfig/font/Inter-Bold.ttf")),
+ INTER_REGULAR(new Font("inter-regular", "/assets/oneconfig/font/Inter-Regular.otf")),
+ INTER_SEMIBOLD(new Font("inter-semibold", "/assets/oneconfig/font/Inter-SemiBold.otf")),
+ INTER_MEDIUM(new Font("inter-medium", "/assets/oneconfig/font/Inter-Medium.otf")),
+ MC_REGULAR(new Font("mc-regular", "/assets/oneconfig/font/Minecraft-Regular.otf"));
+
+ public final Font font;
+
+ Fonts(Font font) {
+ this.font = font;
+ }
+
+
+}