Search in sources :

Example 16 with ReadablePoint

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

the class AbstractGuiColorPicker method draw.

@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
    super.draw(renderer, size, renderInfo);
    if (renderInfo.layer == 0) {
        int width = size.getWidth();
        int height = size.getHeight();
        // Draw outline
        renderer.drawRect(0, 0, width, height, OUTLINE_COLOR);
        // Draw color
        renderer.drawRect(1, 1, width - 2, height - 2, color);
    } else if (renderInfo.layer == 1) {
        ReadablePoint offsetPoint = new Point(0, size.getHeight());
        ReadableDimension offsetSize = new Dimension(PICKER_SIZE, PICKER_SIZE);
        OffsetGuiRenderer offsetRenderer = new OffsetGuiRenderer(renderer, offsetPoint, offsetSize);
        offsetRenderer.startUsing();
        try {
            picker.draw(offsetRenderer, offsetSize, renderInfo);
        } finally {
            offsetRenderer.stopUsing();
        }
    }
}
Also used : ReadableDimension(de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension) OffsetGuiRenderer(de.johni0702.minecraft.gui.OffsetGuiRenderer) 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) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint) Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) ReadablePoint(de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)

Example 17 with ReadablePoint

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

the class AbstractGuiTextArea method mouseClick.

@Override
public boolean mouseClick(ReadablePoint position, int button) {
    if (getContainer() != null) {
        getContainer().convertFor(this, (Point) (position = new Point(position)));
    }
    boolean hovering = isMouseHovering(position);
    if (hovering && isFocused() && button == 0) {
        updateCurrentOffset();
        int mouseX = position.getX() - BORDER;
        int mouseY = position.getY() - BORDER;
        TextRenderer fontRenderer = MCVer.getFontRenderer();
        int textY = clamp(mouseY / (fontRenderer.fontHeight + LINE_SPACING) + currentYOffset, 0, text.length - 1);
        if (cursorY != textY) {
            currentXOffset = 0;
        }
        String line = text[textY].substring(currentXOffset);
        int textX = fontRenderer.trimToWidth(line, mouseX).length() + currentXOffset;
        setCursorPosition(textX, textY);
    }
    setFocused(hovering);
    return hovering;
}
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) TextRenderer(net.minecraft.client.font.TextRenderer)

Example 18 with ReadablePoint

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

the class AbstractGuiTextArea method typeKey.

@Override
public boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown) {
    if (keyCode == Keyboard.KEY_TAB) {
        Focusable other = shiftDown ? previous : next;
        if (other != null) {
            setFocused(false);
            other.setFocused(true);
        }
        return true;
    }
    if (!this.focused) {
        return false;
    }
    if (Screen.hasControlDown()) {
        switch(keyCode) {
            case // Select all
            Keyboard.KEY_A:
                cursorX = cursorY = 0;
                selectionY = text.length - 1;
                selectionX = text[selectionY].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(cutSelectedText());
                }
                return true;
        }
    }
    boolean words = Screen.hasControlDown();
    boolean select = Screen.hasShiftDown();
    switch(keyCode) {
        case Keyboard.KEY_HOME:
            cursorX = 0;
            break;
        case Keyboard.KEY_END:
            cursorX = text[cursorY].length();
            break;
        case Keyboard.KEY_LEFT:
            if (cursorX == 0) {
                if (cursorY > 0) {
                    cursorY--;
                    cursorX = text[cursorY].length();
                }
            } else {
                if (words) {
                    cursorX -= getPreviousWordLength();
                } else {
                    cursorX--;
                }
            }
            break;
        case Keyboard.KEY_RIGHT:
            if (cursorX == text[cursorY].length()) {
                if (cursorY < text.length - 1) {
                    cursorY++;
                    cursorX = 0;
                }
            } else {
                if (words) {
                    cursorX += getNextWordLength();
                } else {
                    cursorX++;
                }
            }
            break;
        case Keyboard.KEY_UP:
            if (cursorY > 0) {
                cursorY--;
                cursorX = Math.min(cursorX, text[cursorY].length());
            }
            break;
        case Keyboard.KEY_DOWN:
            if (cursorY + 1 < text.length) {
                cursorY++;
                cursorX = Math.min(cursorX, text[cursorY].length());
            }
            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) {
        selectionX = cursorX;
        selectionY = cursorY;
    }
    return true;
}
Also used : Focusable(de.johni0702.minecraft.gui.function.Focusable)

Example 19 with ReadablePoint

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

the class AbstractGuiHorizontalScrollbar method mouseClick.

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

Example 20 with ReadablePoint

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

the class AbstractGuiHorizontalScrollbar method isMouseHoveringBar.

protected boolean isMouseHoveringBar(ReadablePoint pos) {
    int bodyWidth = getLastSize().getWidth() - BORDER_LEFT - BORDER_RIGHT;
    int barOffset = (int) (bodyWidth * offset) + BORDER_LEFT;
    int barWidth = (int) (bodyWidth * zoom);
    return pos.getX() >= barOffset && pos.getY() > BORDER_TOP && pos.getX() <= barOffset + barWidth && pos.getY() < getLastSize().getHeight() - BORDER_BOTTOM;
}
Also used : Point(de.johni0702.minecraft.gui.utils.lwjgl.Point) 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