Search in sources :

Example 21 with ReadablePoint

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

the class AbstractGuiSlider method mouseDrag.

@Override
public boolean mouseDrag(ReadablePoint position, int button, long timeSinceLastCall) {
    if (dragging) {
        Point pos = new Point(position);
        if (getContainer() != null) {
            getContainer().convertFor(this, pos);
        }
        updateValue(pos);
    }
    return dragging;
}
Also used : Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)

Example 22 with ReadablePoint

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

the class AbstractGuiTextField method typeKey.

@Override
public boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown) {
    if (!this.focused) {
        return false;
    }
    if (keyCode == Keyboard.KEY_TAB) {
        Focusable other = shiftDown ? previous : next;
        if (other != null) {
            setFocused(false);
            other.setFocused(true);
            // If the other field is a text field, by default select all its text (saves a Ctrl+A)
            if (other instanceof AbstractGuiTextField) {
                AbstractGuiTextField<?> field = (AbstractGuiTextField<?>) other;
                field.cursorPos = 0;
                field.selectionPos = field.text.length();
            }
        }
        return true;
    }
    if (keyCode == Keyboard.KEY_RETURN) {
        onEnter();
        return true;
    }
    String textBefore = text;
    try {
        if (Screen.hasControlDown()) {
            switch(keyCode) {
                case // Select all
                Keyboard.KEY_A:
                    cursorPos = 0;
                    selectionPos = text.length();
                    return true;
                case // Copy
                Keyboard.KEY_C:
                    MCVer.setClipboardString(getSelectedText());
                    return true;
                case // Paste
                Keyboard.KEY_V:
                    if (isEnabled()) {
                        writeText(MCVer.getClipboardString());
                    }
                    return true;
                case // Cut
                Keyboard.KEY_X:
                    if (isEnabled()) {
                        MCVer.setClipboardString(deleteSelectedText());
                    }
                    return true;
            }
        }
        boolean words = Screen.hasControlDown();
        boolean select = Screen.hasShiftDown();
        switch(keyCode) {
            case Keyboard.KEY_HOME:
                cursorPos = 0;
                break;
            case Keyboard.KEY_END:
                cursorPos = text.length();
                break;
            case Keyboard.KEY_LEFT:
                if (cursorPos != 0) {
                    if (words) {
                        cursorPos -= getPreviousWordLength();
                    } else {
                        cursorPos--;
                    }
                }
                break;
            case Keyboard.KEY_RIGHT:
                if (cursorPos != text.length()) {
                    if (words) {
                        cursorPos += getNextWordLength();
                    } else {
                        cursorPos++;
                    }
                }
                break;
            case Keyboard.KEY_BACK:
                if (isEnabled()) {
                    if (getSelectedText().length() > 0) {
                        deleteSelectedText();
                    } else if (words) {
                        deletePreviousWord();
                    } else {
                        deletePreviousChar();
                    }
                }
                return true;
            case Keyboard.KEY_DELETE:
                if (isEnabled()) {
                    if (getSelectedText().length() > 0) {
                        deleteSelectedText();
                    } else if (words) {
                        deleteNextWord();
                    } else {
                        deleteNextChar();
                    }
                }
                return true;
            default:
                if (isEnabled()) {
                    if (keyChar == '\r') {
                        keyChar = '\n';
                    }
                    writeChar(keyChar);
                }
                return true;
        }
        if (!select) {
            selectionPos = cursorPos;
        }
        return true;
    } finally {
        if (!textBefore.equals(text)) {
            onTextChanged(textBefore);
        }
    }
}
Also used : Focusable(de.johni0702.minecraft.gui.function.Focusable)

Example 23 with ReadablePoint

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

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

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

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