mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-22 05:02:25 +00:00
75 lines
1.5 KiB
Java
75 lines
1.5 KiB
Java
package crazypants.render;
|
|
|
|
import java.awt.Rectangle;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class GuiToolTip {
|
|
|
|
private static final long DELAY = 500;
|
|
|
|
protected Rectangle bounds;
|
|
|
|
private long mouseOverStart;
|
|
|
|
protected final List<String> text;
|
|
|
|
private int lastMouseX = -1;
|
|
|
|
private int lastMouseY = -1;
|
|
|
|
public GuiToolTip(Rectangle bounds, String... lines) {
|
|
this.bounds = bounds;
|
|
if (lines != null) {
|
|
text = new ArrayList<String>(lines.length);
|
|
for (String line : lines) {
|
|
text.add(line);
|
|
}
|
|
} else {
|
|
text = new ArrayList<String>();
|
|
}
|
|
}
|
|
|
|
public GuiToolTip(Rectangle bounds, List<String> lines) {
|
|
this.bounds = bounds;
|
|
if (lines == null) {
|
|
text = new ArrayList<String>();
|
|
} else {
|
|
text = new ArrayList<String>(lines);
|
|
}
|
|
}
|
|
|
|
public void onTick(int mouseX, int mouseY) {
|
|
if (lastMouseX != mouseX || lastMouseY != mouseY) {
|
|
mouseOverStart = 0;
|
|
}
|
|
|
|
if (bounds.contains(mouseX, mouseY)) {
|
|
if (mouseOverStart == 0) {
|
|
mouseOverStart = System.currentTimeMillis();
|
|
}
|
|
} else {
|
|
mouseOverStart = 0;
|
|
}
|
|
|
|
lastMouseX = mouseX;
|
|
lastMouseY = mouseY;
|
|
}
|
|
|
|
public boolean shouldDraw() {
|
|
updateText();
|
|
if (mouseOverStart == 0) {
|
|
return false;
|
|
}
|
|
return System.currentTimeMillis() - mouseOverStart >= DELAY;
|
|
}
|
|
|
|
protected void updateText() {
|
|
}
|
|
|
|
public List<String> getToolTipText() {
|
|
return text;
|
|
}
|
|
|
|
}
|