aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
diff options
context:
space:
mode:
authorsyeyoung <cyong06@naver.com>2021-02-04 21:55:02 +0900
committersyeyoung <cyong06@naver.com>2021-02-04 21:55:02 +0900
commitc37bda238c5072fa50dfa2d87aa137e1bdf5c4ac (patch)
tree5a276b3db53c9275cb0da74cf8aed0cfa0e79491 /src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
parent809f6b70870ec2a0fd4e4abfd24539e30d8db11b (diff)
downloadSkyblock-Dungeons-Guide-c37bda238c5072fa50dfa2d87aa137e1bdf5c4ac.tar.gz
Skyblock-Dungeons-Guide-c37bda238c5072fa50dfa2d87aa137e1bdf5c4ac.tar.bz2
Skyblock-Dungeons-Guide-c37bda238c5072fa50dfa2d87aa137e1bdf5c4ac.zip
move guis
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java')
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java206
1 files changed, 206 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
new file mode 100755
index 00000000..4eae2298
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
@@ -0,0 +1,206 @@
+package kr.syeyoung.dungeonsguide.gui;
+
+import lombok.AccessLevel;
+import lombok.Getter;
+import net.minecraft.client.Minecraft;
+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.*;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+@Getter
+public class MPanel {
+ protected Rectangle bounds = new Rectangle(0,0,0,0); // relative to parent
+
+ protected List<MPanel> childComponents = new CopyOnWriteArrayList<MPanel>();
+
+ protected Color backgroundColor = new Color(0,0,0,0);
+
+ protected Rectangle lastAbsClip = new Rectangle(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.setBounds(new Rectangle(pt.x, pt.y, getBounds().width, getBounds().height));
+ }
+
+ public void setSize(Dimension dim) {
+ this.setBounds(new Rectangle(getBounds().x, getBounds().y, dim.width, dim.height));
+ }
+
+ public Dimension getSize() {
+ return getBounds().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;
+
+ for (MPanel childComponent : childComponents) {
+ childComponent.resize0(getBounds().width, getBounds().height);
+ }
+ onBoundsUpdate();
+ }
+
+ public void onBoundsUpdate() {
+
+ }
+
+ 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 - getBounds().x;
+ int relMousey = relMousey0 - getBounds().y;
+
+ GlStateManager.translate(getBounds().x, getBounds().y, 0);
+ GlStateManager.color(1,1,1,0);
+
+
+ Rectangle absBound = getBounds().getBounds();
+ absBound.setLocation(absBound.x + parentPoint.x, absBound.y + parentPoint.y);
+ Rectangle clip = determineClip(parentClip, absBound);
+ lastAbsClip = clip;
+
+ clip(resolution, clip.x, clip.y, clip.width, clip.height);
+ GlStateManager.pushAttrib();
+ GL11.glEnable(GL11.GL_SCISSOR_TEST);
+
+ GlStateManager.pushAttrib();
+ GuiScreen.drawRect(0,0, getBounds().width, getBounds().height, backgroundColor.getRGB());
+ GlStateManager.popAttrib();
+
+ GlStateManager.pushMatrix();
+ GlStateManager.pushAttrib();
+ render(absMousex, absMousey, relMousex, relMousey, partialTicks, clip);
+ GlStateManager.popAttrib();
+ GlStateManager.popMatrix();
+
+ GL11.glDisable(GL11.GL_SCISSOR_TEST);
+ GL11.glPopAttrib();
+
+
+ Point newPt = new Point(parentPoint.x + getBounds().x, parentPoint.y + getBounds().y);
+
+ for (MPanel mPanel : getChildComponents()){
+ GlStateManager.pushMatrix();
+ GlStateManager.pushAttrib();
+ mPanel.render0(resolution, newPt, clip, absMousex, absMousey, relMousex, relMousey, partialTicks);
+ GlStateManager.popAttrib();
+ GlStateManager.popMatrix();
+ }
+ }
+
+ 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, Rectangle scissor) {}
+
+ public void resize0(int parentWidth, int parentHeight) {
+ resize(parentWidth, parentHeight);
+ }
+
+ public void resize(int parentWidth, int parentHeight) {}
+
+
+ public void keyTyped0(char typedChar, int keyCode) {
+ for (MPanel childComponent : getChildComponents()) {
+ childComponent.keyTyped0(typedChar, keyCode);
+ }
+
+ if (isFocused)
+ keyTyped(typedChar, keyCode);
+ }
+ public void keyTyped(char typedChar, int keyCode) {}
+
+ public boolean mouseClicked0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int mouseButton) {
+ int relMousex = relMouseX0 - getBounds().x;
+ int relMousey = relMouseY0 - getBounds().y;
+
+ boolean noClip = true;
+ boolean focusedOverall = false;
+ for (MPanel childComponent : getChildComponents()) {
+ if (childComponent.mouseClicked0(absMouseX, absMouseY, relMousex, relMousey, mouseButton)) {
+ noClip = false;
+ focusedOverall = true;
+ }
+ }
+
+ if (getBounds().contains(relMouseX0, relMouseY0) && noClip) {
+ isFocused = true;
+ focusedOverall = true;
+ } else {
+ isFocused = false;
+ }
+
+ mouseClicked(absMouseX, absMouseY, relMousex, relMousey, mouseButton);
+ return focusedOverall;
+ }
+
+ public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {}
+
+ public void mouseReleased0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int state) {
+ int relMousex = relMouseX0 - getBounds().x;
+ int relMousey = relMouseY0 - getBounds().y;
+
+ for (MPanel childComponent : getChildComponents()) {
+ childComponent.mouseReleased0(absMouseX, absMouseY, relMousex, relMousey, state);
+ }
+ mouseReleased(absMouseX, absMouseY, relMousex, relMousey, state);
+ }
+ public void mouseReleased(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int state) {}
+
+ public void mouseClickMove0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int clickedMouseButton, long timeSinceLastClick) {
+ int relMousex = relMouseX0 - getBounds().x;
+ int relMousey = relMouseY0 - getBounds().y;
+
+ for (MPanel childComponent : getChildComponents()) {
+ childComponent.mouseClickMove0(absMouseX, absMouseY, relMousex, relMousey, clickedMouseButton, timeSinceLastClick);
+ }
+ mouseClickMove(absMouseX, absMouseY, relMousex, relMousey, clickedMouseButton, timeSinceLastClick);
+ }
+ public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) {}
+
+ public void mouseScrolled0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) {
+ int relMousex = relMouseX0 - getBounds().x;
+ int relMousey = relMouseY0 - getBounds().y;
+
+ for (MPanel childComponent : getChildComponents()) {
+ childComponent.mouseScrolled0(absMouseX, absMouseY, relMousex, relMousey, scrollAmount);
+ }
+ mouseScrolled(absMouseX, absMouseY, relMousex, relMousey, scrollAmount);
+ }
+ public void mouseScrolled(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) {}
+}