Search in sources :

Example 66 with Vector2i

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

the class CardLayoutTest method testSwitchCard.

@Test
public void testSwitchCard() throws Exception {
    Vector2i result = cardLayout.getPreferredContentSize(canvas, canvas.size());
    // Preferred width should be the longest preferred width among widgets
    assertEquals(50, result.x);
    // Preferred height should be the tallest preferred height among widgets
    assertEquals(15, result.y);
    // Switch to widget1
    cardLayout.setDisplayedCard("widget1");
    cardLayout.onDraw(canvas);
    verify(canvas).drawWidget(widget1);
    // Switch to widget2
    cardLayout.setDisplayedCard("widget2");
    cardLayout.onDraw(canvas);
    verify(canvas).drawWidget(widget2);
    // Switch to widget3
    cardLayout.setDisplayedCard("widget3");
    cardLayout.onDraw(canvas);
    verify(canvas).drawWidget(widget3);
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) Test(org.junit.Test)

Example 67 with Vector2i

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

the class ColumnLayoutTest method testThreeColumnsAutosizedMinimallySized.

@Test
public void testThreeColumnsAutosizedMinimallySized() throws Exception {
    columnLayout.setAutoSizeColumns(true);
    columnLayout.setFillVerticalSpace(false);
    Vector2i result = columnLayout.getPreferredContentSize(canvas, canvas.size());
    assertEquals(75, result.x);
    assertEquals(20, result.y);
    columnLayout.onDraw(canvas);
    verify(canvas).drawWidget(itemAt1x1, Rect2i.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2), ((CANVAS_HEIGHT - 20) / 2), 50, 10));
    verify(canvas).drawWidget(itemAt2x1, Rect2i.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50, ((CANVAS_HEIGHT - 20) / 2), 5, 10));
    verify(canvas).drawWidget(itemAt3x1, Rect2i.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50 + 5, ((CANVAS_HEIGHT - 20) / 2), 20, 10));
    verify(canvas).drawWidget(itemAt1x2, Rect2i.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2), ((CANVAS_HEIGHT - 20) / 2) + 10, 50, 10));
    verify(canvas).drawWidget(itemAt2x2, Rect2i.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50, ((CANVAS_HEIGHT - 20) / 2) + 10, 5, 10));
    verify(canvas).drawWidget(itemAt3x2, Rect2i.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50 + 5, ((CANVAS_HEIGHT - 20) / 2) + 10, 20, 10));
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) Test(org.junit.Test)

Example 68 with Vector2i

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

the class ColumnLayoutTest method testThreeColumnsProportionallySized.

@Test
public void testThreeColumnsProportionallySized() throws Exception {
    columnLayout.setAutoSizeColumns(false);
    columnLayout.setFillVerticalSpace(false);
    columnLayout.setColumnWidths(0.5f, 0.2f, 0.3f);
    Vector2i result = columnLayout.getPreferredContentSize(canvas, canvas.size());
    // This is the size of the first column divided by its ratio.
    // In general, the minimum column size / ratio guarantees the ration
    // and insures that every column has at least as much as its preferred size
    assertEquals(100, result.x);
    assertEquals(20, result.y);
    columnLayout.onDraw(canvas);
    // Gets half of entire area
    verify(canvas).drawWidget(itemAt1x1, Rect2i.createFromMinAndSize(0, ((CANVAS_HEIGHT - 20) / 2), CANVAS_WIDTH / 2, 10));
    // Gets one-fifth of entire area
    verify(canvas).drawWidget(itemAt2x1, Rect2i.createFromMinAndSize(CANVAS_WIDTH / 2, ((CANVAS_HEIGHT - 20) / 2), CANVAS_WIDTH * 2 / 10, 10));
    // Gets three-tens of entire area
    verify(canvas).drawWidget(itemAt3x1, Rect2i.createFromMinAndSize(CANVAS_WIDTH / 2 + CANVAS_WIDTH * 2 / 10, ((CANVAS_HEIGHT - 20) / 2), CANVAS_WIDTH * 3 / 10, 10));
    // Gets half of entire area
    verify(canvas).drawWidget(itemAt1x2, Rect2i.createFromMinAndSize(0, ((CANVAS_HEIGHT - 20) / 2) + 10, CANVAS_WIDTH / 2, 10));
    // Gets one-fifth of entire area
    verify(canvas).drawWidget(itemAt2x2, Rect2i.createFromMinAndSize(CANVAS_WIDTH / 2, ((CANVAS_HEIGHT - 20) / 2) + 10, CANVAS_WIDTH * 2 / 10, 10));
    // Gets three-tens of entire area
    verify(canvas).drawWidget(itemAt3x2, Rect2i.createFromMinAndSize(CANVAS_WIDTH / 2 + CANVAS_WIDTH * 2 / 10, ((CANVAS_HEIGHT - 20) / 2) + 10, CANVAS_WIDTH * 3 / 10, 10));
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) Test(org.junit.Test)

Example 69 with Vector2i

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

the class ColumnLayoutTest method setup.

@Before
public void setup() {
    columnLayout = new ColumnLayout();
    itemAt1x1 = mock(UIWidget.class);
    itemAt2x1 = mock(UIWidget.class);
    itemAt3x1 = mock(UIWidget.class);
    itemAt1x2 = mock(UIWidget.class);
    itemAt2x2 = mock(UIWidget.class);
    itemAt3x2 = mock(UIWidget.class);
    canvas = mock(Canvas.class);
    // +-----------------------------------+  +---+  +-------+
    // |                                   |  |2x1|  |       |
    // |               1x1                 |  +---+  |  3x1  |
    // |                                   |         |       |
    // +-----------------------------------+         +-------+
    when(canvas.calculateRestrictedSize(eq(itemAt1x1), any(Vector2i.class))).thenReturn(new Vector2i(50, 10));
    when(canvas.calculateRestrictedSize(eq(itemAt2x1), any(Vector2i.class))).thenReturn(new Vector2i(5, 5));
    when(canvas.calculateRestrictedSize(eq(itemAt3x1), any(Vector2i.class))).thenReturn(new Vector2i(10, 10));
    // +--------------+  +---+  +--------------+
    // |              |  |2x2|  |              |
    // |     1x2      |  +---+  |      3x2     |
    // |              |         |              |
    // +--------------+         +--------------+
    when(canvas.calculateRestrictedSize(eq(itemAt1x2), any(Vector2i.class))).thenReturn(new Vector2i(20, 10));
    when(canvas.calculateRestrictedSize(eq(itemAt2x2), any(Vector2i.class))).thenReturn(new Vector2i(5, 5));
    when(canvas.calculateRestrictedSize(eq(itemAt3x2), any(Vector2i.class))).thenReturn(new Vector2i(20, 10));
    Vector2i availableSize = new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT);
    when(canvas.size()).thenReturn(availableSize);
    columnLayout.setColumns(3);
    columnLayout.addWidget(itemAt1x1);
    columnLayout.addWidget(itemAt2x1);
    columnLayout.addWidget(itemAt3x1);
    columnLayout.addWidget(itemAt1x2);
    columnLayout.addWidget(itemAt2x2);
    columnLayout.addWidget(itemAt3x2);
}
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 70 with Vector2i

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

the class RowLayoutTest method testSomeRelativeWidths.

@Test
public void testSomeRelativeWidths() throws Exception {
    // Sets relative width for first widget only
    rowLayout.setColumnRatios(0.5f);
    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 first determined for widget with relative width, then split equally among remaining widgets
    final int width1 = CANVAS_WIDTH / 2;
    final int width2 = (CANVAS_WIDTH - width1) / 2;
    final int width3 = (CANVAS_WIDTH - width1) / 2;
    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)

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