Search in sources :

Example 1 with Dimension

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

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

the class AbstractGuiDropdownMenu method calcMinSize.

@Override
protected ReadableDimension calcMinSize() {
    TextRenderer fontRenderer = MCVer.getFontRenderer();
    int maxWidth = 0;
    for (V value : values) {
        int width = fontRenderer.getWidth(toString.apply(value));
        if (width > maxWidth) {
            maxWidth = width;
        }
    }
    return new Dimension(11 + maxWidth + fontRenderer.fontHeight, fontRenderer.fontHeight + 4);
}
Also used : 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) TextRenderer(net.minecraft.client.font.TextRenderer)

Example 3 with Dimension

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

the class AbstractGuiDropdownMenu method layout.

@Override
public void layout(ReadableDimension size, RenderInfo renderInfo) {
    super.layout(size, renderInfo);
    TextRenderer fontRenderer = MCVer.getFontRenderer();
    if (renderInfo.layer == 1) {
        ReadablePoint offsetPoint = new Point(0, size.getHeight());
        ReadableDimension offsetSize = new Dimension(size.getWidth(), (fontRenderer.fontHeight + 5) * values.length);
        dropdown.layout(offsetSize, renderInfo.offsetMouse(0, offsetPoint.getY()).layer(0));
    }
}
Also used : ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) 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) TextRenderer(net.minecraft.client.font.TextRenderer)

Example 4 with Dimension

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

the class VerticalLayout method calcMinSize.

@Override
public ReadableDimension calcMinSize(GuiContainer<?> container) {
    int maxWidth = 0;
    int height = 0;
    int spacing = 0;
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        height += spacing;
        spacing = this.spacing;
        GuiElement element = entry.getKey();
        ReadableDimension minSize = element.getMinSize();
        int width = minSize.getWidth();
        if (width > maxWidth) {
            maxWidth = width;
        }
        height += minSize.getHeight();
    }
    return new Dimension(maxWidth, height);
}
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)

Example 5 with Dimension

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

the class CustomLayout method layOut.

@Override
@SuppressWarnings("unchecked")
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer container, ReadableDimension size) {
    result.clear();
    if (parent == null) {
        Collection<GuiElement> elements = container.getChildren();
        for (GuiElement element : elements) {
            result.put(element, Pair.of(new Point(0, 0), new Dimension(element.getMinSize())));
        }
    } else {
        Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> elements = parent.layOut(container, size);
        for (Map.Entry<GuiElement, Pair<ReadablePoint, ReadableDimension>> entry : elements.entrySet()) {
            Pair<ReadablePoint, ReadableDimension> pair = entry.getValue();
            result.put(entry.getKey(), Pair.of(new Point(pair.getLeft()), new Dimension(pair.getRight())));
        }
    }
    layout((T) container, size.getWidth(), size.getHeight());
    return (Map) result;
}
Also used : ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) 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) 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)

Aggregations

Dimension (de.johni0702.minecraft.gui.utils.lwjgl.Dimension)19 ReadableDimension (de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension)19 Point (de.johni0702.minecraft.gui.utils.lwjgl.Point)14 ReadablePoint (de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)14 GuiElement (de.johni0702.minecraft.gui.element.GuiElement)9 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 TextRenderer (net.minecraft.client.font.TextRenderer)5 OffsetGuiRenderer (de.johni0702.minecraft.gui.OffsetGuiRenderer)4 Pair (org.apache.commons.lang3.tuple.Pair)4 WritablePoint (de.johni0702.minecraft.gui.utils.lwjgl.WritablePoint)2 GuiRenderer (de.johni0702.minecraft.gui.GuiRenderer)1 RenderInfo (de.johni0702.minecraft.gui.RenderInfo)1 GuiButton (de.johni0702.minecraft.gui.element.GuiButton)1 GuiDropdownMenu (de.johni0702.minecraft.gui.element.advanced.GuiDropdownMenu)1 VerticalLayout (de.johni0702.minecraft.gui.layout.VerticalLayout)1 WritableDimension (de.johni0702.minecraft.gui.utils.lwjgl.WritableDimension)1 File (java.io.File)1 IOException (java.io.IOException)1 CrashException (net.minecraft.util.crash.CrashException)1