aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/lwjgl
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-03 17:38:50 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-05-03 17:38:50 +0200
commitb798930b21b89b81be05a31281f768667a6dd7f3 (patch)
tree8611e7a51f65910da99b22034f078c23b13f8546 /src/main/java/io/polyfrost/oneconfig/lwjgl
parente5ef86b9b3fd0f5e687416acc667f368444e4459 (diff)
downloadOneConfig-b798930b21b89b81be05a31281f768667a6dd7f3.tar.gz
OneConfig-b798930b21b89b81be05a31281f768667a6dd7f3.tar.bz2
OneConfig-b798930b21b89b81be05a31281f768667a6dd7f3.zip
multiple scissors system
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/lwjgl')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/Scissor.java22
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/ScissorManager.java40
2 files changed, 62 insertions, 0 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/Scissor.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/Scissor.java
new file mode 100644
index 0000000..dcd570a
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/Scissor.java
@@ -0,0 +1,22 @@
+package io.polyfrost.oneconfig.lwjgl;
+
+public class Scissor {
+ public int x;
+ public int y;
+ public int width;
+ public int height;
+
+ public Scissor(int x, int y, int width, int height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+
+ public Scissor(Scissor scissor) {
+ this.x = scissor.x;
+ this.y = scissor.y;
+ this.width = scissor.width;
+ this.height = scissor.height;
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/ScissorManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/ScissorManager.java
new file mode 100644
index 0000000..46d84b6
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/ScissorManager.java
@@ -0,0 +1,40 @@
+package io.polyfrost.oneconfig.lwjgl;
+
+import org.lwjgl.nanovg.NanoVG;
+
+import java.util.ArrayList;
+
+public class ScissorManager {
+ private static final ArrayList<Scissor> scissors = new ArrayList<>();
+
+ public static Scissor scissor(long vg, int x, int y, int width, int height) {
+ Scissor scissor = new Scissor(x, y, width, height);
+ if (scissors.contains(scissor)) return scissor;
+ scissors.add(scissor);
+ applyScissors(vg);
+ return scissor;
+ }
+
+ public static void resetScissor(long vg, Scissor scissor) {
+ if (scissors.contains(scissor)) {
+ scissors.remove(scissor);
+ applyScissors(vg);
+ }
+ }
+
+ private static void applyScissors(long vg) {
+ NanoVG.nvgResetScissor(vg);
+ if (scissors.size() <= 0) return;
+ Scissor finalScissor = new Scissor(scissors.get(0));
+ for (int i = 1; i < scissors.size(); i++) {
+ Scissor scissor = scissors.get(i);
+ int rightX = Math.min(scissor.x + scissor.width, finalScissor.x + finalScissor.width);
+ int rightY = Math.min(scissor.y + scissor.height, finalScissor.y + finalScissor.height);
+ finalScissor.x = Math.max(finalScissor.x, scissor.x);
+ finalScissor.y = Math.max(finalScissor.y, scissor.y);
+ finalScissor.width = rightX - finalScissor.x;
+ finalScissor.height = rightY - finalScissor.y;
+ }
+ NanoVG.nvgScissor(vg, finalScissor.x, finalScissor.y, finalScissor.width, finalScissor.height);
+ }
+}