Search in sources :

Example 46 with Rect2i

use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.

the class UIScrollbar method onDraw.

@Override
public void onDraw(Canvas canvas) {
    if (vertical) {
        canvas.setPart("sliderVertical");
    } else {
        canvas.setPart("sliderHorizontal");
    }
    canvas.drawBackground();
    canvas.addInteractionRegion(sliderListener);
    canvas.setPart("handle");
    if (vertical) {
        sliderSize = canvas.size().y - canvas.getCurrentStyle().getFixedHeight();
    } else {
        sliderSize = canvas.size().x - canvas.getCurrentStyle().getFixedWidth();
    }
    if (sliderSize > handleSize) {
        int drawLocation = pixelOffsetFor(getValue());
        Rect2i handleRegion;
        if (vertical) {
            handleSize = canvas.getCurrentStyle().getFixedHeight();
            handleRegion = Rect2i.createFromMinAndSize(0, drawLocation, canvas.getCurrentStyle().getFixedWidth(), handleSize);
        } else {
            handleSize = canvas.getCurrentStyle().getFixedWidth();
            handleRegion = Rect2i.createFromMinAndSize(drawLocation, 0, handleSize, canvas.getCurrentStyle().getFixedHeight());
        }
        canvas.drawBackground(handleRegion);
        canvas.addInteractionRegion(handleListener, handleRegion);
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i)

Example 47 with Rect2i

use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.

the class UISlider method onDraw.

@Override
public void onDraw(Canvas canvas) {
    canvas.setPart(SLIDER);
    canvas.drawBackground();
    canvas.setPart(TICKER);
    String display = getDisplayText();
    int tickerWidth = canvas.getCurrentStyle().getFont().getWidth(display);
    tickerWidth += canvas.getCurrentStyle().getMargin().getTotalWidth();
    sliderWidth = canvas.size().x - tickerWidth;
    int drawLocation = pixelOffsetFor(getValue(), sliderWidth);
    Rect2i tickerRegion = Rect2i.createFromMinAndSize(drawLocation, 0, tickerWidth, canvas.size().y);
    try (SubRegion ignored = canvas.subRegion(tickerRegion, false)) {
        canvas.drawBackground();
        canvas.drawText(display);
        if (isEnabled()) {
            canvas.addInteractionRegion(tickerListener);
        }
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) SubRegion(org.terasology.rendering.nui.SubRegion)

Example 48 with Rect2i

use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.

the class UITabBox method onDraw.

@Override
public void onDraw(Canvas canvas) {
    if (contents.size() != 0) {
        Rect2i region = canvas.getRegion();
        Rect2i buttonRegion = Rect2i.createFromMinAndSize(region.minX(), region.minY(), region.width(), tabBarHeight);
        Rect2i boxRegion = Rect2i.createFromMinAndMax(region.minX(), region.minY() + tabBarHeight, region.width(), region.height() - tabBarHeight);
        canvas.drawWidget(contents.get(currentTab), boxRegion);
        canvas.drawWidget(buttonLayout, buttonRegion);
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i)

Example 49 with Rect2i

use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.

the class UIText method drawCursor.

/**
 * Draws the cursor in the text field.
 *
 * @param canvas The canvas on which the widget resides
 */
protected void drawCursor(Canvas canvas) {
    if (blinkCounter < BLINK_RATE) {
        Font font = canvas.getCurrentStyle().getFont();
        String beforeCursor = text.get();
        if (getCursorPosition() < text.get().length()) {
            beforeCursor = beforeCursor.substring(0, getCursorPosition());
        }
        List<String> lines = TextLineBuilder.getLines(font, beforeCursor, canvas.size().x);
        // TODO: Support different alignments
        int lastLineWidth = font.getWidth(lines.get(lines.size() - 1));
        Rect2i region = Rect2i.createFromMinAndSize(lastLineWidth, (lines.size() - 1) * font.getLineHeight(), 1, font.getLineHeight());
        canvas.drawTexture(cursorTexture, region, canvas.getCurrentStyle().getTextColor());
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) Font(org.terasology.rendering.assets.font.Font)

Example 50 with Rect2i

use of org.terasology.math.geom.Rect2i in project Terasology by MovingBlocks.

the class ContainerFlowContainerRenderSpace method addRightFloat.

@Override
public Rect2i addRightFloat(int y, int width, int height) {
    int posY = y;
    while (true) {
        int availableWidth = getAvailableWidthAt(posY);
        if (availableWidth >= width) {
            int x = 0;
            Rect2i lastRight = findLastAtYPosition(rightFloats, posY);
            if (lastRight != null) {
                x = lastRight.minX();
            }
            Rect2i floatRect = Rect2i.createFromMinAndSize(x - width, posY, width, height);
            rightFloats.add(floatRect);
            return floatRect;
        } else {
            Rect2i lastLeft = findLastAtYPosition(leftFloats, posY);
            Rect2i lastRight = findLastAtYPosition(rightFloats, posY);
            if (lastLeft != null && lastRight != null) {
                posY = Math.min(lastLeft.maxY(), lastRight.maxY());
            } else if (lastLeft != null) {
                posY = lastLeft.maxY();
            } else if (lastRight != null) {
                posY = lastRight.maxY();
            }
        }
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i)

Aggregations

Rect2i (org.terasology.math.geom.Rect2i)59 Vector2i (org.terasology.math.geom.Vector2i)13 SubRegion (org.terasology.rendering.nui.SubRegion)8 BaseVector2i (org.terasology.math.geom.BaseVector2i)7 Font (org.terasology.rendering.assets.font.Font)5 LayoutHint (org.terasology.rendering.nui.LayoutHint)5 SurfaceHeightFacet (org.terasology.world.generation.facets.SurfaceHeightFacet)4 ByteBuffer (java.nio.ByteBuffer)3 List (java.util.List)3 Color (org.terasology.rendering.nui.Color)3 BufferedImage (java.awt.image.BufferedImage)2 Test (org.junit.Test)2 UIWidget (org.terasology.rendering.nui.UIWidget)2 FallbackParagraphRenderStyle (org.terasology.rendering.nui.widgets.browser.ui.style.FallbackParagraphRenderStyle)2 ParagraphRenderStyle (org.terasology.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle)2 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 TIntList (gnu.trove.list.TIntList)1 Graphics2D (java.awt.Graphics2D)1 DataBufferInt (java.awt.image.DataBufferInt)1