diff options
author | syeyoung <cyong06@naver.com> | 2021-07-25 20:37:22 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2021-07-25 20:37:22 +0900 |
commit | a6b8e47c879ce5a1c69d0552cdb26a3b3e95e4b6 (patch) | |
tree | 2eab5dc84e6dcaf426ef100d7dfd0a2f0dd93771 /src/main/java/kr/syeyoung/dungeonsguide/gui | |
parent | a7b6db18ec1471ba604df91652741a04bc436fa2 (diff) | |
download | Skyblock-Dungeons-Guide-a6b8e47c879ce5a1c69d0552cdb26a3b3e95e4b6.tar.gz Skyblock-Dungeons-Guide-a6b8e47c879ce5a1c69d0552cdb26a3b3e95e4b6.tar.bz2 Skyblock-Dungeons-Guide-a6b8e47c879ce5a1c69d0552cdb26a3b3e95e4b6.zip |
new config.
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/gui')
11 files changed, 429 insertions, 30 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java index feef2848..c5428c14 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java @@ -61,7 +61,7 @@ public class MGui extends GuiScreen { GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); GlStateManager.color(1, 1, 1, 1); GlStateManager.scale(1.0/scaledResolution.getScaleFactor(), 1.0/scaledResolution.getScaleFactor(), 1.0d); - mainPanel.render0(scaledResolution, new Point(0,0), new Rectangle(0,0,Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight), i, j, i, j, partialTicks); + mainPanel.render0(1, new Point(0,0), new Rectangle(0,0,Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight), i, j, i, j, partialTicks); GlStateManager.popAttrib(); GlStateManager.popMatrix(); GlStateManager.enableBlend(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java index a91cb6c6..0f842b34 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java @@ -23,8 +23,8 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; import org.lwjgl.opengl.GL11; @@ -49,6 +49,8 @@ public class MPanel { @Setter protected MPanel parent; + private boolean debug = false; + public void setBackgroundColor(Color c) { if (c == null) return; this.backgroundColor = c; @@ -109,7 +111,7 @@ public class MPanel { @Setter private boolean ignoreBoundOnClip; - public void render0(ScaledResolution resolution, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { // 0,0 - a a + public void render0(double scale, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { // 0,0 - a a lastParentPoint = parentPoint; int relMousex = relMousex0 - getBounds().x; @@ -127,7 +129,8 @@ public class MPanel { lastAbsClip = clip; if (clip.getSize().height * clip.getSize().width == 0) return; - clip(resolution, clip.x, clip.y, clip.width, clip.height); + this.scale = scale; + clip(clip.x, clip.y, clip.width, clip.height); GlStateManager.pushAttrib(); GL11.glEnable(GL11.GL_SCISSOR_TEST); @@ -147,28 +150,30 @@ public class MPanel { render(absMousex, absMousey, relMousex, relMousey, partialTicks, clip); GlStateManager.popAttrib(); GlStateManager.popMatrix(); + if (debug && lastAbsClip.contains(absMousex, absMousey)) { + Gui.drawRect(0, 0, getBounds().width, getBounds().height, 0x2200FF00); + GL11.glDisable(GL11.GL_SCISSOR_TEST); +// Gui.drawRect(0, 0, getPreferredSize().width, getPreferredSize().height, 0x220000FF); + } 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(resolution, newPt, clip, absMousex, absMousey, relMousex, relMousey, partialTicks); + mPanel.render0(scale, newPt, clip, absMousex, absMousey, relMousex, relMousey, partialTicks); GlStateManager.popAttrib(); GlStateManager.popMatrix(); } } - - public static void clip(ScaledResolution resolution, int x, int y, int width, int height) { + protected double scale; + public void clip(int x, int y, int width, int height) { if (width < 0 || height < 0) return; -// int scale = resolution.getScaleFactor(); - int scale = 1; - GL11.glScissor((x ) * scale, Minecraft.getMinecraft().displayHeight - (y + height) * scale, (width) * scale, height * scale); + GL11.glScissor((int) (x * scale), Minecraft.getMinecraft().displayHeight - (int) ((y + height) * scale), (int)(width* scale), (int) (height * scale)); } protected Rectangle determineClip(Rectangle rect1, Rectangle rect2) { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MCollapsable.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MCollapsable.java new file mode 100644 index 00000000..ef10377e --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MCollapsable.java @@ -0,0 +1,131 @@ +/* + * 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.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL11; + +import java.awt.*; + +/** + * Note it is passive. + */ +public class MCollapsable extends MPanel { + @Getter + @Setter + private boolean collapsed = true; + + private MPanel representing; + @Getter + private MList lowerElements; + + @Getter @Setter + private int leftPad = 0, leftPadElements = 13; + + private Runnable onPreferedSizeChange; + + public MCollapsable(MPanel representing, Runnable onPreferedSizeChange) { + this.representing = representing; + super.add(representing); + lowerElements = new MList(); + lowerElements.setGap(0); + super.add(lowerElements); + + this.onPreferedSizeChange = onPreferedSizeChange; + } + + @Override + public Dimension getPreferredSize() { + Dimension rep = representing.getPreferredSize(); + if (collapsed) { + return new Dimension(rep.width+leftPad+10, rep.height); + } else { + Dimension lowerElem = lowerElements.getPreferredSize(); + return new Dimension(Math.max(rep.width+leftPad+10, leftPadElements + lowerElem.width), rep.height+lowerElem.height+lowerElements.getGap()); + } + } + + @Override + public void setBounds(Rectangle bounds) { + super.setBounds(bounds); + Dimension representingSize =this.representing.getPreferredSize(); + Dimension lowerSize = lowerElements.getPreferredSize(); + + representing.setBounds(new Rectangle(new Point(leftPad+10, 0), new Dimension(bounds.width - (leftPad+10), representingSize.height))); + lowerElements.setBounds(new Rectangle(new Point(leftPadElements, representingSize.height+lowerElements.getGap()), new Dimension(bounds.width - (leftPadElements), lowerSize.height))); + lowerElements.realignChildren(); + } + + @Override + public void render0(double scale, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { + super.render0(scale, parentPoint, parentClip, absMousex, absMousey, relMousex0, relMousey0, partialTicks); + + clip(lastAbsClip.x, lastAbsClip.y, lastAbsClip.width, lastAbsClip.height); +// GL11.glEnable(GL11.GL_SCISSOR_TEST); + + + GlStateManager.pushMatrix(); + GlStateManager.pushAttrib(); + + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.enableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + if (collapsed) { + GlStateManager.translate(leftPad + 10 - fr.getStringWidth(">"),(bounds.height - fr.FONT_HEIGHT)/2,0); + } else { + GlStateManager.translate(leftPad + fr.FONT_HEIGHT,(representing.getPreferredSize().height - fr.getStringWidth(">"))/2,0); + GlStateManager.rotate(90, 0,0,1); + } + + fr.drawString(">", 0,0, -1); + + GlStateManager.popAttrib(); + GlStateManager.popMatrix(); + GL11.glDisable(GL11.GL_SCISSOR_TEST); + } + + @Override + public void add(MPanel child) { + lowerElements.add(child); + if (onPreferedSizeChange != null) onPreferedSizeChange.run(); + } + + @Override + public void remove(MPanel panel) { + lowerElements.remove(panel); + if (onPreferedSizeChange != null) onPreferedSizeChange.run(); + } + + @Override + public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { + if (relMouseX >= leftPad && relMouseY >= 0 && relMouseX <= leftPad + 10 && relMouseY <= representing.getPreferredSize().height) { + collapsed = !collapsed; + if (onPreferedSizeChange != null) onPreferedSizeChange.run(); + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MList.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MList.java index f6df0e19..9719f63f 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MList.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MList.java @@ -20,6 +20,7 @@ package kr.syeyoung.dungeonsguide.gui.elements; import kr.syeyoung.dungeonsguide.gui.MPanel; import lombok.Getter; +import lombok.Setter; import net.minecraft.client.gui.Gui; import java.awt.*; @@ -28,6 +29,9 @@ public class MList extends MPanel { @Getter private int gap = 5; + @Getter @Setter + private boolean drawLine = true; + public void setGap(int gap) { this.gap = gap; realignChildren(); @@ -35,19 +39,35 @@ public class MList extends MPanel { private final int gapLineColor = 0xFFFFFFFF; - protected void realignChildren() { + public void realignChildren() { int y = 0; for (MPanel childComponent : getChildComponents()) { Dimension preferedSize = childComponent.getPreferredSize(); childComponent.setBounds(new Rectangle(0, y, bounds.width, Math.max(10, preferedSize.height))); y += preferedSize.height; - y += gap; + if (gap > 0) + y += gap; } setSize(new Dimension(getSize().width, Math.max(0, y-gap))); } @Override + public Dimension getPreferredSize() { + int maxW = 0; + int h = 0; + for (MPanel childComponent : getChildComponents()) { + Dimension preferedSize = childComponent.getPreferredSize(); + if (preferedSize.width > maxW) maxW = preferedSize.width; + h += preferedSize.height; + if (gap > 0) h += gap; + } + return new Dimension(maxW, Math.max(0, h-gap)); + } + + @Override public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + if (gap <= 0) return; + if (!drawLine) return; for (int i = 1; i < getChildComponents().size(); i++) { MPanel panel = getChildComponents().get(i); Rectangle bound = panel.getBounds(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPanelScaledGUI.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPanelScaledGUI.java new file mode 100644 index 00000000..64599058 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPanelScaledGUI.java @@ -0,0 +1,199 @@ +/* + * 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.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.opengl.GL11; + +import java.awt.*; + +public class MPanelScaledGUI extends MPanel { + @Getter + private double scale = 1.0; + + private double relativeScale; + + public void setScale(double scale) { + this.scale = scale; + for (MPanel childComponent : childComponents) { + childComponent.resize0((int) (getBounds().width/scale), (int) (getBounds().height/scale)); + } + } + + @Override + 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((int) (getBounds().width/scale), (int) (getBounds().height/scale)); + } + onBoundsUpdate(); + } + + public Dimension getEffectiveDimension() { + return new Dimension((int)(getBounds().width / scale), (int)(getBounds().height / scale)); + } + + @Override + public void render0(double parentScale, Point parentPoint, Rectangle parentClip, int absMousex0, int absMousey0, int relMousex0, int relMousey0, float partialTicks) { + lastParentPoint = parentPoint; + + GlStateManager.translate(getBounds().x, getBounds().y, 5); + GlStateManager.color(1,1,1,0); + + Rectangle absBound = getBounds().getBounds(); + absBound.setLocation(absBound.x + parentPoint.x, absBound.y + parentPoint.y); + + Rectangle clip; + if (isIgnoreBoundOnClip()) clip = parentClip; + else clip = determineClip(parentClip, absBound); + lastAbsClip = clip; + + if (clip.getSize().height * clip.getSize().width == 0) return; + + int absMousex = (int) (absMousex0 / scale), absMousey = (int) (absMousey0 / scale); + int relMousex = (int) ((relMousex0 - getBounds().x) / scale); + int relMousey = (int) ((relMousey0 - getBounds().y) /scale); + + // FROM HERE, IT IS SCALED + + GlStateManager.scale(this.scale, this.scale, 1); + clip = new Rectangle((int) (clip.x / scale), (int) (clip.y / scale), (int) (clip.width / scale), (int) (clip.height / scale)); + + + this.relativeScale = parentScale * this.scale; + clip(clip.x, clip.y, clip.width, clip.height); + + + GlStateManager.pushAttrib(); + GL11.glEnable(GL11.GL_SCISSOR_TEST); + + GlStateManager.pushAttrib(); + GuiScreen.drawRect(0,0, (int) (getBounds().width / scale), (int) (getBounds().height / scale), backgroundColor.getRGB()); + GlStateManager.enableBlend(); + GlStateManager.popAttrib(); + + GlStateManager.pushMatrix(); + GlStateManager.pushAttrib(); + + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.enableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + + render(absMousex, absMousey, relMousex, relMousey, partialTicks, clip); + GlStateManager.popAttrib(); + GlStateManager.popMatrix(); + + GL11.glDisable(GL11.GL_SCISSOR_TEST); + GlStateManager.popAttrib(); + + + Point newPt = new Point((int) ((parentPoint.x + getBounds().x) / scale), (int) ((parentPoint.y + getBounds().y) / scale)); + + for (MPanel mPanel : getChildComponents()){ + GlStateManager.pushMatrix(); + GlStateManager.pushAttrib(); + mPanel.render0(scale, newPt,clip,absMousex, absMousey, relMousex, relMousey, partialTicks); + GlStateManager.popAttrib(); + GlStateManager.popMatrix(); + } + } + + @Override + public void clip(int x, int y, int width, int height) { + if (width < 0 || height < 0) return; + + GL11.glScissor((int) (x * relativeScale), Minecraft.getMinecraft().displayHeight - (int) ((y + height) * relativeScale), (int)(width* relativeScale), (int) (height * relativeScale)); + } + + @Override + public void resize0(int parentWidth, int parentHeight) { + super.resize0(parentWidth, parentHeight); + } + + + public boolean mouseClicked0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int mouseButton) { + int relMousex = (int) ((relMouseX0 - getBounds().x) / scale); + int relMousey = (int) ((relMouseY0 - getBounds().y) / scale); + absMouseX = (int) (absMouseX / scale); + absMouseY = (int) (absMouseY / scale); + + 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 mouseReleased0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int state) { + int relMousex = (int) ((relMouseX0 - getBounds().x) / scale); + int relMousey = (int) ((relMouseY0 - getBounds().y) / scale); + absMouseX = (int) (absMouseX / scale); + absMouseY = (int) (absMouseY / scale); + + for (MPanel childComponent : getChildComponents()) { + childComponent.mouseReleased0(absMouseX, absMouseY, relMousex, relMousey, state); + } + mouseReleased(absMouseX, absMouseY, relMousex, relMousey, state); + } + public void mouseClickMove0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int clickedMouseButton, long timeSinceLastClick) { + int relMousex = (int) ((relMouseX0 - getBounds().x) / scale); + int relMousey = (int) ((relMouseY0 - getBounds().y) / scale); + absMouseX = (int) (absMouseX / scale); + absMouseY = (int) (absMouseY / scale); + + for (MPanel childComponent : getChildComponents()) { + childComponent.mouseClickMove0(absMouseX, absMouseY, relMousex, relMousey, clickedMouseButton, timeSinceLastClick); + } + mouseClickMove(absMouseX, absMouseY, relMousex, relMousey, clickedMouseButton, timeSinceLastClick); + } + public void mouseScrolled0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) { + int relMousex = (int) ((relMouseX0 - getBounds().x) / scale); + int relMousey = (int) ((relMouseY0 - getBounds().y) / scale); + absMouseX = (int) (absMouseX / scale); + absMouseY = (int) (absMouseY / scale); + + for (MPanel childComponent : getChildComponents()) { + childComponent.mouseScrolled0(absMouseX, absMouseY, relMousex, relMousey, scrollAmount); + } + mouseScrolled(absMouseX, absMouseY, relMousex, relMousey, scrollAmount); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPortableColorEdit.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPortableColorEdit.java index 3ee4e516..9bd3b130 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPortableColorEdit.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPortableColorEdit.java @@ -201,7 +201,7 @@ public class MPortableColorEdit extends MPanel { } @Override - public void render0(ScaledResolution resolution, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { + public void render0(double scale, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { int relMousex = relMousex0 - getBounds().x; int relMousey = relMousey0 - getBounds().y; @@ -213,8 +213,8 @@ public class MPortableColorEdit extends MPanel { 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); +this.scale =scale; + clip(clip.x, clip.y, clip.width, clip.height); GlStateManager.pushAttrib(); GL11.glDisable(GL11.GL_SCISSOR_TEST); @@ -237,7 +237,7 @@ public class MPortableColorEdit extends MPanel { for (MPanel mPanel : getChildComponents()){ GlStateManager.pushMatrix(); GlStateManager.pushAttrib(); - mPanel.render0(resolution, newPt, new Rectangle(newPt, new Dimension(getBounds().getSize())), absMousex, absMousey, relMousex, relMousey, partialTicks); + mPanel.render0(scale, newPt, new Rectangle(newPt, new Dimension(getBounds().getSize())), absMousex, absMousey, relMousex, relMousey, partialTicks); GlStateManager.popAttrib(); GlStateManager.popMatrix(); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollBar.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollBar.java index ecd94b07..215c7c6d 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollBar.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollBar.java @@ -37,6 +37,10 @@ public class MScrollBar extends MPanel { @Getter private int current; + @Getter + @Setter + private int width = 10; + public void addToCurrent(int dv) { int current2 = current + dv; @@ -48,7 +52,7 @@ public class MScrollBar extends MPanel { @Override public Dimension getPreferredSize() { - return new Dimension(axis == Axis.X ? -1 : 20, axis == Axis.Y ? -1 : 20); + return new Dimension(axis == Axis.X ? -1 : width, axis == Axis.Y ? -1 : width); } @Getter diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollablePanel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollablePanel.java index bdbf51d0..42a3cb91 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollablePanel.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollablePanel.java @@ -40,8 +40,6 @@ public class MScrollablePanel extends MPanel { private final int axis; // 1: Y 2: X 3: both. - private Dimension totalContentArea = new Dimension(); - private MPanel viewPort; @Getter private MPanel contentArea; @@ -135,23 +133,28 @@ public class MScrollablePanel extends MPanel { @Override public void setBounds(Rectangle bounds) { super.setBounds(bounds); - boolean hideX = false, hideY = false; - if (bounds.width > contentAreaDim.width && hideScrollBarWhenNotNecessary) hideX = true; - if (bounds.height > contentAreaDim.height && hideScrollBarWhenNotNecessary) hideY = true; + boolean hideX = (axis & 2) == 0, hideY = (axis & 1) == 0; + viewPort.setBounds(new Rectangle(0,0,bounds.width, bounds.height)); + evalulateContentArea(); + if (bounds.width >= contentAreaDim.width && hideScrollBarWhenNotNecessary) hideX = true; + if (bounds.height >= contentAreaDim.height && hideScrollBarWhenNotNecessary) hideY = true; - if (axis == 3 && !(hideX || hideY)) { + if (!(hideX || hideY)) { Dimension preferedX = scrollBarX.getPreferredSize(); Dimension preferedY = scrollBarY.getPreferredSize(); scrollBarY.setBounds(new Rectangle(bounds.width - preferedY.width, 0, preferedY.width, bounds.height - preferedX.height)); scrollBarX.setBounds(new Rectangle(0, bounds.height - preferedX.height, bounds.width - preferedY.width, preferedX.height)); - } else if (axis == 2 || (axis == 3 && hideY)) { + } else if ((hideY && !hideX)) { Dimension preferedX = scrollBarX.getPreferredSize(); scrollBarY.setBounds(new Rectangle(0,0,0,0)); scrollBarX.setBounds(new Rectangle(0, bounds.height - preferedX.height, bounds.width, preferedX.height)); - } else if (axis == 1 || (axis == 3 && hideX)) { + } else if ((hideX && !hideY)) { Dimension preferedY = scrollBarY.getPreferredSize(); scrollBarX.setBounds(new Rectangle(0,0,0,0)); scrollBarY.setBounds(new Rectangle(bounds.width - preferedY.width, 0, preferedY.width, bounds.height)); + } else if (hideX && hideY){ + scrollBarY.setBounds(new Rectangle(0,0,0,0)); + scrollBarX.setBounds(new Rectangle(0,0,0,0)); } viewPort.setBounds(new Rectangle(0,0,bounds.width-scrollBarY.getBounds().width, bounds.height - scrollBarX.getBounds().height)); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MSpacer.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MSpacer.java new file mode 100644 index 00000000..11336a7c --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MSpacer.java @@ -0,0 +1,36 @@ +/* + * 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 java.awt.*; + +public class MSpacer extends MPanel { + + int width, height; + public MSpacer(int x, int y, int width, int height) { + setBounds(new Rectangle(x,y,width,height)); + this.width = width; this.height = height; + } + @Override + public Dimension getPreferredSize() { + return new Dimension(width, height); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java index a971cc30..6d8b3f51 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java @@ -68,7 +68,7 @@ public class MTextField extends MPanel { Gui.drawRect(1,1,getBounds().width - 1, getBounds().height - 1, Color.black.getRGB()); Minecraft mc = Minecraft.getMinecraft(); - clip(new ScaledResolution(mc), clip.x + 1, clip.y + 1, clip.width - 2, clip.height - 2); + clip(clip.x + 1, clip.y + 1, clip.width - 2, clip.height - 2); FontRenderer fr = mc.fontRendererObj; int y = (getBounds().height - fr.FONT_HEIGHT) / 2; GlStateManager.enableBlend(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltip.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltip.java index 561ecb0c..7492f17d 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltip.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltip.java @@ -50,7 +50,7 @@ public class MTooltip extends MPanel { return super.getTooltipsOpen() - 1; } - public void render0(ScaledResolution resolution, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { // 0,0 - a a + 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; @@ -61,7 +61,8 @@ public class MTooltip extends MPanel { Rectangle clip = getBounds().getBounds(); GlStateManager.pushAttrib(); GL11.glEnable(GL11.GL_SCISSOR_TEST); - clip(resolution, clip.x, clip.y, clip.width, clip.height); + this.scale = scale; + clip(clip.x, clip.y, clip.width, clip.height); GlStateManager.pushAttrib(); GuiScreen.drawRect(0,0, getBounds().width, getBounds().height, backgroundColor.getRGB()); @@ -83,7 +84,7 @@ public class MTooltip extends MPanel { for (MPanel mPanel : getChildComponents()){ GlStateManager.pushMatrix(); GlStateManager.pushAttrib(); - mPanel.render0(resolution, newPt, clip, absMousex, absMousey, relMousex, relMousey, partialTicks); + mPanel.render0(scale, newPt, clip, absMousex, absMousey, relMousex, relMousey, partialTicks); GlStateManager.popAttrib(); GlStateManager.popMatrix(); } |