Search in sources :

Example 6 with GuiElement

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

the class AbstractGuiContainer method addElements.

@Override
public T addElements(LayoutData layoutData, GuiElement... elements) {
    if (layoutData == null) {
        layoutData = LayoutData.NONE;
    }
    for (GuiElement element : elements) {
        this.elements.put(element, layoutData);
        element.setContainer(this);
    }
    return getThis();
}
Also used : AbstractComposedGuiElement(de.johni0702.minecraft.gui.element.AbstractComposedGuiElement) GuiElement(de.johni0702.minecraft.gui.element.GuiElement) ComposedGuiElement(de.johni0702.minecraft.gui.element.ComposedGuiElement)

Example 7 with GuiElement

use of de.johni0702.minecraft.gui.element.GuiElement 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 8 with GuiElement

use of de.johni0702.minecraft.gui.element.GuiElement 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 9 with GuiElement

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

the class HorizontalLayout method layOut.

@Override
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container, ReadableDimension size) {
    int x = 0;
    int spacing = 0;
    Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> map = new LinkedHashMap<>();
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        x += spacing;
        spacing = this.spacing;
        GuiElement element = entry.getKey();
        Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA;
        Dimension elementSize = new Dimension(element.getMinSize());
        ReadableDimension elementMaxSize = element.getMaxSize();
        elementSize.setWidth(Math.min(size.getWidth() - x, Math.min(elementSize.getWidth(), elementMaxSize.getWidth())));
        elementSize.setHeight(Math.min(size.getHeight(), elementMaxSize.getHeight()));
        int remainingHeight = size.getHeight() - elementSize.getHeight();
        int y = (int) (data.alignment * remainingHeight);
        map.put(element, Pair.<ReadablePoint, ReadableDimension>of(new Point(x, y), elementSize));
        x += elementSize.getWidth();
    }
    if (alignment != Alignment.LEFT) {
        int remaining = size.getWidth() - x;
        if (alignment == Alignment.CENTER) {
            remaining /= 2;
        }
        for (Pair<ReadablePoint, ReadableDimension> pair : map.values()) {
            ((Point) pair.getLeft()).translate(remaining, 0);
        }
    }
    return map;
}
Also used : Dimension(de.johni0702.minecraft.gui.utils.lwjgl.Dimension) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) 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) LinkedHashMap(java.util.LinkedHashMap) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) GuiElement(de.johni0702.minecraft.gui.element.GuiElement) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Pair(org.apache.commons.lang3.tuple.Pair)

Example 10 with GuiElement

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

the class HorizontalLayout method calcMinSize.

@Override
public ReadableDimension calcMinSize(GuiContainer<?> container) {
    int maxHeight = 0;
    int width = 0;
    int spacing = 0;
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        width += spacing;
        spacing = this.spacing;
        GuiElement element = entry.getKey();
        ReadableDimension minSize = element.getMinSize();
        int height = minSize.getHeight();
        if (height > maxHeight) {
            maxHeight = height;
        }
        width += minSize.getWidth();
    }
    return new Dimension(width, maxHeight);
}
Also used : ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) Dimension(de.johni0702.minecraft.gui.utils.lwjgl.Dimension) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GuiElement(de.johni0702.minecraft.gui.element.GuiElement) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)

Aggregations

GuiElement (de.johni0702.minecraft.gui.element.GuiElement)15 ReadableDimension (de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension)14 ReadablePoint (de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)13 Point (de.johni0702.minecraft.gui.utils.lwjgl.Point)10 Dimension (de.johni0702.minecraft.gui.utils.lwjgl.Dimension)9 LinkedHashMap (java.util.LinkedHashMap)8 Map (java.util.Map)8 Pair (org.apache.commons.lang3.tuple.Pair)6 CrashException (net.minecraft.util.crash.CrashException)4 CrashReport (net.minecraft.util.crash.CrashReport)4 CrashReportSection (net.minecraft.util.crash.CrashReportSection)4 OffsetGuiRenderer (de.johni0702.minecraft.gui.OffsetGuiRenderer)3 AbstractComposedGuiElement (de.johni0702.minecraft.gui.element.AbstractComposedGuiElement)3 ComposedGuiElement (de.johni0702.minecraft.gui.element.ComposedGuiElement)3 RenderInfo (de.johni0702.minecraft.gui.RenderInfo)2 VerticalLayout (de.johni0702.minecraft.gui.layout.VerticalLayout)2 GuiRenderer (de.johni0702.minecraft.gui.GuiRenderer)1 GuiButton (de.johni0702.minecraft.gui.element.GuiButton)1 GuiDropdownMenu (de.johni0702.minecraft.gui.element.advanced.GuiDropdownMenu)1 File (java.io.File)1