Search in sources :

Example 71 with Vector2i

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

the class RowLayoutTest method testNoRelativeWidths.

@Test
public void testNoRelativeWidths() throws Exception {
    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 equally among 3 widgets as they have no relative widths
    verify(canvas).drawWidget(itemAt1x1, Rect2i.createFromMinAndSize(0, 0, CANVAS_WIDTH / 3, CANVAS_HEIGHT));
    verify(canvas).drawWidget(itemAt1x2, Rect2i.createFromMinAndSize(CANVAS_WIDTH / 3, 0, CANVAS_WIDTH / 3, CANVAS_HEIGHT));
    verify(canvas).drawWidget(itemAt1x3, Rect2i.createFromMinAndSize(CANVAS_WIDTH / 3 + CANVAS_WIDTH / 3, 0, CANVAS_WIDTH / 3, CANVAS_HEIGHT));
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) Test(org.junit.Test)

Example 72 with Vector2i

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

the class ZoomableLayoutTest method testZoomOut.

@Test
public void testZoomOut() throws Exception {
    zoomableLayout.onDraw(canvas);
    // zoom out 2x from top left corner
    zoomableLayout.zoom(2, 2, new Vector2i(0, 0));
    zoomableLayout.onDraw(canvas);
    // world size doubled
    assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH * 2 * 2, WORLD_HEIGHT * 2));
    assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT));
    assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / (WORLD_WIDTH * 2 * 2), CANVAS_HEIGHT / (WORLD_HEIGHT * 2)));
    verify(canvas).drawWidget(item1, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos1.x / 4), ceilToInt(pos1.y / 4)), new Vector2i(ceilToInt((pos1.x + size1.x) / 4), ceilToInt((pos1.y + size1.y) / 4))));
    verify(canvas).drawWidget(item2, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos2.x / 4), ceilToInt(pos2.y / 4)), new Vector2i(ceilToInt((pos2.x + size2.x) / 4), ceilToInt((pos2.y + size2.y) / 4))));
    verify(canvas).drawWidget(item3, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos3.x / 4), ceilToInt(pos3.y / 4)), new Vector2i(ceilToInt((pos3.x + size3.x) / 4), ceilToInt((pos3.y + size3.y) / 4))));
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) Vector2i(org.terasology.math.geom.Vector2i) Test(org.junit.Test)

Example 73 with Vector2i

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

the class ZoomableLayoutTest method setup.

@Before
public void setup() {
    zoomableLayout = new ZoomableLayout();
    item1 = mock(ZoomableLayout.PositionalWidget.class);
    item2 = mock(ZoomableLayout.PositionalWidget.class);
    item3 = mock(ZoomableLayout.PositionalWidget.class);
    canvas = mock(Canvas.class);
    // 
    // +------+
    // |  1   |
    // +------+
    // +-+
    // |2|
    // +-+
    // 
    // +---+
    // | 3 |
    // |   |
    // +---+
    // positions of the widgets in the world
    pos1 = new Vector2f(10, 10);
    pos2 = new Vector2f(40, 40);
    pos3 = new Vector2f(80, 70);
    when(item1.getPosition()).thenReturn(pos1);
    when(item2.getPosition()).thenReturn(pos2);
    when(item3.getPosition()).thenReturn(pos3);
    // size of widgets
    size1 = new Vector2f(20, 10);
    size2 = new Vector2f(5, 10);
    size3 = new Vector2f(10, 20);
    when(item1.getSize()).thenReturn(size1);
    when(item2.getSize()).thenReturn(size2);
    when(item3.getSize()).thenReturn(size3);
    when(item1.isVisible()).thenReturn(true);
    when(item2.isVisible()).thenReturn(true);
    when(item3.isVisible()).thenReturn(true);
    Vector2i availableSize = new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT);
    when(canvas.size()).thenReturn(availableSize);
    zoomableLayout.setWindowSize(new Vector2f(WORLD_WIDTH, WORLD_HEIGHT));
    zoomableLayout.addWidget(item1);
    zoomableLayout.addWidget(item2);
    zoomableLayout.addWidget(item3);
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) Canvas(org.terasology.rendering.nui.Canvas) Vector2i(org.terasology.math.geom.Vector2i) Before(org.junit.Before)

Example 74 with Vector2i

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

the class ZoomableLayoutTest method testScaling.

@Test
public void testScaling() throws Exception {
    zoomableLayout.onDraw(canvas);
    // world size scaled to fit ratio of screen size - world size now 200 x 100
    assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH * 2, WORLD_HEIGHT));
    assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT));
    assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / (WORLD_WIDTH * 2), CANVAS_HEIGHT / WORLD_HEIGHT));
    // coordinates on widgets scaled down by half
    verify(canvas).drawWidget(item1, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos1.x / 2), ceilToInt(pos1.y / 2)), new Vector2i(ceilToInt((pos1.x + size1.x) / 2), ceilToInt((pos1.y + size1.y) / 2))));
    verify(canvas).drawWidget(item2, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos2.x / 2), ceilToInt(pos2.y / 2)), new Vector2i(ceilToInt((pos2.x + size2.x) / 2), ceilToInt((pos2.y + size2.y) / 2))));
    verify(canvas).drawWidget(item3, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos3.x / 2), ceilToInt(pos3.y / 2)), new Vector2i(ceilToInt((pos3.x + size3.x) / 2), ceilToInt((pos3.y + size3.y) / 2))));
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) Vector2i(org.terasology.math.geom.Vector2i) Test(org.junit.Test)

Example 75 with Vector2i

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

the class ZoomableLayoutTest method testZoomInAndDrag.

@Test
public void testZoomInAndDrag() throws Exception {
    zoomableLayout.onDraw(canvas);
    // zoom in 2x towards left top corner
    zoomableLayout.zoom(0.5f, 0.5f, new Vector2i(0, 0));
    zoomableLayout.onDraw(canvas);
    // world size halved
    assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH, WORLD_HEIGHT / 2));
    assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT));
    assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / WORLD_WIDTH, CANVAS_HEIGHT / (WORLD_HEIGHT / 2)));
    verify(canvas).drawWidget(item1, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos1.x), ceilToInt(pos1.y)), new Vector2i(ceilToInt(pos1.x + size1.x), ceilToInt(pos1.y + size1.y))));
    verify(canvas).drawWidget(item2, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos2.x), ceilToInt(pos2.y)), new Vector2i(ceilToInt(pos2.x + size2.x), ceilToInt(pos2.y + size2.y))));
    verify(canvas).drawWidget(item3, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos3.x), ceilToInt(pos3.y)), new Vector2i(ceilToInt(pos3.x + size3.x), ceilToInt(pos3.y + size3.y))));
    // simulate drag to item2
    zoomableLayout.setWindowPosition(pos2);
    zoomableLayout.onDraw(canvas);
    // item1 out of canvas
    verify(canvas).drawWidget(item1, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos1.x - pos2.x), ceilToInt(pos1.y - pos2.y)), new Vector2i(ceilToInt(pos1.x + size1.x - pos2.x), ceilToInt(pos1.y + size1.y - pos2.y))));
    verify(canvas).drawWidget(item2, Rect2i.createFromMinAndMax(Vector2i.zero(), new Vector2i(ceilToInt(size2.x), ceilToInt(size2.y))));
    verify(canvas).drawWidget(item3, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos3.x - pos2.x), ceilToInt(pos3.y - pos2.y)), new Vector2i(ceilToInt(pos3.x + size3.x - pos2.x), ceilToInt(pos3.y + size3.y - pos2.y))));
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) 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