Search in sources :

Example 36 with Vector2i

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

the class RowLayoutTest method testAllRelativeWidths.

@Test
public void testAllRelativeWidths() throws Exception {
    // Set relative width for all 3 widgets
    rowLayout.setColumnRatios(0.4f, 0.5f, 0.1f);
    rowLayout.setHorizontalSpacing(0);
    Vector2i result = rowLayout.getPreferredContentSize(canvas, canvas.size());
    // Preferred width should be width of canvas
    assertEquals(CANVAS_WIDTH, result.x);
    // Preferred height should be the height of the tallest widget
    assertEquals(15, result.y);
    rowLayout.onDraw(canvas);
    // Width split according to the relative widths of the widgets
    // Gets 4/10 of the entire area
    final int width1 = CANVAS_WIDTH * 4 / 10;
    // Gets 1/2 of the entire area
    final int width2 = CANVAS_WIDTH / 2;
    // Gets 1/10 of the entire area
    final int width3 = CANVAS_WIDTH / 10;
    verify(canvas).drawWidget(itemAt1x1, Rect2i.createFromMinAndSize(0, 0, width1, CANVAS_HEIGHT));
    verify(canvas).drawWidget(itemAt1x2, Rect2i.createFromMinAndSize(width1, 0, width2, CANVAS_HEIGHT));
    verify(canvas).drawWidget(itemAt1x3, Rect2i.createFromMinAndSize(width1 + width2, 0, width3, CANVAS_HEIGHT));
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) Test(org.junit.Test)

Example 37 with Vector2i

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

the class RowLayoutTest method setup.

@Before
public void setup() {
    rowLayout = new RowLayout();
    itemAt1x1 = mock(UIWidget.class);
    itemAt1x2 = mock(UIWidget.class);
    itemAt1x3 = mock(UIWidget.class);
    canvas = mock(Canvas.class);
    // +-----------------------------------+  +---+  +-------+
    // |                                   |  |1x2|  |       |
    // |               1x1                 |  +---+  |       |
    // |                                   |         |  1x3  |
    // +-----------------------------------+         |       |
    // |       |
    // +-------+
    when(canvas.calculateRestrictedSize(eq(itemAt1x1), any(Vector2i.class))).thenReturn(new Vector2i(50, 10));
    when(canvas.calculateRestrictedSize(eq(itemAt1x2), any(Vector2i.class))).thenReturn(new Vector2i(5, 5));
    when(canvas.calculateRestrictedSize(eq(itemAt1x3), any(Vector2i.class))).thenReturn(new Vector2i(10, 15));
    Vector2i availableSize = new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT);
    when(canvas.size()).thenReturn(availableSize);
    rowLayout.addWidget(itemAt1x1, null);
    rowLayout.addWidget(itemAt1x2, null);
    rowLayout.addWidget(itemAt1x3, null);
}
Also used : Canvas(org.terasology.rendering.nui.Canvas) Vector2i(org.terasology.math.geom.Vector2i) UIWidget(org.terasology.rendering.nui.UIWidget) Before(org.junit.Before)

Example 38 with Vector2i

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

the class CanvasImpl method calculateRestrictedSize.

@Override
public Vector2i calculateRestrictedSize(UIWidget widget, Vector2i sizeRestrictions) {
    if (widget == null) {
        return sizeRestrictions;
    }
    String family = (widget.getFamily() != null) ? widget.getFamily() : state.family;
    UISkin skin = (widget.getSkin() != null) ? widget.getSkin() : state.skin;
    UIStyle elementStyle = skin.getStyleFor(family, widget.getClass(), UIWidget.BASE_PART, widget.getMode());
    Rect2i region = applyStyleToSize(Rect2i.createFromMinAndSize(Vector2i.zero(), sizeRestrictions), elementStyle);
    try (SubRegion ignored = subRegionForWidget(widget, region, false)) {
        Vector2i preferredSize = widget.getPreferredContentSize(this, elementStyle.getMargin().shrink(sizeRestrictions));
        preferredSize = elementStyle.getMargin().grow(preferredSize);
        return applyStyleToSize(preferredSize, elementStyle);
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) UISkin(org.terasology.rendering.nui.skin.UISkin) UIStyle(org.terasology.rendering.nui.skin.UIStyle) Vector2i(org.terasology.math.geom.Vector2i) BaseVector2i(org.terasology.math.geom.BaseVector2i) SubRegion(org.terasology.rendering.nui.SubRegion)

Example 39 with Vector2i

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

the class CanvasImpl method preRender.

@Override
public void preRender() {
    interactionRegions.clear();
    Vector2i size = renderer.getTargetSize();
    state = new CanvasState(null, Rect2i.createFromMinAndSize(0, 0, size.x, size.y));
    renderer.preRender();
    renderer.crop(state.cropRegion);
    focusDrawn = false;
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) BaseVector2i(org.terasology.math.geom.BaseVector2i)

Example 40 with Vector2i

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

the class CanvasImpl method processMouseWheel.

@Override
public boolean processMouseWheel(int wheelTurns, Vector2i pos) {
    for (InteractionRegion next : mouseOverRegions) {
        if (next.region.contains(pos)) {
            Vector2i relPos = new Vector2i(pos);
            relPos.sub(next.region.min());
            if (next.listener.onMouseWheel(new NUIMouseWheelEvent(mouse, keyboard, relPos, wheelTurns))) {
                clickedRegion = next;
                nuiManager.setFocus(next.element);
                return true;
            }
        }
    }
    return false;
}
Also used : NUIMouseWheelEvent(org.terasology.rendering.nui.events.NUIMouseWheelEvent) Vector2i(org.terasology.math.geom.Vector2i) BaseVector2i(org.terasology.math.geom.BaseVector2i)

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