diff options
author | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-11-23 17:38:00 +0900 |
---|---|---|
committer | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-11-23 17:38:00 +0900 |
commit | 8292e2b632d34a92f98e8dd896750b5b5ab011bd (patch) | |
tree | 5d714771d737b866e33b840c21ed004ccc9dac72 /src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements | |
parent | fdc4638c4bbd84e1429812387d0f3a2626b95ae6 (diff) | |
download | Skyblock-Dungeons-Guide-8292e2b632d34a92f98e8dd896750b5b5ab011bd.tar.gz Skyblock-Dungeons-Guide-8292e2b632d34a92f98e8dd896750b5b5ab011bd.tar.bz2 Skyblock-Dungeons-Guide-8292e2b632d34a92f98e8dd896750b5b5ab011bd.zip |
gui stuff
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements')
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MButton.java | 51 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabel.java | 31 |
2 files changed, 82 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MButton.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MButton.java new file mode 100644 index 00000000..e6c675ca --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MButton.java @@ -0,0 +1,51 @@ +package kr.syeyoung.dungeonsguide.roomedit.elements; + +import kr.syeyoung.dungeonsguide.roomedit.MPanel; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import org.lwjgl.opengl.GL11; +import org.w3c.dom.css.Rect; + +import java.awt.*; + +@Getter +@Setter +public class MButton extends MPanel { + private String text; + + private Color foreground = Color.white; + private Color hover = Color.gray; + private Color disabled = Color.darkGray; + + private boolean enabled; + + private Runnable onActionPerformed; + + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { + Dimension bounds = getSize(); + + Color bg = backgroundColor; + if (!enabled) { + bg = disabled; + } else if (new Rectangle(new Point(0,0),bounds).contains(relMousex0, relMousey0)) { + bg = hover; + } + GL11.glClearColor(bg.getRed(), bg.getGreen(), bg.getBlue(), bg.getAlpha()); + + FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj; + int width = renderer.getStringWidth(text); + int x = (bounds.width - width) / 2; + int y = (bounds.height - renderer.FONT_HEIGHT) / 2; + + renderer.drawString(text, x,y, foreground.getRGB()); + } + + @Override + protected void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { + if (onActionPerformed != null && new Rectangle(new Point(0,0),getSize()).contains(relMouseX, relMouseY)) + onActionPerformed.run(); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabel.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabel.java new file mode 100644 index 00000000..1bc0c0f7 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabel.java @@ -0,0 +1,31 @@ +package kr.syeyoung.dungeonsguide.roomedit.elements; + +import kr.syeyoung.dungeonsguide.roomedit.MPanel; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; + +import java.awt.*; + +public class MLabel extends MPanel { + @Getter + @Setter + private String text; + + @Getter + @Setter + private Color foreground = Color.white; + + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { + Dimension bounds = getSize(); + + FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj; + int width = renderer.getStringWidth(text); + int x = (bounds.width - width) / 2; + int y = (bounds.height - renderer.FONT_HEIGHT) / 2; + + renderer.drawString(text, x,y, foreground.getRGB()); + } +} |