diff options
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/lwjgl/font')
3 files changed, 85 insertions, 0 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Font.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Font.java new file mode 100644 index 0000000..970c073 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Font.java @@ -0,0 +1,39 @@ +package cc.polyfrost.oneconfig.lwjgl.font; + +import java.nio.ByteBuffer; + +public class Font { + private final String fileName; + private final String name; + private boolean loaded = false; + private ByteBuffer buffer = null; + + public Font(String name, String fileName) { + this.name = name; + this.fileName = fileName; + } + + public String getName() { + return name; + } + + public String getFileName() { + return fileName; + } + + public boolean isLoaded() { + return loaded; + } + + void setLoaded(boolean loaded) { + this.loaded = loaded; + } + + public ByteBuffer getBuffer() { + return buffer; + } + + void setBuffer(ByteBuffer buffer) { + this.buffer = buffer; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/FontManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/FontManager.java new file mode 100644 index 0000000..0974019 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/FontManager.java @@ -0,0 +1,31 @@ +package cc.polyfrost.oneconfig.lwjgl.font; + +import cc.polyfrost.oneconfig.lwjgl.IOUtil; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import static org.lwjgl.nanovg.NanoVG.nvgCreateFontMem; + +public class FontManager { + public static FontManager INSTANCE = new FontManager(); + + public void initialize(long vg) { + for (Fonts fonts : Fonts.values()) { + Font font = fonts.font; + int loaded = -1; + try { + ByteBuffer buffer = IOUtil.resourceToByteBuffer(font.getFileName()); + loaded = nvgCreateFontMem(vg, font.getName(), buffer, 0); + font.setBuffer(buffer); + } catch (IOException e) { + e.printStackTrace(); + } + if (loaded == -1) { + throw new RuntimeException("Failed to initialize font " + font.getName()); + } else { + font.setLoaded(true); + } + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Fonts.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Fonts.java new file mode 100644 index 0000000..aef639c --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/font/Fonts.java @@ -0,0 +1,15 @@ +package cc.polyfrost.oneconfig.lwjgl.font; + +public enum Fonts { + INTER_BOLD(new Font("inter-bold", "/assets/oneconfig/font/Inter-Bold.otf")), + 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; + } +} |