diff options
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.java | 32 |
1 files changed, 19 insertions, 13 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 2f2fa36..1eaf8dd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -1,7 +1,5 @@ package cc.polyfrost.oneconfig.gui.pages; -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.utils.MathUtils; import org.lwjgl.input.Mouse; @@ -9,8 +7,8 @@ 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 scrollPercent = 0f; - private float yDiff, scrollAmount; + private float currentScrollf = 0f; + private float scrollTarget; protected final String title; @@ -20,22 +18,30 @@ 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. */ + public int drawStatic(long vg, int x, int y) { + return 0; + } + public void finishUpAndClose() { } public void scrollWithDraw(long vg, int x, int y) { + int currentScroll = (int) (currentScrollf * 100); + draw(vg, x, y + currentScroll); int dWheel = Mouse.getDWheel(); - scrollAmount += dWheel / 120f; - scrollPercent = MathUtils.easeOut(scrollPercent, scrollAmount, 20f); + 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; + } + + currentScrollf = MathUtils.easeOut(currentScrollf, scrollTarget, 20f); - int currentScroll = (int) yDiff + (int) (scrollPercent * 100); - if(currentScroll > 0) { - currentScroll = 0; - scrollPercent = 0; - scrollAmount = 0; - } - draw(vg, x, y + currentScroll); } public String getTitle() { |