From 15f6cc9eb567b6ef685bc6c1a6f3364270300914 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 22 Dec 2018 13:17:31 +0800 Subject: from aei but like jei now --- src/main/java/me/shedaniel/gui/widget/TextBox.java | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 src/main/java/me/shedaniel/gui/widget/TextBox.java (limited to 'src/main/java/me/shedaniel/gui/widget/TextBox.java') diff --git a/src/main/java/me/shedaniel/gui/widget/TextBox.java b/src/main/java/me/shedaniel/gui/widget/TextBox.java new file mode 100755 index 000000000..40cf9924b --- /dev/null +++ b/src/main/java/me/shedaniel/gui/widget/TextBox.java @@ -0,0 +1,71 @@ +package me.shedaniel.gui.widget; + +import me.shedaniel.gui.AEIRenderHelper; +import net.minecraft.client.gui.GuiTextField; + +import java.awt.*; + +/** + * Created by James on 8/3/2018. + */ +public class TextBox extends Control implements IFocusable { + + private GuiTextField textField; + + public TextBox(int x, int y, int width, int height) { + super(x, y, width, height); + textField = new GuiTextField(-1, AEIRenderHelper.getFontRenderer(), x, y, width, height); + this.onClick = this::doMouseClick; + this.onKeyDown = this::onKeyPressed; + this.charPressed = this::charTyped; + } + + @Override + public void draw() { + textField.drawTextField(0, 0, 0); + } + + @Override + public boolean hasFocus() { + return textField.isFocused(); + } + + @Override + public void setFocused(boolean val) { + textField.setFocused(val); + } + + protected boolean doMouseClick(int button) { + Point mouseLoc = AEIRenderHelper.getMouseLoc(); + if (!hasFocus()) + setFocused(true); + return textField.mouseClicked(mouseLoc.x, mouseLoc.y, 0); + } + + protected boolean onKeyPressed(int first, int second, int third) { + boolean handled = textField.keyPressed(first, second, third); + if (handled) { + AEIRenderHelper.updateSearch(); + } + + return handled; + } + + public String getText() { + return textField.getText(); + } + + public void setText(String value) { + textField.setText(value); + } + + protected void charTyped(char p_charTyped_1_, int p_charTyped_2_) { + textField.charTyped(p_charTyped_1_, p_charTyped_2_); + AEIRenderHelper.updateSearch(); + } + + @Override + public void tick() { + textField.tick(); + } +} -- cgit