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
|
package me.shedaniel.gui.widget;
import me.shedaniel.gui.REIRenderHelper;
import net.minecraft.client.gui.widget.TextFieldWidget;
import java.awt.*;
/**
* Created by James on 8/3/2018.
*/
public class TextBox extends Control implements IFocusable {
private TextFieldWidget textField;
public TextBox(int x, int y, int width, int height) {
super(x, y, width, height);
textField = new TextFieldWidget(-1, REIRenderHelper.getFontRenderer(), x, y, width, height);
this.onClick = this::doMouseClick;
this.onKeyDown = this::onKeyPressed;
this.charPressed = this::charTyped;
}
@Override
public void draw() {
textField.render(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 = REIRenderHelper.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) {
REIRenderHelper.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_);
REIRenderHelper.updateSearch();
}
@Override
public void tick() {
textField.tick();
}
}
|