use of de.johni0702.minecraft.gui.utils.lwjgl.ReadableColor 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 de.johni0702.minecraft.gui.utils.lwjgl.ReadableColor in project jGui by ReplayMod.
the class AbstractGuiTextField method draw.
@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
this.size = size;
updateCurrentOffset();
super.draw(renderer, size, renderInfo);
int width = size.getWidth(), height = size.getHeight();
TextRenderer fontRenderer = MCVer.getFontRenderer();
int posY = height / 2 - fontRenderer.fontHeight / 2;
// Draw black rect once pixel smaller than gray rect
renderer.drawRect(0, 0, width, height, isFocused() ? ReadableColor.WHITE : BORDER_COLOR);
renderer.drawRect(1, 1, width - 2, height - 2, ReadableColor.BLACK);
if (text.isEmpty() && !isFocused() && !Strings.isNullOrEmpty(hint)) {
// Draw hint
String text = fontRenderer.trimToWidth(hint, width - 2 * BORDER);
renderer.drawString(BORDER, posY, textColorDisabled, text);
} else {
// Draw text
String renderText = text.substring(currentOffset);
renderText = fontRenderer.trimToWidth(renderText, width - 2 * BORDER);
ReadableColor color = isEnabled() ? textColorEnabled : textColorDisabled;
int lineEnd = renderer.drawString(BORDER, height / 2 - fontRenderer.fontHeight / 2, color, renderText);
// Draw selection
int from = getSelectionFrom();
int to = getSelectionTo();
String leftStr = renderText.substring(0, clamp(from - currentOffset, 0, renderText.length()));
String rightStr = renderText.substring(clamp(to - currentOffset, 0, renderText.length()));
int left = BORDER + fontRenderer.getWidth(leftStr);
int right = lineEnd - fontRenderer.getWidth(rightStr) - 1;
renderer.invertColors(right, height - 2, left, 2);
// Draw cursor
if (blinkCursorTick / 6 % 2 == 0 && focused) {
String beforeCursor = renderText.substring(0, cursorPos - currentOffset);
int posX = BORDER + fontRenderer.getWidth(beforeCursor);
if (cursorPos == text.length()) {
renderer.drawString(posX, posY, CURSOR_COLOR, "_", true);
} else {
renderer.drawRect(posX, posY - 1, 1, 1 + fontRenderer.fontHeight, CURSOR_COLOR);
}
}
}
}
use of de.johni0702.minecraft.gui.utils.lwjgl.ReadableColor in project jGui by ReplayMod.
the class AbstractGuiTimeline method drawMarker.
protected void drawMarker(GuiRenderer renderer, ReadableDimension size, int time, boolean big) {
int visibleLength = (int) (length * zoom);
double positionInVisible = time - offset;
double fractionOfVisible = positionInVisible / visibleLength;
int positionX = (int) (BORDER_LEFT + fractionOfVisible * (size.getWidth() - BORDER_LEFT - BORDER_RIGHT));
int height = size.getHeight() / (big ? 3 : 6);
ReadableColor color = big ? Colors.LIGHT_GRAY : Colors.WHITE;
renderer.drawRect(positionX, size.getHeight() - BORDER_BOTTOM - height, 1, height, color);
}
Aggregations