Search in sources :

Example 1 with Rectanglei

use of org.terasology.joml.geom.Rectanglei 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);
        Rectanglei position;
        if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT) {
            position = containerRenderSpace.addLeftFloat(yShift, paragraphWidth, height);
        } else {
            position = containerRenderSpace.addRightFloat(yShift, paragraphWidth, height);
        }
        Rectanglei paragraphBorderRegion = new Rectanglei(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);
                Rectanglei backgroundRegion = RectUtility.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 : Color(org.terasology.nui.Color) Rectanglei(org.terasology.joml.geom.Rectanglei) Vector2i(org.joml.Vector2i) FallbackParagraphRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.FallbackParagraphRenderStyle) ParagraphRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle)

Example 2 with Rectanglei

use of org.terasology.joml.geom.Rectanglei in project Terasology by MovingBlocks.

the class TextFlowRenderable method render.

@Override
public void render(Canvas canvas, Rectanglei bounds, TextRenderStyle defaultRenderStyle) {
    TextRenderStyle safeRenderStyle = getTextRenderStyle(defaultRenderStyle);
    Font font = safeRenderStyle.getFont(hyperlink != null);
    int lineHeight = font.getLineHeight();
    Rectanglei bottomBounds = new Rectanglei(bounds.minX, bounds.maxY - lineHeight).setSize(bounds.getSizeX(), lineHeight);
    canvas.drawTextRaw(text, font, safeRenderStyle.getColor(hyperlink != null), bottomBounds);
}
Also used : TextRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.TextRenderStyle) FallbackTextRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.FallbackTextRenderStyle) Rectanglei(org.terasology.joml.geom.Rectanglei) Font(org.terasology.nui.asset.font.Font)

Example 3 with Rectanglei

use of org.terasology.joml.geom.Rectanglei in project Terasology by MovingBlocks.

the class ContainerFlowContainerRenderSpace method addRightFloat.

@Override
public Rectanglei addRightFloat(int y, int width, int height) {
    int posY = y;
    while (true) {
        int availableWidth = getAvailableWidthAt(posY);
        if (availableWidth >= width) {
            int x = 0;
            Rectanglei lastRight = findLastAtYPosition(rightFloats, posY);
            if (lastRight != null) {
                x = lastRight.minX;
            }
            Rectanglei floatRect = RectUtility.createFromMinAndSize(x - width, posY, width, height);
            rightFloats.add(floatRect);
            return floatRect;
        } else {
            Rectanglei lastLeft = findLastAtYPosition(leftFloats, posY);
            Rectanglei 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 : Rectanglei(org.terasology.joml.geom.Rectanglei)

Example 4 with Rectanglei

use of org.terasology.joml.geom.Rectanglei in project Terasology by MovingBlocks.

the class ContainerFlowContainerRenderSpace method addLeftFloat.

@Override
public Rectanglei addLeftFloat(int y, int width, int height) {
    int posY = y;
    while (true) {
        int availableWidth = getAvailableWidthAt(posY);
        if (availableWidth >= width) {
            int x = 0;
            Rectanglei lastLeft = findLastAtYPosition(leftFloats, posY);
            if (lastLeft != null) {
                x = lastLeft.maxX;
            }
            Rectanglei floatRect = RectUtility.createFromMinAndSize(x, posY, width, height);
            leftFloats.add(floatRect);
            return floatRect;
        } else {
            Rectanglei lastLeft = findLastAtYPosition(leftFloats, posY);
            Rectanglei 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 : Rectanglei(org.terasology.joml.geom.Rectanglei)

Example 5 with Rectanglei

use of org.terasology.joml.geom.Rectanglei in project Terasology by MovingBlocks.

the class ContainerFlowContainerRenderSpace method getNextWidthChange.

@Override
public int getNextWidthChange(int y) {
    Rectanglei lastLeftFloat = findLastAtYPosition(leftFloats, y);
    Rectanglei 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 : Rectanglei(org.terasology.joml.geom.Rectanglei)

Aggregations

Rectanglei (org.terasology.joml.geom.Rectanglei)24 Vector2i (org.joml.Vector2i)9 Vector2f (org.joml.Vector2f)6 ByteBuffer (java.nio.ByteBuffer)3 Test (org.junit.jupiter.api.Test)3 FontMeshBuilder (org.terasology.engine.rendering.assets.font.FontMeshBuilder)3 Mesh (org.terasology.engine.rendering.assets.mesh.Mesh)3 MeshBuilder (org.terasology.engine.rendering.assets.mesh.MeshBuilder)3 TextureRegion (org.terasology.engine.rendering.assets.texture.TextureRegion)3 Rectanglef (org.terasology.joml.geom.Rectanglef)3 UITextureRegion (org.terasology.nui.UITextureRegion)3 BufferedImage (java.awt.image.BufferedImage)2 Matrix4f (org.joml.Matrix4f)2 Vector2ic (org.joml.Vector2ic)2 Color (org.terasology.nui.Color)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