use of net.minecraft.client.font.TextRenderer in project jGui by ReplayMod.
the class AbstractGuiTextArea method draw.
@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
this.size = size;
updateCurrentOffset();
super.draw(renderer, size, renderInfo);
TextRenderer fontRenderer = MCVer.getFontRenderer();
int width = size.getWidth();
int height = size.getHeight();
// Draw black rect once pixel smaller than gray rect
renderer.drawRect(0, 0, width, height, BACKGROUND_COLOR);
renderer.drawRect(1, 1, width - 2, height - 2, ReadableColor.BLACK);
ReadableColor textColor = isEnabled() ? textColorEnabled : textColorDisabled;
int lineHeight = fontRenderer.fontHeight + LINE_SPACING;
int contentHeight = height - BORDER * 2;
int maxLines = contentHeight / lineHeight;
int contentWidth = width - BORDER * 2;
// Draw hint if applicable
if (hint != null && !isFocused() && Arrays.stream(text).allMatch(String::isEmpty)) {
for (int i = 0; i < maxLines && i < hint.length; i++) {
String line = fontRenderer.trimToWidth(hint[i], contentWidth);
int posY = BORDER + i * lineHeight;
renderer.drawString(BORDER, posY, textColorDisabled, line, true);
}
return;
}
// Draw lines
for (int i = 0; i < maxLines && i + currentYOffset < text.length; i++) {
int lineY = i + currentYOffset;
String line = text[lineY];
int leftTrimmed = 0;
if (lineY == cursorY) {
line = line.substring(currentXOffset);
leftTrimmed = currentXOffset;
}
line = fontRenderer.trimToWidth(line, contentWidth);
// Draw line
int posY = BORDER + i * lineHeight;
int lineEnd = renderer.drawString(BORDER, posY, textColor, line, true);
// Draw selection
int fromX = getSelectionFromX();
int fromY = getSelectionFromY();
int toX = getSelectionToX();
int toY = getSelectionToY();
if (lineY > fromY && lineY < toY) {
// Whole line selected
renderer.invertColors(lineEnd, posY - 1 + lineHeight, BORDER, posY - 1);
} else if (lineY == fromY && lineY == toY) {
// Part of line selected
String leftStr = line.substring(0, clamp(fromX - leftTrimmed, 0, line.length()));
String rightStr = line.substring(clamp(toX - leftTrimmed, 0, line.length()));
int left = BORDER + fontRenderer.getWidth(leftStr);
int right = lineEnd - fontRenderer.getWidth(rightStr) - 1;
renderer.invertColors(right, posY - 1 + lineHeight, left, posY - 1);
} else if (lineY == fromY) {
// End of line selected
String rightStr = line.substring(clamp(fromX - leftTrimmed, 0, line.length()));
renderer.invertColors(lineEnd, posY - 1 + lineHeight, lineEnd - fontRenderer.getWidth(rightStr), posY - 1);
} else if (lineY == toY) {
// Beginning of line selected
String leftStr = line.substring(0, clamp(toX - leftTrimmed, 0, line.length()));
int right = BORDER + fontRenderer.getWidth(leftStr);
renderer.invertColors(right, posY - 1 + lineHeight, BORDER, posY - 1);
}
// Draw cursor
if (lineY == cursorY && blinkCursorTick / 6 % 2 == 0 && focused) {
String beforeCursor = line.substring(0, cursorX - leftTrimmed);
int posX = BORDER + fontRenderer.getWidth(beforeCursor);
if (cursorX == text[lineY].length()) {
renderer.drawString(posX, posY, CURSOR_COLOR, "_", true);
} else {
renderer.drawRect(posX, posY - 1, 1, 1 + fontRenderer.fontHeight, CURSOR_COLOR);
}
}
}
}
use of net.minecraft.client.font.TextRenderer in project jGui by ReplayMod.
the class AbstractGuiTextField method mouseClick.
@Override
public boolean mouseClick(ReadablePoint position, int button) {
if (getContainer() != null) {
getContainer().convertFor(this, (Point) (position = new Point(position)));
}
boolean hovering = isMouseHovering(position);
if (hovering && isFocused() && button == 0) {
updateCurrentOffset();
int mouseX = position.getX() - BORDER;
TextRenderer fontRenderer = MCVer.getFontRenderer();
String text = this.text.substring(currentOffset);
int textX = fontRenderer.trimToWidth(text, mouseX).length() + currentOffset;
setCursorPosition(textX);
return true;
}
setFocused(hovering);
// Do not yet return true to allow focusables later in the event chain to be notified of the focus change
return false;
}
use of net.minecraft.client.font.TextRenderer in project jGui by ReplayMod.
the class AbstractGuiTooltip method draw.
@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
super.draw(renderer, size, renderInfo);
int width = size.getWidth();
int height = size.getHeight();
// Draw background
// Top to bottom
renderer.drawRect(1, 0, width - 2, height, BACKGROUND_COLOR);
// Left pixel row
renderer.drawRect(0, 1, 1, height - 2, BACKGROUND_COLOR);
// Right pixel row
renderer.drawRect(width - 1, 1, 1, height - 2, BACKGROUND_COLOR);
// Draw the border, it gets darker from top to bottom
// Top border
renderer.drawRect(1, 1, width - 2, 1, BORDER_LIGHT);
// Bottom border
renderer.drawRect(1, height - 2, width - 2, 1, BORDER_DARK);
// Left border
renderer.drawRect(1, 2, 1, height - 4, BORDER_LIGHT, BORDER_LIGHT, BORDER_DARK, BORDER_DARK);
// Right border
renderer.drawRect(width - 2, 2, 1, height - 4, BORDER_LIGHT, BORDER_LIGHT, BORDER_DARK, BORDER_DARK);
TextRenderer fontRenderer = MCVer.getFontRenderer();
int y = LINE_SPACING + 1;
for (String line : text) {
renderer.drawString(LINE_SPACING + 1, y, color, line, true);
y += fontRenderer.fontHeight + LINE_SPACING;
}
}
use of net.minecraft.client.font.TextRenderer in project jGui by ReplayMod.
the class AbstractGuiTooltip method calcMinSize.
@Override
public ReadableDimension calcMinSize() {
TextRenderer fontRenderer = MCVer.getFontRenderer();
int height = 1 + LINE_SPACING + text.length * (fontRenderer.fontHeight + LINE_SPACING);
int width = 0;
for (String line : text) {
int w = fontRenderer.getWidth(line);
if (w > width) {
width = w;
}
}
width += 4 * 2;
return new Dimension(width, height);
}
use of net.minecraft.client.font.TextRenderer in project jGui by ReplayMod.
the class AbstractGuiCheckbox method calcMinSize.
@Override
public ReadableDimension calcMinSize() {
TextRenderer fontRenderer = MCVer.getFontRenderer();
int height = fontRenderer.fontHeight + 2;
int width = height + 2 + fontRenderer.getWidth(label);
return new Dimension(width, height);
}
Aggregations