Search in sources :

Example 51 with Rect2i

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

the class ContainerFlowContainerRenderSpace method getNextWidthChange.

@Override
public int getNextWidthChange(int y) {
    Rect2i lastLeftFloat = findLastAtYPosition(leftFloats, y);
    Rect2i lastRightFloat = findLastAtYPosition(rightFloats, y);
    if (lastLeftFloat != null && lastRightFloat != null) {
        return Math.min(lastLeftFloat.maxY(), lastRightFloat.maxY());
    } else if (lastLeftFloat != null) {
        return lastLeftFloat.maxY();
    } else if (lastRightFloat != null) {
        return lastRightFloat.maxY();
    } else {
        return Integer.MAX_VALUE;
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i)

Example 52 with Rect2i

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

the class DocumentRenderer method renderParagraph.

public static int renderParagraph(Canvas canvas, ParagraphRenderable.HyperlinkRegister register, ParagraphRenderStyle baseRenderStyle, int xShift, int leftIndent, int rightIndent, ContainerRenderSpace containerRenderSpace, int containerWidth, int startY, ParagraphData paragraphData) {
    int yShift = startY;
    ParagraphRenderable paragraphContents = paragraphData.getParagraphContents();
    ParagraphRenderStyle paragraphRenderStyle = getParagraphRenderStyle(baseRenderStyle, paragraphData);
    ParagraphRenderStyle.ClearStyle clearStyle = paragraphRenderStyle.getClearStyle();
    if (clearStyle != ParagraphRenderStyle.ClearStyle.NONE) {
        yShift = Math.max(yShift, containerRenderSpace.getNextClearYPosition(clearStyle));
    }
    ParagraphRenderStyle.FloatStyle floatStyle = paragraphRenderStyle.getFloatStyle();
    if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT || floatStyle == ParagraphRenderStyle.FloatStyle.RIGHT) {
        int leftParagraphIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth);
        int rightParagraphIndent = paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
        int paragraphWidth = Math.max(paragraphRenderStyle.getParagraphMinimumWidth().getValue(containerWidth), paragraphContents.getContentsMinWidth(paragraphRenderStyle) + leftParagraphIndent + rightParagraphIndent);
        int height = paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
        int paragraphHeight = paragraphContents.getPreferredContentsHeight(paragraphRenderStyle, 0, new ContainerFlowContainerRenderSpace(paragraphWidth), leftParagraphIndent + rightParagraphIndent);
        height += paragraphHeight;
        height += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
        Rect2i position;
        if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT) {
            position = containerRenderSpace.addLeftFloat(yShift, paragraphWidth, height);
        } else {
            position = containerRenderSpace.addRightFloat(yShift, paragraphWidth, height);
        }
        Rect2i paragraphBorderRegion = Rect2i.createFromMinAndMax(position.minX() + paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth), position.minY() + paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth), position.maxX() - paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) - 1, position.maxY() - paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth) - 1);
        Color paragraphBackground = paragraphRenderStyle.getParagraphBackground();
        if (paragraphBackground != null) {
            canvas.drawFilledRectangle(paragraphBorderRegion, paragraphBackground);
        }
        Vector2i paragraphStart = new Vector2i(position.minX(), position.minY() + paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth));
        paragraphContents.renderContents(canvas, paragraphStart, new ContainerFlowContainerRenderSpace(paragraphWidth), leftParagraphIndent, rightParagraphIndent, paragraphRenderStyle, paragraphRenderStyle.getHorizontalAlignment(), register);
        yShift = position.minY();
    } else {
        yShift += paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth);
        int leftParagraphIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth);
        int rightParagraphIndent = paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
        int paragraphHeight = paragraphContents.getPreferredContentsHeight(paragraphRenderStyle, yShift + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth), containerRenderSpace, leftIndent + leftParagraphIndent + rightParagraphIndent + rightIndent);
        Color paragraphBackground = paragraphRenderStyle.getParagraphBackground();
        if (paragraphBackground != null) {
            int borderAdvance = 0;
            int borderHeight = paragraphHeight + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth);
            while (borderAdvance < borderHeight) {
                int backgroundStart = yShift + borderAdvance;
                int availableBackgroundWidth = containerRenderSpace.getWidthForVerticalPosition(backgroundStart);
                int backgroundAdvance = containerRenderSpace.getAdvanceForVerticalPosition(backgroundStart);
                int maxSpace = containerRenderSpace.getNextWidthChange(backgroundStart);
                Rect2i backgroundRegion = Rect2i.createFromMinAndSize(xShift + paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + backgroundAdvance, backgroundStart, availableBackgroundWidth - 1, Math.min(maxSpace, borderHeight - borderAdvance) - 1);
                canvas.drawFilledRectangle(backgroundRegion, paragraphBackground);
                borderAdvance += maxSpace - backgroundStart;
            }
        }
        yShift += paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
        paragraphContents.renderContents(canvas, new Vector2i(xShift, yShift), containerRenderSpace, leftIndent + leftParagraphIndent, rightIndent + rightParagraphIndent, paragraphRenderStyle, paragraphRenderStyle.getHorizontalAlignment(), register);
        yShift += paragraphHeight;
        yShift += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth);
        yShift += paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
    }
    return yShift - startY;
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) Color(org.terasology.rendering.nui.Color) Vector2i(org.terasology.math.geom.Vector2i) FallbackParagraphRenderStyle(org.terasology.rendering.nui.widgets.browser.ui.style.FallbackParagraphRenderStyle) ParagraphRenderStyle(org.terasology.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle)

Example 53 with Rect2i

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

the class DocumentRenderer method getParagraphsPreferredHeight.

public static int getParagraphsPreferredHeight(ParagraphRenderStyle baseRenderStyle, Collection<ParagraphData> paragraphs, ContainerRenderSpace containerRenderSpace, int yStart) {
    int containerWidth = containerRenderSpace.getContainerWidth();
    int yShift = yStart;
    for (ParagraphData paragraphData : paragraphs) {
        ParagraphRenderStyle paragraphRenderStyle = getParagraphRenderStyle(baseRenderStyle, paragraphData);
        ParagraphRenderStyle.ClearStyle clearStyle = paragraphRenderStyle.getClearStyle();
        if (clearStyle != ParagraphRenderStyle.ClearStyle.NONE) {
            yShift = Math.max(yShift, containerRenderSpace.getNextClearYPosition(clearStyle));
        }
        ParagraphRenderStyle.FloatStyle floatStyle = paragraphRenderStyle.getFloatStyle();
        if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT || floatStyle == ParagraphRenderStyle.FloatStyle.RIGHT) {
            int paragraphMinWidth = Math.max(paragraphRenderStyle.getParagraphMinimumWidth().getValue(containerWidth), paragraphData.getParagraphContents().getContentsMinWidth(paragraphRenderStyle));
            int paragraphSideIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
            int height = paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
            height += paragraphData.getParagraphContents().getPreferredContentsHeight(paragraphRenderStyle, 0, new ContainerFlowContainerRenderSpace(paragraphMinWidth), paragraphSideIndent);
            height += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
            if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT) {
                Rect2i position = containerRenderSpace.addLeftFloat(yShift, paragraphMinWidth, height);
                yShift = position.minY();
            } else {
                Rect2i position = containerRenderSpace.addRightFloat(yShift, paragraphMinWidth, height);
                yShift = position.minY();
            }
        } else {
            yShift += paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
            int paragraphSideIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
            yShift += paragraphData.getParagraphContents().getPreferredContentsHeight(paragraphRenderStyle, yShift, containerRenderSpace, paragraphSideIndent);
            yShift += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
        }
    }
    return yShift - yStart;
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) ParagraphData(org.terasology.rendering.nui.widgets.browser.data.ParagraphData) FallbackParagraphRenderStyle(org.terasology.rendering.nui.widgets.browser.ui.style.FallbackParagraphRenderStyle) ParagraphRenderStyle(org.terasology.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle)

Example 54 with Rect2i

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

the class LineTest method testRelativeToAbsolute.

@Test
public void testRelativeToAbsolute() {
    Rect2i relativeRegion = Rect2i.createFromMinAndMax(5, 10, 20, 15);
    assertEquals(Line.relativeToAbsolute(relativeRegion, cropRegion), Rect2i.createFromMinAndSize(cropRegion.minX() + relativeRegion.minX(), cropRegion.minY() + relativeRegion.minY(), relativeRegion.width(), relativeRegion.height()));
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) Test(org.junit.Test)

Example 55 with Rect2i

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

the class Rect2iTest method testContains.

@Test
public void testContains() {
    Rect2i a = Rect2i.createFromMinAndMax(0, 0, 0, 0);
    assertTrue(a.contains(0, 0));
    assertFalse(a.contains(1, 0));
    assertFalse(a.contains(0, 1));
    assertFalse(a.contains(1, 1));
    assertFalse(a.contains(-1, 0));
    assertFalse(a.contains(0, -1));
    assertFalse(a.contains(-1, 1));
    assertFalse(a.contains(1, -1));
    assertFalse(a.contains(-1, -1));
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) Test(org.junit.Test)

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