diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-06 16:49:24 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-06 16:49:24 +0200 |
commit | 3c7d6a1a4d49ef40969bef2cb67825862c41407c (patch) | |
tree | ac25bfc89e8e853142c64222676f32b6c19dff90 /src/main/java/cc/polyfrost/oneconfig/gui/pages | |
parent | 5c7f1f9e2613b0ca5efac351e2c5e15c9deb0069 (diff) | |
download | OneConfig-3c7d6a1a4d49ef40969bef2cb67825862c41407c.tar.gz OneConfig-3c7d6a1a4d49ef40969bef2cb67825862c41407c.tar.bz2 OneConfig-3c7d6a1a4d49ef40969bef2cb67825862c41407c.zip |
fix scrolling
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/pages')
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java | 10 | ||||
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java | 40 |
2 files changed, 31 insertions, 19 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java index dde6a2b..acd01a1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -1,20 +1,21 @@ package cc.polyfrost.oneconfig.gui.pages; -import cc.polyfrost.oneconfig.OneConfig; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.data.OptionPage; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; import cc.polyfrost.oneconfig.gui.elements.BasicButton; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton; import cc.polyfrost.oneconfig.lwjgl.RenderManager; +import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import java.util.ArrayList; +import java.util.HashMap; public class ModConfigPage extends Page { private final OptionPage page; private final ArrayList<BasicButton> categories = new ArrayList<>(); private String selectedCategory; + private int totalSize = 724; public ModConfigPage(OptionPage page) { super(page.name); @@ -95,6 +96,7 @@ public class ModConfigPage extends Page { page.draw(vg, optionX, optionY); optionY += page.getHeight() + 16; } + totalSize = optionY - y; // Draw last options if (page.categories.get(selectedCategory).subcategories.keySet().size() > 0) { @@ -116,12 +118,12 @@ public class ModConfigPage extends Page { } } } - RenderManager.drawRoundedRect(vg, x, y + 1500, 500, 100, OneConfigConfig.WHITE_90, 16); } @Override public int drawStatic(long vg, int x, int y) { // Category buttons + if(categories.size() <= 1) return 0; int buttonX = x + 16; for (BasicButton button : categories) { if (button.getWidth() == 0) @@ -158,6 +160,6 @@ public class ModConfigPage extends Page { @Override public int getMaxScrollHeight() { - return 1600; + return totalSize; } } 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; } |