aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltip.java
blob: 7492f17d2a16bca0f760f3ac6f7b8464e0ad45ca (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 *     Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
 *     Copyright (C) 2021  cyoung06
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Affero General Public License as published
 *     by the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Affero General Public License for more details.
 *
 *     You should have received a copy of the GNU Affero General Public License
 *     along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package kr.syeyoung.dungeonsguide.gui.elements;

import kr.syeyoung.dungeonsguide.gui.MPanel;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import org.lwjgl.opengl.GL11;

import java.awt.*;

public class MTooltip extends MPanel {
    @Getter @Setter
    private MRootPanel root;

    public void open(MPanel component) {
        component.openTooltip(this);
    }
    public void close() {
        if (root != null)
        root.removeTooltip(this);
    }


    public boolean isOpen() {
        return root != null;
    }

    @Override
    public int getTooltipsOpen() {
        return super.getTooltipsOpen() - 1;
    }

    public void render0(double scale, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { // 0,0 - a a
        int relMousex = relMousex0 - getBounds().x;
        int relMousey = relMousey0 - getBounds().y;

        GlStateManager.translate(getBounds().x, getBounds().y, 300);
        GlStateManager.color(1,1,1,0);


        Rectangle clip = getBounds().getBounds();
        GlStateManager.pushAttrib();
        GL11.glEnable(GL11.GL_SCISSOR_TEST);
        this.scale = scale;
        clip(clip.x, clip.y, clip.width, clip.height);

        GlStateManager.pushAttrib();
        GuiScreen.drawRect(0,0, getBounds().width, getBounds().height,  backgroundColor.getRGB());
        GlStateManager.enableBlend();
        GlStateManager.popAttrib();

        GlStateManager.pushMatrix();
        GlStateManager.pushAttrib();
        render(absMousex, absMousey, relMousex, relMousey, partialTicks, clip);
        GlStateManager.popAttrib();
        GlStateManager.popMatrix();

        GL11.glDisable(GL11.GL_SCISSOR_TEST);
        GlStateManager.popAttrib();


        Point newPt = new Point(parentPoint.x + getBounds().x, parentPoint.y + getBounds().y);

        for (MPanel mPanel : getChildComponents()){
            GlStateManager.pushMatrix();
            GlStateManager.pushAttrib();
            mPanel.render0(scale, newPt, clip, absMousex, absMousey, relMousex, relMousey, partialTicks);
            GlStateManager.popAttrib();
            GlStateManager.popMatrix();
        }
    }
}