use of buildcraft.lib.client.guide.node.FormatString in project BuildCraft by BuildCraft.
the class GuidePart method renderLine.
/**
* @param current The current location of the rendering. This will be different from start if this line needed to
* render over 2 (or more!) pages
* @param line The line to render
* @param x The x position the page rendering started from
* @param y The y position the page rendering started from
* @param width The width of rendering space available
* @param height The height of rendering space available
* @return The position for the next line to render at. Will automatically be the next page or line if necessary.
*/
protected PagePosition renderLine(PagePosition current, PageLine line, int x, int y, int width, int height, int pageRenderIndex) {
wasHovered = false;
wasIconHovered = false;
// Firstly break off the last chunk if the total length is greater than the width allows
int allowedWidth = width - INDENT_WIDTH * line.indent;
if (allowedWidth <= 0) {
throw new IllegalStateException("Was indented too far");
}
String toRender = line.text;
ISimpleDrawable icon = line.startIcon;
FormatString next = FormatString.split(line.text);
int neededSpace = fontRenderer.getFontHeight(line.text);
if (icon != null) {
neededSpace = Math.max(16, neededSpace);
}
current = current.guaranteeSpace(neededSpace, height);
int _x = x + INDENT_WIDTH * line.indent;
if (icon != null && current.page == pageRenderIndex) {
int iconX = _x - 18;
int iconY = y + current.pixel - 5;
GuiRectangle rect = new GuiRectangle(iconX, iconY, 16, 16);
if (rect.contains(gui.mouse) && line.startIconHovered != null) {
icon = line.startIconHovered;
}
icon.drawAt(iconX, iconY);
}
while (next != null) {
FormatString[] strings = next.wrap(fontRenderer, allowedWidth);
String text = strings[0].getFormatted();
boolean render = current.page == pageRenderIndex;
int _y = y + current.pixel;
int _w = fontRenderer.getStringWidth(text);
GuiRectangle rect = new GuiRectangle(_x, _y, _w, neededSpace);
wasHovered |= rect.contains(gui.mouse);
if (render) {
if (wasHovered && line.link) {
Gui.drawRect(_x - 2, _y - 2, _x + _w + 2, _y - 2 + neededSpace, 0xFFD3AD6C);
}
fontRenderer.drawString(text, _x, _y, 0);
}
next = strings.length == 1 ? null : strings[1];
current = current.nextLine(fontRenderer.getFontHeight(text) + 3, height);
}
int additional = LINE_HEIGHT - fontRenderer.getFontHeight(toRender) - 3;
current = current.nextLine(additional, height);
return current;
}
Aggregations