Search in sources :

Example 21 with Point

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

the class VerticalLayout method layOut.

@Override
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container, ReadableDimension size) {
    int y = 0;
    int spacing = 0;
    Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> map = new LinkedHashMap<>();
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        y += 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.setHeight(Math.min(size.getHeight() - y, Math.min(elementSize.getHeight(), elementMaxSize.getHeight())));
        elementSize.setWidth(Math.min(size.getWidth(), (data.maximizeWidth ? elementMaxSize : elementSize).getWidth()));
        int remainingWidth = size.getWidth() - elementSize.getWidth();
        int x = (int) (data.alignment * remainingWidth);
        map.put(element, Pair.<ReadablePoint, ReadableDimension>of(new Point(x, y), elementSize));
        y += elementSize.getHeight();
    }
    if (alignment != Alignment.TOP) {
        int remaining = size.getHeight() - y;
        if (alignment == Alignment.CENTER) {
            remaining /= 2;
        }
        for (Pair<ReadablePoint, ReadableDimension> pair : map.values()) {
            ((Point) pair.getLeft()).translate(0, remaining);
        }
    }
    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 22 with Point

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

the class AbstractGuiContainer method convertFor.

@Override
public void convertFor(GuiElement element, Point point, int relativeLayer) {
    if (layedOutElements == null || !layedOutElements.containsKey(element)) {
        layout(null, new RenderInfo(0, 0, 0, relativeLayer));
    }
    checkState(layedOutElements != null, "Cannot convert position unless rendered at least once.");
    Pair<ReadablePoint, ReadableDimension> pair = layedOutElements.get(element);
    checkState(pair != null, "Element " + element + " not part of " + this);
    ReadablePoint pos = pair.getKey();
    if (getContainer() != null) {
        getContainer().convertFor(this, point, relativeLayer + getLayer());
    }
    point.translate(-pos.getX(), -pos.getY());
}
Also used : ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) RenderInfo(de.johni0702.minecraft.gui.RenderInfo) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)

Example 23 with Point

use of de.johni0702.minecraft.gui.utils.lwjgl.Point 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 24 with Point

use of de.johni0702.minecraft.gui.utils.lwjgl.Point 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 25 with Point

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

the class AbstractGuiTimeline method getTimeAt.

/**
 * Returns the time which the mouse is at.
 * @param mouseX X coordinate of the mouse
 * @param mouseY Y coordinate of the mouse
 * @return The time or -1 if the mouse isn't on the timeline
 */
protected int getTimeAt(int mouseX, int mouseY) {
    if (getLastSize() == null) {
        return -1;
    }
    Point mouse = new Point(mouseX, mouseY);
    getContainer().convertFor(this, mouse);
    mouseX = mouse.getX();
    mouseY = mouse.getY();
    if (mouseX < 0 || mouseY < 0 || mouseX > size.getWidth() || mouseY > size.getHeight()) {
        return -1;
    }
    int width = size.getWidth();
    int bodyWidth = width - BORDER_LEFT - BORDER_RIGHT;
    double segmentLength = length * zoom;
    double segmentTime = segmentLength * (mouseX - BORDER_LEFT) / bodyWidth;
    return Math.min(Math.max((int) Math.round(offset + segmentTime), 0), length);
}
Also used : 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)

Aggregations

Point (de.johni0702.minecraft.gui.utils.lwjgl.Point)25 ReadablePoint (de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)25 ReadableDimension (de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension)11 Dimension (de.johni0702.minecraft.gui.utils.lwjgl.Dimension)8 GuiElement (de.johni0702.minecraft.gui.element.GuiElement)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 Pair (org.apache.commons.lang3.tuple.Pair)4 CrashException (net.minecraft.util.crash.CrashException)2 CrashReport (net.minecraft.util.crash.CrashReport)2 CrashReportSection (net.minecraft.util.crash.CrashReportSection)2 RenderInfo (de.johni0702.minecraft.gui.RenderInfo)1 WritablePoint (de.johni0702.minecraft.gui.utils.lwjgl.WritablePoint)1 Window (net.minecraft.client.util.Window)1