aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-04-18 17:05:30 +0100
committerGitHub <noreply@github.com>2022-04-18 17:05:30 +0100
commit2265233e317298db1da920430b8f8c21d6e3067e (patch)
treea1339d9dfb2188100c7da55454605913d6773eb1 /src
parenta0a6032206ed0326653424c580b0b2900e357f29 (diff)
parentcf164be0c8f43c3d1387c9c9f7ae73c2cf1b3a02 (diff)
downloadOneConfig-2265233e317298db1da920430b8f8c21d6e3067e.tar.gz
OneConfig-2265233e317298db1da920430b8f8c21d6e3067e.tar.bz2
OneConfig-2265233e317298db1da920430b8f8c21d6e3067e.zip
Merge pull request #3 from Wyvest/master
nanovg
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/OneConfig.java2
-rw-r--r--src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java37
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/Window.java111
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java270
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java105
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCColorPicker.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCSelector.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java35
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCTextField.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/BasicWindowPage.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/HomePage.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/ModsPage.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/SettingsPage.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/StorePage.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/hud/HudCore.java3
-rw-r--r--src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java20
-rw-r--r--src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/IOUtil.java53
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/Lwjgl2FunctionProvider.java39
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java194
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/font/Font.java39
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java34
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/image/Image.java20
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java39
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/plugin/ClassTransformer.java55
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/plugin/LoadingPlugin.java52
-rw-r--r--src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java189
-rw-r--r--src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java451
-rw-r--r--src/main/java/io/polyfrost/oneconfig/test/TestHud.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java24
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/Theme.java310
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/Themes.java53
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java113
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java48
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java90
-rw-r--r--src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java15
-rw-r--r--src/main/java/io/polyfrost/oneconfig/utils/TickDelay.java2
-rw-r--r--src/main/resources/assets/oneconfig/font/Inter-Bold.ttfbin0 -> 316100 bytes
-rw-r--r--src/main/resources/assets/oneconfig/font/Minecraft-Regular.otfbin0 -> 11016 bytes
-rw-r--r--src/main/resources/assets/oneconfig/font/OFL-INTER-BOLD.txt93
41 files changed, 683 insertions, 1857 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/OneConfig.java b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
index 7f29c39..5d20af3 100644
--- a/src/main/java/io/polyfrost/oneconfig/OneConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
@@ -4,7 +4,6 @@ import io.polyfrost.oneconfig.command.OneConfigCommand;
import io.polyfrost.oneconfig.config.OneConfigConfig;
import io.polyfrost.oneconfig.hud.HudCore;
import io.polyfrost.oneconfig.test.TestConfig;
-import io.polyfrost.oneconfig.themes.Themes;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
@@ -37,6 +36,5 @@ public class OneConfig {
ClientCommandHandler.instance.registerCommand(new OneConfigCommand());
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new HudCore());
- Themes.openTheme(new File("OneConfig/themes/one.zip").getAbsoluteFile());
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java b/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java
index df727a0..b210146 100644
--- a/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java
+++ b/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java
@@ -1,21 +1,16 @@
package io.polyfrost.oneconfig.command;
-import io.polyfrost.oneconfig.gui.Window;
import io.polyfrost.oneconfig.hud.gui.HudGui;
-import io.polyfrost.oneconfig.themes.Themes;
+import io.polyfrost.oneconfig.test.TestNanoVGGui;
import io.polyfrost.oneconfig.utils.TickDelay;
import net.minecraft.client.Minecraft;
-import net.minecraft.command.ICommand;
+import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
-import net.minecraft.util.BlockPos;
-import net.minecraft.util.ChatComponentText;
-import org.jetbrains.annotations.NotNull;
-import java.io.File;
import java.util.ArrayList;
import java.util.List;
-public class OneConfigCommand implements ICommand {
+public class OneConfigCommand extends CommandBase {
private static final Minecraft mc = Minecraft.getMinecraft();
@@ -39,37 +34,21 @@ public class OneConfigCommand implements ICommand {
@Override
public void processCommand(ICommandSender sender, String[] args) {
- if (args.length == 0) new TickDelay(() -> mc.displayGuiScreen(new Window()), 1);
+ if (args.length == 0) ; //new TickDelay(() -> mc.displayGuiScreen(new Window()), 1);
else {
switch (args[0]) {
case "hud":
new TickDelay(() -> mc.displayGuiScreen(new HudGui()), 1);
break;
- case "theme":
- mc.thePlayer.addChatMessage(new ChatComponentText("reloading theme!"));
- Themes.openTheme(new File("OneConfig/themes/one.zip").getAbsoluteFile());
+ case "lwjgl":
+ new TickDelay(() -> mc.displayGuiScreen(new TestNanoVGGui()), 1);
break;
}
}
}
@Override
- public boolean canCommandSenderUseCommand(ICommandSender sender) {
- return true;
- }
-
- @Override
- public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) {
- return null;
- }
-
- @Override
- public boolean isUsernameIndex(String[] args, int index) {
- return false;
- }
-
- @Override
- public int compareTo(@NotNull ICommand o) {
- return 0;
+ public int getRequiredPermissionLevel() {
+ return -1;
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/Window.java b/src/main/java/io/polyfrost/oneconfig/gui/Window.java
deleted file mode 100644
index fa672d5..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/Window.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package io.polyfrost.oneconfig.gui;
-
-import io.polyfrost.oneconfig.gui.elements.OCBlock;
-import io.polyfrost.oneconfig.gui.elements.OCStoreBlock;
-import io.polyfrost.oneconfig.themes.Theme;
-import io.polyfrost.oneconfig.themes.Themes;
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.GuiScreen;
-import net.minecraft.client.gui.ScaledResolution;
-import net.minecraft.util.ResourceLocation;
-
-import java.awt.*;
-
-import static io.polyfrost.oneconfig.renderer.Renderer.clamp;
-import static io.polyfrost.oneconfig.renderer.Renderer.easeOut;
-
-public class Window extends GuiScreen {
- private float currentProgress = 0f;
- public static Window currentWindow;
- private final Theme t = Themes.getActiveTheme();
- private final int guiScaleToRestore;
- long secondCounter = System.currentTimeMillis();
- long prevTime = System.currentTimeMillis();
- int frames = 0;
- OCBlock block = new OCBlock(() -> {
- t.getFont().drawString("hi", 10, 10, 1f, 1f, -1);
- },750, 144);
- ResourceLocation example = new ResourceLocation("oneconfig", "textures/hudsettings.png");
- OCStoreBlock storeBlock = new OCStoreBlock("OneConfig Theme", "OneConfig default theme with the default look you love.", example, new Color(27,27,27,255).getRGB());
- public static ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());
-
- public Window() {
- super.initGui();
- currentWindow = this;
- guiScaleToRestore = Minecraft.getMinecraft().gameSettings.guiScale;
- Minecraft.getMinecraft().gameSettings.guiScale = 1;
- }
-
- public boolean doesGuiPauseGame() {
- return false;
- }
-
- public void drawScreen(int mouseX, int mouseY, float partialTicks) {
- resolution = new ScaledResolution(Minecraft.getMinecraft());
- super.drawScreen(mouseX, mouseY, partialTicks);
- currentProgress = clamp(easeOut(currentProgress, 1f));
- int alphaVal = (int) (50 * currentProgress);
- drawGradientRect(0, 0, super.width, super.height, new Color(80, 80, 80, alphaVal).getRGB(), new Color(80, 80, 80, alphaVal + 10).getRGB());
- long secondDelta = System.currentTimeMillis() - secondCounter;
- long deltaTime = System.currentTimeMillis() - prevTime;
- //if(deltaTime >= 15) {
- // prevTime = System.currentTimeMillis();
- // frames++;
- // drawWindow();
- //}
- if(secondDelta >= 1000) {
- secondCounter = System.currentTimeMillis();
- //System.out.println(frames + "FPS");
- //Minecraft.getMinecraft().thePlayer.sendChatMessage(frames + "FPS");
- frames = 0;
- }
- drawWindow();
- }
-
- public void drawWindow() {
- Color testingColor = new Color(127, 144, 155, 255);
- //System.out.println(testingColor.getRGB());
- int middleX = this.width / 2;
- int middleY = this.height / 2;
- int left = middleX - 800;
- int right = (int) (1600 * currentProgress);
- int top = middleY - 512;
- int bottom = (int) (1024 * currentProgress);
- //Gui.drawRect(left - 1, top - 1, right + 1, bottom + 1, testingColor.getRGB());
- //new Color(16, 17, 19, 255).getRGB()
- //t.getTextureManager().draw(ThemeElement.BACKGROUND, left, top, right, bottom);
- //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 480, top + 40, 640, 48);
- //t.getTextureManager().draw(ThemeElement.SEARCH, left + 504, top + 48, 32, 32);
- //t.getFont().drawString("Search all of OneConfig", left + 548, top + 48, 1.1f, 1f, new Color(242,242,242,255).getRGB());
-
- //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1504, top + 32, 64, 64);
- //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1424, top + 32, 64, 64);
- //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1344, top + 32, 64, 64);
- //block.draw(200, 300);
- block.draw(100,200);
- //t.getTextureManager().draw(ThemeElement.CLOSE, left + 1504, top + 32, 64, 64);
- //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 100, top + 100, 296, 64);
- //t.getTextureManager().draw(ThemeElement.CLOSE);
-
- //Renderer.drawRoundRect(left,top,right,bottom,30, testingColor.getRGB());
- //Renderer.drawRoundRect(left + 1,top + 1,right - 2,bottom - 2,30, t.getBaseColor().getRGB());
- //t.getTextureManager().draw(ThemeElement.LOGO, left + 24, top + 24, 64, 64); // 0.875
- //t.getBoldFont().drawString("OneConfig", left + 93f, top + 25, 1f,1f);
- //Gui.drawRect(left, top, right, bottom, t.getBaseColor().getRGB());
-
- //Gui.drawRect(left, top, right, top + 100, t.getTitleBarColor().getRGB());
- //Gui.drawRect(left, top + 100, right, top + 101, testingColor.getRGB());
-
-
- //font.drawString("OneConfig is pog!\nWow, this font renderer actually works :D", 50, 50, 1f, 1f);
- }
-
- public static Window getWindow() {
- return currentWindow;
- }
-
- @Override
- public void onGuiClosed() {
- Minecraft.getMinecraft().gameSettings.guiScale = guiScaleToRestore;
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java
deleted file mode 100644
index abcd5ca..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java
+++ /dev/null
@@ -1,270 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements;
-
-import io.polyfrost.oneconfig.renderer.Renderer;
-import io.polyfrost.oneconfig.themes.Theme;
-import io.polyfrost.oneconfig.themes.Themes;
-import io.polyfrost.oneconfig.themes.textures.ThemeElement;
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.renderer.GlStateManager;
-import org.jetbrains.annotations.NotNull;
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.input.Mouse;
-
-import java.awt.*;
-
-import static io.polyfrost.oneconfig.gui.Window.resolution;
-
-/**
- * Default simple block for all the GUI elements. If you are making custom ones, your class should extend this one.
- */
-@SuppressWarnings("unused")
-public class OCBlock {
- public static final Theme theme = Themes.getActiveTheme();
- private static final Minecraft mc = Minecraft.getMinecraft();
- private final boolean bold;
- private final Color elementColor = theme.getElementColor();
- private final Color hoverColor = theme.getHoverColor();
- private final Runnable draw;
- /**
- * Width of the element in pixels.
- */
- public int width;
- /**
- * Height of the element in pixels.
- */
- public int height;
- private Color color;
- private String text;
- private ThemeElement element;
- private boolean clicked = false;
- private boolean rightClicked = false;
- private int mouseX, mouseY;
- private boolean hovered;
- private float percentHoveredRed = 0f;
- private float percentHoveredGreen = 0f;
- private float percentHoveredBlue = 0f;
- private float percentHoveredAlpha = 0f;
-
- /**
- * Create a basic element.
- */
- public OCBlock(int width, int height) {
- this(null, false, theme.getElementColor().getRGB(), width, height);
- }
-
- /**
- * Create a new basic element.
- *
- * @param color color of the element
- * @param width width of the element
- * @param height height of the element
- * @deprecated This method DOES NOT respect the theme colors for the element. Use of {@link #OCBlock(int, int)} is recommended instead.
- */
- @Deprecated()
- public OCBlock(int color, int width, int height) {
- this(null, false, color, width, height);
- }
-
- /**
- * Create a new element with the specified text, and automatic width/height + padding.
- *
- * @param text text to use
- * @param bold weather or not to use bold text
- * @param color color for the text
- */
- public OCBlock(@NotNull String text, boolean bold, int color) {
- this(text, bold, color, theme.getFont().getWidth(text) + 6, theme.getFont().getHeight() + 4);
- }
-
- /**
- * Create a new element with the specified text, and custom width/height.
- *
- * @param text text to use
- * @param bold weather or not to use bold text
- * @param color color for the text (use {@link Theme#getTextColor()} or {@link Theme#getAccentTextColor()} for default colors)
- */
- public OCBlock(String text, boolean bold, int color, int width, int height) {
- this.draw = null;
- this.text = text;
- this.bold = bold;
- this.color = Renderer.getColorFromInt(color);
- this.width = width;
- this.height = height;
- }
-
- /**
- * Create a new Element with the specified image.
- *
- * @param element element to use
- * @param colorMask color mast to use (-1 for default)
- */
- public OCBlock(ThemeElement element, int colorMask, int width, int height) {
- this.draw = null;
- this.element = element;
- this.color = Renderer.getColorFromInt(colorMask);
- this.width = width;
- this.height = height;
- this.bold = false;
- }
-
- /**
- * Create a new Element with a custom render script. The {@link Runnable} should ONLY contain #draw() calls or equivalent.
- *
- * @param whatToDraw a {@link Runnable}, containing draw scripts for elements. You will need to instantiate the objects first, if they are sub-elements.
- */
- public OCBlock(Runnable whatToDraw, int width, int height) {
- this.draw = whatToDraw;
- this.bold = false;
- this.width = width;
- this.height = height;
- }
-
- /**
- * Draw the element at the specified coordinates.
- */
- public void draw(int x, int y) {
- GlStateManager.enableBlend();
- percentHoveredRed = smooth(percentHoveredRed, elementColor.getRed() / 255f, hoverColor.getRed() / 255f);
- percentHoveredGreen = smooth(percentHoveredGreen, elementColor.getGreen() / 255f, hoverColor.getGreen() / 255f);
- percentHoveredBlue = smooth(percentHoveredBlue, elementColor.getBlue() / 255f, hoverColor.getBlue() / 255f);
- percentHoveredAlpha = smooth(percentHoveredAlpha, elementColor.getAlpha() / 255f, hoverColor.getAlpha() / 255f);
- GlStateManager.color(percentHoveredRed, percentHoveredGreen, percentHoveredBlue, percentHoveredAlpha);
- update(x, y);
- if (draw != null) {
- draw.run();
- }
- if (element != null) {
- theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height);
- GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f);
- theme.getTextureManager().draw(element, x, y, width, height);
- }
- if (text == null) {
- theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height);
- } else {
- theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height);
- if (bold) {
- theme.getBoldFont().drawString(text, x + 3, y + 2, 1f, 1f, color.getRGB());
- } else {
- theme.getFont().drawString(text, x + 3, y + 2, 1.1f, 1f, color.getRGB());
- }
- }
- GlStateManager.disableBlend();
-
-
- }
-
- /**
- * Update this elements click, key and hover status. Call this method at the end of your 'draw' function, if overridden.
- */
- public void update(int x, int y) {
- int mouseX = Mouse.getX() / resolution.getScaleFactor();
- int mouseY = Math.abs((Mouse.getY() / resolution.getScaleFactor()) - resolution.getScaledHeight());
- hovered = mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height;
- if (hovered) {
- onHover();
- if (Mouse.isButtonDown(0) && !clicked) {
- onClick(0);
- }
- clicked = Mouse.isButtonDown(0);
-
- if (Mouse.isButtonDown(1) && !rightClicked) {
- onClick(1);
- }
- rightClicked = Mouse.isButtonDown(1);
- onKeyPress(Keyboard.getEventKey());
- }
- if (clicked) {
- Renderer.color(theme.getClickColor());
- }
- if (!hovered && clicked) clicked = false;
- }
-
- /**
- * Draw the element with the specified coordinates, width and height.
- */
- public void draw(int x, int y, int width, int height) {
- this.width = width;
- this.height = height;
- draw(x, y);
- }
-
-
- /**
- * Override this method to set a function when a key is pressed while this element is hovered.
- *
- * @param keyCode key code that was pressed (check org.lwjgl.Keyboard for keymap)
- */
- public void onKeyPress(int keyCode) {
-
- }
-
- /**
- * Override this method to set a function when the element is hovered.
- *
- * @param button the button that was pressed (0 is left, 1 is right)
- */
- public void onClick(int button) {
-
- }
-
-
- /**
- * Override this method to set a function when the element is hovered.
- */
- public void onHover() {
-
- }
-
-
- private float smooth(float current, float min, float max) {
- current = Renderer.easeOut(current, isHovered() ? 1f : 0f);
- if (current <= min) {
- current = min;
- }
-
- if (current >= max) {
- current = max;
- }
- return current;
- }
-
- public int getHeight() {
- return height;
- }
-
- public void setHeight(int height) {
- this.height = height;
- }
-
- public Color getColor() {
- return color;
- }
-
- public void setColor(Color color) {
- this.color = color;
- }
-
- public int getWidth() {
- return width;
- }
-
- public void setWidth(int width) {
- this.width = width;
- }
-
- public String getText() {
- return text;
- }
-
- public void setText(String text) {
- this.text = text;
- }
-
- public boolean isHovered() {
- return hovered;
- }
-
- public boolean isClicked() {
- return clicked;
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java
deleted file mode 100644
index 5f78baa..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements;
-
-import io.polyfrost.oneconfig.renderer.Renderer;
-import io.polyfrost.oneconfig.themes.textures.ThemeElement;
-import net.minecraft.client.renderer.GlStateManager;
-import org.jetbrains.annotations.NotNull;
-
-import java.awt.*;
-
-public class OCButton extends OCBlock {
- private final Color elementColor = theme.getElementColor();
- private final Color hoverColor = theme.getHoverColor();
- private float percentHoveredRed = 0f;
- private float percentHoveredGreen = 0f;
- private float percentHoveredBlue = 0f;
- private float percentHoveredAlpha = 0f;
- private float percentDescription = 0f;
- private ThemeElement element;
- private boolean alwaysShowDesc = true;
- private String title, description;
-
- /**
- * Create an empty button.
- */
- public OCButton(int width, int height) {
- super(width, height);
- }
-
- /**
- * Create a new button with the specified texture.
- */
- public OCButton(ThemeElement element) {
- super(element.size + 2, element.size + 2);
- this.element = element;
- }
-
- public OCButton(@NotNull String title, @NotNull String description, ThemeElement icon, boolean alwaysShowDesc) {
- super(icon.size + theme.getBoldFont().getWidth(title) + 20, icon.size + 10);
- this.element = icon;
- this.title = title;
- this.description = description;
- this.alwaysShowDesc = alwaysShowDesc;
- }
-
-
- public OCButton(@NotNull String title, @NotNull String description, ThemeElement icon, boolean alwaysShowDesc, int width, int height) {
- super(width, height);
- this.element = icon;
- this.title = title;
- this.description = description;
- this.alwaysShowDesc = alwaysShowDesc;
- }
-
- public void draw(int x, int y) {
- super.update(x, y);
-
- percentHoveredRed = smooth(percentHoveredRed, elementColor.getRed() / 255f, hoverColor.getRed() / 255f);
- percentHoveredGreen = smooth(percentHoveredGreen, elementColor.getGreen() / 255f, hoverColor.getGreen() / 255f);
- percentHoveredBlue = smooth(percentHoveredBlue, elementColor.getBlue() / 255f, hoverColor.getBlue() / 255f);
- percentHoveredAlpha = smooth(percentHoveredAlpha, elementColor.getAlpha() / 255f, hoverColor.getAlpha() / 255f);
- if (!alwaysShowDesc) {
- percentDescription = Renderer.clamp(Renderer.easeOut(percentDescription, isHovered() ? 1f : 0f));
- }
- GlStateManager.color(percentHoveredRed, percentHoveredGreen, percentHoveredBlue, percentHoveredAlpha);
- if (isClicked()) {
- //Renderer.setGlColor(theme.getClickColor());
- }
-
- theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height);
- if (element != null) {
- GlStateManager.color(1f, 1f, 1f, isClicked() ? 0.6f : 1f);
- theme.getTextureManager().draw(element, x + 19, y + 8, element.size, element.size);
- if (title != null) {
- if (alwaysShowDesc) {
- theme.getBoldFont().drawString(title, x + element.size + 25, y + 30, 1.2f, 1.2f, isClicked() ? theme.getTextColor().darker().getRGB() : theme.getTextColor().getRGB());
- theme.getFont().drawString(description, x + element.size + 25, y + theme.getBoldFont().getHeight() + 37, 1.2f, 1.2f, isClicked() ? theme.getAccentTextColor().darker().getRGB() : theme.getAccentTextColor().getRGB());
- } else {
- int titleY = y + 48;
- titleY -= (int) (percentDescription * 18);
- Color targetColor = theme.getAccentTextColor();
- Color currentColor = isClicked() ? targetColor.darker() : new Color(targetColor.getRed(), targetColor.getGreen(), targetColor.getBlue(), (int) (targetColor.getAlpha() * percentDescription));
- theme.getFont().drawString(description, x + element.size + 25, y + theme.getBoldFont().getHeight() + 37, 1.2f, 1.2f, currentColor.getRGB());
- theme.getBoldFont().drawString(title, x + element.size + 25, titleY, 1.2f, 1.2f, isClicked() ? theme.getTextColor().darker().getRGB() : theme.getTextColor().getRGB());
- }
- }
- }
- }
-
-
- private float smooth(float current, float min, float max) {
- current = Renderer.easeOut(current, isHovered() ? 1f : 0f);
- if (current <= min) {
- current = min;
- }
-
- if (current >= max) {
- current = max;
- }
- return current;
- }
-
- public void onHover() {
-
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCColorPicker.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCColorPicker.java
deleted file mode 100644
index e055d25..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCColorPicker.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements;
-
-public class OCColorPicker {
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCSelector.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCSelector.java
deleted file mode 100644
index 83805fa..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCSelector.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements;
-
-public class OCSelector {
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java
deleted file mode 100644
index d7fa7e9..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements;
-
-import io.polyfrost.oneconfig.renderer.Renderer;
-import net.minecraft.util.ResourceLocation;
-
-import java.awt.*;
-
-public class OCStoreBlock extends OCBlock {
- private final ResourceLocation image;
- private final String description;
- private final String title;
- private final Color color;
-
- public OCStoreBlock(String title, String description, ResourceLocation image, int color) {
- super(color, 300, 400);
- this.color = Renderer.getColorFromInt(color);
- this.description = description;
- this.title = title;
- this.image = image;
- }
-
- public void draw(int x, int y) {
- //super.draw(x, y);
- Renderer.drawScaledImage(image, x, y, 300, 150);
- //Gui.drawRect(x,y,x + 300, y + 150, -1);
- theme.getBoldFont().drawSplitString(title, x + 2, y + 152, 200, -1);
-
-
- //super.update();
- }
-
- public void draw(int x, int y, int width, int height) {
- draw(x, y);
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCTextField.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCTextField.java
deleted file mode 100644
index da0df96..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCTextField.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package io.polyfrost.oneconfig.gui.elements;
-
-public class OCTextField {
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/BasicWindowPage.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/BasicWindowPage.java
deleted file mode 100644
index 0d09526..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/pages/BasicWindowPage.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package io.polyfrost.oneconfig.gui.pages;
-
-public class BasicWindowPage {
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/HomePage.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/HomePage.java
deleted file mode 100644
index 65ad1e9..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/pages/HomePage.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package io.polyfrost.oneconfig.gui.pages;
-
-public class HomePage {
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModsPage.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModsPage.java
deleted file mode 100644
index 4cbda94..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModsPage.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package io.polyfrost.oneconfig.gui.pages;
-
-public class ModsPage {
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/SettingsPage.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/SettingsPage.java
deleted file mode 100644
index 9fecc75..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/pages/SettingsPage.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package io.polyfrost.oneconfig.gui.pages;
-
-public class SettingsPage {
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/StorePage.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/StorePage.java
deleted file mode 100644
index 4aa1616..0000000
--- a/src/main/java/io/polyfrost/oneconfig/gui/pages/StorePage.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package io.polyfrost.oneconfig.gui.pages;
-
-public class StorePage {
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/HudCore.java b/src/main/java/io/polyfrost/oneconfig/hud/HudCore.java
index a292905..a532ebd 100644
--- a/src/main/java/io/polyfrost/oneconfig/hud/HudCore.java
+++ b/src/main/java/io/polyfrost/oneconfig/hud/HudCore.java
@@ -15,9 +15,8 @@ public class HudCore {
@SubscribeEvent
public void onRender(RenderGameOverlayEvent.Post event) {
if (event.type != RenderGameOverlayEvent.ElementType.ALL || editing) return;
- ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
for (BasicHud hud : huds) {
- hud.drawAll(hud.getXScaled(sr.getScaledWidth()), hud.getYScaled(sr.getScaledHeight()), hud.scale);
+ hud.drawAll(hud.getXScaled(Minecraft.getMinecraft().displayWidth), hud.getYScaled(Minecraft.getMinecraft().displayHeight), hud.scale);
}
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java b/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java
index 7620a26..cfd6a9d 100644
--- a/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java
+++ b/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java
@@ -2,12 +2,10 @@ package io.polyfrost.oneconfig.hud.gui;
import io.polyfrost.oneconfig.hud.HudCore;
import io.polyfrost.oneconfig.hud.interfaces.BasicHud;
-import io.polyfrost.oneconfig.renderer.Renderer;
+import io.polyfrost.oneconfig.lwjgl.RenderManager;
import io.polyfrost.oneconfig.test.TestHud;
-import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
-import net.minecraft.client.gui.ScaledResolution;
import org.lwjgl.input.Keyboard;
import java.awt.*;
@@ -15,7 +13,6 @@ import java.io.IOException;
import java.util.ArrayList;
public class HudGui extends GuiScreen {
- private final ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
private BasicHud editingHud;
private boolean isDragging;
private boolean isScaling;
@@ -68,10 +65,13 @@ public class HudGui extends GuiScreen {
color = new Color(43, 159, 235).getRGB();
if (isDragging) Gui.drawRect(x, y, x + width, y + height, new Color(108, 176, 255, 60).getRGB());
}
- Renderer.drawLine(x - 2 / 4f, y, x + width + 2 / 4f, y, 2, color);
- Renderer.drawLine(x, y, x, y + height, 2, color);
- Renderer.drawLine(x + width, y, x + width, y + height, 2, color);
- Renderer.drawLine(x - 2 / 4f, y + height, x + width + 2 / 4f, y + height, 2, color);
+ int finalColor = color;
+ RenderManager.setupAndDraw(true, (vg) -> {
+ RenderManager.drawLine(vg, x - 2 / 4f, y, x + width + 2 / 4f, y, 2, finalColor);
+ RenderManager.drawLine(vg, x, y, x, y + height, 2, finalColor);
+ RenderManager.drawLine(vg, x + width, y, x + width, y + height, 2, finalColor);
+ RenderManager.drawLine(vg, x - 2 / 4f, y + height, x + width + 2 / 4f, y + height, 2, finalColor);
+ });
if (hud == editingHud && !isDragging) {
Gui.drawRect(x + width - 3, y + height - 3, x + width + 3, y + height + 3, new Color(43, 159, 235).getRGB());
@@ -125,7 +125,7 @@ public class HudGui extends GuiScreen {
}
}
if (smallestDiff != -1) {
- Renderer.drawDottedLine(smallestLine, 0, smallestLine, this.height, 2, 12, new Color(255, 255, 255).getRGB());
+ RenderManager.drawDottedLine(smallestLine, 0, smallestLine, this.height, 2, 12, new Color(255, 255, 255).getRGB());
return smallestLine - smallestOffset;
}
return pos;
@@ -156,7 +156,7 @@ public class HudGui extends GuiScreen {
}
}
if (smallestDiff != -1) {
- Renderer.drawDottedLine(0, smallestLine, this.width, smallestLine, 2, 12, new Color(255, 255, 255).getRGB());
+ RenderManager.drawDottedLine(0, smallestLine, this.width, smallestLine, 2, 12, new Color(255, 255, 255).getRGB());
return smallestLine - smallestOffset;
}
return pos;
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java
index cce2440..f69bff4 100644
--- a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java
+++ b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java
@@ -1,6 +1,6 @@
package io.polyfrost.oneconfig.hud.interfaces;
-import io.polyfrost.oneconfig.renderer.Renderer;
+import io.polyfrost.oneconfig.lwjgl.RenderManager;
import java.awt.*;
@@ -55,7 +55,7 @@ public abstract class BasicHud {
}
private void drawBackground(float x, float y, float scale) {
- Renderer.drawRoundRect((int) x, (int) y, (int) (getTotalWidth(scale) + paddingX * scale), (int) (getTotalHeight(scale) + paddingY * scale), (int) (2 * scale), new Color(0, 0, 0, 120).getRGB());
+ RenderManager.setupAndDraw((vg) -> RenderManager.drawRoundedRect(vg, x, y, getTotalWidth(scale) + paddingX * scale, getTotalHeight(scale) + paddingY * scale, new Color(0, 0, 0, 120).getRGB(), 2 * scale));
}
public float getXScaled(int screenWidth) {
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java
index 3c9cf4c..299e7b8 100644
--- a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java
+++ b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java
@@ -1,6 +1,6 @@
package io.polyfrost.oneconfig.hud.interfaces;
-import io.polyfrost.oneconfig.renderer.Renderer;
+import io.polyfrost.oneconfig.lwjgl.RenderManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@@ -68,7 +68,7 @@ public class TextHud extends BasicHud {
private void drawText(List<String> lines, int x, int y, float scale) {
for (int i = 0; i < lines.size(); i++) {
- Renderer.drawScaledString(lines.get(i), x, y + i * 12, 0xffffff, shadow, scale);
+ RenderManager.drawScaledString(lines.get(i), x, y + i * 12, 0xffffff, shadow, scale);
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/IOUtil.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/IOUtil.java
new file mode 100644
index 0000000..f5105fb
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/IOUtil.java
@@ -0,0 +1,53 @@
+package io.polyfrost.oneconfig.lwjgl;
+
+import org.apache.commons.io.IOUtils;
+
+import java.io.*;
+import java.net.URL;
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+public final class IOUtil {
+
+ private IOUtil() {
+ }
+
+ /**
+ * Taken from legui under MIT License
+ * https://github.com/SpinyOwl/legui/blob/develop/LICENSE
+ */
+ @SuppressWarnings("RedundantCast")
+ public static ByteBuffer resourceToByteBuffer(String path) throws IOException {
+ byte[] bytes;
+ path = path.trim();
+ if (path.startsWith("http")) {
+ bytes = IOUtils.toByteArray(new URL(path));
+ } else {
+ InputStream stream;
+ File file = new File(path);
+ if (file.exists() && file.isFile()) {
+ stream = new FileInputStream(file);
+ } else {
+ stream = IOUtil.class.getResourceAsStream(path);
+ }
+ if (stream == null) {
+ throw new FileNotFoundException(path);
+ }
+ bytes = IOUtils.toByteArray(stream);
+ }
+ ByteBuffer data = ByteBuffer.allocateDirect(bytes.length).order(ByteOrder.nativeOrder())
+ .put(bytes);
+ ((Buffer) data).flip();
+ return data;
+ }
+
+ public static ByteBuffer resourceToByteBufferNullable(String path) {
+ try {
+ return resourceToByteBuffer(path);
+ } catch (Exception ignored) {
+ return null;
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/Lwjgl2FunctionProvider.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/Lwjgl2FunctionProvider.java
new file mode 100644
index 0000000..ea1a44b
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/Lwjgl2FunctionProvider.java
@@ -0,0 +1,39 @@
+package io.polyfrost.oneconfig.lwjgl;
+
+import org.lwjgl.opengl.GLContext;
+import org.lwjgl.system.FunctionProvider;
+
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+/**
+ * Taken from LWJGLTwoPointFive under The Unlicense
+ * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/
+ */
+public class Lwjgl2FunctionProvider implements FunctionProvider {
+
+ private final Method m_getFunctionAddress;
+
+ public Lwjgl2FunctionProvider() {
+ try {
+ m_getFunctionAddress = GLContext.class.getDeclaredMethod("getFunctionAddress", String.class);
+ m_getFunctionAddress.setAccessible(true);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public long getFunctionAddress(CharSequence functionName) {
+ try {
+ return (long) m_getFunctionAddress.invoke(null, functionName.toString());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public long getFunctionAddress(ByteBuffer byteBuffer) {
+ throw new UnsupportedOperationException();
+ }
+} \ No newline at end of file
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
new file mode 100644
index 0000000..72cb75a
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
@@ -0,0 +1,194 @@
+package io.polyfrost.oneconfig.lwjgl;
+
+import io.polyfrost.oneconfig.lwjgl.font.Font;
+import io.polyfrost.oneconfig.lwjgl.font.FontManager;
+import io.polyfrost.oneconfig.lwjgl.image.Image;
+import io.polyfrost.oneconfig.lwjgl.image.ImageLoader;
+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.opengl.Display;
+import org.lwjgl.opengl.GL11;
+
+import java.awt.*;
+import java.util.function.LongConsumer;
+
+import static org.lwjgl.nanovg.NanoVG.*;
+import static org.lwjgl.nanovg.NanoVGGL2.NVG_ANTIALIAS;
+import static org.lwjgl.nanovg.NanoVGGL2.nvgCreate;
+
+public final class RenderManager {
+ private RenderManager() {
+
+ }
+
+ //nanovg
+
+ private static long vg = -1;
+
+ public static void setupAndDraw(LongConsumer consumer) {
+ setupAndDraw(false, consumer);
+ }
+
+ public static void setupAndDraw(boolean mcScaling, LongConsumer consumer) {
+ if (vg == -1) {
+ vg = nvgCreate(NVG_ANTIALIAS);
+ if (vg == -1) {
+ throw new RuntimeException("Failed to create nvg context");
+ }
+ FontManager.INSTANCE.initialize(vg);
+ }
+
+ Framebuffer fb = Minecraft.getMinecraft().getFramebuffer();
+ if (!fb.isStencilEnabled()) {
+ fb.enableStencil();
+ }
+ GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
+
+ if (mcScaling) {
+ ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());
+ nvgBeginFrame(vg, (float) resolution.getScaledWidth_double(), (float) resolution.getScaledHeight_double(), 1);
+ } else {
+ nvgBeginFrame(vg, Display.getWidth(), Display.getHeight(), 1);
+ }
+
+ consumer.accept(vg);
+
+ nvgEndFrame(vg);
+
+ GlStateManager.popAttrib();
+ }
+
+ public static void drawRect(long vg, float x, float y, float width, float height, int color) {
+ nvgBeginPath(vg);
+ nvgRect(vg, x, y, width, height);
+ NVGColor nvgColor = color(vg, color);
+ nvgFill(vg);
+ nvgColor.free();
+ }
+
+ public static void drawRoundedRect(long vg, float x, float y, float width, float height, int color, float radius) {
+ nvgBeginPath(vg);
+ nvgRoundedRect(vg, x, y, width, height, radius);
+ color(vg, color);
+ NVGColor nvgColor = color(vg, color);
+ nvgFill(vg);
+ nvgColor.free();
+ }
+
+ public static void drawCircle(long vg, float x, float y, float radius, int color) {
+ nvgBeginPath(vg);
+ nvgCircle(vg, x, y, radius);
+ NVGColor nvgColor = color(vg, color);
+ nvgFill(vg);
+ 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) {
+ nvgBeginPath(vg);
+ nvgFontSize(vg, size);
+ nvgFontFace(vg, fontName);
+ nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
+ NVGColor nvgColor = color(vg, color);
+ nvgText(vg, x, y, text);
+ nvgFill(vg);
+ nvgColor.free();
+ }
+
+ public static void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, Font font) {
+ drawWrappedString(vg, text, x, y, width, color, size, font.getName());
+ }
+
+ public static void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, String fontName) {
+ nvgBeginPath(vg);
+ nvgFontSize(vg, size);
+ nvgFontFace(vg, fontName);
+ nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
+ NVGColor nvgColor = color(vg, color);
+ nvgTextBox(vg, x, y, width, text);
+ nvgFill(vg);
+ nvgColor.free();
+ }
+
+ public static void drawImage(long vg, String fileName, float x, float y, float width, float height) {
+ if (ImageLoader.INSTANCE.loadImage(vg, fileName)) {
+ NVGPaint imagePaint = NVGPaint.calloc();
+ Image image = ImageLoader.INSTANCE.getImage(fileName);
+ nvgBeginPath(vg);
+ nvgImagePattern(vg, x, y, width, height, 0, image.getReference(), 1, imagePaint);
+ nvgRect(vg, x, y, width, height);
+ nvgFillPaint(vg, imagePaint);
+ nvgFill(vg);
+ imagePaint.free();
+ }
+ }
+
+ public static void drawLine(long vg, float x, float y, float endX, float endY, float width, int color) {
+ nvgBeginPath(vg);
+ nvgMoveTo(vg, x, y);
+ nvgLineTo(vg, endX, endY);
+ NVGColor nvgColor = color(vg, color);
+ nvgStrokeColor(vg, nvgColor);
+ nvgStrokeWidth(vg, width);
+ nvgStroke(vg);
+ nvgColor.free();
+ }
+
+ public static NVGColor color(long vg, int color) {
+ NVGColor nvgColor = NVGColor.calloc();
+ nvgRGBA((byte) (color >> 16 & 0xFF), (byte) (color >> 8 & 0xFF), (byte) (color & 0xFF), (byte) (color >> 24 & 0xFF), nvgColor);
+ nvgFillColor(vg, nvgColor);
+ return nvgColor;
+ }
+
+ //gl
+
+ public static void drawScaledString(String text, float x, float y, int color, boolean shadow, float scale) {
+ GlStateManager.pushMatrix();
+ GlStateManager.scale(scale, scale, 1);
+ Minecraft.getMinecraft().fontRendererObj.drawString(text, x * (1 / scale), y * (1 / scale), color, shadow);
+ GlStateManager.popMatrix();
+ }
+
+ public static void color(Color color) {
+ color(color.getRGB());
+ }
+
+ public static void color(int color) {
+ float f = (float) (color >> 24 & 255) / 255.0F;
+ float f1 = (float) (color >> 16 & 255) / 255.0F;
+ float f2 = (float) (color >> 8 & 255) / 255.0F;
+ float f3 = (float) (color & 255) / 255.0F;
+ GlStateManager.color(f1, f2, f3, f);
+ }
+
+ public static void drawDottedLine(float sx, float sy, float ex, float ey, int width, int factor, int color) {
+ GlStateManager.pushMatrix();
+ GL11.glLineStipple(factor, (short) 0xAAAA);
+ GL11.glEnable(GL11.GL_LINE_STIPPLE);
+ GlStateManager.pushMatrix();
+ GlStateManager.disableTexture2D();
+ GlStateManager.enableBlend();
+ GlStateManager.disableAlpha();
+ GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
+ color(color);
+ GL11.glLineWidth(width);
+ GL11.glBegin(GL11.GL_LINES);
+ GL11.glVertex2d(sx, sy);
+ GL11.glVertex2d(ex, ey);
+ GL11.glEnd();
+ GlStateManager.disableBlend();
+ GlStateManager.enableAlpha();
+ GlStateManager.enableTexture2D();
+ GlStateManager.popMatrix();
+ GL11.glDisable(GL11.GL_LINE_STIPPLE);
+ GlStateManager.popMatrix();
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/font/Font.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/Font.java
new file mode 100644
index 0000000..f250a46
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/Font.java
@@ -0,0 +1,39 @@
+package io.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/io/polyfrost/oneconfig/lwjgl/font/FontManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java
new file mode 100644
index 0000000..20a8cc7
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/font/FontManager.java
@@ -0,0 +1,34 @@
+package io.polyfrost.oneconfig.lwjgl.font;
+
+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("mc-regular", "/assets/oneconfig/font/Minecraft-Regular.otf"));
+ for (Font font : fonts) {
+ 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/io/polyfrost/oneconfig/lwjgl/image/Image.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/image/Image.java
new file mode 100644
index 0000000..2ed7276
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/image/Image.java
@@ -0,0 +1,20 @@
+package io.polyfrost.oneconfig.lwjgl.image;
+
+import java.nio.ByteBuffer;
+
+public class Image {
+ private final int reference;
+ private final ByteBuffer buffer;
+ public Image(int reference, ByteBuffer buffer) {
+ this.reference = reference;
+ this.buffer = buffer;
+ }
+
+ public ByteBuffer getBuffer() {
+ return buffer;
+ }
+
+ public int getReference() {
+ return reference;
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java
new file mode 100644
index 0000000..b0cb6d4
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java
@@ -0,0 +1,39 @@
+package io.polyfrost.oneconfig.lwjgl.image;
+
+import io.polyfrost.oneconfig.lwjgl.IOUtil;
+import org.lwjgl.nanovg.NanoVG;
+import org.lwjgl.stb.STBImage;
+
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+
+public class ImageLoader {
+ private final HashMap<String, Image> imageHashMap = new HashMap<>();
+ public static ImageLoader INSTANCE = new ImageLoader();
+
+ public boolean loadImage(long vg, String fileName) {
+ if (!imageHashMap.containsKey(fileName)) {
+ int[] width = {0};
+ int[] height = {0};
+ int[] channels = {0};
+
+ ByteBuffer image = IOUtil.resourceToByteBufferNullable(fileName);
+ if (image == null) {
+ return false;
+ }
+
+ ByteBuffer buffer = STBImage.stbi_load_from_memory(image, width, height, channels, 4);
+ if (buffer == null) {
+ return false;
+ }
+
+ imageHashMap.put(fileName, new Image(NanoVG.nvgCreateImageRGBA(vg, width[0], height[0], NanoVG.NVG_IMAGE_REPEATX | NanoVG.NVG_IMAGE_REPEATY | NanoVG.NVG_IMAGE_GENERATE_MIPMAPS, buffer), buffer));
+ return true;
+ }
+ return true;
+ }
+
+ public Image getImage(String fileName) {
+ return imageHashMap.get(fileName);
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/plugin/ClassTransformer.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/plugin/ClassTransformer.java
new file mode 100644
index 0000000..066677b
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/plugin/ClassTransformer.java
@@ -0,0 +1,55 @@
+package io.polyfrost.oneconfig.lwjgl.plugin;
+
+import net.minecraft.launchwrapper.IClassTransformer;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.*;
+
+/**
+ * Taken from LWJGLTwoPointFive under The Unlicense
+ * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/
+ */
+public class ClassTransformer implements IClassTransformer {
+ @Override
+ public byte[] transform(String name, String transformedName, byte[] basicClass) {
+ if (name.equals("org.lwjgl.nanovg.NanoVGGLConfig")) {
+ ClassReader reader = new ClassReader(basicClass);
+ ClassNode node = new ClassNode();
+ reader.accept(node, ClassReader.EXPAND_FRAMES);
+
+ for (MethodNode method : node.methods) {
+ if (method.name.equals("configGL")) {
+ InsnList list = new InsnList();
+
+ list.add(new VarInsnNode(Opcodes.LLOAD, 0));
+ list.add(new TypeInsnNode(Opcodes.NEW, "io/polyfrost/oneconfig/lwjgl/Lwjgl2FunctionProvider"));
+ list.add(new InsnNode(Opcodes.DUP));
+ list.add(new MethodInsnNode(
+ Opcodes.INVOKESPECIAL,
+ "io/polyfrost/oneconfig/lwjgl/Lwjgl2FunctionProvider",
+ "<init>",
+ "()V",
+ false
+ ));
+ list.add(new MethodInsnNode(
+ Opcodes.INVOKESTATIC,
+ "org/lwjgl/nanovg/NanoVGGLConfig",
+ "config",
+ "(JLorg/lwjgl/system/FunctionProvider;)V",
+ false
+ ));
+ list.add(new InsnNode(Opcodes.RETURN));
+
+ method.instructions.clear();
+ method.instructions.insert(list);
+ }
+ }
+
+ ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
+ node.accept(cw);
+ return cw.toByteArray();
+ }
+ return basicClass;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/plugin/LoadingPlugin.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/plugin/LoadingPlugin.java
new file mode 100644
index 0000000..1f48135
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/plugin/LoadingPlugin.java
@@ -0,0 +1,52 @@
+package io.polyfrost.oneconfig.lwjgl.plugin;
+
+import net.minecraft.launchwrapper.Launch;
+import net.minecraft.launchwrapper.LaunchClassLoader;
+import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
+
+import java.lang.reflect.Field;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Taken from LWJGLTwoPointFive under The Unlicense
+ * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/
+ */
+public class LoadingPlugin implements IFMLLoadingPlugin {
+
+ public LoadingPlugin() {
+ try {
+ Field f_exceptions = LaunchClassLoader.class.getDeclaredField("classLoaderExceptions");
+ f_exceptions.setAccessible(true);
+ Set<String> exceptions = (Set<String>) f_exceptions.get(Launch.classLoader);
+ exceptions.remove("org.lwjgl.");
+ } catch (Exception e) {
+ throw new RuntimeException("e");
+ }
+ }
+
+ @Override
+ public String[] getASMTransformerClass() {
+ return new String[]{"io.polyfrost.oneconfig.lwjgl.plugin.ClassTransformer"};
+ }
+
+ @Override
+ public String getModContainerClass() {
+ return null;
+ }
+
+ @Override
+ public String getSetupClass() {
+ return null;
+ }
+
+ @Override
+ public void injectData(Map<String, Object> data) {
+
+ }
+
+ @Override
+ public String getAccessTransformerClass() {
+ return null;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
deleted file mode 100644
index b77b8cd..0000000
--- a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
+++ /dev/null
@@ -1,189 +0,0 @@
-package io.polyfrost.oneconfig.renderer;
-
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.FontRenderer;
-import net.minecraft.client.gui.Gui;
-import net.minecraft.client.renderer.GlStateManager;
-import net.minecraft.client.renderer.Tessellator;
-import net.minecraft.client.renderer.WorldRenderer;
-import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
-import net.minecraft.util.ResourceLocation;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.lwjgl.opengl.GL11;
-
-import java.awt.*;
-
-public class Renderer extends Gui {
- public static final Logger renderLog = LogManager.getLogger("OneConfig Renderer");
- private static final Minecraft mc = Minecraft.getMinecraft();
- private static final FontRenderer fr = mc.fontRendererObj;
- private static final Tessellator tessellator = Tessellator.getInstance();
- private static final WorldRenderer worldRenderer = tessellator.getWorldRenderer();
-
-
- /**
- * Draw a basic rectangle. Please note that this is to be used WITH a {@link net.minecraft.client.renderer.GlStateManager#color(float, float, float)} before to color it.
- */
- public static void drawRectangle(int x, int y, int width, int height) {
- int right = x + width;
- int bottom = y + height;
- if (x < right) {
- x = right;
- }
- if (y < bottom) {
- y = bottom;
- }
- GlStateManager.enableBlend();
- GlStateManager.disableTexture2D();
- GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
- worldRenderer.begin(7, DefaultVertexFormats.POSITION);
- worldRenderer.pos(x, bottom, 0.0D).endVertex();
- worldRenderer.pos(right, bottom, 0.0D).endVertex();
- worldRenderer.pos(right, y, 0.0D).endVertex();
- worldRenderer.pos(x, y, 0.0D).endVertex();
- tessellator.draw();
- GlStateManager.enableTexture2D();
- GlStateManager.disableBlend();
- }
-
- public static void drawScaledString(String text, float x, float y, int color, boolean shadow, float scale) {
- GlStateManager.pushMatrix();
- GlStateManager.scale(scale, scale, 1);
- mc.fontRendererObj.drawString(text, x * (1 / scale), y * (1 / scale), color, shadow);
- GlStateManager.popMatrix();
- }
-
- public static void drawScaledImage(ResourceLocation location, int x, int y, int targetX, int targetY) {
- GlStateManager.enableBlend();
- GlStateManager.color(1f, 1f, 1f, 1f);
- mc.getTextureManager().bindTexture(location);
- Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, targetX, targetY, targetX, targetY, targetX, targetY);
- }
-
- public static void drawRegularPolygon(double x, double y, int radius, int sides, int color, double lowerAngle, double upperAngle) {
- GL11.glDisable(GL11.GL_TEXTURE_2D);
- color(color);
- GlStateManager.enableBlend();
- GlStateManager.disableAlpha();
- worldRenderer.begin(GL11.GL_POLYGON, DefaultVertexFormats.POSITION);
- worldRenderer.pos(x, y, 0).endVertex();
- //GL11.glHint(GL11.GL_POLYGON_SMOOTH_HINT, GL11.GL_NICEST);
- //GL11.glEnable(GL11.GL_POLYGON_SMOOTH);
- //GL11.glCullFace(GL11.GL_FRONT);
- //GL11.glCullFace(GL11.GL_FRONT_AND_BACK);
- //GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
- //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
- //GL11.glEnable(ARBMultisample.GL_MULTISAMPLE_ARB);
-
-
- for (int i = 0; i <= sides; i++) {
- double angle = ((Math.PI * 2) * i / sides) + Math.toRadians(180);
- if (angle > lowerAngle && angle < upperAngle) { // >0 <4.75; >4.7 <6.3; >6.25 <7.9; >7.8 <10 80 side mode
- worldRenderer.pos(x + Math.sin(angle) * radius, y + Math.cos(angle) * radius, 0).endVertex();
- }
- }
- tessellator.draw();
- GlStateManager.disableBlend();
- //GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
- GL11.glEnable(GL11.GL_TEXTURE_2D);
- }
-
- public static void drawRegularPolygon(double x, double y, int radius, int sides, int color) {
- drawRegularPolygon(x, y, radius, sides, color, 0d, 10000d);
- }
-
- /**
- * Draw a round rectangle at the given coordinates.
- *
- * @param radius radius of the corners
- * @param color color as a rgba integer
- */
- public static void drawRoundRect(int x, int y, int width, int height, int radius, int color) {
- GL11.glEnable(GL11.GL_BLEND);
- //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
- Gui.drawRect(x + radius, y, (x + width - radius), (y + radius), color); // top
- Gui.drawRect(x + radius, (y + height - radius), (x + width - radius), (y + height), color); // bottom
- Gui.drawRect(x, (y + radius), (x + width), (y + height - radius), color); // main
- drawRegularPolygon(x + radius, y + radius, radius, 80, color, 0d, 4.75d); // top left
- drawRegularPolygon(x + width - radius, y + radius, radius, 80, color, 7.8d, 10d); // top right
- drawRegularPolygon(x + radius, y + height - radius, radius, 80, color, 4.7d, 6.3d); // bottom left
- drawRegularPolygon(x + width - radius, y + height - radius, radius, 80, color, 6.25d, 7.9d); // bottom right
- GL11.glDisable(GL11.GL_BLEND);
- GL11.glColor4f(1f, 1f, 1f, 1f);
- }
-
- public static float clamp(float number) {
- return number < (float) 0.0 ? (float) 0.0 : Math.min(number, (float) 1.0);
- }
-
- public static float easeOut(float current, float goal) {
- if (Math.floor(Math.abs(goal - current) / (float) 0.01) > 0) {
- return current + (goal - current) / (float) 20.0;
- } else {
- return goal;
- }
- }
-
- /**
- * Return a java.awt.Color object from the given Integer.
- *
- * @param color rgba color, parsed into an integer
- */
- public static Color getColorFromInt(int color) {
- float f = (float) (color >> 16 & 255) / 255.0F;
- float f1 = (float) (color >> 8 & 255) / 255.0F;
- float f2 = (float) (color & 255) / 255.0F;
- float f3 = (float) (color >> 24 & 255) / 255.0F;
- return new Color(f, f1, f2, f3);
- }
-
- /**
- * Set GL color from the given Color variable.
- */
- public static void color(Color color) {
- GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f);
- }
-
- /**
- * Set GL color from the given color as an Integer.
- */
- public static void color(int color) {
- float f1 = (float) (color >> 8 & 255) / 255.0F;
- float f = (float) (color >> 16 & 255) / 255.0F;
- float f2 = (float) (color & 255) / 255.0F;
- float f3 = (float) (color >> 24 & 255) / 255.0F;
- GlStateManager.color(f, f1, f2, f3);
- }
-
- public static void drawLine(float sx, float sy, float ex, float ey, int width, int color) {
- float f = (float) (color >> 24 & 255) / 255.0F;
- float f1 = (float) (color >> 16 & 255) / 255.0F;
- float f2 = (float) (color >> 8 & 255) / 255.0F;
- float f3 = (float) (color & 255) / 255.0F;
- GlStateManager.pushMatrix();
- GlStateManager.disableTexture2D();
- GlStateManager.enableBlend();
- GlStateManager.disableAlpha();
- GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
- GlStateManager.color(f1, f2, f3, f);
- GL11.glLineWidth(width);
- GL11.glBegin(GL11.GL_LINES);
- GL11.glVertex2d(sx, sy);
- GL11.glVertex2d(ex, ey);
- GL11.glEnd();
- GlStateManager.disableBlend();
- GlStateManager.enableAlpha();
- GlStateManager.enableTexture2D();
- GlStateManager.popMatrix();
- }
-
- public static void drawDottedLine(float sx, float sy, float ex, float ey, int width, int factor, int color) {
- GlStateManager.pushMatrix();
- GL11.glLineStipple(factor, (short) 0xAAAA);
- GL11.glEnable(GL11.GL_LINE_STIPPLE);
- drawLine(sx, sy, ex, ey, width, color);
- GL11.glDisable(GL11.GL_LINE_STIPPLE);
- GlStateManager.popMatrix();
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java b/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java
deleted file mode 100644
index d26b953..0000000
--- a/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java
+++ /dev/null
@@ -1,451 +0,0 @@
-package io.polyfrost.oneconfig.renderer;
-
-import net.minecraft.client.renderer.GlStateManager;
-import org.lwjgl.BufferUtils;
-import org.lwjgl.opengl.GL11;
-import org.lwjgl.util.glu.GLU;
-
-import java.awt.*;
-import java.awt.image.BufferedImage;
-import java.awt.image.DataBuffer;
-import java.awt.image.DataBufferByte;
-import java.awt.image.DataBufferInt;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.IntBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-
-/**
- * A TrueType font implementation originally for Slick, then edited for Bobjob's Engine, now for Minecraft
- *
- * @author James Chambers (Jimmy) (original in Slick)
- * @author Jeremy Adams (elias4444) (original in Slick)
- * @author Kevin Glass (kevglass) (original in Slick)
- * @author Peter Korzuszek (genail) (original in Slick)
- * @author version edited by David Aaron Muhar (bobjob) (modified in Bobjob's Engine)
- */
-public class TrueTypeFont {
- public final static int ALIGN_LEFT = 0, ALIGN_RIGHT = 1, ALIGN_CENTER = 2;
- /**
- * Array that holds necessary information about the font characters
- */
- private final IntObject[] charArray = new IntObject[256];
-
- /**
- * Map of user defined font characters (Character <-> IntObject)
- */
- private final Map<Character, IntObject> customChars = new HashMap<>();
-
- /**
- * Boolean flag on whether AntiAliasing is enabled or not
- */
- private final boolean antiAlias;
-
- /**
- * Font's size
- */
- private final int fontSize;
- /**
- * Default font texture width
- */
- private final int textureWidth = 512;
- /**
- * Default font texture height
- */
- private final int textureHeight = 512;
- /**
- * A reference to Java's AWT Font that we create our font texture from
- */
- private final Font font;
- /**
- * Font's height
- */
- private int fontHeight = 0;
- /**
- * Texture used to cache the font 0-255 characters
- */
- private int fontTextureID;
-
-
- public TrueTypeFont(Font font, boolean antiAlias, char[] additionalChars) {
- this.font = font;
- this.fontSize = font.getSize() + 3;
- this.antiAlias = antiAlias;
-
- createSet(additionalChars);
-
- fontHeight -= 1;
- if (fontHeight <= 0) fontHeight = 1;
- }
-
-
- public TrueTypeFont(Font font, boolean antiAlias) {
- this(font, antiAlias, null);
- }
-
- public static int loadImage(BufferedImage bufferedImage) {
- try {
- short width = (short) bufferedImage.getWidth();
- short height = (short) bufferedImage.getHeight();
- //textureLoader.bpp = bufferedImage.getColorModel().hasAlpha() ? (byte)32 : (byte)24;
- int bpp = (byte) bufferedImage.getColorModel().getPixelSize();
- ByteBuffer byteBuffer;
- DataBuffer db = bufferedImage.getData().getDataBuffer();
- if (db instanceof DataBufferInt) {
- int[] intI = ((DataBufferInt) (bufferedImage.getData().getDataBuffer())).getData();
- byte[] newI = new byte[intI.length * 4];
- for (int i = 0; i < intI.length; i++) {
- byte[] b = intToByteArray(intI[i]);
- int newIndex = i * 4;
-
- newI[newIndex] = b[1];
- newI[newIndex + 1] = b[2];
- newI[newIndex + 2] = b[3];
- newI[newIndex + 3] = b[0];
- }
-
- byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(newI);
- } else {
- byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
- }
- byteBuffer.flip();
-
-
- int internalFormat = GL11.GL_RGBA8, format = GL11.GL_RGBA;
- IntBuffer textureId = BufferUtils.createIntBuffer(1);
-
- GL11.glGenTextures(textureId);
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId.get(0));
-
-
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
-
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
-
- GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
-
-
- GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, internalFormat, width, height, format, GL11.GL_UNSIGNED_BYTE, byteBuffer);
- return textureId.get(0);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- return -1;
- }
-
- public static boolean isSupported(String fontname) {
- Font[] font = getFonts();
- for (int i = font.length - 1; i >= 0; i--) {
- if (font[i].getName().equalsIgnoreCase(fontname)) return true;
- }
- return false;
- }
-
- public static Font[] getFonts() {
- return GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
- }
-
- public static byte[] intToByteArray(int value) {
- return new byte[]{(byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) value};
- }
-
- private BufferedImage getFontImage(char ch) {
- // Create a temporary image to extract the character's size
- BufferedImage tempfontImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = (Graphics2D) tempfontImage.getGraphics();
- if (antiAlias) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- }
- g.setFont(font);
- FontMetrics fontMetrics = g.getFontMetrics();
- int charwidth = fontMetrics.charWidth(ch) + 8;
-
- if (charwidth <= 0) {
- charwidth = 7;
- }
- int charheight = fontMetrics.getHeight() + 3;
- if (charheight <= 0) {
- charheight = fontSize;
- }
-
- // Create another image holding the character we are creating
- BufferedImage fontImage;
- fontImage = new BufferedImage(charwidth, charheight, BufferedImage.TYPE_INT_ARGB);
- Graphics2D gt = (Graphics2D) fontImage.getGraphics();
- if (antiAlias) {
- gt.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- }
- gt.setFont(font);
-
- gt.setColor(Color.WHITE);
- int charx = 3;
- int chary = 1;
- gt.drawString(String.valueOf(ch), (charx), (chary) + fontMetrics.getAscent());
-
- return fontImage;
-
- }
-
- private void createSet(char[] customCharsArray) {
- try {
- BufferedImage imgTemp = new BufferedImage(textureWidth, textureHeight, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = (Graphics2D) imgTemp.getGraphics();
-
- g.setColor(new Color(0, 0, 0, 1));
- g.fillRect(0, 0, textureWidth, textureHeight);
-
- int customCharsLength = (customCharsArray != null) ? customCharsArray.length : 0;
- int rowHeight = 0;
- int positionX = 0;
- int positionY = 0;
-
- // ignore some characters because they don't have visual representation
- for (int i = 0; i < 224 + customCharsLength; i++) {
- if (i >= 95 && i <= 128) continue;
-
- char ch = (i < 224) ? (char) (i + 32) : customCharsArray[i - 224];
-
- BufferedImage fontImage = getFontImage(ch);
-
- IntObject newIntObject = new IntObject();
-
- newIntObject.width = fontImage.getWidth();
- newIntObject.height = fontImage.getHeight();
-
- if (positionX + newIntObject.width >= textureWidth) {
- positionX = 0;
- positionY += rowHeight;
- rowHeight = 0;
- }
-
- newIntObject.storedX = positionX;
- newIntObject.storedY = positionY;
-
- if (newIntObject.height > fontHeight) {
- fontHeight = newIntObject.height;
- }
-
- if (newIntObject.height > rowHeight) {
- rowHeight = newIntObject.height;
- }
-
- // Draw it here
- g.drawImage(fontImage, positionX, positionY, null);
-
- positionX += newIntObject.width;
-
- if (i < 224) { // standard characters
- charArray[i + 32] = newIntObject;
- } else { // custom characters
- customChars.put(ch, newIntObject);
- }
- }
-
- fontTextureID = loadImage(imgTemp);
-
- //ImageIO.write(imgTemp, "png", new File("./OneConfig/bitmap.png"));
- } catch (Exception e) {
- System.err.println("Failed to create font.");
- e.printStackTrace();
- }
- }
-
- private void drawQuad(float drawX, float drawY, float drawX2, float drawY2, float srcX, float srcY, float srcX2, float srcY2) {
- float DrawWidth = drawX2 - drawX;
- float DrawHeight = drawY2 - drawY;
- float TextureSrcX = srcX / textureWidth;
- float TextureSrcY = srcY / textureHeight;
- float SrcWidth = srcX2 - srcX;
- float SrcHeight = srcY2 - srcY;
- float RenderWidth = (SrcWidth / textureWidth);
- float RenderHeight = (SrcHeight / textureHeight);
-
- GlStateManager.bindTexture(fontTextureID);
-
- GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
- GL11.glTexCoord2f(TextureSrcX + RenderWidth, TextureSrcY); // 2
- GL11.glVertex2f(drawX + DrawWidth, drawY + DrawHeight); // 1
- GL11.glTexCoord2f(TextureSrcX, TextureSrcY); // 1
- GL11.glVertex2f(drawX, drawY + DrawHeight); // 2
- GL11.glTexCoord2f(TextureSrcX + RenderWidth, TextureSrcY + RenderHeight); // 4
- GL11.glVertex2f(drawX + DrawWidth, drawY); // 3
- GL11.glTexCoord2f(TextureSrcX, TextureSrcY + RenderHeight); // 3
- GL11.glVertex2f(drawX, drawY); // 4
- GL11.glEnd();
- }
-
- public int getWidth(String text) {
- int totalWidth = 0;
- IntObject intObject;
- int currentChar;
- for (int i = 0; i < text.length(); i++) {
- currentChar = text.charAt(i);
- if (currentChar < 256) {
- intObject = charArray[currentChar];
- } else {
- intObject = customChars.get((char) currentChar);
- }
-
- if (intObject != null) totalWidth += intObject.width;
- }
- return totalWidth;
- }
-
- public int getHeight() {
- return fontHeight;
- }
-
- public void drawString(String text, float x, float y, float scaleX, float scaleY, int color) {
- drawString(text, x, y, scaleX, scaleY, ALIGN_LEFT, color);
- }
-
- public void drawSplitString(String text, float x, float y, int wrapWidth, int color) {
- try { // time taken: 0.035ms to do complete cycle
- wrapWidth += 140; // it needs this extra to work properly (why?)
- List<String> splitString = new ArrayList<>();
- String[] words = text.split("\\W+");
- int totalWidth = 0;
- String line = "";
- for (String word : words) {
- int width = getWidth(word);
- word += " "; // add the space
- totalWidth += width;
- line += word;
- if (totalWidth >= wrapWidth) { // wrap line if it is too long
- splitString.add(line);
- totalWidth = 0;
- line = "";
- }
- }
- if (!line.equals("")) { // add extra if there is any (last line)
- splitString.add(line);
- }
- int i1 = 0;
- for (String string : splitString) {
- drawString(string, x, y + i1, 1f, 1f, color); // draw it
- i1 += getHeight();
- }
- } catch (Exception e) { // be safe kids
- e.printStackTrace();
- }
- }
-
- public void drawString(String text, float x, float y, float scaleX, float scaleY, int format, int color) {
- int startIndex = 0;
- int endIndex = text.length() - 1;
- IntObject intObject;
- int charCurrent;
-
-
- int totalWidth = 0;
- int i = startIndex, d, c;
- float startY = 0;
-
- switch (format) {
- case ALIGN_RIGHT: {
- d = -1;
- c = 8;
-
- while (i < endIndex) {
- if (text.charAt(i) == '\n') startY -= fontHeight;
- i++;
- }
- break;
- }
- case ALIGN_CENTER: {
- for (int l = startIndex; l <= endIndex; l++) {
- charCurrent = text.charAt(l);
- if (charCurrent == '\n') break;
- if (charCurrent < 256) {
- intObject = charArray[charCurrent];
- } else {
- intObject = customChars.get((char) charCurrent);
- }
- totalWidth += intObject.width - 9;
- }
- totalWidth /= -9;
- }
- case ALIGN_LEFT:
- default: {
- d = 1;
- c = 9;
- break;
- }
-
- }
-
- GlStateManager.enableAlpha();
- GlStateManager.enableBlend();
-
- Renderer.color(color);
- while (i >= startIndex && i <= endIndex) {
- charCurrent = text.charAt(i);
- if (charCurrent < 256) {
- intObject = charArray[charCurrent];
- } else {
- intObject = customChars.get((char) charCurrent);
- }
-
- if (intObject != null) {
- if (d < 0) totalWidth += (intObject.width - c) * d;
- drawQuad((totalWidth + intObject.width) * scaleX + x, startY * scaleY + y, totalWidth * scaleX + x, (startY + intObject.height) * scaleY + y, intObject.storedX + intObject.width, intObject.storedY + intObject.height, intObject.storedX, intObject.storedY);
- if (d > 0) totalWidth += (intObject.width - c) * d;
- } else if (charCurrent == '\n') {
- startY += fontHeight * d;
- totalWidth = 0;
- if (format == ALIGN_CENTER) {
- for (int l = i + 1; l <= endIndex; l++) {
- charCurrent = text.charAt(l);
- if (charCurrent == '\n') break;
- if (charCurrent < 256) {
- intObject = charArray[charCurrent];
- } else {
- intObject = customChars.get((char) charCurrent);
- }
- totalWidth += intObject.width - 9;
- }
- totalWidth /= -2;
- }
- }
- i += d;
- }
- GlStateManager.disableBlend();
- GlStateManager.color(1f, 1f, 1f, 1f);
- }
-
- public void destroy() {
- IntBuffer scratch = BufferUtils.createIntBuffer(1);
- scratch.put(0, fontTextureID);
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
- GL11.glDeleteTextures(scratch);
- }
-
- private static class IntObject {
- /**
- * Character's width
- */
- public int width;
-
- /**
- * Character's height
- */
- public int height;
-
- /**
- * Character's stored x position
- */
- public int storedX;
-
- /**
- * Character's stored y position
- */
- public int storedY;
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestHud.java b/src/main/java/io/polyfrost/oneconfig/test/TestHud.java
index 67f0610..9008e3d 100644
--- a/src/main/java/io/polyfrost/oneconfig/test/TestHud.java
+++ b/src/main/java/io/polyfrost/oneconfig/test/TestHud.java
@@ -1,7 +1,7 @@
package io.polyfrost.oneconfig.test;
import io.polyfrost.oneconfig.hud.interfaces.BasicHud;
-import io.polyfrost.oneconfig.renderer.Renderer;
+import io.polyfrost.oneconfig.lwjgl.RenderManager;
import net.minecraft.client.Minecraft;
public class TestHud extends BasicHud {
@@ -18,6 +18,6 @@ public class TestHud extends BasicHud {
@Override
public void draw(int x, int y, float scale) {
- Renderer.drawScaledString("FPS: " + Minecraft.getDebugFPS(), x, y, 0xffffff, false, scale);
+ RenderManager.drawScaledString("FPS: " + Minecraft.getDebugFPS(), x, y, 0xffffff, false, scale);
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java b/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java
new file mode 100644
index 0000000..c1badc2
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java
@@ -0,0 +1,24 @@
+package io.polyfrost.oneconfig.test;
+
+import io.polyfrost.oneconfig.lwjgl.RenderManager;
+import net.minecraft.client.gui.GuiScreen;
+
+import java.awt.*;
+
+public class TestNanoVGGui extends GuiScreen {
+
+ @Override
+ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
+ super.drawScreen(mouseX, mouseY, partialTicks);
+ drawRect(0, 0, width, height, Color.BLACK.getRGB());
+ 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.drawLine(vg, 0, 0, 100, 100, 7, Color.PINK.getRGB());
+ });
+ drawString(fontRendererObj, "Hello!", 0, 0, -1);
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java b/src/main/java/io/polyfrost/oneconfig/themes/Theme.java
deleted file mode 100644
index 5f2bfac..0000000
--- a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java
+++ /dev/null
@@ -1,310 +0,0 @@
-package io.polyfrost.oneconfig.themes;
-
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import io.polyfrost.oneconfig.renderer.Renderer;
-import io.polyfrost.oneconfig.renderer.TrueTypeFont;
-import io.polyfrost.oneconfig.themes.textures.TextureManager;
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.renderer.texture.DynamicTexture;
-import net.minecraft.client.resources.FileResourcePack;
-import net.minecraft.crash.CrashReport;
-import net.minecraft.util.ReportedException;
-import net.minecraft.util.ResourceLocation;
-
-import javax.imageio.ImageIO;
-import java.awt.*;
-import java.awt.image.BufferedImage;
-import java.io.*;
-
-@SuppressWarnings("unused")
-public class Theme extends FileResourcePack {
- private final File themeFile;
- private final File themeConfigFile;
- private static final Minecraft mc = Minecraft.getMinecraft();
- private final long loadedTime = System.currentTimeMillis();
- private final JsonObject packMetadata;
- private final JsonObject packConfig;
- private final Color accentColor;
- private final Color elementColor;
- private final Color titleBarColor;
- private final Color baseColor;
- private final Color hoverColor;
- private final Color clickColor;
- private final Color closeColor;
- private final Color titleColor;
- private final Color subTitleColor;
- private final boolean roundCorners;
- private final String description;
- private final String title;
- private final int version;
- private final TextureManager manager;
- private final TrueTypeFont boldFont;
- private final TrueTypeFont normalFont;
- private boolean ready;
-
-
-
- /**
- * Create a new theme instance for the window.
- * @param themePack file of the pack
- * @throws IOException if an error occurs reading metadata or unpacking, etc.
- */
- protected Theme(File themePack) throws IOException {
- super(themePack);
- ready = false;
- long start = System.nanoTime();
- themeFile = themePack;
- themeConfigFile = new File(themeFile.getPath() + ".json");
- packMetadata = new JsonParser().parse(new InputStreamReader(getInputStreamByName("pack.json"))).getAsJsonObject();
- try {
- unpackConfig();
- } catch (Exception e) {
- Themes.themeLog.error("failed to unpack config!", e);
- unpackConfig();
- }
- packConfig = new JsonParser().parse(new FileReader(themeConfigFile)).getAsJsonObject();
- JsonObject colors = packConfig.getAsJsonObject("colors");
- accentColor = Renderer.getColorFromInt(colors.get("accent_color").getAsInt());
- baseColor = Renderer.getColorFromInt(colors.get("base_color").getAsInt());
- titleBarColor = Renderer.getColorFromInt(colors.get("title_bar").getAsInt());
- elementColor = Renderer.getColorFromInt(colors.get("element_color").getAsInt());
- clickColor = Renderer.getColorFromInt(colors.get("click_color").getAsInt());
- closeColor = Renderer.getColorFromInt(colors.get("close_color").getAsInt());
- titleColor = Renderer.getColorFromInt(colors.get("title_color").getAsInt());
- hoverColor = Renderer.getColorFromInt(colors.get("hover_color").getAsInt());
- subTitleColor = Renderer.getColorFromInt(colors.get("subtitle_color").getAsInt());
- roundCorners = packConfig.get("round_corners").getAsBoolean();
- String title, description;
- int version;
- try {
- title = packMetadata.get("name").getAsString();
- description = packMetadata.get("description").getAsString();
- version = packMetadata.get("version").getAsInt();
- } catch (Exception e) {
- title = "null";
- description = "no valid pack.json found!";
- version = -1;
- Themes.themeLog.error("pack has invalid metadata! Using default values.");
- }
- this.title = title;
- this.description = description;
- this.version = version;
- TrueTypeFont normalFontTemp;
- TrueTypeFont boldFontTemp;
- try {
- boldFontTemp = new TrueTypeFont(Font.createFont(Font.TRUETYPE_FONT, getResource("textures/fonts/font_bold.ttf")).deriveFont(30f), true);
- normalFontTemp = new TrueTypeFont(Font.createFont(Font.TRUETYPE_FONT, getResource("textures/fonts/font.ttf")).deriveFont(18f), true);
- } catch (FontFormatException e) {
- Themes.themeLog.error("failed to derive fonts, is theme invalid?",e);
- e.printStackTrace();
- try {
- normalFontTemp = new TrueTypeFont(Font.createFont(Font.TRUETYPE_FONT, mc.getResourceManager().getResource(new ResourceLocation("oneconfig", "textures/fonts/font.ttf")).getInputStream()).deriveFont(12f), true);
- boldFontTemp = new TrueTypeFont(Font.createFont(Font.TRUETYPE_FONT, mc.getResourceManager().getResource(new ResourceLocation("oneconfig", "textures/fonts/font_bold.ttf")).getInputStream()).deriveFont(30f), true);
- } catch (FontFormatException ex) {
- ex.printStackTrace();
- throw new ReportedException(new CrashReport("Failed to get fallback fonts! game will crash :(", ex));
- }
- }
- normalFont = normalFontTemp;
- boldFont = boldFontTemp;
- manager = new TextureManager(this);
- if(Themes.VERSION != version) {
- Themes.themeLog.warn("Theme was made for a different version of OneConfig! This may cause issues in the GUI.");
- }
- Themes.themeLog.info("Successfully loaded theme in " + ((float) (System.nanoTime() - start)) / 1000000f + "ms");
- ready = true;
-
- }
-
- /**
- * Attempt to unpack the theme default config if it doesn't already exist.
- */
- private void unpackConfig() throws IOException {
- if (themeConfigFile.createNewFile()) {
- Themes.themeLog.warn("Creating config file for theme " + themeFile.getName() + ", assuming it has never been opened before.");
- BufferedReader streamReader = new BufferedReader(new InputStreamReader(getInputStreamByName("default_config.json")));
- StringBuilder responseStrBuilder = new StringBuilder();
- String inputStr;
- while ((inputStr = streamReader.readLine()) != null)
- responseStrBuilder.append(inputStr);
- FileWriter fileWriter = new FileWriter(themeConfigFile);
- fileWriter.write(responseStrBuilder.toString());
- fileWriter.close();
- }
-
- }
-
-
- /**
- * get a ResourceLocation of an image in the current theme.
- * @param name path of the resource (e.g. textures/logos/logo.png)
- * @throws IOException if the item cannot be located or pack is corrupt.
- */
- public ResourceLocation getLocationFromName(String name) throws IOException {
- return mc.getTextureManager().getDynamicTextureLocation(name, new DynamicTexture(ImageIO.read(getInputStreamByName(name))));
- }
-
-
-
- /**
- * Get the accent color for the window, used on separators, lines, etc.
- */
- public Color getAccentColor() {
- return accentColor;
- }
- /**
- * Get the base color for the window, used for the main background.
- */
- public Color getBaseColor() {
- return baseColor;
- }
- /**
- * Get the color used for the title bar.
- */
- public Color getTitleBarColor() {
- return titleBarColor;
- }
- /**
- * Get the base color for the buttons, items, and most elements.
- */
- public Color getElementColor() {
- return elementColor;
- }
- /**
- * Get the accent color for elements when they are hovered.
- */
- public Color getHoverColor() {
- return hoverColor;
- }
- /**
- * Get the accent color for elements when they are clicked.
- */
- public Color getClickColor() {
- return clickColor;
- }
- /**
- * Get the color for the close/destroy buttons.
- */
- public Color getCloseColor() {
- return closeColor;
- }
- /**
- * Get the color for the main text, like titles, config element items, etc.
- */
- public Color getTextColor() {
- return titleColor;
- }
- /**
- * Get the accent color for the text, used for subtitles, etc.
- */
- public Color getAccentTextColor() {
- return subTitleColor;
- }
- /**
- * Weather or not to round off the corners of pretty much every element.
- */
- public boolean shouldRoundCorners() {
- return roundCorners;
- }
-
-
- /**
- * Get the InputStream of a resource in the pack.
- * @param name name of the resource
- * @throws IOException an error occurs reading
- */
- public InputStream getResource(String name) throws IOException {
- return getInputStreamByName(name);
- }
-
- /**
- * Get this pack's metadata json.
- */
- public JsonObject getPackMetaData() {
- return packMetadata;
- }
-
- /**
- * Get the pack's config file.
- */
- public JsonObject getPackConfig() {
- return packConfig;
- }
-
- /**
- * Get the pack's description.
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * Get the friendly name of the pack.
- */
- public String getName() {
- return title;
- }
-
- /**
- * Get the pack's title image.
- */
- public BufferedImage getImage() {
- try {
- return getPackImage();
- } catch (IOException e) {
- Themes.themeLog.error("Failed to parse pack image. Is pack invalid??");
- //e.printStackTrace();
- }
- return null;
- }
-
- /**
- * Get the pack's version. Not used yet, but will be when more features are added for theme compatability.
- */
- public int getVersion() {
- return version;
- }
-
- /**
- * Get the source file of this theme.
- */
- public File getThemeFile() {
- return themeFile;
- }
-
- /**
- * Get the texture manager for this theme, with all drawing utilities.
- */
- public TextureManager getTextureManager() {
- return manager;
- }
-
- /**
- * Get the font from this theme.
- */
- public TrueTypeFont getFont() {
- return normalFont;
- }
-
- /**
- * Get the bold, larger font from this theme.
- */
- public TrueTypeFont getBoldFont() {
- return boldFont;
- }
-
- /**
- * Get the time this theme was loaded. (used for debugging)
- */
- public long getLoadedTime() {
- return loadedTime;
- }
-
- /**
- * Check if the theme is fully loaded or not.
- */
- public boolean isReady() {
- return ready;
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/Themes.java b/src/main/java/io/polyfrost/oneconfig/themes/Themes.java
deleted file mode 100644
index 240c97d..0000000
--- a/src/main/java/io/polyfrost/oneconfig/themes/Themes.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package io.polyfrost.oneconfig.themes;
-
-import io.polyfrost.oneconfig.OneConfig;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
-
-public class Themes {
- public static final int VERSION = 0;
- public static Theme activeTheme;
- public static final Logger themeLog = LogManager.getLogger("OneConfig Themes");
-
- /**
- * Return a list of all available themes in the directory.
- * @return list of themes
- */
- public static List<File> getThemes() {
- FilenameFilter filter = (dir, name) -> name.endsWith(".zip");
- return Arrays.asList(Objects.requireNonNull(OneConfig.themesDir.listFiles(filter)));
- }
-
- /**
- * Return the active theme instance.
- */
- public static Theme getActiveTheme() {
- return activeTheme;
- }
-
- /**
- * Open a new theme in the window, and restart the GUI.
- * @param theme Theme file to open
- */
- public static void openTheme(File theme) {
- try {
- activeTheme = new Theme(theme);
- } catch (IOException e) {
- e.printStackTrace();
- }
- // TODO restart gui
- }
-
-
- public String toString() {
- return "OneConfig Theme {loaded=" + activeTheme.getLoadedTime() + ", name=" + activeTheme.getName() + ", desc=" + activeTheme.getDescription() + ", ready=" + activeTheme.isReady() + "}";
- }
-
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java b/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java
deleted file mode 100644
index a2e96d4..0000000
--- a/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package io.polyfrost.oneconfig.themes.textures;
-
-import io.polyfrost.oneconfig.themes.Theme;
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.Gui;
-import net.minecraft.client.renderer.GlStateManager;
-import net.minecraft.client.renderer.texture.DynamicTexture;
-import net.minecraft.crash.CrashReport;
-import net.minecraft.util.ReportedException;
-import net.minecraft.util.ResourceLocation;
-import org.jetbrains.annotations.NotNull;
-
-import javax.imageio.ImageIO;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static io.polyfrost.oneconfig.themes.Themes.activeTheme;
-import static io.polyfrost.oneconfig.themes.Themes.themeLog;
-
-public class TextureManager {
- private static final Minecraft mc = Minecraft.getMinecraft();
- private final List<ResourceLocation> resources = new ArrayList<>();
- private final List<TickableTexture> tickableTextures = new ArrayList<>();
-
- /**
- * Create a new texture manager for this theme, used for drawing of icons, etc.
- */
- public TextureManager(Theme theme) {
- for (ThemeElement element : ThemeElement.values()) {
- BufferedImage img;
- try {
- img = ImageIO.read(theme.getResource(element.location));
- } catch (Exception e) {
- themeLog.error("failed to get themed texture: " + element.location + ", having to fallback to default one. Is pack invalid?");
- try {
- img = ImageIO.read(mc.getResourceManager().getResource(new ResourceLocation("oneconfig", element.location)).getInputStream());
- } catch (IOException ex) {
- themeLog.fatal("failed to get fallback texture: " + element.location + ", game will crash :(");
- throw new ReportedException(new CrashReport("TextureManager failure: FALLBACK_ERROR_OR_MISSING", ex));
- }
- }
- ResourceLocation location = mc.getTextureManager().getDynamicTextureLocation(element.location, new DynamicTexture(img));
- resources.add(location);
- if (img.getWidth() != element.size) {
- themeLog.warn("Theme element " + element.name() + " with size " + img.getWidth() + "px is not recommended, expected " + element.size + "px. Continuing anyway.");
- }
- if (element.ordinal() < 26) {
- if (img.getWidth() != img.getHeight()) {
- themeLog.info("found tickable animated texture (" + element.name() + "). Loading texture");
- try {
- tickableTextures.add(new TickableTexture(element));
- } catch (IOException e) {
- themeLog.error("failed to create TickableTexture " + element.location + ". Just going to load it as a normal texture, this may break things!");
- e.printStackTrace();
- }
- }
- } else {
- if (element.ordinal() < 29) {
- if (img.getHeight() != 144 || img.getWidth() != 758) {
- themeLog.warn("found badly sized button texture " + element.location);
- }
- }
- }
- }
- }
-
- /**
- * Draw the specified {@link ThemeElement} at the coordinates, scaled to the width and height.
- *
- * @param element element to draw
- * @param x x coordinate (top left)
- * @param y y coordinate (top left)
- * @param width width of the image
- * @param height height of the image
- */
- public void draw(@NotNull ThemeElement element, int x, int y, int width, int height) {
- if (activeTheme.isReady()) {
- ResourceLocation location = resources.get(element.ordinal());
- mc.getTextureManager().bindTexture(location);
- GlStateManager.enableBlend();
- try {
- if (!tickableTextures.isEmpty()) {
- for (TickableTexture texture : tickableTextures) {
- if (texture.getElement().equals(element)) {
- texture.draw(x, y);
- } else {
- Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, width, height, width, height, width, height);
- }
- }
- } else {
- Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, width, height, width, height, width, height);
- }
- GlStateManager.disableBlend();
- GlStateManager.color(1f, 1f, 1f, 1f);
- } catch (Exception e) {
- themeLog.error("Error occurred drawing texture " + element.name() + ", is theme invalid?", e);
- }
- }
- }
-
- /**
- * Draw the specified {@link ThemeElement} at the coordinates, using its recommended width and height.
- *
- * @param element element to draw
- * @param x x coordinate (top left)
- * @param y y coordinate (top left)
- */
- public void draw(@NotNull ThemeElement element, int x, int y) {
- this.draw(element, x, y, element.size, element.size);
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java b/src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java
deleted file mode 100644
index 2ab3bc9..0000000
--- a/src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package io.polyfrost.oneconfig.themes.textures;
-
-public enum ThemeElement {
- DISCORD("textures/icons/discord.png", 128),
- DOCS("textures/icons/docs.png", 128),
- FEEDBACK("textures/icons/feedback.png", 128),
- GUIDE("textures/icons/guide.png", 128),
- HUD_SETTINGS("textures/icons/hudsettings.png", 128),
- MOD_SETTINGS("textures/icons/modsettings.png", 128),
- STORE("textures/icons/store.png", 128),
- THEMES("textures/icons/themes.png", 128),
- UPDATE("textures/icons/update.png", 128),
-
- BACK_ARROW("textures/smallicons/backarrow.png", 32),
- FORWARD_ARROW("textures/smallicons/forward.png", 32),
- HOME("textures/smallicons/home.png", 32),
- SEARCH("textures/smallicons/search.png", 32),
- MAGNIFY("textures/smallicons/magnify.png", 64),
- MINIMIZE("textures/smallicons/minimize.png", 64),
- CLOSE("textures/smallicons/close.png", 64),
-
- ALL_MODS("textures/mod/allmods.png", 32),
- HUD_MODS("textures/mod/hudmods.png", 32),
- QOL_MODS("textures/mod/qolmods.png", 32),
- HYPIXEL("textures/mod/hypixel.png", 32),
- PERFORMANCE("textures/mod/performance.png", 32),
- PVP("textures/mod/pvp.png", 32),
- SKYBLOCK("textures/mod/skyblock.png", 32),
- UTILITIES("textures/mod/utilities.png", 32),
-
- LOGO("textures/logos/logo.png", 128),
- SMALL_LOGO("textures/logos/logo_small.png", 64),
-
- BUTTON("textures/window/button.png", 758),
- BUTTON_HOVER("textures/window/button_hover.png", 758),
- BUTTON_CLICK("textures/window/button_click.png", 758),
-
- BACKGROUND("textures/window/background.png", 1600);
-
-
- public final String location;
- public final int size;
-
- ThemeElement(String location, int size) {
- this.location = location;
- this.size = size;
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java b/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java
deleted file mode 100644
index 5fe1242..0000000
--- a/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package io.polyfrost.oneconfig.themes.textures;
-
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.Gui;
-import net.minecraft.client.renderer.GlStateManager;
-import net.minecraft.client.renderer.texture.DynamicTexture;
-import net.minecraft.util.ResourceLocation;
-
-import javax.imageio.ImageIO;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import static io.polyfrost.oneconfig.themes.Themes.getActiveTheme;
-import static io.polyfrost.oneconfig.themes.Themes.themeLog;
-
-@SuppressWarnings("unused")
-public class TickableTexture {
- private final int framesToSkip;
- private final BufferedImage image;
- private final int sizeX, sizeY, frames;
- private final ThemeElement thisElement;
- private final ResourceLocation location;
- private int tick;
- private int tick2;
-
- public TickableTexture(ThemeElement element) throws IOException {
- thisElement = element;
- InputStream inputStream = getActiveTheme().getResource(element.location);
- image = ImageIO.read(inputStream);
- location = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation(element.location, new DynamicTexture(image));
- sizeX = image.getWidth();
- sizeY = image.getHeight();
- frames = sizeY / sizeX;
- int frametime;
- try {
- JsonObject jsonObject = new JsonParser().parse(new InputStreamReader(getActiveTheme().getResource(element.location + ".json"))).getAsJsonObject();
- frametime = jsonObject.get("frametime").getAsInt();
- if (frametime == 0) {
- frametime = 1;
- themeLog.warn("You cannot have a frame tick time of 0. This will mean there is no animation as it will happen impossibly fast. Defaulting to 1, as we assume you wanted it fast.");
- }
- } catch (Exception e) {
- themeLog.error("failed to load metadata for tickable texture (" + element.location + "). Setting default (5)");
- frametime = 5;
- }
- framesToSkip = frametime;
- }
-
- public void draw(int x, int y) {
- GlStateManager.enableBlend();
- GlStateManager.color(1f, 1f, 1f, 1f);
- Minecraft.getMinecraft().getTextureManager().bindTexture(location);
- if (tick < frames) {
- Gui.drawModalRectWithCustomSizedTexture(x, y, 0, (tick * sizeX), sizeX, sizeX, sizeX, sizeX);
- tick2++;
- if (tick2 == framesToSkip) {
- tick2 = 0;
- tick++;
- }
- }
- if (tick == frames) {
- tick = 0;
- }
- GlStateManager.disableBlend();
- }
-
- public BufferedImage getImage() {
- return image;
- }
-
- public int getFrameTime() {
- return framesToSkip;
- }
-
- public int getSizeX() {
- return sizeX;
- }
-
- public int getSizeY() {
- return sizeY;
- }
-
- public ThemeElement getElement() {
- return thisElement;
- }
-}
diff --git a/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java
new file mode 100644
index 0000000..e2e5184
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java
@@ -0,0 +1,15 @@
+package io.polyfrost.oneconfig.utils;
+
+public class MathUtils {
+ public static float clamp(float number) {
+ return number < (float) 0.0 ? (float) 0.0 : Math.min(number, (float) 1.0);
+ }
+
+ public static float easeOut(float current, float goal) {
+ if (Math.floor(Math.abs(goal - current) / (float) 0.01) > 0) {
+ return current + (goal - current) / (float) 20.0;
+ } else {
+ return goal;
+ }
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/utils/TickDelay.java b/src/main/java/io/polyfrost/oneconfig/utils/TickDelay.java
index 33b02fe..b28a20a 100644
--- a/src/main/java/io/polyfrost/oneconfig/utils/TickDelay.java
+++ b/src/main/java/io/polyfrost/oneconfig/utils/TickDelay.java
@@ -6,7 +6,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
public class TickDelay {
- Integer delay;
+ int delay;
Runnable function;
public TickDelay(Runnable functionName, int ticks) {
diff --git a/src/main/resources/assets/oneconfig/font/Inter-Bold.ttf b/src/main/resources/assets/oneconfig/font/Inter-Bold.ttf
new file mode 100644
index 0000000..76a215c
--- /dev/null
+++ b/src/main/resources/assets/oneconfig/font/Inter-Bold.ttf
Binary files differ
diff --git a/src/main/resources/assets/oneconfig/font/Minecraft-Regular.otf b/src/main/resources/assets/oneconfig/font/Minecraft-Regular.otf
new file mode 100644
index 0000000..54f08ad
--- /dev/null
+++ b/src/main/resources/assets/oneconfig/font/Minecraft-Regular.otf
Binary files differ
diff --git a/src/main/resources/assets/oneconfig/font/OFL-INTER-BOLD.txt b/src/main/resources/assets/oneconfig/font/OFL-INTER-BOLD.txt
new file mode 100644
index 0000000..b525cbf
--- /dev/null
+++ b/src/main/resources/assets/oneconfig/font/OFL-INTER-BOLD.txt
@@ -0,0 +1,93 @@
+Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter)
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at:
+http://scripts.sil.org/OFL
+
+
+-----------------------------------------------------------
+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
+-----------------------------------------------------------
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide
+development of collaborative font projects, to support the font creation
+efforts of academic and linguistic communities, and to provide a free and
+open framework in which fonts may be shared and improved in partnership
+with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and
+redistributed freely as long as they are not sold by themselves. The
+fonts, including any derivative works, can be bundled, embedded,
+redistributed and/or sold with any software provided that any reserved
+names are not used by derivative works. The fonts and derivatives,
+however, cannot be released under any other type of license. The
+requirement for fonts to remain under this license does not apply
+to any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright
+Holder(s) under this license and clearly marked as such. This may
+include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the
+copyright statement(s).
+
+"Original Version" refers to the collection of Font Software components as
+distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to, deleting,
+or substituting -- in part or in whole -- any of the components of the
+Original Version, by changing formats or by porting the Font Software to a
+new environment.
+
+"Author" refers to any designer, engineer, programmer, technical
+writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Font Software, to use, study, copy, merge, embed, modify,
+redistribute, and sell modified and unmodified copies of the Font
+Software, subject to the following conditions:
+
+1) Neither the Font Software nor any of its individual components,
+in Original or Modified Versions, may be sold by itself.
+
+2) Original or Modified Versions of the Font Software may be bundled,
+redistributed and/or sold with any software, provided that each copy
+contains the above copyright notice and this license. These can be
+included either as stand-alone text files, human-readable headers or
+in the appropriate machine-readable metadata fields within text or
+binary files as long as those fields can be easily viewed by the user.
+
+3) No Modified Version of the Font Software may use the Reserved Font
+Name(s) unless explicit written permission is granted by the corresponding
+Copyright Holder. This restriction only applies to the primary font name as
+presented to the users.
+
+4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
+Software shall not be used to promote, endorse or advertise any
+Modified Version, except to acknowledge the contribution(s) of the
+Copyright Holder(s) and the Author(s) or with their explicit written
+permission.
+
+5) The Font Software, modified or unmodified, in part or in whole,
+must be distributed entirely under this license, and must not be
+distributed under any other license. The requirement for fonts to
+remain under this license does not apply to any document created
+using the Font Software.
+
+TERMINATION
+This license becomes null and void if any of the above conditions are
+not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
+OTHER DEALINGS IN THE FONT SOFTWARE.