Search in sources :

Example 1 with OffsetGuiRenderer

use of de.johni0702.minecraft.gui.OffsetGuiRenderer 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 OffsetGuiRenderer

use of de.johni0702.minecraft.gui.OffsetGuiRenderer 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)

Example 3 with OffsetGuiRenderer

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

the class AbstractGuiScreen method draw.

@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
    if (renderInfo.layer == 0) {
        switch(background) {
            case NONE:
                break;
            case DEFAULT:
                // #if MC>=11600
                wrapped.renderBackground(renderer.getMatrixStack());
                // #endif
                break;
            case TRANSPARENT:
                int top = 0xc0_10_10_10, bottom = 0xd0_10_10_10;
                renderer.drawRect(0, 0, size.getWidth(), size.getHeight(), top, top, bottom, bottom);
                break;
            case DIRT:
                // #if MC>=11600
                wrapped.renderBackgroundTexture(0);
                // #endif
                break;
        }
        if (title != null) {
            ReadableDimension titleSize = title.getMinSize();
            int x = screenSize.getWidth() / 2 - titleSize.getWidth() / 2;
            OffsetGuiRenderer eRenderer = new OffsetGuiRenderer(renderer, new Point(x, 10), new Dimension(0, 0));
            title.draw(eRenderer, titleSize, renderInfo);
        }
    }
    super.draw(renderer, size, renderInfo);
    if (renderInfo.layer == getMaxLayer()) {
        final GuiElement tooltip = forEach(GuiElement.class, e -> e.getTooltip(renderInfo));
        if (tooltip != null) {
            final ReadableDimension tooltipSize = tooltip.getMinSize();
            int x, y;
            if (renderInfo.mouseX + 8 + tooltipSize.getWidth() < screenSize.getWidth()) {
                x = renderInfo.mouseX + 8;
            } else {
                x = screenSize.getWidth() - tooltipSize.getWidth() - 1;
            }
            if (renderInfo.mouseY + 8 + tooltipSize.getHeight() < screenSize.getHeight()) {
                y = renderInfo.mouseY + 8;
            } else {
                y = screenSize.getHeight() - tooltipSize.getHeight() - 1;
            }
            final ReadablePoint position = new Point(x, y);
            try {
                OffsetGuiRenderer eRenderer = new OffsetGuiRenderer(renderer, position, tooltipSize);
                tooltip.draw(eRenderer, tooltipSize, renderInfo);
            } catch (Exception ex) {
                CrashReport crashReport = CrashReport.create(ex, "Rendering Gui Tooltip");
                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());
                category = crashReport.addElement("Tooltip details");
                MCVer.addDetail(category, "Element", tooltip::toString);
                MCVer.addDetail(category, "Position", position::toString);
                MCVer.addDetail(category, "Size", tooltipSize::toString);
                throw new CrashException(crashReport);
            }
        }
    }
}
Also used : CrashException(net.minecraft.util.crash.CrashException) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) CrashReport(net.minecraft.util.crash.CrashReport) OffsetGuiRenderer(de.johni0702.minecraft.gui.OffsetGuiRenderer) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Dimension(de.johni0702.minecraft.gui.utils.lwjgl.Dimension) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) CrashReportSection(net.minecraft.util.crash.CrashReportSection) GuiElement(de.johni0702.minecraft.gui.element.GuiElement) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) CrashException(net.minecraft.util.crash.CrashException)

Example 4 with OffsetGuiRenderer

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

the class AbstractGuiHorizontalScrollbar 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();
    renderer.bindTexture(TEXTURE);
    // Draw background
    // 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_BG_X, TEXTURE_BG_Y, TEXTURE_BG_WIDTH, TEXTURE_BG_HEIGHT, BORDER_TOP + 1, BORDER_BOTTOM, BORDER_LEFT + 1, BORDER_RIGHT);
    // Draw slider
    int bodyWidth = size.getWidth() - BORDER_LEFT - BORDER_RIGHT;
    int barOffset = (int) (bodyWidth * offset) + BORDER_LEFT;
    int barWidth = (int) (bodyWidth * zoom);
    Utils.drawDynamicRect(new OffsetGuiRenderer(renderer, new Point(barOffset, BORDER_TOP), size), barWidth, height - (BORDER_TOP + 1) - BORDER_BOTTOM, TEXTURE_FG_X, TEXTURE_FG_Y, TEXTURE_FG_WIDTH, TEXTURE_FG_HEIGHT, 2, 1, 1, 1);
}
Also used : OffsetGuiRenderer(de.johni0702.minecraft.gui.OffsetGuiRenderer) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)

Example 5 with OffsetGuiRenderer

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

the class AbstractGuiColorPicker method draw.

@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
    super.draw(renderer, size, renderInfo);
    if (renderInfo.layer == 0) {
        int width = size.getWidth();
        int height = size.getHeight();
        // Draw outline
        renderer.drawRect(0, 0, width, height, OUTLINE_COLOR);
        // Draw color
        renderer.drawRect(1, 1, width - 2, height - 2, color);
    } else if (renderInfo.layer == 1) {
        ReadablePoint offsetPoint = new Point(0, size.getHeight());
        ReadableDimension offsetSize = new Dimension(PICKER_SIZE, PICKER_SIZE);
        OffsetGuiRenderer offsetRenderer = new OffsetGuiRenderer(renderer, offsetPoint, offsetSize);
        offsetRenderer.startUsing();
        try {
            picker.draw(offsetRenderer, offsetSize, renderInfo);
        } finally {
            offsetRenderer.stopUsing();
        }
    }
}
Also used : ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) OffsetGuiRenderer(de.johni0702.minecraft.gui.OffsetGuiRenderer) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Dimension(de.johni0702.minecraft.gui.utils.lwjgl.Dimension) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)

Aggregations

OffsetGuiRenderer (de.johni0702.minecraft.gui.OffsetGuiRenderer)7 ReadablePoint (de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)7 Point (de.johni0702.minecraft.gui.utils.lwjgl.Point)6 ReadableDimension (de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension)6 Dimension (de.johni0702.minecraft.gui.utils.lwjgl.Dimension)4 GuiElement (de.johni0702.minecraft.gui.element.GuiElement)3 CrashException (net.minecraft.util.crash.CrashException)3 CrashReport (net.minecraft.util.crash.CrashReport)3 CrashReportSection (net.minecraft.util.crash.CrashReportSection)3 AbstractComposedGuiElement (de.johni0702.minecraft.gui.element.AbstractComposedGuiElement)1 ComposedGuiElement (de.johni0702.minecraft.gui.element.ComposedGuiElement)1 WritablePoint (de.johni0702.minecraft.gui.utils.lwjgl.WritablePoint)1 TextRenderer (net.minecraft.client.font.TextRenderer)1 Pair (org.apache.commons.lang3.tuple.Pair)1