aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/lwjgl/image
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-03 18:25:32 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-03 18:25:32 +0200
commita0ff501947a84b268e099524a06b56a6b900dad2 (patch)
treedb27ca1b28dbc7e57b8c99f54c80732d3042e856 /src/main/java/cc/polyfrost/oneconfig/lwjgl/image
parentb798930b21b89b81be05a31281f768667a6dd7f3 (diff)
downloadOneConfig-a0ff501947a84b268e099524a06b56a6b900dad2.tar.gz
OneConfig-a0ff501947a84b268e099524a06b56a6b900dad2.tar.bz2
OneConfig-a0ff501947a84b268e099524a06b56a6b900dad2.zip
move to cc.polyfrost
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/lwjgl/image')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Image.java21
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/lwjgl/image/ImageLoader.java45
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java47
3 files changed, 113 insertions, 0 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Image.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Image.java
new file mode 100644
index 0000000..2e63154
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Image.java
@@ -0,0 +1,21 @@
+package cc.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/cc/polyfrost/oneconfig/lwjgl/image/ImageLoader.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/ImageLoader.java
new file mode 100644
index 0000000..8e72828
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/ImageLoader.java
@@ -0,0 +1,45 @@
+package cc.polyfrost.oneconfig.lwjgl.image;
+
+import cc.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 void removeImage(String fileName) {
+ imageHashMap.remove(fileName);
+ }
+
+ public Image getImage(String fileName) {
+ return imageHashMap.get(fileName);
+ }
+
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java
new file mode 100644
index 0000000..f5e4213
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java
@@ -0,0 +1,47 @@
+package cc.polyfrost.oneconfig.lwjgl.image;
+
+public enum Images {
+ CHEVRON_ARROW("/assets/oneconfig/textures/gui/general/arrows/chevron.png"),
+ DROPDOWN_ARROW("/assets/oneconfig/textures/gui/general/arrows/dropdown_arrow.png"),
+ UP_ARROW("/assets/oneconfig/textures/gui/general/arrows/up_arrow.png"),
+ CIRCLE_ARROW("/assets/oneconfig/textures/gui/general/arrows/circle_arrow.png"),
+
+ CHECKMARK("/assets/oneconfig/textures/gui/general/configs/checkmark.png"),
+ FAVORITE("/assets/oneconfig/textures/gui/general/configs/favorite_active.png"),
+ FAVORITE_OFF("/assets/oneconfig/textures/gui/general/configs/favorite_inactive.png"),
+ HIDE_EYE("/assets/oneconfig/textures/gui/general/configs/hide_eye.png"),
+ HIDE_EYE_OFF("/assets/oneconfig/textures/gui/general/configs/hide_eye_off.png"),
+
+ // TODO color picker ones
+ COLOR_BASE("/assets/oneconfig/textures/gui/general/color/color_base.png"),
+
+
+ SHARE("/assets/oneconfig/textures/gui/general/nav/share.png"),
+ LAUNCH("/assets/oneconfig/textures/gui/general/nav/launch.png"),
+ SEARCH("/assets/oneconfig/textures/gui/general/nav/search.png"),
+ MINIMIZE("/assets/oneconfig/textures/gui/general/nav/minimize.png"),
+ CLOSE("/assets/oneconfig/textures/gui/general/nav/close.png"),
+
+ LOGO("/assets/oneconfig/textures/gui/general/logo.png"),
+
+ HUD("/assets/oneconfig/textures/gui/icons/hud/hud.png"),
+ HUD_SETTINGS("/assets/oneconfig/textures/gui/icons/hud/settings.png"),
+
+ MOD_BOX("/assets/oneconfig/textures/gui/icons/mod/mod_box.png"),
+ MODS("/assets/oneconfig/textures/gui/icons/mod/mods.png"),
+ PERFORMANCE("/assets/oneconfig/textures/gui/icons/mod/performance.png"),
+
+ DASHBOARD("/assets/oneconfig/textures/gui/icons/dashboard.png"),
+ PREFERENCES("/assets/oneconfig/textures/gui/icons/preferences.png"),
+ PROFILES("/assets/oneconfig/textures/gui/icons/profiles.png"),
+ SCREENSHOT("/assets/oneconfig/textures/gui/icons/screenshot.png"),
+ THEMES("/assets/oneconfig/textures/gui/icons/themes.png"),
+ UPDATES("/assets/oneconfig/textures/gui/icons/updates.png"),
+ ;
+
+ public final String filePath;
+
+ Images(String filePath) {
+ this.filePath = filePath;
+ }
+}