aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
index 1eaf8dd..e8d48fe 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
@@ -1,5 +1,7 @@
package cc.polyfrost.oneconfig.gui.pages;
+import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor;
+import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager;
import cc.polyfrost.oneconfig.utils.MathUtils;
import org.lwjgl.input.Mouse;
@@ -7,7 +9,7 @@ import org.lwjgl.input.Mouse;
* A page is a 1056x728 rectangle of the GUI. It is the main content of the gui, and can be switched back and forwards easily. All the content of OneConfig is in a page.
*/
public abstract class Page {
- private float currentScrollf = 0f;
+ private float currentScroll = 0f;
private float scrollTarget;
protected final String title;
@@ -18,8 +20,11 @@ public abstract class Page {
public abstract void draw(long vg, int x, int y);
- /** Use this method to draw elements that are static on the page (ignore the scrolling).
- * @return the total height of the elements, so they are excluded from the scissor rectangle. */
+ /**
+ * Use this method to draw elements that are static on the page (ignore the scrolling).
+ *
+ * @return the total height of the elements, so they are excluded from the scissor rectangle.
+ */
public int drawStatic(long vg, int x, int y) {
return 0;
}
@@ -28,20 +33,23 @@ public abstract class Page {
}
public void scrollWithDraw(long vg, int x, int y) {
- int currentScroll = (int) (currentScrollf * 100);
- draw(vg, x, y + currentScroll);
- int dWheel = Mouse.getDWheel();
- if(dWheel > 120) dWheel = 120;
- if(!(Math.abs((scrollTarget * 100) - 728) >= getMaxScrollHeight() && dWheel < 0)) {
- scrollTarget += dWheel / 120f;
- }
- if(scrollTarget > 0f) { // fyi this is anti overscroll protection
- scrollTarget = 0;
+ int maxScroll = getMaxScrollHeight();
+ int scissorOffset = drawStatic(vg, x, y);
+ Scissor scissor = ScissorManager.scissor(vg, x, y + scissorOffset, x + 1056, y + 728 - scissorOffset);
+ if (maxScroll <= 728) {
+ draw(vg, x, y);
+ ScissorManager.resetScissor(vg, scissor);
+ return;
}
+ draw(vg, x, (int) (y + currentScroll));
+ int dWheel = Mouse.getDWheel();
+ scrollTarget += dWheel;
- currentScrollf = MathUtils.easeOut(currentScrollf, scrollTarget, 20f);
-
+ if (scrollTarget > 0f) scrollTarget = 0f;
+ else if (scrollTarget < -maxScroll + 728) scrollTarget = -maxScroll + 728;
+ currentScroll = MathUtils.easeOut(currentScroll, scrollTarget, 10f);
+ ScissorManager.resetScissor(vg, scissor);
}
public String getTitle() {
@@ -58,7 +66,9 @@ public abstract class Page {
return false;
}
- /** Use this method to set the maximum scroll height of the page. */
+ /**
+ * Use this method to set the maximum scroll height of the page.
+ */
public int getMaxScrollHeight() {
return 728;
}