Search in sources :

Example 61 with Vector2i

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

the class UIIconBar method getIconSize.

private Vector2i getIconSize(Canvas canvas) {
    UIStyle iconStyle = canvas.getCurrentStyle();
    int width = iconStyle.getFixedWidth();
    int height = iconStyle.getFixedHeight();
    if (width == 0) {
        width = iconStyle.getMinWidth();
    }
    if (height == 0) {
        height = iconStyle.getMinHeight();
    }
    if (width == 0) {
        width = icon.getWidth();
    }
    if (height == 0) {
        height = icon.getHeight();
    }
    return new Vector2i(width, height);
}
Also used : UIStyle(org.terasology.rendering.nui.skin.UIStyle) Vector2i(org.terasology.math.geom.Vector2i)

Example 62 with Vector2i

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

the class UISlider method getPreferredContentSize.

@Override
public Vector2i getPreferredContentSize(Canvas canvas, Vector2i areaHint) {
    Vector2i result = new Vector2i();
    canvas.setPart(SLIDER);
    result.x = canvas.getCurrentStyle().getFixedWidth();
    if (result.x == 0) {
        result.x = canvas.getCurrentStyle().getMinWidth();
    }
    result.y = canvas.getCurrentStyle().getFixedHeight();
    if (result.y == 0) {
        result.y = canvas.getCurrentStyle().getMinHeight();
    }
    canvas.setPart(TICKER);
    int tickerWidth = canvas.getCurrentStyle().getFont().getWidth(getDisplayText());
    tickerWidth += canvas.getCurrentStyle().getMargin().getTotalWidth();
    result.x = Math.max(result.x, tickerWidth);
    if (canvas.getCurrentStyle().getFixedWidth() != 0) {
        result.x = Math.max(result.x, canvas.getCurrentStyle().getFixedWidth());
    } else {
        result.x = Math.max(result.x, canvas.getCurrentStyle().getMinWidth());
    }
    if (canvas.getCurrentStyle().getFixedHeight() != 0) {
        result.y = Math.max(result.y, canvas.getCurrentStyle().getFixedHeight());
    } else {
        result.y = Math.max(result.y, canvas.getCurrentStyle().getMinHeight());
    }
    return result;
}
Also used : Vector2i(org.terasology.math.geom.Vector2i)

Example 63 with Vector2i

use of org.terasology.math.geom.Vector2i 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 64 with Vector2i

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

the class InputSystem method processMouseInput.

private void processMouseInput(float delta) {
    if (!isCapturingMouse()) {
        return;
    }
    Vector2i deltaMouse = mouse.getDelta();
    // process mouse movement x axis
    if (deltaMouse.x != 0) {
        float xValue = deltaMouse.x * inputDeviceConfig.getMouseSensitivity();
        MouseAxisEvent event = MouseAxisEvent.create(MouseAxis.X, xValue, delta);
        send(event);
    }
    // process mouse movement y axis
    if (deltaMouse.y != 0) {
        int yMovement = inputDeviceConfig.isMouseYAxisInverted() ? deltaMouse.y * -1 : deltaMouse.y;
        float yValue = yMovement * inputDeviceConfig.getMouseSensitivity();
        MouseAxisEvent event = MouseAxisEvent.create(MouseAxis.Y, yValue, delta);
        send(event);
    }
    // process mouse clicks
    for (MouseAction action : mouse.getInputQueue()) {
        switch(action.getInput().getType()) {
            case MOUSE_BUTTON:
                processMouseButtonInput(delta, action);
                break;
            case MOUSE_WHEEL:
                processMouseWheelInput(delta, action);
                break;
            default:
                break;
        }
    }
}
Also used : MouseAction(org.terasology.input.device.MouseAction) Vector2i(org.terasology.math.geom.Vector2i) MouseAxisEvent(org.terasology.input.events.MouseAxisEvent)

Example 65 with Vector2i

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

the class BehaviorEditor method drawConnection.

private void drawConnection(Canvas canvas, Vector2f from, Vector2f to, Color color) {
    Vector2i s = worldToScreen(from);
    Vector2i e = worldToScreen(to);
    canvas.drawLine(s.x, s.y, e.x, e.y, color);
}
Also used : Vector2i(org.terasology.math.geom.Vector2i)

Aggregations

Vector2i (org.terasology.math.geom.Vector2i)76 UIWidget (org.terasology.rendering.nui.UIWidget)17 Rect2i (org.terasology.math.geom.Rect2i)14 BaseVector2i (org.terasology.math.geom.BaseVector2i)13 LayoutHint (org.terasology.rendering.nui.LayoutHint)13 List (java.util.List)9 Test (org.junit.Test)9 Vector2f (org.terasology.math.geom.Vector2f)6 Canvas (org.terasology.rendering.nui.Canvas)5 SubRegion (org.terasology.rendering.nui.SubRegion)5 UIStyle (org.terasology.rendering.nui.skin.UIStyle)5 UILabel (org.terasology.rendering.nui.widgets.UILabel)5 Before (org.junit.Before)4 Font (org.terasology.rendering.assets.font.Font)4 Color (org.terasology.rendering.nui.Color)4 Border (org.terasology.math.Border)3 Vector3f (org.terasology.math.geom.Vector3f)3 Mesh (org.terasology.rendering.assets.mesh.Mesh)3 HorizontalAlign (org.terasology.rendering.nui.HorizontalAlign)3 Sets (com.google.common.collect.Sets)2