Search in sources :

Example 26 with ReadablePoint

use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.

the class AbstractGuiContainer method layout.

@Override
public void layout(ReadableDimension size, RenderInfo renderInfo) {
    super.layout(size, renderInfo);
    if (size == null)
        return;
    try {
        layedOutElements = layout.layOut(this, size);
    } catch (Exception ex) {
        CrashReport crashReport = CrashReport.create(ex, "Gui Layout");
        renderInfo.addTo(crashReport);
        CrashReportSection category = crashReport.addElement("Gui container details");
        MCVer.addDetail(category, "Container", this::toString);
        MCVer.addDetail(category, "Layout", layout::toString);
        throw new CrashException(crashReport);
    }
    for (final Map.Entry<GuiElement, Pair<ReadablePoint, ReadableDimension>> e : layedOutElements.entrySet()) {
        GuiElement element = e.getKey();
        if (element instanceof ComposedGuiElement) {
            if (((ComposedGuiElement) element).getMaxLayer() < renderInfo.layer) {
                continue;
            }
        } else {
            if (element.getLayer() != renderInfo.layer) {
                continue;
            }
        }
        ReadablePoint ePosition = e.getValue().getLeft();
        ReadableDimension eSize = e.getValue().getRight();
        element.layout(eSize, renderInfo.offsetMouse(ePosition.getX(), ePosition.getY()).layer(renderInfo.getLayer() - element.getLayer()));
    }
}
Also used : CrashException(net.minecraft.util.crash.CrashException) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) CrashReport(net.minecraft.util.crash.CrashReport) CrashReportSection(net.minecraft.util.crash.CrashReportSection) AbstractComposedGuiElement(de.johni0702.minecraft.gui.element.AbstractComposedGuiElement) GuiElement(de.johni0702.minecraft.gui.element.GuiElement) ComposedGuiElement(de.johni0702.minecraft.gui.element.ComposedGuiElement) AbstractComposedGuiElement(de.johni0702.minecraft.gui.element.AbstractComposedGuiElement) ComposedGuiElement(de.johni0702.minecraft.gui.element.ComposedGuiElement) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) CrashException(net.minecraft.util.crash.CrashException) Pair(org.apache.commons.lang3.tuple.Pair)

Example 27 with ReadablePoint

use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.

the class AbstractGuiOverlay method draw.

@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
    super.draw(renderer, size, renderInfo);
    if (mouseVisible && 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) 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 28 with ReadablePoint

use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.

the class AbstractGuiVerticalList method convert.

private ReadablePoint convert(ReadablePoint readablePoint) {
    if (getContainer() != null) {
        Point point = new Point(readablePoint);
        getContainer().convertFor(this, point);
        return point;
    }
    return readablePoint;
}
Also used : Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)

Example 29 with ReadablePoint

use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.

the class AbstractGuiTexturedButton method setTexturePosH.

@Override
public T setTexturePosH(final ReadablePoint pos) {
    this.textureNormal = pos;
    this.textureHover = new ReadablePoint() {

        @Override
        public int getX() {
            return pos.getX() + textureSize.getWidth();
        }

        @Override
        public int getY() {
            return pos.getY();
        }

        @Override
        public void getLocation(WritablePoint dest) {
            dest.setLocation(getX(), getY());
        }
    };
    return getThis();
}
Also used : ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) WritablePoint(de.johni0702.minecraft.gui.utils.lwjgl.WritablePoint)

Example 30 with ReadablePoint

use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.

the class GridLayout method layOut.

@Override
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container, ReadableDimension size) {
    Preconditions.checkState(columns != 0, "Columns may not be 0.");
    int elements = container.getElements().size();
    int rows = (elements - 1 + columns) / columns;
    if (rows < 1) {
        return Collections.emptyMap();
    }
    int cellWidth = (size.getWidth() + spacingX) / columns - spacingX;
    int cellHeight = (size.getHeight() + spacingY) / rows - spacingY;
    Pair<int[], int[]> maxCellSize = null;
    if (!cellsEqualSize) {
        maxCellSize = calcNeededCellSize(container);
    }
    Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> map = new LinkedHashMap<>();
    Iterator<Map.Entry<GuiElement, LayoutData>> iter = container.getElements().entrySet().iterator();
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < columns; j++) {
            if (!iter.hasNext()) {
                return map;
            }
            int x = j * (cellWidth + spacingX);
            int y = i * (cellHeight + spacingY);
            if (maxCellSize != null) {
                cellWidth = maxCellSize.getLeft()[j];
                cellHeight = maxCellSize.getRight()[i];
                x = 0;
                for (int x1 = 0; x1 < j; x1++) {
                    x += maxCellSize.getLeft()[x1];
                    x += spacingX;
                }
                y = 0;
                for (int y1 = 0; y1 < i; y1++) {
                    y += maxCellSize.getRight()[y1];
                    y += spacingY;
                }
            }
            Map.Entry<GuiElement, LayoutData> entry = iter.next();
            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(cellWidth, elementMaxSize.getWidth()));
            elementSize.setHeight(Math.min(cellHeight, elementMaxSize.getHeight()));
            int remainingWidth = cellWidth - elementSize.getWidth();
            int remainingHeight = cellHeight - elementSize.getHeight();
            x += (int) (data.alignmentX * remainingWidth);
            y += (int) (data.alignmentY * remainingHeight);
            map.put(element, Pair.<ReadablePoint, ReadableDimension>of(new Point(x, y), elementSize));
        }
    }
    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) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

ReadablePoint (de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)28 Point (de.johni0702.minecraft.gui.utils.lwjgl.Point)23 ReadableDimension (de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension)12 GuiElement (de.johni0702.minecraft.gui.element.GuiElement)8 Dimension (de.johni0702.minecraft.gui.utils.lwjgl.Dimension)8 Pair (org.apache.commons.lang3.tuple.Pair)6 OffsetGuiRenderer (de.johni0702.minecraft.gui.OffsetGuiRenderer)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 TextRenderer (net.minecraft.client.font.TextRenderer)4 CrashException (net.minecraft.util.crash.CrashException)4 CrashReport (net.minecraft.util.crash.CrashReport)4 CrashReportSection (net.minecraft.util.crash.CrashReportSection)4 WritablePoint (de.johni0702.minecraft.gui.utils.lwjgl.WritablePoint)3 AbstractComposedGuiElement (de.johni0702.minecraft.gui.element.AbstractComposedGuiElement)2 ComposedGuiElement (de.johni0702.minecraft.gui.element.ComposedGuiElement)2 Focusable (de.johni0702.minecraft.gui.function.Focusable)2 RenderInfo (de.johni0702.minecraft.gui.RenderInfo)1