aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/OneConfig.java1
-rw-r--r--src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java68
-rw-r--r--src/main/java/io/polyfrost/oneconfig/renderer/shaders/ShaderHelper.java4
3 files changed, 64 insertions, 9 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/OneConfig.java b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
index 7596ab5..9d6ed49 100644
--- a/src/main/java/io/polyfrost/oneconfig/OneConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
@@ -1,6 +1,7 @@
package io.polyfrost.oneconfig;
import io.polyfrost.oneconfig.command.OneConfigCommand;
+import io.polyfrost.oneconfig.renderer.Renderer;
import io.polyfrost.oneconfig.test.TestConfig;
import io.polyfrost.oneconfig.themes.Themes;
import net.minecraft.client.Minecraft;
diff --git a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
index 313a1d0..235371f 100644
--- a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
+++ b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
@@ -4,9 +4,13 @@ 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.*;
@@ -14,6 +18,9 @@ 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 Tessellator tessellator = Tessellator.getInstance();
+ private static WorldRenderer worldRenderer = tessellator.getWorldRenderer();
+
public static void drawRectangle(int left, int top, int right, int bottom, int color) {
Gui.drawRect(left, top, right, bottom, color);
@@ -33,8 +40,54 @@ public class Renderer extends Gui {
Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, targetX, targetY, targetX, targetY, targetX, targetY);
}
- public static void drawRoundRectangle(int left, int top, int right, int bottom, int cornerRadius, int color) {
+ public static void drawRegularPolygon(double x, double y, int radius, int sides, int color, double lowerAngle, double upperAngle) {
+ float f3 = (float) (color >> 24 & 255) / 255.0F;
+ float f = (float) (color >> 16 & 255) / 255.0F;
+ float f1 = (float) (color >> 8 & 255) / 255.0F;
+ float f2 = (float) (color & 255) / 255.0F;
+
+ GL11.glDisable(GL11.GL_TEXTURE_2D);
+ GlStateManager.color(f, f1, f2, f3);
+ 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.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
+
+ 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, 10d);
+ }
+ /**
+ * 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(double x, double y, double width, double height, int radius, int color) {
+ GL11.glEnable(GL11.GL_BLEND);
+ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
+ Gui.drawRect((int) x + radius, (int) y, (int) (x + width - radius), (int) (y + radius), color); // top
+ Gui.drawRect((int) x + radius, (int) (y + height - radius), (int) (x + width - radius), (int) (y + height), color); // bottom
+ Gui.drawRect((int) x, (int) y + radius, (int) (x + width), (int) (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);
}
public static float clamp(float number) {
@@ -49,11 +102,16 @@ public class Renderer extends Gui {
}
}
+ /**
+ * 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;
+ 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);
}
diff --git a/src/main/java/io/polyfrost/oneconfig/renderer/shaders/ShaderHelper.java b/src/main/java/io/polyfrost/oneconfig/renderer/shaders/ShaderHelper.java
deleted file mode 100644
index 892719e..0000000
--- a/src/main/java/io/polyfrost/oneconfig/renderer/shaders/ShaderHelper.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package io.polyfrost.oneconfig.renderer.shaders;
-
-public class ShaderHelper {
-}