aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java
blob: 1eaf8dd3f3ee45ae3696a4e17af6f07e8933d9b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package cc.polyfrost.oneconfig.gui.pages;

import cc.polyfrost.oneconfig.utils.MathUtils;
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 scrollTarget;

    protected final String title;

    Page(String title) {
        this.title = title;
    }

    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();
        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);


    }

    public String getTitle() {
        return title;
    }

    public void keyTyped(char key, int keyCode) {
    }

    /**
     * Overwrite this method and make it return true if you want this to always be the base in breadcrumbs
     */
    public boolean isBase() {
        return false;
    }

    /** Use this method to set the maximum scroll height of the page. */
    public int getMaxScrollHeight() {
        return 728;
    }
}