use of org.joml.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, RectUtility.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2), ((CANVAS_HEIGHT - 20) / 2), 50, 10));
verify(canvas).drawWidget(itemAt2x1, RectUtility.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50, ((CANVAS_HEIGHT - 20) / 2), 5, 10));
verify(canvas).drawWidget(itemAt3x1, RectUtility.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50 + 5, ((CANVAS_HEIGHT - 20) / 2), 20, 10));
verify(canvas).drawWidget(itemAt1x2, RectUtility.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2), ((CANVAS_HEIGHT - 20) / 2) + 10, 50, 10));
verify(canvas).drawWidget(itemAt2x2, RectUtility.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50, ((CANVAS_HEIGHT - 20) / 2) + 10, 5, 10));
verify(canvas).drawWidget(itemAt3x2, RectUtility.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50 + 5, ((CANVAS_HEIGHT - 20) / 2) + 10, 20, 10));
}
use of org.joml.Vector2i in project Terasology by MovingBlocks.
the class ColumnLayoutTest method setup.
@BeforeEach
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);
}
use of org.joml.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, new Rectanglei(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, new Rectanglei(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, new Rectanglei(new Vector2i(ceilToInt(pos3.x / 4), ceilToInt(pos3.y / 4)), new Vector2i(ceilToInt((pos3.x + size3.x) / 4), ceilToInt((pos3.y + size3.y) / 4))));
}
use of org.joml.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, new Rectanglei(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, new Rectanglei(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, new Rectanglei(new Vector2i(ceilToInt(pos3.x / 2), ceilToInt(pos3.y / 2)), new Vector2i(ceilToInt((pos3.x + size3.x) / 2), ceilToInt((pos3.y + size3.y) / 2))));
}
use of org.joml.Vector2i in project Terasology by MovingBlocks.
the class PlayerFactory method findSpawnPos.
private Optional<Vector3f> findSpawnPos(Vector3fc targetPos, float entityHeight) {
int targetBlockX = TeraMath.floorToInt(targetPos.x());
int targetBlockY = TeraMath.floorToInt(targetPos.y());
int targetBlockZ = TeraMath.floorToInt(targetPos.z());
Vector2i center = new Vector2i(targetBlockX, targetBlockZ);
for (Vector2ic pos : SpiralIterable.clockwise(center).maxRadius(32).scale(2).build()) {
Vector3i testPos = new Vector3i(pos.x(), targetBlockY, pos.y());
Vector3i spawnPos = findOpenVerticalPosition(testPos, entityHeight);
if (spawnPos != null) {
return Optional.of(new Vector3f(spawnPos.x(), spawnPos.y() + entityHeight, spawnPos.z()));
}
}
return Optional.empty();
}
Aggregations