Search in sources :

Example 21 with Rect2i

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

the class UITreeView method onDraw.

@Override
public void onDraw(Canvas canvas) {
    updateListeners();
    canvas.setPart(TREE_NODE);
    int currentHeight = 0;
    for (int i = 0; i < model.get().getNodeCount(); i++) {
        Tree<T> node = model.get().getNode(i);
        TreeViewListenerSet treeViewListenerSet = treeViewListenerSets.get(i);
        ExpandButtonInteractionListener buttonListener = expandListeners.get(i);
        // Calculate the node's height and overall region.
        int nodeHeight = canvas.getCurrentStyle().getMargin().grow(itemRenderer.getPreferredSize(node.getValue(), canvas).addX(node.getDepth() * levelIndent.get())).getY();
        Rect2i nodeRegion = Rect2i.createFromMinAndSize((node.getDepth() + 1) * levelIndent.get(), currentHeight, canvas.size().x - (node.getDepth() + 1) * levelIndent.get(), nodeHeight);
        // Draw the expand/contract button.
        if (!node.isLeaf()) {
            canvas.setPart(EXPAND_BUTTON);
            setButtonMode(canvas, node, buttonListener);
            Rect2i buttonRegion = Rect2i.createFromMinAndSize(node.getDepth() * levelIndent.get(), currentHeight, levelIndent.get(), nodeHeight);
            drawButton(canvas, buttonRegion, buttonListener);
            canvas.setPart(TREE_NODE);
        }
        if (state.getSelectedIndex() != null && state.getSelectedIndex() == i && state.getAlternativeWidget() != null) {
            // Draw an alternative widget in place of the node (with the same size).
            canvas.drawWidget(state.getAlternativeWidget(), nodeRegion);
            currentHeight += nodeHeight;
        } else {
            // Draw the node itself.
            setNodeMode(canvas, node, treeViewListenerSet);
            drawNode(canvas, nodeRegion, node, treeViewListenerSet);
            currentHeight += nodeHeight;
            // Draw the dragging hints if the current node is a drag&drop target.
            if (state.getMouseOverIndex() != null && state.getMouseOverIndex() == i) {
                drawDragHint(canvas, nodeRegion);
            }
        }
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i)

Example 22 with Rect2i

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

the class FlowParagraphRenderable method renderContents.

@Override
public void renderContents(Canvas canvas, Vector2i startPos, ContainerRenderSpace containerRenderSpace, int leftIndent, int rightIndent, ParagraphRenderStyle defaultStyle, HorizontalAlign horizontalAlign, HyperlinkRegister hyperlinkRegister) {
    int y = startPos.y;
    for (LaidFlowLine<FlowRenderable> line : updateCacheIfNeeded(defaultStyle, startPos.y, containerRenderSpace)) {
        int x = 0;
        int insetXAdvance = containerRenderSpace.getAdvanceForVerticalPosition(y);
        int availableWidth = containerRenderSpace.getWidthForVerticalPosition(y);
        if (horizontalAlign == HorizontalAlign.LEFT || horizontalAlign == HorizontalAlign.CENTER) {
            availableWidth -= leftIndent;
        }
        if (horizontalAlign == HorizontalAlign.RIGHT || horizontalAlign == HorizontalAlign.CENTER) {
            availableWidth -= rightIndent;
        }
        int lineHeight = line.getHeight();
        int lineWidth = line.getWidth();
        int alignOffset = horizontalAlign.getOffset(lineWidth, availableWidth);
        for (FlowRenderable flowRenderable : line.getFlowRenderables()) {
            int elementWidth = flowRenderable.getWidth(defaultStyle);
            Rect2i renderableRegion = Rect2i.createFromMinAndSize(insetXAdvance + leftIndent + alignOffset + startPos.x + x, y, elementWidth, lineHeight);
            String hyperlink = flowRenderable.getAction();
            if (hyperlink != null) {
                hyperlinkRegister.registerHyperlink(renderableRegion, hyperlink);
            }
            flowRenderable.render(canvas, renderableRegion, defaultStyle);
            x += elementWidth;
        }
        y += lineHeight;
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) FlowRenderable(org.terasology.rendering.nui.widgets.browser.data.basic.flow.FlowRenderable)

Example 23 with Rect2i

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

the class TextFlowRenderable method render.

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

Example 24 with Rect2i

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

the class ContainerFlowContainerRenderSpace method addLeftFloat.

@Override
public Rect2i addLeftFloat(int y, int width, int height) {
    int posY = y;
    while (true) {
        int availableWidth = getAvailableWidthAt(posY);
        if (availableWidth >= width) {
            int x = 0;
            Rect2i lastLeft = findLastAtYPosition(leftFloats, posY);
            if (lastLeft != null) {
                x = lastLeft.maxX();
            }
            Rect2i floatRect = Rect2i.createFromMinAndSize(x, posY, width, height);
            leftFloats.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)

Example 25 with Rect2i

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

the class ContainerFlowContainerRenderSpace method getAvailableWidthAt.

private int getAvailableWidthAt(int y) {
    int width = containerWidth;
    Rect2i lastRight = findLastAtYPosition(rightFloats, y);
    if (lastRight != null) {
        width = lastRight.minX();
    }
    Rect2i lastLeft = findLastAtYPosition(leftFloats, y);
    if (lastLeft != null) {
        width -= lastLeft.maxX();
    }
    return width;
}
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