Search in sources :

Example 16 with Point

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

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

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

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

the class AbstractGuiSlider method draw.

@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
    super.draw(renderer, size, renderInfo);
    int width = size.getWidth();
    int height = size.getHeight();
    renderer.bindTexture(GuiButton.WIDGETS_TEXTURE);
    // Draw background
    renderer.drawTexturedRect(0, 0, 0, 46, width / 2, height);
    renderer.drawTexturedRect(width / 2, 0, 200 - width / 2, 46, width / 2, height);
    // Draw slider
    int sliderX = (width - 8) * value / steps;
    renderer.drawTexturedRect(sliderX, 0, 0, 66, 4, 20);
    renderer.drawTexturedRect(sliderX + 4, 0, 196, 66, 4, 20);
    // Draw text
    int color = 0xe0e0e0;
    if (!isEnabled()) {
        color = 0xa0a0a0;
    } else if (isMouseHovering(new Point(renderInfo.mouseX, renderInfo.mouseY))) {
        color = 0xffffa0;
    }
    renderer.drawCenteredString(width / 2, height / 2 - 4, color, text);
}
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)

Example 20 with Point

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

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