Search in sources :

Example 1 with RenderInfo

use of de.johni0702.minecraft.gui.RenderInfo in project jGui by ReplayMod.

the class AbstractGuiDropdownMenu method draw.

@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
    super.draw(renderer, size, renderInfo);
    TextRenderer fontRenderer = MCVer.getFontRenderer();
    if (renderInfo.layer == 0) {
        int width = size.getWidth();
        int height = size.getHeight();
        // Draw box
        renderer.drawRect(0, 0, width, height, OUTLINE_COLOR);
        renderer.drawRect(1, 1, width - 2, height - 2, ReadableColor.BLACK);
        renderer.drawRect(width - height, 0, 1, height, OUTLINE_COLOR);
        // Draw triangle
        int base = height - 6;
        int tHeight = base / 2;
        int x = width - 3 - base / 2;
        int y = height / 2 - 2;
        for (int layer = tHeight; layer > 0; layer--) {
            renderer.drawRect(x - layer, y + (tHeight - layer), layer * 2 - 1, 1, OUTLINE_COLOR);
        }
        renderer.drawString(3, height / 2 - fontRenderer.fontHeight / 2, ReadableColor.WHITE, toString.apply(getSelectedValue()));
    } else if (renderInfo.layer == 1) {
        ReadablePoint offsetPoint = new Point(0, size.getHeight());
        ReadableDimension offsetSize = new Dimension(size.getWidth(), (fontRenderer.fontHeight + 5) * values.length);
        OffsetGuiRenderer offsetRenderer = new OffsetGuiRenderer(renderer, offsetPoint, offsetSize);
        offsetRenderer.startUsing();
        try {
            dropdown.draw(offsetRenderer, offsetSize, renderInfo.offsetMouse(0, offsetPoint.getY()).layer(0));
        } finally {
            offsetRenderer.stopUsing();
        }
    }
}
Also used : ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) OffsetGuiRenderer(de.johni0702.minecraft.gui.OffsetGuiRenderer) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) Dimension(de.johni0702.minecraft.gui.utils.lwjgl.Dimension) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) TextRenderer(net.minecraft.client.font.TextRenderer)

Example 2 with RenderInfo

use of de.johni0702.minecraft.gui.RenderInfo in project jGui by ReplayMod.

the class AbstractGuiDropdownMenu method layout.

@Override
public void layout(ReadableDimension size, RenderInfo renderInfo) {
    super.layout(size, renderInfo);
    TextRenderer fontRenderer = MCVer.getFontRenderer();
    if (renderInfo.layer == 1) {
        ReadablePoint offsetPoint = new Point(0, size.getHeight());
        ReadableDimension offsetSize = new Dimension(size.getWidth(), (fontRenderer.fontHeight + 5) * values.length);
        dropdown.layout(offsetSize, renderInfo.offsetMouse(0, offsetPoint.getY()).layer(0));
    }
}
Also used : ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) Dimension(de.johni0702.minecraft.gui.utils.lwjgl.Dimension) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) TextRenderer(net.minecraft.client.font.TextRenderer)

Example 3 with RenderInfo

use of de.johni0702.minecraft.gui.RenderInfo 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);
            }
        }
    }
}
Also used : ReadableColor(de.johni0702.minecraft.gui.utils.lwjgl.ReadableColor) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) TextRenderer(net.minecraft.client.font.TextRenderer)

Example 4 with RenderInfo

use of de.johni0702.minecraft.gui.RenderInfo in project jGui by ReplayMod.

the class AbstractGuiTimeline method draw.

@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
    this.size = size;
    super.draw(renderer, size, renderInfo);
    int width = size.getWidth();
    int height = size.getHeight();
    renderer.bindTexture(TEXTURE);
    // We have to increase the border size as there is one pixel row which is part of the border while drawing
    // but isn't during position calculations due to shadows
    Utils.drawDynamicRect(renderer, width, height, TEXTURE_X, TEXTURE_Y, TEXTURE_WIDTH, TEXTURE_HEIGHT, BORDER_TOP + 1, BORDER_BOTTOM, BORDER_LEFT + 1, BORDER_RIGHT);
    if (drawMarkers) {
        drawMarkers(renderer, size);
    }
    drawTimelineCursor(renderer, size);
}
Also used : Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)

Example 5 with RenderInfo

use of de.johni0702.minecraft.gui.RenderInfo in project jGui by ReplayMod.

the class AbstractGuiContainer method draw.

@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
    super.draw(renderer, size, renderInfo);
    if (backgroundColor != null && renderInfo.getLayer() == 0) {
        renderer.drawRect(0, 0, size.getWidth(), size.getHeight(), backgroundColor);
    }
    for (final Map.Entry<GuiElement, Pair<ReadablePoint, ReadableDimension>> e : layedOutElements.entrySet()) {
        GuiElement element = e.getKey();
        boolean strict;
        if (element instanceof ComposedGuiElement) {
            if (((ComposedGuiElement) element).getMaxLayer() < renderInfo.layer) {
                continue;
            }
            strict = renderInfo.layer == 0;
        } else {
            if (element.getLayer() != renderInfo.layer) {
                continue;
            }
            strict = true;
        }
        final ReadablePoint ePosition = e.getValue().getLeft();
        final ReadableDimension eSize = e.getValue().getRight();
        try {
            OffsetGuiRenderer eRenderer = new OffsetGuiRenderer(renderer, ePosition, eSize, strict);
            eRenderer.startUsing();
            e.getKey().draw(eRenderer, eSize, renderInfo.offsetMouse(ePosition.getX(), ePosition.getY()).layer(renderInfo.getLayer() - e.getKey().getLayer()));
            eRenderer.stopUsing();
        } catch (Exception ex) {
            CrashReport crashReport = CrashReport.create(ex, "Rendering Gui");
            renderInfo.addTo(crashReport);
            CrashReportSection category = crashReport.addElement("Gui container details");
            MCVer.addDetail(category, "Container", this::toString);
            MCVer.addDetail(category, "Width", () -> "" + size.getWidth());
            MCVer.addDetail(category, "Height", () -> "" + size.getHeight());
            MCVer.addDetail(category, "Layout", layout::toString);
            category = crashReport.addElement("Gui element details");
            MCVer.addDetail(category, "Element", () -> e.getKey().toString());
            MCVer.addDetail(category, "Position", ePosition::toString);
            MCVer.addDetail(category, "Size", eSize::toString);
            if (e.getKey() instanceof GuiContainer) {
                MCVer.addDetail(category, "Layout", () -> ((GuiContainer) e.getKey()).getLayout().toString());
            }
            throw new CrashException(crashReport);
        }
    }
}
Also used : CrashException(net.minecraft.util.crash.CrashException) CrashReport(net.minecraft.util.crash.CrashReport) CrashReportSection(net.minecraft.util.crash.CrashReportSection) AbstractComposedGuiElement(de.johni0702.minecraft.gui.element.AbstractComposedGuiElement) ComposedGuiElement(de.johni0702.minecraft.gui.element.ComposedGuiElement) CrashException(net.minecraft.util.crash.CrashException) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) OffsetGuiRenderer(de.johni0702.minecraft.gui.OffsetGuiRenderer) AbstractComposedGuiElement(de.johni0702.minecraft.gui.element.AbstractComposedGuiElement) GuiElement(de.johni0702.minecraft.gui.element.GuiElement) ComposedGuiElement(de.johni0702.minecraft.gui.element.ComposedGuiElement) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

ReadablePoint (de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)19 Point (de.johni0702.minecraft.gui.utils.lwjgl.Point)16 ReadableDimension (de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension)15 Dimension (de.johni0702.minecraft.gui.utils.lwjgl.Dimension)9 OffsetGuiRenderer (de.johni0702.minecraft.gui.OffsetGuiRenderer)7 GuiElement (de.johni0702.minecraft.gui.element.GuiElement)5 TextRenderer (net.minecraft.client.font.TextRenderer)5 CrashException (net.minecraft.util.crash.CrashException)4 CrashReport (net.minecraft.util.crash.CrashReport)4 CrashReportSection (net.minecraft.util.crash.CrashReportSection)4 RenderInfo (de.johni0702.minecraft.gui.RenderInfo)3 ReadableColor (de.johni0702.minecraft.gui.utils.lwjgl.ReadableColor)3 WritablePoint (de.johni0702.minecraft.gui.utils.lwjgl.WritablePoint)3 GuiRenderer (de.johni0702.minecraft.gui.GuiRenderer)2 AbstractComposedGuiElement (de.johni0702.minecraft.gui.element.AbstractComposedGuiElement)2 ComposedGuiElement (de.johni0702.minecraft.gui.element.ComposedGuiElement)2 Pair (org.apache.commons.lang3.tuple.Pair)2 GuiContainer (de.johni0702.minecraft.gui.container.GuiContainer)1 GuiButton (de.johni0702.minecraft.gui.element.GuiButton)1 GuiDropdownMenu (de.johni0702.minecraft.gui.element.advanced.GuiDropdownMenu)1