aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/renderer
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-08-24 22:51:58 +0200
committerGitHub <noreply@github.com>2022-08-24 22:51:58 +0200
commitdaed9569a0f1d2231c4f824f6cffd72d5f8ae8bd (patch)
tree6efee702c616d96e40a3e69ce89425f0936a7598 /src/main/java/cc/polyfrost/oneconfig/renderer
parenta76b49be6dbeb0be3f88870e33d3e10e0e7f8e1c (diff)
downloadOneConfig-daed9569a0f1d2231c4f824f6cffd72d5f8ae8bd.tar.gz
OneConfig-daed9569a0f1d2231c4f824f6cffd72d5f8ae8bd.tar.bz2
OneConfig-daed9569a0f1d2231c4f824f6cffd72d5f8ae8bd.zip
Notifs (#111)
* Start on notifications * Finish notifications (pog) * oop * internalizing * misc: set default duration to 4000ms * Scaling notifs stuff Co-authored-by: Wyvest <45589059+Wyvest@users.noreply.github.com>
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/renderer')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/renderer/Icon.java88
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java142
2 files changed, 201 insertions, 29 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/Icon.java b/src/main/java/cc/polyfrost/oneconfig/renderer/Icon.java
new file mode 100644
index 0000000..a256b57
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/renderer/Icon.java
@@ -0,0 +1,88 @@
+/*
+ * This file is part of OneConfig.
+ * OneConfig - Next Generation Config Library for Minecraft: Java Edition
+ * Copyright (C) 2021, 2022 Polyfrost.
+ * <https://polyfrost.cc> <https://github.com/Polyfrost/>
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * OneConfig is licensed under the terms of version 3 of the GNU Lesser
+ * General Public License as published by the Free Software Foundation, AND
+ * under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
+ * either version 1.0 of the Additional Terms, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License. If not, see <https://www.gnu.org/licenses/>. You should
+ * have also received a copy of the Additional Terms Applicable
+ * to OneConfig, as published by Polyfrost. If not, see
+ * <https://polyfrost.cc/legal/oneconfig/additional-terms>
+ */
+
+package cc.polyfrost.oneconfig.renderer;
+
+import com.google.gson.annotations.SerializedName;
+
+public class Icon {
+ private final Object icon;
+ public final Type type;
+
+ public Icon(String filePath) {
+ this.icon = filePath;
+ this.type = filePath.endsWith(".svg") ? Type.SVG : Type.IMAGE;
+ }
+
+ public Icon(SVG svg) {
+ this.icon = svg;
+ this.type = Type.SVG;
+ }
+
+ public Icon(Image image) {
+ this.icon = image;
+ this.type = Type.IMAGE;
+ }
+
+ public SVG getSVG() {
+ return (SVG) icon;
+ }
+
+ public Image getImage() {
+ return (Image) icon;
+ }
+
+ public void draw(long vg, float x, float y, float width, float height, int color, float scale) {
+ if (type == Type.SVG) {
+ RenderManager.drawSvg(vg, getSVG(), x, y, width, height, color, scale);
+ } else if (type == Type.IMAGE) {
+ RenderManager.drawImage(vg, getImage(), x, y, width, height, color);
+ }
+ }
+
+ public void draw(long vg, float x, float y, float width, float height, int color) {
+ if (type == Type.SVG) {
+ RenderManager.drawSvg(vg, getSVG(), x, y, width, height, color);
+ } else if (type == Type.IMAGE) {
+ RenderManager.drawImage(vg, getImage(), x, y, width, height, color);
+ }
+ }
+
+ public void draw(long vg, float x, float y, float width, float height) {
+ if (type == Type.SVG) {
+ RenderManager.drawSvg(vg, getSVG(), x, y, width, height);
+ } else if (type == Type.IMAGE) {
+ RenderManager.drawImage(vg, getImage(), x, y, width, height);
+ }
+ }
+
+ public enum Type {
+ @SerializedName("0")
+ SVG,
+ @SerializedName("1")
+ IMAGE
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
index cfdb4ad..4d54621 100644
--- a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
+++ b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java
@@ -42,6 +42,7 @@ import org.lwjgl.nanovg.NVGColor;
import org.lwjgl.nanovg.NVGPaint;
import org.lwjgl.opengl.GL11;
+import java.util.Arrays;
import java.util.function.LongConsumer;
import java.util.regex.Pattern;
@@ -320,17 +321,27 @@ public final class RenderManager {
* @param size The size.
* @param font The font.
*/
- public static void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, Font font) {
+ public static void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, float lineHeight, Font font) {
nvgBeginPath(vg);
nvgFontSize(vg, size);
nvgFontFace(vg, font.getName());
- nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
+ nvgTextLineHeight(vg, lineHeight);
+ nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP); // Align top because center is weird with wrapping
NVGColor nvgColor = color(vg, color);
nvgTextBox(vg, x, y, width, text);
nvgFill(vg);
nvgColor.free();
}
+ public static float getWrappedStringHeight(long vg, String text, float width, float fontSize, float lineHeight, Font font) {
+ float[] bounds = new float[4];
+ nvgFontSize(vg, fontSize);
+ nvgFontFace(vg, font.getName());
+ nvgTextLineHeight(vg, lineHeight);
+ nvgTextBoxBounds(vg, 0, 0, width, text, bounds);
+ return bounds[3] - bounds[1];
+ }
+
/**
* Draw a formatted URL (a string in blue with an underline) that when clicked, opens the given text.
*
@@ -567,6 +578,26 @@ public final class RenderManager {
}
/**
+ * Translate to a location
+ *
+ * @param vg The NanoVG context
+ * @param x The x scale
+ * @param y The y scale
+ */
+ public static void translate(long vg, float x, float y) {
+ nvgTranslate(vg, x, y);
+ }
+
+ /**
+ * Reset all transforms
+ *
+ * @param vg The NanoVG context
+ */
+ public static void resetTransform(long vg) {
+ nvgResetTransform(vg);
+ }
+
+ /**
* Sets the global alpha value to render with.
*
* @param vg The NanoVG context.
@@ -577,7 +608,7 @@ public final class RenderManager {
}
/**
- * Draws a SVG with the provided file path and parameters.
+ * Draws an SVG with the provided file path and parameters.
*
* @param vg The NanoVG context.
* @param filePath The file path.
@@ -585,11 +616,12 @@ public final class RenderManager {
* @param y The y position.
* @param width The width.
* @param height The height.
+ * @param scale The scale
*/
- public static void drawSvg(long vg, String filePath, float x, float y, float width, float height) {
- float w = width;
- float h = height;
- if (OneConfigGui.INSTANCE != null) {
+ public static void drawSvg(long vg, String filePath, float x, float y, float width, float height, float scale) {
+ float w = width * scale;
+ float h = height * scale;
+ if (OneConfigGui.INSTANCE != null && OneConfigGui.isOpen()) {
w *= OneConfigGui.INSTANCE.getScaleFactor();
h *= OneConfigGui.INSTANCE.getScaleFactor();
}
@@ -606,7 +638,7 @@ public final class RenderManager {
}
/**
- * Draws a SVG with the provided file path and parameters.
+ * Draws an SVG with the provided file path and parameters.
*
* @param vg The NanoVG context.
* @param filePath The file path.
@@ -614,15 +646,30 @@ public final class RenderManager {
* @param y The y position.
* @param width The width.
* @param height The height.
- * @param color The color.
*/
- public static void drawSvg(long vg, String filePath, float x, float y, float width, float height, int color) {
- float w = width;
- float h = height;
- if (OneConfigGui.INSTANCE != null) {
- w *= OneConfigGui.INSTANCE.getScaleFactor();
- h *= OneConfigGui.INSTANCE.getScaleFactor();
+ public static void drawSvg(long vg, String filePath, float x, float y, float width, float height) {
+ float scale = 1;
+ if (OneConfigGui.isOpen()) {
+ scale = OneConfigGui.getScaleFactor();
}
+ drawSvg(vg, filePath, x, y, width, height, scale);
+ }
+
+ /**
+ * Draws an SVG with the provided file path and parameters.
+ *
+ * @param vg The NanoVG context.
+ * @param filePath The file path.
+ * @param x The x position.
+ * @param y The y position.
+ * @param width The width.
+ * @param height The height.
+ * @param color The color.
+ * @param scale The scale
+ */
+ public static void drawSvg(long vg, String filePath, float x, float y, float width, float height, int color, float scale) {
+ float w = width * scale;
+ float h = height * scale;
if (AssetLoader.INSTANCE.loadSVG(vg, filePath, w, h)) {
NVGPaint imagePaint = NVGPaint.calloc();
int image = AssetLoader.INSTANCE.getSVG(filePath, w, h);
@@ -639,15 +686,30 @@ public final class RenderManager {
/**
* Draws an SVG with the provided file path and parameters.
*
- * @see RenderManager#drawSvg(long, String, float, float, float, float)
+ * @param vg The NanoVG context.
+ * @param filePath The file path.
+ * @param x The x position.
+ * @param y The y position.
+ * @param width The width.
+ * @param height The height.
+ * @param color The color.
*/
- public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height) {
- float w = width;
- float h = height;
- if (OneConfigGui.INSTANCE != null) {
- w *= OneConfigGui.INSTANCE.getScaleFactor();
- h *= OneConfigGui.INSTANCE.getScaleFactor();
+ public static void drawSvg(long vg, String filePath, float x, float y, float width, float height, int color) {
+ float scale = 1;
+ if (OneConfigGui.isOpen()) {
+ scale = OneConfigGui.getScaleFactor();
}
+ drawSvg(vg, filePath, x, y, width, height, color, scale);
+ }
+
+ /**
+ * Draws an SVG with the provided file path and parameters.
+ *
+ * @see RenderManager#drawSvg(long, String, float, float, float, float)
+ */
+ public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height, float scale) {
+ float w = width * scale;
+ float h = height * scale;
if (AssetLoader.INSTANCE.loadSVG(vg, svg, w, h)) {
drawSvg(vg, svg.filePath, x, y, width, height);
}
@@ -656,21 +718,43 @@ public final class RenderManager {
/**
* Draws an SVG with the provided file path and parameters.
*
- * @see RenderManager#drawSvg(long, String, float, float, float, float, int)
+ * @see RenderManager#drawSvg(long, String, float, float, float, float)
*/
- public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height, int color) {
- float w = width;
- float h = height;
- if (OneConfigGui.INSTANCE != null) {
- w *= OneConfigGui.INSTANCE.getScaleFactor();
- h *= OneConfigGui.INSTANCE.getScaleFactor();
+ public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height) {
+ float scale = 1;
+ if (OneConfigGui.isOpen()) {
+ scale = OneConfigGui.getScaleFactor();
}
+ drawSvg(vg, svg, x, y, width, height, scale);
+ }
+
+ /**
+ * Draws an SVG with the provided file path and parameters.
+ *
+ * @see RenderManager#drawSvg(long, String, float, float, float, float, int)
+ */
+ public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height, int color, float scale) {
+ float w = width * scale;
+ float h = height * scale;
if (AssetLoader.INSTANCE.loadSVG(vg, svg, w, h)) {
drawSvg(vg, svg.filePath, x, y, width, height, color);
}
}
/**
+ * Draws an SVG with the provided file path and parameters.
+ *
+ * @see RenderManager#drawSvg(long, String, float, float, float, float)
+ */
+ public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height, int color) {
+ float scale = 1;
+ if (OneConfigGui.isOpen()) {
+ scale = OneConfigGui.getScaleFactor();
+ }
+ drawSvg(vg, svg, x, y, width, height, color, scale);
+ }
+
+ /**
* Draw a circle with an info icon inside of it
*
* @param vg The NanoVG context.