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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
package kr.syeyoung.dungeonsguide.roomedit;
import lombok.AccessLevel;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import org.lwjgl.opengl.GL11;
import org.w3c.dom.css.Rect;
import java.awt.*;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
@Getter
public class MPanel {
protected Rectangle bounds = new Rectangle(0,0,0,0); // relative to parent
protected List<MPanel> childComponents = new ArrayList<MPanel>();
protected Color backgroundColor = new Color(0,0,0,0);
@Getter(AccessLevel.PUBLIC)
protected boolean isFocused;
public void setBackgroundColor(Color c) {
if (c == null) return;
this.backgroundColor = c;
}
public void setPosition(Point pt) {
this.bounds.x = pt.x;
this.bounds.y = pt.y;
}
public void setSize(Dimension dim) {
this.bounds.width = dim.width;
this.bounds.height = dim.height;
}
public Dimension getSize() {
return bounds.getSize();
}
public void setBounds(Rectangle bounds) {
if (bounds == null) return;
this.bounds.x = bounds.x;
this.bounds.y = bounds.y;
this.bounds.width = bounds.width;
this.bounds.height = bounds.height;
}
public void add(MPanel child) {
this.childComponents.add(child);
}
public void remove(MPanel panel) {
this.childComponents.remove(panel);
}
public void render0(ScaledResolution resolution, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { // 0,0 - a a
int relMousex = relMousex0 - bounds.x;
int relMousey = relMousey0 - bounds.y;
GL11.glPushAttrib(GL11.GL_SCISSOR_BIT);
GL11.glTranslated(bounds.x, bounds.y, 0);
Rectangle absBound = bounds.getBounds(); // 0,0 - a a
absBound.setLocation(absBound.x + parentPoint.x, absBound.y + parentPoint.y);
Rectangle clip = determineClip(parentClip, absBound);
GlStateManager.enableBlend();
GlStateManager.disableTexture2D();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
clip(resolution, clip.x, clip.y, clip.width, clip.height);
GL11.glEnable(GL11.GL_SCISSOR_TEST);
if (backgroundColor != null)
GL11.glColor4ub((byte)backgroundColor.getRed(), (byte)backgroundColor.getGreen() , (byte)backgroundColor.getBlue() , (byte)backgroundColor.getAlpha() );
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3i(0, 0,0);
GL11.glVertex3i(0, bounds.height,0);
GL11.glVertex3i(bounds.width, bounds.height,0);
GL11.glVertex3i(bounds.width, 0,0);
GL11.glEnd();
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
GL11.glPushMatrix();
render(absMousex, absMousey, relMousex, relMousey, partialTicks);
GL11.glPopMatrix();
GL11.glDisable(GL11.GL_SCISSOR_TEST);
GL11.glPopAttrib();
Point newPt = new Point(parentPoint.x + bounds.x, parentPoint.y + bounds.y);
for (MPanel mPanel : childComponents){
GL11.glPushMatrix();
mPanel.render0(resolution, newPt, clip, absMousex, absMousey, relMousex, relMousey, partialTicks);
GL11.glPopMatrix();
}
}
public void clip(ScaledResolution resolution, int x, int y, int width, int height) {
int scale = resolution.getScaleFactor();
GL11.glScissor((x ) * scale, Minecraft.getMinecraft().displayHeight - (y + height) * scale, (width) * scale, height * scale);
}
private Rectangle determineClip(Rectangle rect1, Rectangle rect2) {
int minX = Math.max(rect1.x, rect2.x);
int minY = Math.max(rect1.y, rect2.y);
int maxX = Math.min(rect1.x + rect1.width, rect2.x + rect2.width);
int maxY = Math.min(rect1.y + rect1.height, rect2.y +rect2.height);
if (minX > maxX) return new Rectangle(0,0,0,0);
if (minY > maxY) return new Rectangle(0,0,0,0);
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
}
public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) {}
protected void keyTyped0(char typedChar, int keyCode) {
for (MPanel childComponent : childComponents) {
childComponent.keyTyped0(typedChar, keyCode);
}
if (isFocused)
keyTyped(typedChar, keyCode);
}
protected void keyTyped(char typedChar, int keyCode) {}
protected boolean mouseClicked0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int mouseButton) {
int relMousex = relMouseX0 - bounds.x;
int relMousey = relMouseY0 - bounds.y;
boolean noClip = true;
boolean focusedOverall = false;
for (MPanel childComponent : childComponents) {
if (childComponent.mouseClicked0(absMouseX, absMouseY, relMouseX0, relMouseY0, mouseButton)) {
noClip = false;
focusedOverall = true;
}
}
if (bounds.contains(relMousex, relMousey) && noClip) {
isFocused = true;
focusedOverall = true;
}
mouseClicked(absMouseX, absMouseY, relMousex, relMousey, mouseButton);
return focusedOverall;
}
protected void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {}
protected void mouseReleased0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int state) {
int relMousex = relMouseX0 - bounds.x;
int relMousey = relMouseY0 - bounds.y;
for (MPanel childComponent : childComponents) {
childComponent.mouseReleased0(absMouseX, absMouseY, relMousex, relMousey, state);
}
mouseReleased(absMouseX, absMouseY, relMousex, relMousey, state);
}
protected void mouseReleased(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int state) {}
protected void mouseClickMove0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int clickedMouseButton, long timeSinceLastClick) {
int relMousex = relMouseX0 - bounds.x;
int relMousey = relMouseY0 - bounds.y;
for (MPanel childComponent : childComponents) {
childComponent.mouseClickMove0(absMouseX, absMouseY, relMousex, relMousey, clickedMouseButton, timeSinceLastClick);
}
mouseClickMove(absMouseX, absMouseY, relMousex, relMousey, clickedMouseButton, timeSinceLastClick);
}
protected void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) {}
protected void mouseScrolled0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) {
int relMousex = relMouseX0 - bounds.x;
int relMousey = relMouseY0 - bounds.y;
for (MPanel childComponent : childComponents) {
childComponent.mouseScrolled0(absMouseX, absMouseY, relMousex, relMousey, scrollAmount);
}
mouseScrolled(absMouseX, absMouseY, relMousex, relMousey, scrollAmount);
}
protected void mouseScrolled(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) {}
}
|