Search in sources :

Example 6 with OffsetGuiRenderer

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

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

the class AbstractGuiScrollable method draw.

@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
    int width = size.getWidth();
    int height = size.getHeight();
    size = super.calcMinSize();
    size = new Dimension(Math.max(width, size.getWidth()), Math.max(height, size.getHeight()));
    renderInfo = renderInfo.offsetMouse(-offsetX, -offsetY);
    OffsetGuiRenderer offsetRenderer = new OffsetGuiRenderer(renderer, negativeOffset, size, renderInfo.layer == 0);
    offsetRenderer.startUsing();
    super.draw(offsetRenderer, size, renderInfo);
    offsetRenderer.stopUsing();
}
Also used : OffsetGuiRenderer(de.johni0702.minecraft.gui.OffsetGuiRenderer) Dimension(de.johni0702.minecraft.gui.utils.lwjgl.Dimension) ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) WritablePoint(de.johni0702.minecraft.gui.utils.lwjgl.WritablePoint) 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